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"
32 #include <rpc/pmap_clnt.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
43 #define SIG_PF void(*)(int)
46 extern getquota_rslt *rquotaproc_getquota_1(getquota_args *argp,
47 struct svc_req *rqstp);
48 extern getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp,
49 struct svc_req *rqstp);
50 extern getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp,
51 struct svc_req *rqstp);
52 extern getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp,
53 struct svc_req *rqstp);
55 static struct option longopts[] =
57 { "help", 0, 0, 'h' },
58 { "version", 0, 0, 'v' },
59 { "port", 1, 0, 'p' },
64 * Global authentication credentials.
66 struct authunix_parms *unix_cred;
68 static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
71 getquota_args rquotaproc_getquota_1_arg;
72 getquota_args rquotaproc_getactivequota_1_arg;
75 xdrproc_t xdr_argument, xdr_result;
76 char *(*local)(char *, struct svc_req *);
78 #ifdef HAVE_TCP_WRAPPER
79 /* remote host authorization check */
80 if (!check_default("rquotad", svc_getcaller(transp),
81 rqstp->rq_proc, RQUOTAPROG)) {
82 svcerr_auth (transp, AUTH_FAILED);
88 * Don't bother authentication for NULLPROC.
90 if (rqstp->rq_proc == NULLPROC) {
91 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
96 * First get authentication.
98 switch (rqstp->rq_cred.oa_flavor) {
100 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
104 svcerr_weakauth(transp);
108 switch (rqstp->rq_proc) {
109 case RQUOTAPROC_GETQUOTA:
110 xdr_argument = (xdrproc_t) xdr_getquota_args;
111 xdr_result = (xdrproc_t) xdr_getquota_rslt;
112 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1;
115 case RQUOTAPROC_GETACTIVEQUOTA:
116 xdr_argument = (xdrproc_t) xdr_getquota_args;
117 xdr_result = (xdrproc_t) xdr_getquota_rslt;
118 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1;
122 svcerr_noproc(transp);
126 (void) memset((char *)&argument, 0, sizeof (argument));
127 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
128 svcerr_decode(transp);
131 result = (*local)((char *)&argument, rqstp);
132 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
133 svcerr_systemerr(transp);
136 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
137 syslog(LOG_ERR, "unable to free arguments");
143 static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
146 ext_getquota_args rquotaproc_getquota_2_arg;
147 ext_getquota_args rquotaproc_getactivequota_2_arg;
150 xdrproc_t xdr_argument, xdr_result;
151 char *(*local)(char *, struct svc_req *);
153 #ifdef HAVE_TCP_WRAPPER
154 /* remote host authorization check */
155 if (!check_default("rquotad", svc_getcaller(transp),
156 rqstp->rq_proc, RQUOTAPROG)) {
157 svcerr_auth (transp, AUTH_FAILED);
163 * Don't bother authentication for NULLPROC.
165 if (rqstp->rq_proc == NULLPROC) {
166 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
171 * First get authentication.
173 switch (rqstp->rq_cred.oa_flavor) {
175 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
179 svcerr_weakauth(transp);
183 switch (rqstp->rq_proc) {
184 case RQUOTAPROC_GETQUOTA:
185 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
186 xdr_result = (xdrproc_t) xdr_getquota_rslt;
187 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2;
190 case RQUOTAPROC_GETACTIVEQUOTA:
191 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
192 xdr_result = (xdrproc_t) xdr_getquota_rslt;
193 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2;
197 svcerr_noproc(transp);
201 (void) memset((char *)&argument, 0, sizeof (argument));
202 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
203 svcerr_decode(transp);
206 result = (*local)((char *)&argument, rqstp);
207 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
208 svcerr_systemerr(transp);
211 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
212 syslog(LOG_ERR, "unable to free arguments");
219 usage(const char *prog, int n)
221 fprintf(stderr, "Usage: %s [-p|--port port] [-h|-?|--help] [-v|--version]\n", prog);
225 int main(int argc, char **argv)
227 register SVCXPRT *transp;
231 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
232 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
234 openlog("rquota", LOG_PID, LOG_DAEMON);
236 while ((c = getopt_long(argc, argv, "hp:v", longopts, NULL)) != EOF) {
244 if (port < 1 || port > 65535) {
245 fprintf(stderr, "%s: bad port number: %s\n",
251 printf("rquotad %s\n", VERSION);
258 if (chdir(NFS_STATEDIR)) {
259 fprintf(stderr, "%s: chdir(%s) failed: %s\n",
260 argv [0], NFS_STATEDIR, strerror(errno));
265 /* WARNING: the following works on Linux and SysV, but not BSD! */
266 signal(SIGCHLD, SIG_IGN);
269 transp = svcudp_create(makesock(port, IPPROTO_UDP));
271 transp = svcudp_create(RPC_ANYSOCK);
272 if (transp == NULL) {
273 syslog(LOG_ERR, "cannot create udp service.");
276 if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquotaprog_1, IPPROTO_UDP)) {
277 syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, udp).");
280 if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, rquotaprog_2, IPPROTO_UDP)) {
281 syslog(LOG_ERR, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, udp).");
288 syslog(LOG_ERR, "svc_run returned");