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.
27 #include <rpc/pmap_clnt.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
35 #define SIG_PF void(*)(int)
38 extern getquota_rslt *rquotaproc_getquota_1(getquota_args *argp,
39 struct svc_req *rqstp);
40 extern getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp,
41 struct svc_req *rqstp);
42 extern getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp,
43 struct svc_req *rqstp);
44 extern getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp,
45 struct svc_req *rqstp);
48 * Global authentication credentials.
50 struct authunix_parms *unix_cred;
52 static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
55 getquota_args rquotaproc_getquota_1_arg;
56 getquota_args rquotaproc_getactivequota_1_arg;
59 xdrproc_t xdr_argument, xdr_result;
60 char *(*local)(char *, struct svc_req *);
63 * Don't bother authentication for NULLPROC.
65 if (rqstp->rq_proc == NULLPROC) {
66 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
71 * First get authentication.
73 switch (rqstp->rq_cred.oa_flavor) {
75 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
79 svcerr_weakauth(transp);
83 switch (rqstp->rq_proc) {
84 case RQUOTAPROC_GETQUOTA:
85 xdr_argument = (xdrproc_t) xdr_getquota_args;
86 xdr_result = (xdrproc_t) xdr_getquota_rslt;
87 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1;
90 case RQUOTAPROC_GETACTIVEQUOTA:
91 xdr_argument = (xdrproc_t) xdr_getquota_args;
92 xdr_result = (xdrproc_t) xdr_getquota_rslt;
93 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1;
97 svcerr_noproc(transp);
101 (void) memset((char *)&argument, 0, sizeof (argument));
102 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
103 svcerr_decode(transp);
106 result = (*local)((char *)&argument, rqstp);
107 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
108 svcerr_systemerr(transp);
111 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
112 syslog(LOG_ERR, "unable to free arguments");
118 static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
121 ext_getquota_args rquotaproc_getquota_2_arg;
122 ext_getquota_args rquotaproc_getactivequota_2_arg;
125 xdrproc_t xdr_argument, xdr_result;
126 char *(*local)(char *, struct svc_req *);
129 * Don't bother authentication for NULLPROC.
131 if (rqstp->rq_proc == NULLPROC) {
132 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
137 * First get authentication.
139 switch (rqstp->rq_cred.oa_flavor) {
141 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
145 svcerr_weakauth(transp);
149 switch (rqstp->rq_proc) {
150 case RQUOTAPROC_GETQUOTA:
151 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
152 xdr_result = (xdrproc_t) xdr_getquota_rslt;
153 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2;
156 case RQUOTAPROC_GETACTIVEQUOTA:
157 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
158 xdr_result = (xdrproc_t) xdr_getquota_rslt;
159 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2;
163 svcerr_noproc(transp);
167 (void) memset((char *)&argument, 0, sizeof (argument));
168 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
169 svcerr_decode(transp);
172 result = (*local)((char *)&argument, rqstp);
173 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
174 svcerr_systemerr(transp);
177 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
178 syslog(LOG_ERR, "unable to free arguments");
184 int main(int argc, char **argv)
186 register SVCXPRT *transp;
188 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
189 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
191 openlog("rquota", LOG_PID, LOG_DAEMON);
193 transp = svcudp_create(RPC_ANYSOCK);
194 if (transp == NULL) {
195 syslog(LOG_ERR, "cannot create udp service.");
198 if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquotaprog_1, IPPROTO_UDP)) {
199 syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, udp).");
202 if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, rquotaprog_2, IPPROTO_UDP)) {
203 syslog(LOG_ERR, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, udp).");
210 syslog(LOG_ERR, "svc_run returned");