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.
23 #ifdef HAVE_TCP_WRAPPER
24 #include "tcpwrapper.h"
31 #include <rpc/pmap_clnt.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
42 #define SIG_PF void(*)(int)
45 extern getquota_rslt *rquotaproc_getquota_1(getquota_args *argp,
46 struct svc_req *rqstp);
47 extern getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp,
48 struct svc_req *rqstp);
49 extern getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp,
50 struct svc_req *rqstp);
51 extern getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp,
52 struct svc_req *rqstp);
54 static struct option longopts[] =
56 { "help", 0, 0, 'h' },
57 { "version", 0, 0, 'v' },
58 { "port", 1, 0, 'p' },
63 * Global authentication credentials.
65 struct authunix_parms *unix_cred;
67 static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
70 getquota_args rquotaproc_getquota_1_arg;
71 getquota_args rquotaproc_getactivequota_1_arg;
74 xdrproc_t xdr_argument, xdr_result;
75 char *(*local)(char *, struct svc_req *);
77 #ifdef HAVE_TCP_WRAPPER
78 /* remote host authorization check */
79 if (!check_default("rquotad", svc_getcaller(transp),
80 rqstp->rq_proc, RQUOTAPROG)) {
81 svcerr_auth (transp, AUTH_FAILED);
87 * Don't bother authentication for NULLPROC.
89 if (rqstp->rq_proc == NULLPROC) {
90 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
95 * First get authentication.
97 switch (rqstp->rq_cred.oa_flavor) {
99 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
103 svcerr_weakauth(transp);
107 switch (rqstp->rq_proc) {
108 case RQUOTAPROC_GETQUOTA:
109 xdr_argument = (xdrproc_t) xdr_getquota_args;
110 xdr_result = (xdrproc_t) xdr_getquota_rslt;
111 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1;
114 case RQUOTAPROC_GETACTIVEQUOTA:
115 xdr_argument = (xdrproc_t) xdr_getquota_args;
116 xdr_result = (xdrproc_t) xdr_getquota_rslt;
117 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1;
121 svcerr_noproc(transp);
125 (void) memset((char *)&argument, 0, sizeof (argument));
126 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
127 svcerr_decode(transp);
130 result = (*local)((char *)&argument, rqstp);
131 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
132 svcerr_systemerr(transp);
135 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
136 syslog(LOG_ERR, "unable to free arguments");
142 static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
145 ext_getquota_args rquotaproc_getquota_2_arg;
146 ext_getquota_args rquotaproc_getactivequota_2_arg;
149 xdrproc_t xdr_argument, xdr_result;
150 char *(*local)(char *, struct svc_req *);
152 #ifdef HAVE_TCP_WRAPPER
153 /* remote host authorization check */
154 if (!check_default("rquotad", svc_getcaller(transp),
155 rqstp->rq_proc, RQUOTAPROG)) {
156 svcerr_auth (transp, AUTH_FAILED);
162 * Don't bother authentication for NULLPROC.
164 if (rqstp->rq_proc == NULLPROC) {
165 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
170 * First get authentication.
172 switch (rqstp->rq_cred.oa_flavor) {
174 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
178 svcerr_weakauth(transp);
182 switch (rqstp->rq_proc) {
183 case RQUOTAPROC_GETQUOTA:
184 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
185 xdr_result = (xdrproc_t) xdr_getquota_rslt;
186 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2;
189 case RQUOTAPROC_GETACTIVEQUOTA:
190 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
191 xdr_result = (xdrproc_t) xdr_getquota_rslt;
192 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2;
196 svcerr_noproc(transp);
200 (void) memset((char *)&argument, 0, sizeof (argument));
201 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
202 svcerr_decode(transp);
205 result = (*local)((char *)&argument, rqstp);
206 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
207 svcerr_systemerr(transp);
210 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
211 syslog(LOG_ERR, "unable to free arguments");
218 usage(const char *prog, int n)
220 fprintf(stderr, "Usage: %s [-p|--port port] [-h|-?|--help] [-v|--version]\n", prog);
224 int main(int argc, char **argv)
226 register SVCXPRT *transp;
230 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
231 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
233 openlog("rquota", LOG_PID, LOG_DAEMON);
235 while ((c = getopt_long(argc, argv, "hp:v", longopts, NULL)) != EOF) {
243 if (port < 1 || port > 65535) {
244 fprintf(stderr, "%s: bad port number: %s\n",
250 printf("rquotad %s\n", VERSION);
257 /* WARNING: the following works on Linux and SysV, but not BSD! */
258 signal(SIGCHLD, SIG_IGN);
261 transp = svcudp_create(makesock(port, IPPROTO_UDP));
263 transp = svcudp_create(RPC_ANYSOCK);
264 if (transp == NULL) {
265 syslog(LOG_ERR, "cannot create udp service.");
268 if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquotaprog_1, IPPROTO_UDP)) {
269 syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, udp).");
272 if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, rquotaprog_2, IPPROTO_UDP)) {
273 syslog(LOG_ERR, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, udp).");
280 syslog(LOG_ERR, "svc_run returned");