]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/rquotad/rquota_svc.c
Use 65534 for anon uid/gid rather than -2
[nfs-utils.git] / utils / rquotad / rquota_svc.c
index e1149664ced37639518c042b22fe890bc1ff97ea..bd2038f2710476a605458c160f57f3f1268c60bf 100644 (file)
  *          as published by the Free Software Foundation; either version
  *          2 of the License, or (at your option) any later version.
  */
-#include "config.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #ifdef HAVE_TCP_WRAPPER
 #include "tcpwrapper.h"
 #include <signal.h>
 #include <getopt.h>
 #include <rpcmisc.h>
+#include <nfslib.h>
 
 #ifdef __STDC__
 #define SIG_PF void(*)(int)
 #endif
 
-extern getquota_rslt *rquotaproc_getquota_1(getquota_args *argp,
-                                           struct svc_req *rqstp);
-extern getquota_rslt *rquotaproc_getactivequota_1(getquota_args *argp,
-                                                 struct svc_req *rqstp);
-extern getquota_rslt *rquotaproc_getquota_2(ext_getquota_args *argp,
-                                           struct svc_req *rqstp);
-extern getquota_rslt *rquotaproc_getactivequota_2(ext_getquota_args *argp,
-                                                 struct svc_req *rqstp);
-
 static struct option longopts[] =
 {
         { "help", 0, 0, 'h' },
@@ -109,13 +104,13 @@ static void rquotaprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
       case RQUOTAPROC_GETQUOTA:
          xdr_argument = (xdrproc_t) xdr_getquota_args;
          xdr_result = (xdrproc_t) xdr_getquota_rslt;
-         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1;
+         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_1_svc;
          break;
 
       case RQUOTAPROC_GETACTIVEQUOTA:
          xdr_argument = (xdrproc_t) xdr_getquota_args;
          xdr_result = (xdrproc_t) xdr_getquota_rslt;
-         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1;
+         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_1_svc;
          break;
 
       default:
@@ -184,13 +179,13 @@ static void rquotaprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
       case RQUOTAPROC_GETQUOTA:
          xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
          xdr_result = (xdrproc_t) xdr_getquota_rslt;
-         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2;
+         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getquota_2_svc;
          break;
 
       case RQUOTAPROC_GETACTIVEQUOTA:
          xdr_argument = (xdrproc_t) xdr_ext_getquota_args;
          xdr_result = (xdrproc_t) xdr_getquota_rslt;
-         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2;
+         local = (char *(*)(char *, struct svc_req *)) rquotaproc_getactivequota_2_svc;
          break;
 
       default:
@@ -222,11 +217,20 @@ usage(const char *prog, int n)
   exit(n);
 }
 
+static void
+killer (int sig)
+{
+   (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
+   (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
+   syslog(LOG_ERR, "caught signal %d, un-registering and exiting.", sig);
+}
+
 int main(int argc, char **argv)
 {
    register SVCXPRT *transp;
-   char c;
+   int c;
    int port = 0;
+   struct sigaction sa;
 
    (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
    (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
@@ -263,12 +267,20 @@ int main(int argc, char **argv)
    }
 
    /* WARNING: the following works on Linux and SysV, but not BSD! */
-   signal(SIGCHLD, SIG_IGN);
+   sa.sa_handler = SIG_IGN;
+   sa.sa_flags = 0;
+   sigemptyset(&sa.sa_mask);
+   sigaction(SIGCHLD, &sa, NULL);
+
+   sa.sa_handler = killer;
+   sigaction(SIGHUP, &sa, NULL);
+   sigaction(SIGINT, &sa, NULL);
+   sigaction(SIGTERM, &sa, NULL);
 
    if (port)
      transp = svcudp_create(makesock(port, IPPROTO_UDP));
    else
-     transp = svcudp_create(RPC_ANYSOCK);
+     transp = svcudp_create(svcudp_socket (RQUOTAPROG, 1));
    if (transp == NULL) {
       syslog(LOG_ERR, "cannot create udp service.");
       exit(1);