rpc - Convert some daemons to TI-RPC
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>
Thu, 27 Nov 2014 23:02:36 +0000 (00:02 +0100)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Thu, 27 Nov 2014 23:07:07 +0000 (00:07 +0100)
- This follows up commit ce0e08e21d42c06c0014fae6b9d27144aa5109b0

libexec/rpc.rquotad/rquotad.c
libexec/rpc.rstatd/rstatd.c
libexec/rpc.rusersd/rusersd.c
libexec/rpc.rwalld/rwalld.c
libexec/rpc.sprayd/sprayd.c
usr.sbin/rpc.statd/statd.c

index 268a2f8..8b87484 100644 (file)
@@ -29,9 +29,9 @@
 
 #include <vfs/ufs/quota.h>
 #include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
 #include <rpcsvc/rquota.h>
 #include <arpa/inet.h>
+#include <netdb.h>
 
 static void cleanup(int);
 static void rquota_service(struct svc_req *request, SVCXPRT *transp);
@@ -57,7 +57,7 @@ int from_inetd = 1;
 void 
 cleanup(int signo __unused)
 {
-       (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
+       (void) rpcb_unset(RQUOTAPROG, RQUOTAVERS, NULL);
        exit(0);
 }
 
@@ -65,22 +65,19 @@ int
 main(void)
 {
        SVCXPRT *transp;
-       int sock = 0;
-       int proto = 0;
-       struct sockaddr_in from;
+       int ok;
+       struct sockaddr_storage from;
        int fromlen;
 
        fromlen = sizeof(from);
        if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
                from_inetd = 0;
-               sock = RPC_ANYSOCK;
-               proto = IPPROTO_UDP;
        }
 
        if (!from_inetd) {
                daemon(0, 0);
 
-               (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
+               (void) rpcb_unset(RQUOTAPROG, RQUOTAVERS, NULL);
 
                (void) signal(SIGINT, cleanup);
                (void) signal(SIGTERM, cleanup);
@@ -90,13 +87,19 @@ main(void)
        openlog("rpc.rquotad", LOG_CONS|LOG_PID, LOG_DAEMON);
 
        /* create and register the service */
-       transp = svcudp_create(sock);
-       if (transp == NULL) {
-               syslog(LOG_ERR, "couldn't create udp service");
-               exit(1);
-       }
-       if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquota_service, proto)) {
-               syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, %s)", proto?"udp":"(inetd)");
+       if (from_inetd) {
+               transp = svc_tli_create(0, NULL, NULL, 0, 0);
+               if (transp == NULL) {
+                       syslog(LOG_ERR, "couldn't create udp service.");
+                       exit(1);
+               }
+               ok = svc_reg(transp, RQUOTAPROG, RQUOTAVERS,
+                            rquota_service, NULL);
+       } else
+               ok = svc_create(rquota_service,
+                               RQUOTAPROG, RQUOTAVERS, "udp");
+       if (!ok) {
+               syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, %s)", (!from_inetd)?"udp":"(inetd)");
                exit(1);
        }
 
index d6d2ee6..1a154f2 100644 (file)
@@ -33,7 +33,6 @@
 #include <rpc/rpc.h>
 #include <signal.h>
 #include <syslog.h>
-#include <rpc/pmap_clnt.h>
 #include <rpcsvc/rstat.h>
 
 extern void rstat_service();
@@ -44,9 +43,9 @@ int closedown = 20;   /* how long to wait before going dormant */
 void
 cleanup(int sig)
 {
-        (void) pmap_unset(RSTATPROG, RSTATVERS_TIME);
-        (void) pmap_unset(RSTATPROG, RSTATVERS_SWTCH);
-        (void) pmap_unset(RSTATPROG, RSTATVERS_ORIG);
+        (void) rpcb_unset(RSTATPROG, RSTATVERS_TIME, NULL);
+        (void) rpcb_unset(RSTATPROG, RSTATVERS_SWTCH, NULL);
+        (void) rpcb_unset(RSTATPROG, RSTATVERS_ORIG, NULL);
         exit(0);
 }
 
