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>
40 #define SIG_PF void(*)(int)
43 extern getquota_rslt *rquotaproc_getquota_1(getquota_args *argp,
44 struct svc_req *rqstp);
45 extern getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp,
46 struct svc_req *rqstp);
47 extern getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp,
48 struct svc_req *rqstp);
49 extern getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp,
50 struct svc_req *rqstp);
53 * Global authentication credentials.
55 struct authunix_parms *unix_cred;
57 static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
60 getquota_args rquotaproc_getquota_1_arg;
61 getquota_args rquotaproc_getactivequota_1_arg;
64 xdrproc_t xdr_argument, xdr_result;
65 char *(*local)(char *, struct svc_req *);
67 #ifdef HAVE_TCP_WRAPPER
68 /* remote host authorization check */
69 if (!check_default("rquotad", svc_getcaller(transp),
70 rqstp->rq_proc, RQUOTAPROG)) {
71 svcerr_auth (transp, AUTH_FAILED);
77 * Don't bother authentication for NULLPROC.
79 if (rqstp->rq_proc == NULLPROC) {
80 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
85 * First get authentication.
87 switch (rqstp->rq_cred.oa_flavor) {
89 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
93 svcerr_weakauth(transp);
97 switch (rqstp->rq_proc) {
98 case RQUOTAPROC_GETQUOTA:
99 xdr_argument = (xdrproc_t) xdr_getquota_args;
100 xdr_result = (xdrproc_t) xdr_getquota_rslt;
101 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1;
104 case RQUOTAPROC_GETACTIVEQUOTA:
105 xdr_argument = (xdrproc_t) xdr_getquota_args;
106 xdr_result = (xdrproc_t) xdr_getquota_rslt;
107 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1;
111 svcerr_noproc(transp);
115 (void) memset((char *)&argument, 0, sizeof (argument));
116 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
117 svcerr_decode(transp);
120 result = (*local)((char *)&argument, rqstp);
121 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
122 svcerr_systemerr(transp);
125 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
126 syslog(LOG_ERR, "unable to free arguments");
132 static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
135 ext_getquota_args rquotaproc_getquota_2_arg;
136 ext_getquota_args rquotaproc_getactivequota_2_arg;
139 xdrproc_t xdr_argument, xdr_result;
140 char *(*local)(char *, struct svc_req *);
142 #ifdef HAVE_TCP_WRAPPER
143 /* remote host authorization check */
144 if (!check_default("rquotad", svc_getcaller(transp),
145 rqstp->rq_proc, RQUOTAPROG)) {
146 svcerr_auth (transp, AUTH_FAILED);
152 * Don't bother authentication for NULLPROC.
154 if (rqstp->rq_proc == NULLPROC) {
155 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
160 * First get authentication.
162 switch (rqstp->rq_cred.oa_flavor) {
164 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
168 svcerr_weakauth(transp);
172 switch (rqstp->rq_proc) {
173 case RQUOTAPROC_GETQUOTA:
174 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
175 xdr_result = (xdrproc_t) xdr_getquota_rslt;
176 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2;
179 case RQUOTAPROC_GETACTIVEQUOTA:
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_getactivequota_2;
186 svcerr_noproc(transp);
190 (void) memset((char *)&argument, 0, sizeof (argument));
191 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
192 svcerr_decode(transp);
195 result = (*local)((char *)&argument, rqstp);
196 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
197 svcerr_systemerr(transp);
200 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
201 syslog(LOG_ERR, "unable to free arguments");
207 int main(int argc, char **argv)
209 register SVCXPRT *transp;
211 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
212 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
214 openlog("rquota", LOG_PID, LOG_DAEMON);
216 /* WARNING: the following works on Linux and SysV, but not BSD! */
217 signal(SIGCHLD, SIG_IGN);
219 transp = svcudp_create(RPC_ANYSOCK);
220 if (transp == NULL) {
221 syslog(LOG_ERR, "cannot create udp service.");
224 if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquotaprog_1, IPPROTO_UDP)) {
225 syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, udp).");
228 if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, rquotaprog_2, IPPROTO_UDP)) {
229 syslog(LOG_ERR, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, udp).");
236 syslog(LOG_ERR, "svc_run returned");