2 * QUOTA An implementation of the diskquota system for the LINUX
3 * operating system. QUOTA is implemented using the BSD systemcall
4 * interface as the means of communication with the user level.
5 * Should work for all filesystems because of integration into the
6 * VFS layer of the operating system.
7 * This is based on the Melbourne quota system wich uses both user and
10 * This part accepts the rquota rpc-requests.
12 * Version: $Id: rquota_svc.c,v 2.6 1996/11/17 16:59:46 mvw Exp mvw $
14 * Author: Marco van Wieringen <mvw@planets.elm.net>
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
26 #ifdef HAVE_TCP_WRAPPER
27 #include "tcpwrapper.h"
35 #include <rpc/pmap_clnt.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
47 #define SIG_PF void(*)(int)
50 extern getquota_rslt *rquotaproc_getquota_1(getquota_args *argp,
51 struct svc_req *rqstp);
52 extern getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp,
53 struct svc_req *rqstp);
54 extern getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp,
55 struct svc_req *rqstp);
56 extern getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp,
57 struct svc_req *rqstp);
59 static struct option longopts[] =
61 { "help", 0, 0, 'h' },
62 { "version", 0, 0, 'v' },
63 { "port", 1, 0, 'p' },
68 * Global authentication credentials.
70 struct authunix_parms *unix_cred;
72 static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
75 getquota_args rquotaproc_getquota_1_arg;
76 getquota_args rquotaproc_getactivequota_1_arg;
79 xdrproc_t xdr_argument, xdr_result;
80 char *(*local)(char *, struct svc_req *);
82 #ifdef HAVE_TCP_WRAPPER
83 /* remote host authorization check */
84 if (!check_default("rquotad", svc_getcaller(transp),
85 rqstp->rq_proc, RQUOTAPROG)) {
86 svcerr_auth (transp, AUTH_FAILED);
92 * Don't bother authentication for NULLPROC.
94 if (rqstp->rq_proc == NULLPROC) {
95 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
100 * First get authentication.
102 switch (rqstp->rq_cred.oa_flavor) {
104 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
108 svcerr_weakauth(transp);
112 switch (rqstp->rq_proc) {
113 case RQUOTAPROC_GETQUOTA:
114 xdr_argument = (xdrproc_t) xdr_getquota_args;
115 xdr_result = (xdrproc_t) xdr_getquota_rslt;
116 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1;
119 case RQUOTAPROC_GETACTIVEQUOTA:
120 xdr_argument = (xdrproc_t) xdr_getquota_args;
121 xdr_result = (xdrproc_t) xdr_getquota_rslt;
122 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1;
126 svcerr_noproc(transp);
130 (void) memset((char *)&argument, 0, sizeof (argument));
131 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
132 svcerr_decode(transp);
135 result = (*local)((char *)&argument, rqstp);
136 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
137 svcerr_systemerr(transp);
140 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
141 syslog(LOG_ERR, "unable to free arguments");
147 static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
150 ext_getquota_args rquotaproc_getquota_2_arg;
151 ext_getquota_args rquotaproc_getactivequota_2_arg;
154 xdrproc_t xdr_argument, xdr_result;
155 char *(*local)(char *, struct svc_req *);
157 #ifdef HAVE_TCP_WRAPPER
158 /* remote host authorization check */
159 if (!check_default("rquotad", svc_getcaller(transp),
160 rqstp->rq_proc, RQUOTAPROG)) {
161 svcerr_auth (transp, AUTH_FAILED);
167 * Don't bother authentication for NULLPROC.
169 if (rqstp->rq_proc == NULLPROC) {
170 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
175 * First get authentication.
177 switch (rqstp->rq_cred.oa_flavor) {
179 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
183 svcerr_weakauth(transp);
187 switch (rqstp->rq_proc) {
188 case RQUOTAPROC_GETQUOTA:
189 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
190 xdr_result = (xdrproc_t) xdr_getquota_rslt;
191 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2;
194 case RQUOTAPROC_GETACTIVEQUOTA:
195 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
196 xdr_result = (xdrproc_t) xdr_getquota_rslt;
197 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2;
201 svcerr_noproc(transp);
205 (void) memset((char *)&argument, 0, sizeof (argument));
206 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
207 svcerr_decode(transp);
210 result = (*local)((char *)&argument, rqstp);
211 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
212 svcerr_systemerr(transp);
215 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
216 syslog(LOG_ERR, "unable to free arguments");
223 usage(const char *prog, int n)
225 fprintf(stderr, "Usage: %s [-p|--port port] [-h|-?|--help] [-v|--version]\n", prog);
232 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
233 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
234 syslog(LOG_ERR, "caught signal %d, un-registering and exiting.", sig);
237 int main(int argc, char **argv)
239 register SVCXPRT *transp;
244 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
245 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
247 openlog("rquota", LOG_PID, LOG_DAEMON);
249 while ((c = getopt_long(argc, argv, "hp:v", longopts, NULL)) != EOF) {
257 if (port < 1 || port > 65535) {
258 fprintf(stderr, "%s: bad port number: %s\n",
264 printf("rquotad %s\n", VERSION);
271 if (chdir(NFS_STATEDIR)) {
272 fprintf(stderr, "%s: chdir(%s) failed: %s\n",
273 argv [0], NFS_STATEDIR, strerror(errno));
278 /* WARNING: the following works on Linux and SysV, but not BSD! */
279 sa.sa_handler = SIG_IGN;
281 sigemptyset(&sa.sa_mask);
282 sigaction(SIGCHLD, &sa, NULL);
284 sa.sa_handler = killer;
285 sigaction(SIGHUP, &sa, NULL);
286 sigaction(SIGINT, &sa, NULL);
287 sigaction(SIGTERM, &sa, NULL);
290 transp = svcudp_create(makesock(port, IPPROTO_UDP));
292 transp = svcudp_create(svcudp_socket (RQUOTAPROG, 1));
293 if (transp == NULL) {
294 syslog(LOG_ERR, "cannot create udp service.");
297 if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquotaprog_1, IPPROTO_UDP)) {
298 syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, udp).");
301 if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, rquotaprog_2, IPPROTO_UDP)) {
302 syslog(LOG_ERR, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, udp).");
309 syslog(LOG_ERR, "svc_run returned");