@@ -54,9 +53,8 @@ int
 main(int argc, char *argv[])
 {
        SVCXPRT *transp;
-        int sock = 0;
-        int proto = 0;
-       struct sockaddr_in from;
+       int ok;
+       struct sockaddr_storage from;
        int fromlen;
 
         if (argc == 2)
@@ -70,16 +68,14 @@ main(int argc, char *argv[])
        fromlen = sizeof(from);
         if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
                 from_inetd = 0;
-                sock = RPC_ANYSOCK;
-                proto = IPPROTO_UDP;
         }
 
         if (!from_inetd) {
                 daemon(0, 0);
 
-                (void)pmap_unset(RSTATPROG, RSTATVERS_TIME);
-                (void)pmap_unset(RSTATPROG, RSTATVERS_SWTCH);
-                (void)pmap_unset(RSTATPROG, RSTATVERS_ORIG);
+                (void)rpcb_unset(RSTATPROG, RSTATVERS_TIME, NULL);
+                (void)rpcb_unset(RSTATPROG, RSTATVERS_SWTCH, NULL);
+                (void)rpcb_unset(RSTATPROG, RSTATVERS_ORIG, NULL);
 
                (void) signal(SIGINT, cleanup);
                (void) signal(SIGTERM, cleanup);
@@ -88,22 +84,40 @@ main(int argc, char *argv[])
 
         openlog("rpc.rstatd", LOG_CONS|LOG_PID, LOG_DAEMON);
 
-       transp = svcudp_create(sock);
-       if (transp == NULL) {
-               syslog(LOG_ERR, "cannot create udp service");
-               exit(1);
+       if (from_inetd) {
+               transp = svc_tli_create(0, NULL, NULL, 0, 0);
+               if (transp == NULL) {
+                       syslog(LOG_ERR, "cannot create udp service.");
+                       exit(1);
+               }
+               ok = svc_reg(transp, RSTATPROG, RSTATVERS_TIME,
+                            rstat_service, NULL);
+       } else
+               ok = svc_create(rstat_service,
+                               RSTATPROG, RSTATVERS_TIME, "udp");
+       if (!ok) {
+               syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, %s)", (!from_inetd)?"udp":"(inetd)");
+               exit(1);
        }
-       if (!svc_register(transp, RSTATPROG, RSTATVERS_TIME, rstat_service, proto)) {
-               syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, %s)", proto?"udp":"(inetd)");
-               exit(1);
+       if (from_inetd)
+               ok = svc_reg(transp, RSTATPROG, RSTATVERS_SWTCH,
+                            rstat_service, NULL);
+       else
+               ok = svc_create(rstat_service,
+                               RSTATPROG, RSTATVERS_SWTCH, "udp");
+       if (!ok) {
+               syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, %s)", (!from_inetd)?"udp":"(inetd)");
+               exit(1);
        }
-       if (!svc_register(transp, RSTATPROG, RSTATVERS_SWTCH, rstat_service, proto)) {
-               syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, %s)", proto?"udp":"(inetd)");
-               exit(1);
-       }
-       if (!svc_register(transp, RSTATPROG, RSTATVERS_ORIG, rstat_service, proto)) {
-               syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, %s)", proto?"udp":"(inetd)");
-               exit(1);
+       if (from_inetd)
+               ok = svc_reg(transp, RSTATPROG, RSTATVERS_ORIG,
+                            rstat_service, NULL);
+       else
+               ok = svc_create(rstat_service,
+                               RSTATPROG, RSTATVERS_ORIG, "udp");
+       if (!ok) {
+               syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, %s)", (!from_inetd)?"udp":"(inetd)");
+               exit(1);
        }
 
         svc_run();
index 053b14a..a96e97b 100644 (file)
@@ -31,7 +31,7 @@
 
 #include <stdlib.h>
 #include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
+#include <sys/socket.h>
 #include <signal.h>
 #include <syslog.h>
 #define utmp rutmp
@@ -45,8 +45,8 @@ int from_inetd = 1;
 void
 cleanup(int sig)
 {
-        (void) pmap_unset(RUSERSPROG, RUSERSVERS_IDLE);
-        (void) pmap_unset(RUSERSPROG, RUSERSVERS_ORIG);
+       (void) rpcb_unset(RUSERSPROG, RUSERSVERS_IDLE, NULL);
+       (void) rpcb_unset(RUSERSPROG, RUSERSVERS_ORIG, NULL);
         exit(0);
 }
 
