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>
44 #define SIG_PF void(*)(int)
47 extern getquota_rslt *rquotaproc_getquota_1(getquota_args *argp,
48 struct svc_req *rqstp);
49 extern getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp,
50 struct svc_req *rqstp);
51 extern getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp,
52 struct svc_req *rqstp);
53 extern getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp,
54 struct svc_req *rqstp);
56 static struct option longopts[] =
58 { "help", 0, 0, 'h' },
59 { "version", 0, 0, 'v' },
60 { "port", 1, 0, 'p' },
65 * Global authentication credentials.
67 struct authunix_parms *unix_cred;
69 static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
72 getquota_args rquotaproc_getquota_1_arg;
73 getquota_args rquotaproc_getactivequota_1_arg;
76 xdrproc_t xdr_argument, xdr_result;
77 char *(*local)(char *, struct svc_req *);
79 #ifdef HAVE_TCP_WRAPPER
80 /* remote host authorization check */
81 if (!check_default("rquotad", svc_getcaller(transp),
82 rqstp->rq_proc, RQUOTAPROG)) {
83 svcerr_auth (transp, AUTH_FAILED);
89 * Don't bother authentication for NULLPROC.
91 if (rqstp->rq_proc == NULLPROC) {
92 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
97 * First get authentication.
99 switch (rqstp->rq_cred.oa_flavor) {
101 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
105 svcerr_weakauth(transp);
109 switch (rqstp->rq_proc) {
110 case RQUOTAPROC_GETQUOTA:
111 xdr_argument = (xdrproc_t) xdr_getquota_args;
112 xdr_result = (xdrproc_t) xdr_getquota_rslt;
113 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1;
116 case RQUOTAPROC_GETACTIVEQUOTA:
117 xdr_argument = (xdrproc_t) xdr_getquota_args;
118 xdr_result = (xdrproc_t) xdr_getquota_rslt;
119 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1;
123 svcerr_noproc(transp);
127 (void) memset((char *)&argument, 0, sizeof (argument));
128 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
129 svcerr_decode(transp);
132 result = (*local)((char *)&argument, rqstp);
133 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
134 svcerr_systemerr(transp);
137 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
138 syslog(LOG_ERR, "unable to free arguments");
144 static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
147 ext_getquota_args rquotaproc_getquota_2_arg;
148 ext_getquota_args rquotaproc_getactivequota_2_arg;
151 xdrproc_t xdr_argument, xdr_result;
152 char *(*local)(char *, struct svc_req *);
154 #ifdef HAVE_TCP_WRAPPER
155 /* remote host authorization check */
156 if (!check_default("rquotad", svc_getcaller(transp),
157 rqstp->rq_proc, RQUOTAPROG)) {
158 svcerr_auth (transp, AUTH_FAILED);
164 * Don't bother authentication for NULLPROC.
166 if (rqstp->rq_proc == NULLPROC) {
167 (void) svc_sendreply(transp, (xdrproc_t) xdr_void, (char *)NULL);
172 * First get authentication.
174 switch (rqstp->rq_cred.oa_flavor) {
176 unix_cred = (struct authunix_parms *)rqstp->rq_clntcred;
180 svcerr_weakauth(transp);
184 switch (rqstp->rq_proc) {
185 case RQUOTAPROC_GETQUOTA:
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_getquota_2;
191 case RQUOTAPROC_GETACTIVEQUOTA:
192 xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
193 xdr_result = (xdrproc_t) xdr_getquota_rslt;
194 local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2;
198 svcerr_noproc(transp);
202 (void) memset((char *)&argument, 0, sizeof (argument));
203 if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument)) {
204 svcerr_decode(transp);
207 result = (*local)((char *)&argument, rqstp);
208 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
209 svcerr_systemerr(transp);
212 if (!svc_freeargs(transp, xdr_argument, (caddr_t) &argument)) {
213 syslog(LOG_ERR, "unable to free arguments");
220 usage(const char *prog, int n)
222 fprintf(stderr, "Usage: %s [-p|--port port] [-h|-?|--help] [-v|--version]\n", prog);
229 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
230 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
231 syslog(LOG_ERR, "caught signal %d, un-registering and exiting.", sig);
234 int main(int argc, char **argv)
236 register SVCXPRT *transp;
241 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
242 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
244 openlog("rquota", LOG_PID, LOG_DAEMON);
246 while ((c = getopt_long(argc, argv, "hp:v", longopts, NULL)) != EOF) {
254 if (port < 1 || port > 65535) {
255 fprintf(stderr, "%s: bad port number: %s\n",
261 printf("rquotad %s\n", VERSION);
268 if (chdir(NFS_STATEDIR)) {
269 fprintf(stderr, "%s: chdir(%s) failed: %s\n",
270 argv [0], NFS_STATEDIR, strerror(errno));
275 /* WARNING: the following works on Linux and SysV, but not BSD! */
276 sa.sa_handler = SIG_IGN;
278 sigemptyset(&sa.sa_mask);
279 sigaction(SIGCHLD, &sa, NULL);
281 sa.sa_handler = killer;
282 sigaction(SIGHUP, &sa, NULL);
283 sigaction(SIGINT, &sa, NULL);
284 sigaction(SIGTERM, &sa, NULL);
287 transp = svcudp_create(makesock(port, IPPROTO_UDP));
289 transp = svcudp_create(svcudp_socket (RQUOTAPROG, 1));
290 if (transp == NULL) {
291 syslog(LOG_ERR, "cannot create udp service.");
294 if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquotaprog_1, IPPROTO_UDP)) {
295 syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, udp).");
298 if (!svc_register(transp, RQUOTAPROG, EXT_RQUOTAVERS, rquotaprog_2, IPPROTO_UDP)) {
299 syslog(LOG_ERR, "unable to register (RQUOTAPROG, EXT_RQUOTAVERS, udp).");
306 syslog(LOG_ERR, "svc_run returned");