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 static struct option longopts[] =
52 { "help", 0, 0, 'h' },
53 { "version", 0, 0, 'v' },
54 { "port", 1, 0, 'p' },
59 * Global authentication credentials.
61 struct authunix_parms *unix_cred;
63 static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
66 getquota_args rquotaproc_getquota_1_arg;
67 getquota_args rquotaproc_getactivequota_1_arg;
70 xdrproc_t xdr_argument, xdr_result;
71 char *(*local)(char *, struct svc_req *);
73 #ifdef HAVE_TCP_WRAPPER
74 /* remote host authorization check */
75 if (!check_default("rquotad", svc_getcaller(transp),
76 rqstp->rq_proc, RQUOTAPROG)) {
77 svcerr_auth (transp, AUTH_FAILED);
83 * Don't bother authentication for NULLPROC.
85 if (rqstp->rq_proc == NULLPROC) {
86 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
91 * First get authentication.
93 switch (rqstp->rq_cred.oa_flavor) {
95 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
99 svcerr_weakauth(transp);
103 switch (rqstp->rq_proc) {
104 case RQUOTAPROC_GETQUOTA:
105 xdr_argument = (xdrproc_t) xdr_getquota_args;
106 xdr_result = (xdrproc_t) xdr_getquota_rslt;
107 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1_svc;
110 case RQUOTAPROC_GETACTIVEQUOTA:
111 xdr_argument = (xdrproc_t) xdr_getquota_args;
112 xdr_result = (xdrproc_t) xdr_getquota_rslt;
113 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1_svc;
117 svcerr_noproc(transp);
121 (void) memset((char *)&argument, 0, sizeof (argument));
122 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
123 svcerr_decode(transp);
126 result = (*local)((char *)&argument, rqstp);
127 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
128 svcerr_systemerr(transp);
131 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
132 syslog(LOG_ERR, "unable to free arguments");
138 static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
141 ext_getquota_args rquotaproc_getquota_2_arg;
142 ext_getquota_args rquotaproc_getactivequota_2_arg;
145 xdrproc_t xdr_argument, xdr_result;
146 char *(*local)(char *, struct svc_req *);
148 #ifdef HAVE_TCP_WRAPPER
149 /* remote host authorization check */
150 if (!check_default("rquotad", svc_getcaller(transp),
151 rqstp->rq_proc, RQUOTAPROG)) {
152 svcerr_auth (transp, AUTH_FAILED);
158 * Don't bother authentication for NULLPROC.
160 if (rqstp->rq_proc == NULLPROC) {
161 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
166 * First get authentication.
168 switch (rqstp->rq_cred.oa_flavor) {
170 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
174 svcerr_weakauth(transp);
178 switch (rqstp->rq_proc) {
179 case RQUOTAPROC_GETQUOTA:
180 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
181 xdr_result = (xdrproc_t) xdr_getquota_rslt;
182 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2_svc;
185 case RQUOTAPROC_GETACTIVEQUOTA:
186 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
187 xdr_result = (xdrproc_t) xdr_getquota_rslt;
188 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2_svc;
192 svcerr_noproc(transp);
196 (void) memset((char *)&argument, 0, sizeof (argument));
197 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
198 svcerr_decode(transp);
201 result = (*local)((char *)&argument, rqstp);
202 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
203 svcerr_systemerr(transp);
206 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
207 syslog(LOG_ERR, "unable to free arguments");
214 usage(const char *prog, int n)
216 fprintf(stderr, "Usage: %s [-p|--port port] [-h|-?|--help] [-v|--version]\n", prog);
223 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
224 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
225 syslog(LOG_ERR, "caught signal %d, un-registering and exiting.", sig);
228 int main(int argc, char **argv)
230 register SVCXPRT *transp;
235 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
236 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
238 openlog("rquota", LOG_PID, LOG_DAEMON);
240 while ((c = getopt_long(argc, argv, "hp:v", longopts, NULL)) != EOF) {
248 if (port < 1 || port > 65535) {
249 fprintf(stderr, "%s: bad port number: %s\n",
255 printf("rquotad %s\n", VERSION);
262 if (chdir(NFS_STATEDIR)) {
263 fprintf(stderr, "%s: chdir(%s) failed: %s\n",
264 argv [0], NFS_STATEDIR, strerror(errno));
269 /* WARNING: the following works on Linux and SysV, but not BSD! */
270 sa.sa_handler = SIG_IGN;
272 sigemptyset(&sa.sa_mask);
273 sigaction(SIGCHLD, &sa, NULL);
275 sa.sa_handler = killer;
276 sigaction(SIGHUP, &sa, NULL);
277 sigaction(SIGINT, &sa, NULL);
278 sigaction(SIGTERM, &sa, NULL);
281 transp = svcudp_create(makesock(port, IPPROTO_UDP));
283 transp = svcudp_create(svcudp_socket (RQUOTAPROG, 1));
284 if (transp == NULL) {
285 syslog(LOG_ERR, "cannot create udp service.");
288 if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquotaprog_1, IPPROTO_UDP)) {
289 syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, udp).");
292 if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, rquotaprog_2, IPPROTO_UDP)) {
293 syslog(LOG_ERR, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, udp).");
300 syslog(LOG_ERR, "svc_run returned");