@@ -54,9 +54,8 @@ int
 main(int argc, char *argv[])
 {
        SVCXPRT *transp;
-        int sock = 0;
-        int proto = 0;
-       struct sockaddr_in from;
+       int ok;
+       struct sockaddr_storage from;
        int fromlen;
 
         /*
@@ -65,8 +64,6 @@ main(int argc, char *argv[])
        fromlen = sizeof(from);
         if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
                 from_inetd = 0;
-                sock = RPC_ANYSOCK;
-                proto = IPPROTO_UDP;
         }
 
         if (!from_inetd) {
@@ -82,21 +79,32 @@ main(int argc, char *argv[])
 
         openlog("rpc.rusersd", LOG_CONS|LOG_PID, LOG_DAEMON);
 
-       transp = svcudp_create(sock);
-       if (transp == NULL) {
-               syslog(LOG_ERR, "cannot create udp service");
-               exit(1);
-       }
-       if (!svc_register(transp, RUSERSPROG, RUSERSVERS_IDLE, rusers_service, proto)) {
-               syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s)", proto?"udp":"(inetd)");
+       if (from_inetd) {
+               transp = svc_tli_create(0, NULL, NULL, 0, 0);
+               if (transp == NULL) {
+                       syslog(LOG_ERR, "cannot create udp service.");
+                       exit(1);
+               }
+               ok = svc_reg(transp, RUSERSPROG, RUSERSVERS_IDLE,
+                   rusers_service, NULL);
+       } else
+               ok = svc_create(rusers_service,
+                   RUSERSPROG, RUSERSVERS_IDLE, "udp");
+       if (!ok) {
+               syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s)", (!from_inetd)?"udp":"(inetd)");
                exit(1);
        }
 
-       if (!svc_register(transp, RUSERSPROG, RUSERSVERS_ORIG, rusers_service, proto)) {
-               syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_ORIG, %s)", proto?"udp":"(inetd)");
+       if (from_inetd)
+               ok = svc_reg(transp, RUSERSPROG, RUSERSVERS_ORIG,
+                   rusers_service, NULL);
+       else
+               ok = svc_create(rusers_service,
+                   RUSERSPROG, RUSERSVERS_ORIG, "udp");
+       if (!ok) {
+               syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_ORIG, %s)", (!from_inetd)?"udp":"(inetd)");
                exit(1);
        }
-
         svc_run();
        syslog(LOG_ERR, "svc_run returned");
        exit(1);
index 50c94f8..8929a7c 100644 (file)
@@ -37,7 +37,6 @@
 #include <string.h>
 #include <syslog.h>
 #include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
 #include <rpcsvc/rwall.h>
 #include <sys/socket.h>
 #include <sys/types.h>
@@ -62,10 +61,8 @@ int
 main(int argc, char *argv[])
 {
        SVCXPRT *transp;
-       int s, salen;
-       struct sockaddr_in sa;
-        int sock = 0;
-        int proto = 0;
+       int ok, salen;
+       struct sockaddr_storage sa;
 
        if (argc == 2 && !strcmp(argv[1], "-n"))
                nodaemon = 1;
@@ -86,42 +83,33 @@ main(int argc, char *argv[])
        salen = sizeof(sa);
         if (getsockname(0, (struct sockaddr *)&sa, &salen) < 0) {
                 from_inetd = 0;
-                sock = RPC_ANYSOCK;
-                proto = IPPROTO_UDP;
         }
 
         if (!from_inetd) {
                 if (!nodaemon)
                         possess();
 
-                (void)pmap_unset(WALLPROG, WALLVERS);
-                if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
-                        err(1, "socket");
-                bzero((char *)&sa, sizeof sa);
-                if (bind(s, (struct sockaddr *)&sa, sizeof sa) < 0)
-                        err(1, "bind");
-
-                salen = sizeof sa;
-                if (getsockname(s, (struct sockaddr *)&sa, &salen))
-                        err(1, "getsockname");
-
-                pmap_set(WALLPROG, WALLVERS, IPPROTO_UDP, ntohs(sa.sin_port));
-                if (dup2(s, 0) < 0)
-                        err(1, "dup2");
-                (void)pmap_unset(WALLPROG, WALLVERS);
+               (void)rpcb_unset(WALLPROG, WALLVERS, NULL);
         }
 
        (void)signal(SIGCHLD, killkids);
 
        openlog("rpc.rwalld", LOG_CONS|LOG_PID, LOG_DAEMON);
 
-       transp = svcudp_create(sock);
-       if (transp == NULL) {
-               syslog(LOG_ERR, "cannot create udp service");
-               exit(1);
-       }
-       if (!svc_register(transp, WALLPROG, WALLVERS, wallprog_1, proto)) {
-               syslog(LOG_ERR, "unable to register (WALLPROG, WALLVERS, %s)", proto?"udp":"(inetd)");
+       /* create and register the service */
+       if (from_inetd) {
+               transp = svc_tli_create(0, NULL, NULL, 0, 0);
+               if (transp == NULL) {
+                       syslog(LOG_ERR, "couldn't create udp service.");
+                       exit(1);
+               }
+               ok = svc_reg(transp, WALLPROG, WALLVERS,
+                   wallprog_1, NULL);
+       } else
+               ok = svc_create(wallprog_1,
+                   WALLPROG, WALLVERS, "udp");
+       if (!ok) {
+               syslog(LOG_ERR, "unable to register (WALLPROG, WALLVERS, %s)", (!from_inetd)?"udp":"(inetd)");
                exit(1);
        }
        svc_run();
index d74618b..d52b61f 100644 (file)
@@ -31,7 +31,6 @@
  */
 
 #include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
 #include <rpcsvc/spray.h>
 #include <signal.h>
 #include <stdio.h>
@@ -60,7 +59,7 @@ static int from_inetd = 1;
 void
 cleanup(int sig)
 {
-       (void) pmap_unset(SPRAYPROG, SPRAYVERS);
+       (void)rpcb_unset(SPRAYPROG, SPRAYVERS, NULL);
        exit(0);
 }
 
@@ -74,8 +73,7 @@ int
 main(int argc, char *argv[])
 {
        SVCXPRT *transp;
-       int sock = 0;
-       int proto = 0;
+       int ok;
        struct sockaddr_in from;
        int fromlen;
 
@@ -85,14 +83,12 @@ main(int argc, char *argv[])
        fromlen = sizeof(from);
        if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
                from_inetd = 0;
-               sock = RPC_ANYSOCK;
-               proto = IPPROTO_UDP;
        }
 
        if (!from_inetd) {
                daemon(0, 0);
 
-               (void) pmap_unset(SPRAYPROG, SPRAYVERS);
+               (void) rpcb_unset(SPRAYPROG, SPRAYVERS, NULL);
 
                (void) signal(SIGINT, cleanup);
                (void) signal(SIGTERM, cleanup);
@@ -104,15 +100,22 @@ main(int argc, char *argv[])
 
        openlog("rpc.sprayd", LOG_CONS|LOG_PID, LOG_DAEMON);
 
-       transp = svcudp_create(sock);
-       if (transp == NULL) {
-               syslog(LOG_ERR, "cannot create udp service");
-               return 1;
-       }
-       if (!svc_register(transp, SPRAYPROG, SPRAYVERS, spray_service, proto)) {
+       if (from_inetd) {
+                transp = svc_tli_create(0, NULL, NULL, 0, 0);
+                if (transp == NULL) {
+                        syslog(LOG_ERR, "cannot create udp service.");
+                        exit(1);
+                }
+                ok = svc_reg(transp, SPRAYPROG, SPRAYVERS,
+                    spray_service, NULL);
+       } else
+               ok = svc_create(spray_service,
+                   SPRAYPROG, SPRAYVERS, "udp");
+
+       if (!ok) {
                syslog(LOG_ERR,
                    "unable to register (SPRAYPROG, SPRAYVERS, %s)",
-                   proto ? "udp" : "(inetd)");
+                   (!from_inetd)?"udp":"(inetd)");
                return 1;
        }
 
index 0049a62..7bd119d 100644 (file)
@@ -39,9 +39,8 @@
 #include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
+#include <string.h>
 #include <syslog.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -56,7 +55,6 @@ static void usage(void);
 int
 main(int argc, char **argv)
 {
-  SVCXPRT *transp;
   struct sigaction sa;
 
   if (argc > 1)
@@ -66,19 +64,12 @@ main(int argc, char **argv)
     debug = 1;
   }
 
-  pmap_unset(SM_PROG, SM_VERS);
-
-  transp = svcudp_create(RPC_ANYSOCK);
-  if (transp == NULL)
-    errx(1, "cannot create udp service");
-  if (!svc_register(transp, SM_PROG, SM_VERS, sm_prog_1, IPPROTO_UDP))
-    errx(1, "unable to register (SM_PROG, SM_VERS, udp)");
+  rpcb_unset(SM_PROG, SM_VERS, NULL);
 
-  transp = svctcp_create(RPC_ANYSOCK, 0, 0);
-  if (transp == NULL)
+  if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "udp"))
+         errx(1, "cannot create udp service");
+  if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "tcp"))
     errx(1, "cannot create tcp service");
-  if (!svc_register(transp, SM_PROG, SM_VERS, sm_prog_1, IPPROTO_TCP))
-    errx(1, "unable to register (SM_PROG, SM_VERS, tcp)");
   init_file("/var/db/statd.status");
 
   /* Note that it is NOT sensible to run this program from inetd - the         */