The branch main has been updated by des:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=7378290edb5ad751d7d1e9bc7f96779d2bef1361

commit 7378290edb5ad751d7d1e9bc7f96779d2bef1361
Author:     Dag-Erling Smørgrav <d...@freebsd.org>
AuthorDate: 2025-08-07 01:23:19 +0000
Commit:     Dag-Erling Smørgrav <d...@freebsd.org>
CommitDate: 2025-08-07 01:23:19 +0000

    rpcbind: Code cleanup
    
    Fix a number of style issues and attempt to reduce the diff to NetBSD.
    
    Reviewed by:    glebius, kib
    Differential Revision:  https://reviews.freebsd.org/D51773
---
 usr.sbin/rpcbind/check_bound.c  |  23 +-
 usr.sbin/rpcbind/pmap_svc.c     |  38 ++--
 usr.sbin/rpcbind/rpcb_stat.c    |  15 +-
 usr.sbin/rpcbind/rpcb_svc.c     |  13 +-
 usr.sbin/rpcbind/rpcb_svc_4.c   |  30 +--
 usr.sbin/rpcbind/rpcb_svc_com.c | 288 +++++++++++++------------
 usr.sbin/rpcbind/rpcbind.c      | 466 ++++++++++++++++++++--------------------
 usr.sbin/rpcbind/rpcbind.h      |  42 ++--
 usr.sbin/rpcbind/warmstart.c    |  12 +-
 9 files changed, 471 insertions(+), 456 deletions(-)

diff --git a/usr.sbin/rpcbind/check_bound.c b/usr.sbin/rpcbind/check_bound.c
index 446dceb3502f..820f76d37346 100644
--- a/usr.sbin/rpcbind/check_bound.c
+++ b/usr.sbin/rpcbind/check_bound.c
@@ -42,13 +42,16 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+
 #include <rpc/rpc.h>
 #include <rpc/svc_dg.h>
+
 #include <netconfig.h>
-#include <syslog.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 #include <unistd.h>
-#include <stdlib.h>
 
 #include "rpcbind.h"
 
@@ -61,9 +64,9 @@ struct fdlist {
 
 static struct fdlist *fdhead;  /* Link list of the check fd's */
 static struct fdlist *fdtail;
-static char *nullstring = "";
+static char nullstring[] = "";
 
-static bool_t check_bound(struct fdlist *, char *uaddr);
+static bool_t check_bound(struct fdlist *, const char *uaddr);
 
 /*
  * Returns 1 if the given address is bound for the given addr & transport
@@ -71,7 +74,7 @@ static bool_t check_bound(struct fdlist *, char *uaddr);
  * Returns 0 for success.
  */
 static bool_t
-check_bound(struct fdlist *fdl, char *uaddr)
+check_bound(struct fdlist *fdl, const char *uaddr)
 {
        int fd;
        struct netbuf *na;
@@ -101,7 +104,7 @@ check_bound(struct fdlist *fdl, char *uaddr)
 }
 
 int
-add_bndlist(struct netconfig *nconf, struct netbuf *baddr __unused)
+add_bndlist(const struct netconfig *nconf, struct netbuf *baddr __unused)
 {
        struct fdlist *fdl;
        struct netconfig *newnconf;
@@ -109,7 +112,7 @@ add_bndlist(struct netconfig *nconf, struct netbuf *baddr 
__unused)
        newnconf = getnetconfigent(nconf->nc_netid);
        if (newnconf == NULL)
                return (-1);
-       fdl = malloc(sizeof (struct fdlist));
+       fdl = malloc(sizeof(*fdl));
        if (fdl == NULL) {
                freenetconfigent(newnconf);
                syslog(LOG_ERR, "no memory!");
@@ -131,7 +134,7 @@ add_bndlist(struct netconfig *nconf, struct netbuf *baddr 
__unused)
 }
 
 bool_t
-is_bound(char *netid, char *uaddr)
+is_bound(const char *netid, const char *uaddr)
 {
        struct fdlist *fdl;
 
@@ -189,7 +192,7 @@ mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char 
*saddr)
                return (NULL);
        }
 
-#ifdef ND_DEBUG
+#ifdef RPCBIND_DEBUG
        if (debugging) {
                if (saddr == NULL) {
                        fprintf(stderr, "mergeaddr: client uaddr = %s\n",
@@ -205,7 +208,7 @@ mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char 
*saddr)
         * This is all we should need for IP 4 and 6
         */
        m_uaddr = addrmerge(svc_getrpccaller(xprt), s_uaddr, c_uaddr, netid);
-#ifdef ND_DEBUG
+#ifdef RPCBIND_DEBUG
        if (debugging)
                fprintf(stderr, "mergeaddr: uaddr = %s, merged uaddr = %s\n",
                                uaddr, m_uaddr);
diff --git a/usr.sbin/rpcbind/pmap_svc.c b/usr.sbin/rpcbind/pmap_svc.c
index cea1606258ae..4dcbb0f6ddd2 100644
--- a/usr.sbin/rpcbind/pmap_svc.c
+++ b/usr.sbin/rpcbind/pmap_svc.c
@@ -35,7 +35,7 @@
 
 /*
  * pmap_svc.c
- * The server procedure for the version 2 portmaper.
+ * The server procedure for the version 2 portmapper.
  * All the portmapper related interface from the portmap side.
  */
 
@@ -47,12 +47,12 @@
 #include <rpc/pmap_prot.h>
 #include <rpc/rpcb_prot.h>
 #ifdef RPCBIND_DEBUG
+#include <stdio.h>
 #include <stdlib.h>
 #endif
 #include "rpcbind.h"
 
-static struct pmaplist *find_service_pmap(rpcprog_t, rpcvers_t,
-                                              rpcprot_t);
+static struct pmaplist *find_service_pmap(rpcprog_t, rpcvers_t, rpcprot_t);
 static bool_t pmapproc_change(struct svc_req *, SVCXPRT *, u_long);
 static bool_t pmapproc_getport(struct svc_req *, SVCXPRT *);
 static bool_t pmapproc_dump(struct svc_req *, SVCXPRT *);
@@ -168,6 +168,11 @@ pmapproc_change(struct svc_req *rqstp __unused, SVCXPRT 
*xprt, unsigned long op)
        uid_t uid;
        char uidbuf[32];
 
+       if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (char *)&reg)) {
+               svcerr_decode(xprt);
+               return (FALSE);
+       }
+
 #ifdef RPCBIND_DEBUG
        if (debugging)
                fprintf(stderr, "%s request for (%lu, %lu) : ",
@@ -175,11 +180,6 @@ pmapproc_change(struct svc_req *rqstp __unused, SVCXPRT 
*xprt, unsigned long op)
                    reg.pm_prog, reg.pm_vers);
 #endif
 
-       if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (char *)&reg)) {
-               svcerr_decode(xprt);
-               return (FALSE);
-       }
-
        if (!check_access(xprt, op, &reg, PMAPVERS)) {
                svcerr_weakauth(xprt);
                return FALSE;
@@ -192,12 +192,12 @@ pmapproc_change(struct svc_req *rqstp __unused, SVCXPRT 
*xprt, unsigned long op)
         * and looping.
         */
        if (__rpc_get_local_uid(xprt, &uid) < 0)
-               rpcbreg.r_owner = "unknown";
+               rpcbreg.r_owner = __UNCONST(rpcbind_unknown);
        else if (uid == 0)
-               rpcbreg.r_owner = "superuser";
+               rpcbreg.r_owner = __UNCONST(rpcbind_superuser);
        else {
                /* r_owner will be strdup-ed later */
-               snprintf(uidbuf, sizeof uidbuf, "%d", uid);
+               snprintf(uidbuf, sizeof(uidbuf), "%d", uid);
                rpcbreg.r_owner = uidbuf;
        }
 
@@ -207,14 +207,14 @@ pmapproc_change(struct svc_req *rqstp __unused, SVCXPRT 
*xprt, unsigned long op)
        if (op == PMAPPROC_SET) {
                char buf[32];
 
-               snprintf(buf, sizeof buf, "0.0.0.0.%d.%d",
+               snprintf(buf, sizeof(buf), "0.0.0.0.%d.%d",
                    (int)((reg.pm_port >> 8) & 0xff),
                    (int)(reg.pm_port & 0xff));
                rpcbreg.r_addr = buf;
                if (reg.pm_prot == IPPROTO_UDP) {
-                       rpcbreg.r_netid = udptrans;
+                       rpcbreg.r_netid = __UNCONST(udptrans);
                } else if (reg.pm_prot == IPPROTO_TCP) {
-                       rpcbreg.r_netid = tcptrans;
+                       rpcbreg.r_netid = __UNCONST(tcptrans);
                } else {
                        ans = FALSE;
                        goto done_change;
@@ -224,9 +224,9 @@ pmapproc_change(struct svc_req *rqstp __unused, SVCXPRT 
*xprt, unsigned long op)
                bool_t ans1, ans2;
 
                rpcbreg.r_addr = NULL;
-               rpcbreg.r_netid = tcptrans;
+               rpcbreg.r_netid = __UNCONST(tcptrans);
                ans1 = map_unset(&rpcbreg, rpcbreg.r_owner);
-               rpcbreg.r_netid = udptrans;
+               rpcbreg.r_netid = __UNCONST(udptrans);
                ans2 = map_unset(&rpcbreg, rpcbreg.r_owner);
                ans = ans1 || ans2;
        } else {
@@ -285,9 +285,9 @@ pmapproc_getport(struct svc_req *rqstp __unused, SVCXPRT 
*xprt)
 #endif
        fnd = find_service_pmap(reg.pm_prog, reg.pm_vers, reg.pm_prot);
        if (fnd) {
-               char serveuaddr[32], *ua;
+               char serveuaddr[32];
                int h1, h2, h3, h4, p1, p2;
-               char *netid;
+               const char *netid, *ua;
 
                if (reg.pm_prot == IPPROTO_UDP) {
                        ua = udp_uaddr;
@@ -303,7 +303,7 @@ pmapproc_getport(struct svc_req *rqstp __unused, SVCXPRT 
*xprt)
                                &h4, &p1, &p2) == 6) {
                        p1 = (fnd->pml_map.pm_port >> 8) & 0xff;
                        p2 = (fnd->pml_map.pm_port) & 0xff;
-                       snprintf(serveuaddr, sizeof serveuaddr,
+                       snprintf(serveuaddr, sizeof(serveuaddr),
                            "%d.%d.%d.%d.%d.%d", h1, h2, h3, h4, p1, p2);
                        if (is_bound(netid, serveuaddr)) {
                                port = fnd->pml_map.pm_port;
diff --git a/usr.sbin/rpcbind/rpcb_stat.c b/usr.sbin/rpcbind/rpcb_stat.c
index 9c03ce368293..9500bb7b7cbe 100644
--- a/usr.sbin/rpcbind/rpcb_stat.c
+++ b/usr.sbin/rpcbind/rpcb_stat.c
@@ -37,15 +37,18 @@
  * Copyright (c) 1990 by Sun Microsystems, Inc.
  */
 
-#include <netconfig.h>
+#include <sys/stat.h>
+
 #include <rpc/rpc.h>
 #include <rpc/rpcb_prot.h>
-#include <sys/stat.h>
 #ifdef PORTMAP
 #include <rpc/pmap_prot.h>
 #endif
+
+#include <netconfig.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "rpcbind.h"
 
 static rpcb_stat_byvers inf;
@@ -96,8 +99,8 @@ rpcbs_unset(rpcvers_t rtype, bool_t success)
 }
 
 void
-rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers, char *netid,
-             char *uaddr)
+rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t vers,
+    const char *netid, const char *uaddr)
 {
        rpcbs_addrlist *al;
        struct netconfig *nconf;
@@ -121,7 +124,7 @@ rpcbs_getaddr(rpcvers_t rtype, rpcprog_t prog, rpcvers_t 
vers, char *netid,
        if (nconf == NULL) {
                return;
        }
-       al = (rpcbs_addrlist *) malloc(sizeof (rpcbs_addrlist));
+       al = malloc(sizeof(*al));
        if (al == NULL) {
                return;
        }
@@ -170,7 +173,7 @@ rpcbs_rmtcall(rpcvers_t rtype, rpcproc_t rpcbproc, 
rpcprog_t prog,
        if (nconf == NULL) {
                return;
        }
-       rl = (rpcbs_rmtcalllist *) malloc(sizeof (rpcbs_rmtcalllist));
+       rl = malloc(sizeof(*rl));
        if (rl == NULL) {
                return;
        }
diff --git a/usr.sbin/rpcbind/rpcb_svc.c b/usr.sbin/rpcbind/rpcb_svc.c
index 94323ab992aa..5a23abe3dbc6 100644
--- a/usr.sbin/rpcbind/rpcb_svc.c
+++ b/usr.sbin/rpcbind/rpcb_svc.c
@@ -46,6 +46,7 @@
 #include <netconfig.h>
 #include <stdio.h>
 #ifdef RPCBIND_DEBUG
+#include <stdio.h>
 #include <stdlib.h>
 #endif
 #include <string.h>
@@ -53,9 +54,9 @@
 #include "rpcbind.h"
 
 static void *rpcbproc_getaddr_3_local(void *, struct svc_req *, SVCXPRT *,
-                                          rpcvers_t);
+    rpcvers_t);
 static void *rpcbproc_dump_3_local(void *, struct svc_req *, SVCXPRT *,
-                                       rpcvers_t);
+    rpcvers_t);
 
 /*
  * Called by svc_getreqset. There is a separate server handle for
@@ -89,7 +90,7 @@ rpcb_service_3(struct svc_req *rqstp, SVCXPRT *transp)
 #endif
                /* This call just logs, no actual checks */
                check_access(transp, rqstp->rq_proc, NULL, RPCBVERS);
-               (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
+               (void) svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
                return;
 
        case RPCBPROC_SET:
@@ -204,7 +205,7 @@ done:
 /* ARGSUSED */
 static void *
 rpcbproc_getaddr_3_local(void *arg, struct svc_req *rqstp __unused,
-                        SVCXPRT *transp __unused, rpcvers_t versnum __unused)
+    SVCXPRT *transp __unused, rpcvers_t versnum __unused)
 {
        RPCB *regp = (RPCB *)arg;
 #ifdef RPCBIND_DEBUG
@@ -212,7 +213,7 @@ rpcbproc_getaddr_3_local(void *arg, struct svc_req *rqstp 
__unused,
                char *uaddr;
 
                uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid),
-                           svc_getrpccaller(transp));
+                   svc_getrpccaller(transp));
                fprintf(stderr, "RPCB_GETADDR req for (%lu, %lu, %s) from %s: ",
                    (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
                    regp->r_netid, uaddr);
@@ -226,7 +227,7 @@ rpcbproc_getaddr_3_local(void *arg, struct svc_req *rqstp 
__unused,
 /* ARGSUSED */
 static void *
 rpcbproc_dump_3_local(void *arg __unused, struct svc_req *rqstp __unused,
-                     SVCXPRT *transp __unused, rpcvers_t versnum __unused)
+    SVCXPRT *transp __unused, rpcvers_t versnum __unused)
 {
        return ((void *)&list_rbl);
 }
diff --git a/usr.sbin/rpcbind/rpcb_svc_4.c b/usr.sbin/rpcbind/rpcb_svc_4.c
index 77240e4d3ef5..817312709cf0 100644
--- a/usr.sbin/rpcbind/rpcb_svc_4.c
+++ b/usr.sbin/rpcbind/rpcb_svc_4.c
@@ -51,12 +51,14 @@
 #include "rpcbind.h"
 
 static void *rpcbproc_getaddr_4_local(void *, struct svc_req *, SVCXPRT *,
-                                     rpcvers_t);
-static void *rpcbproc_getversaddr_4_local(void *, struct svc_req *, SVCXPRT *, 
rpcvers_t);
-static void *rpcbproc_getaddrlist_4_local
-       (void *, struct svc_req *, SVCXPRT *, rpcvers_t);
+    rpcvers_t);
+static void *rpcbproc_getversaddr_4_local(void *, struct svc_req *, SVCXPRT *,
+    rpcvers_t);
+static void *rpcbproc_getaddrlist_4_local(void *, struct svc_req *, SVCXPRT *,
+    rpcvers_t);
 static void free_rpcb_entry_list(rpcb_entry_list_ptr *);
-static void *rpcbproc_dump_4_local(void *, struct svc_req *, SVCXPRT *, 
rpcvers_t);
+static void *rpcbproc_dump_4_local(void *, struct svc_req *, SVCXPRT *,
+    rpcvers_t);
 
 /*
  * Called by svc_getreqset. There is a separate server handle for
@@ -88,8 +90,7 @@ rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
                        fprintf(stderr, "RPCBPROC_NULL\n");
 #endif
                check_access(transp, rqstp->rq_proc, NULL, RPCBVERS4);
-               (void) svc_sendreply(transp, (xdrproc_t) xdr_void,
-                                       (char *)NULL);
+               (void) svc_sendreply(transp, (xdrproc_t) xdr_void, NULL);
                return;
 
        case RPCBPROC_SET:
@@ -257,7 +258,7 @@ done:
 /* ARGSUSED */
 static void *
 rpcbproc_getaddr_4_local(void *arg, struct svc_req *rqstp, SVCXPRT *transp,
-                        rpcvers_t rpcbversnum __unused)
+    rpcvers_t rpcbversnum __unused)
 {
        RPCB *regp = (RPCB *)arg;
 #ifdef RPCBIND_DEBUG
@@ -315,7 +316,7 @@ rpcbproc_getversaddr_4_local(void *arg, struct svc_req 
*rqstp, SVCXPRT *transp,
 /* ARGSUSED */
 static void *
 rpcbproc_getaddrlist_4_local(void *arg, struct svc_req *rqstp __unused,
-                            SVCXPRT *transp, rpcvers_t versnum __unused)
+    SVCXPRT *transp, rpcvers_t versnum __unused)
 {
        RPCB *regp = (RPCB *)arg;
        static rpcb_entry_list_ptr rlist;
@@ -384,7 +385,7 @@ rpcbproc_getaddrlist_4_local(void *arg, struct svc_req 
*rqstp __unused,
                /*
                 * Add it to rlist.
                 */
-               rp = malloc(sizeof (rpcb_entry_list));
+               rp = malloc(sizeof(*rp));
                if (rp == NULL)
                        goto fail;
                a = &rp->rpcb_entry_map;
@@ -397,7 +398,7 @@ rpcbproc_getaddrlist_4_local(void *arg, struct svc_req 
*rqstp __unused,
                if (rlist == NULL) {
                        rlist = rp;
                        tail = rp;
-               } else {
+               } else if (tail != NULL) {
                        tail->rpcb_entry_next = rp;
                        tail = rp;
                }
@@ -417,9 +418,10 @@ rpcbproc_getaddrlist_4_local(void *arg, struct svc_req 
*rqstp __unused,
         * Perhaps wrong, but better than it not getting counted at all.
         */
        rpcbs_getaddr(RPCBVERS4 - 2, prog, vers, transp->xp_netid, maddr);
-       return (void *)&rlist;
+       return (&rlist);
 
-fail:  free_rpcb_entry_list(&rlist);
+fail:
+       free_rpcb_entry_list(&rlist);
        return (NULL);
 }
 
@@ -444,7 +446,7 @@ free_rpcb_entry_list(rpcb_entry_list_ptr *rlistp)
 /* ARGSUSED */
 static void *
 rpcbproc_dump_4_local(void *arg __unused, struct svc_req *req __unused,
-                     SVCXPRT *xprt __unused, rpcvers_t versnum __unused)
+    SVCXPRT *xprt __unused, rpcvers_t versnum __unused)
 {
        return ((void *)&list_rbl);
 }
diff --git a/usr.sbin/rpcbind/rpcb_svc_com.c b/usr.sbin/rpcbind/rpcb_svc_com.c
index 15ecda213abc..a82cf44bfa3c 100644
--- a/usr.sbin/rpcbind/rpcb_svc_com.c
+++ b/usr.sbin/rpcbind/rpcb_svc_com.c
@@ -110,7 +110,7 @@ static int check_rmtcalls(struct pollfd *, int);
 static void xprt_set_caller(SVCXPRT *, struct finfo *);
 static void send_svcsyserr(SVCXPRT *, struct finfo *);
 static void handle_reply(int, SVCXPRT *);
-static void find_versions(rpcprog_t, char *, rpcvers_t *, rpcvers_t *);
+static void find_versions(rpcprog_t, const char *, rpcvers_t *, rpcvers_t *);
 static rpcblist_ptr find_service(rpcprog_t, rpcvers_t, char *);
 static char *getowner(SVCXPRT *, char *, size_t);
 static int add_pmaplist(RPCB *);
@@ -122,17 +122,17 @@ static int del_pmaplist(RPCB *);
 /* ARGSUSED */
 void *
 rpcbproc_set_com(void *arg, struct svc_req *rqstp __unused, SVCXPRT *transp,
-                rpcvers_t rpcbversnum)
+    rpcvers_t rpcbversnum)
 {
-       RPCB *regp = (RPCB *)arg;
+       RPCB *regp = arg;
        static bool_t ans;
        char owner[64];
 
 #ifdef RPCBIND_DEBUG
        if (debugging)
-               fprintf(stderr, "RPCB_SET request for (%lu, %lu, %s, %s) : ",
-                   (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
-                   regp->r_netid, regp->r_addr);
+               fprintf(stderr, "%s: RPCB_SET request for (%lu, %lu, %s, %s): ",
+                   __func__, (unsigned long)regp->r_prog,
+                   (unsigned long)regp->r_vers, regp->r_netid, regp->r_addr);
 #endif
        ans = map_set(regp, getowner(transp, owner, sizeof owner));
 #ifdef RPCBIND_DEBUG
@@ -145,7 +145,7 @@ rpcbproc_set_com(void *arg, struct svc_req *rqstp __unused, 
SVCXPRT *transp,
 }
 
 bool_t
-map_set(RPCB *regp, char *owner)
+map_set(RPCB *regp, const char *owner)
 {
        RPCB reg, *a;
        rpcblist_ptr rbl, fnd;
@@ -170,7 +170,7 @@ map_set(RPCB *regp, char *owner)
        /*
         * add to the end of the list
         */
-       rbl = malloc(sizeof (RPCBLIST));
+       rbl = malloc(sizeof(*rbl));
        if (rbl == NULL)
                return (FALSE);
        a = &(rbl->rpcb_map);
@@ -186,7 +186,7 @@ map_set(RPCB *regp, char *owner)
                free(rbl);
                return (FALSE);
        }
-       rbl->rpcb_next = (rpcblist_ptr)NULL;
+       rbl->rpcb_next = NULL;
        if (list_rbl == NULL) {
                list_rbl = rbl;
        } else {
@@ -196,7 +196,7 @@ map_set(RPCB *regp, char *owner)
                fnd->rpcb_next = rbl;
        }
 #ifdef PORTMAP
-       (void) add_pmaplist(regp);
+       (void)add_pmaplist(regp);
 #endif
        return (TRUE);
 }
@@ -207,17 +207,17 @@ map_set(RPCB *regp, char *owner)
 /* ARGSUSED */
 void *
 rpcbproc_unset_com(void *arg, struct svc_req *rqstp __unused, SVCXPRT *transp,
-                  rpcvers_t rpcbversnum)
+    rpcvers_t rpcbversnum)
 {
-       RPCB *regp = (RPCB *)arg;
+       RPCB *regp = arg;
        static bool_t ans;
        char owner[64];
 
 #ifdef RPCBIND_DEBUG
        if (debugging)
-               fprintf(stderr, "RPCB_UNSET request for (%lu, %lu, %s) : ",
-                   (unsigned long)regp->r_prog, (unsigned long)regp->r_vers,
-                   regp->r_netid);
+               fprintf(stderr, "%s: RPCB_UNSET request for (%lu, %lu, %s): ",
+                   __func__, (unsigned long)regp->r_prog,
+                   (unsigned long)regp->r_vers, regp->r_netid);
 #endif
        ans = map_unset(regp, getowner(transp, owner, sizeof owner));
 #ifdef RPCBIND_DEBUG
@@ -230,7 +230,7 @@ rpcbproc_unset_com(void *arg, struct svc_req *rqstp 
__unused, SVCXPRT *transp,
 }
 
 bool_t
-map_unset(RPCB *regp, char *owner)
+map_unset(RPCB *regp, const char *owner)
 {
        int ans = 0;
        rpcblist_ptr rbl, prev, tmp;
@@ -252,7 +252,7 @@ map_unset(RPCB *regp, char *owner)
                 * Check whether appropriate uid. Unset only
                 * if superuser or the owner itself.
                 */
-               if (strcmp(owner, "superuser") &&
+               if (strcmp(owner, rpcbind_superuser) &&
                        strcmp(rbl->rpcb_map.r_owner, owner))
                        return (0);
                /* found it; rbl moves forward, prev stays */
@@ -270,21 +270,21 @@ map_unset(RPCB *regp, char *owner)
        }
 #ifdef PORTMAP
        if (ans)
-               (void) del_pmaplist(regp);
+               (void)del_pmaplist(regp);
 #endif
        /*
         * We return 1 either when the entry was not there or it
         * was able to unset it.  It can come to this point only if
-        * atleast one of the conditions is true.
+        * at least one of the conditions is true.
         */
        return (1);
 }
 
 void
-delete_prog(unsigned int prog)
+delete_prog(rpcprog_t prog)
 {
        RPCB reg;
-       register rpcblist_ptr rbl;
+       rpcblist_ptr rbl;
 
        for (rbl = list_rbl; rbl != NULL; rbl = rbl->rpcb_next) {
                if ((rbl->rpcb_map.r_prog != prog))
@@ -294,14 +294,18 @@ delete_prog(unsigned int prog)
                reg.r_prog = rbl->rpcb_map.r_prog;
                reg.r_vers = rbl->rpcb_map.r_vers;
                reg.r_netid = strdup(rbl->rpcb_map.r_netid);
-               (void) map_unset(&reg, "superuser");
-               free(reg.r_netid);
+               if (reg.r_netid == NULL)
+                       syslog(LOG_ERR, "%s: %m", __func__);
+               else {
+                       (void)map_unset(&reg, rpcbind_superuser);
+                       free(reg.r_netid);
+               }
        }
 }
 
 void *
 rpcbproc_getaddr_com(RPCB *regp, struct svc_req *rqstp __unused,
-                    SVCXPRT *transp, rpcvers_t rpcbversnum, rpcvers_t verstype)
+    SVCXPRT *transp, rpcvers_t rpcbversnum, rpcvers_t verstype)
 {
        static char *uaddr;
        char *saddr = NULL;
@@ -333,23 +337,23 @@ rpcbproc_getaddr_com(RPCB *regp, struct svc_req *rqstp 
__unused,
        }
 #ifdef RPCBIND_DEBUG
        if (debugging)
-               fprintf(stderr, "getaddr: %s\n", uaddr);
+               fprintf(stderr, "%s: %s\n", __func__, uaddr);
 #endif
        /* XXX: should have used some defined constant here */
        rpcbs_getaddr(rpcbversnum - 2, regp->r_prog, regp->r_vers,
                transp->xp_netid, uaddr);
-       return (void *)&uaddr;
+       return (&uaddr);
 }
 
 /* ARGSUSED */
 void *
 rpcbproc_gettime_com(void *arg __unused, struct svc_req *rqstp __unused,
-                    SVCXPRT *transp __unused, rpcvers_t rpcbversnum __unused)
+    SVCXPRT *transp __unused, rpcvers_t rpcbversnum __unused)
 {
        static time_t curtime;
 
-       (void) time(&curtime);
-       return (void *)&curtime;
+       (void)time(&curtime);
+       return (&curtime);
 }
 
 /*
@@ -359,9 +363,9 @@ rpcbproc_gettime_com(void *arg __unused, struct svc_req 
*rqstp __unused,
 /* ARGSUSED */
 void *
 rpcbproc_uaddr2taddr_com(void *arg, struct svc_req *rqstp __unused,
-                        SVCXPRT *transp, rpcvers_t rpcbversnum __unused)
+    SVCXPRT *transp, rpcvers_t rpcbversnum __unused)
 {
-       char **uaddrp = (char **)arg;
+       char **uaddrp = arg;
        struct netconfig *nconf;
        static struct netbuf nbuf;
        static struct netbuf *taddr;
@@ -370,10 +374,10 @@ rpcbproc_uaddr2taddr_com(void *arg, struct svc_req *rqstp 
__unused,
        taddr = NULL;
        if (((nconf = rpcbind_get_conf(transp->xp_netid)) == NULL) ||
            ((taddr = uaddr2taddr(nconf, *uaddrp)) == NULL)) {
-               (void) memset((char *)&nbuf, 0, sizeof (struct netbuf));
-               return (void *)&nbuf;
+               memset(&nbuf, 0, sizeof(nbuf));
+               return (&nbuf);
        }
-       return (void *)taddr;
+       return (taddr);
 }
 
 /*
@@ -383,9 +387,9 @@ rpcbproc_uaddr2taddr_com(void *arg, struct svc_req *rqstp 
__unused,
 /* ARGSUSED */
 void *
 rpcbproc_taddr2uaddr_com(void *arg, struct svc_req *rqstp __unused,
-                        SVCXPRT *transp, rpcvers_t rpcbversnum __unused)
+    SVCXPRT *transp, rpcvers_t rpcbversnum __unused)
 {
-       struct netbuf *taddr = (struct netbuf *)arg;
+       struct netbuf *taddr = arg;
        static char *uaddr;
        struct netconfig *nconf;
 
@@ -393,7 +397,7 @@ rpcbproc_taddr2uaddr_com(void *arg, struct svc_req *rqstp 
__unused,
        int fd;
 
        if ((fd = open("/dev/null", O_RDONLY)) == -1) {
-               uaddr = (char *)strerror(errno);
+               uaddr = strerror(errno);
                return (&uaddr);
        }
 #endif /* CHEW_FDS */
@@ -480,7 +484,7 @@ static struct rmtcallfd_list *rmthead;
 static struct rmtcallfd_list *rmttail;
 
 int
-create_rmtcall_fd(struct netconfig *nconf)
+create_rmtcall_fd(const struct netconfig *nconf)
 {
        int fd;
        struct rmtcallfd_list *rmt;
@@ -488,21 +492,20 @@ create_rmtcall_fd(struct netconfig *nconf)
 
        if ((fd = __rpc_nconf2fd(nconf)) == -1) {
                if (debugging)
-                       fprintf(stderr,
-       "create_rmtcall_fd: couldn't open \"%s\" (errno %d)\n",
-                       nconf->nc_device, errno);
+                       fprintf(stderr, "%s: couldn't open \"%s\": %m\n",
+                           __func__, nconf->nc_device);
                return (-1);
        }
-       xprt = svc_tli_create(fd, 0, (struct t_bind *) 0, 0, 0);
+       xprt = svc_tli_create(fd, 0, NULL, 0, 0);
        if (xprt == NULL) {
                if (debugging)
-                       fprintf(stderr,
-                               "create_rmtcall_fd: svc_tli_create failed\n");
+                       fprintf(stderr, "%s: svc_tli_create failed\n",
+                           __func__);
                return (-1);
        }
-       rmt = malloc(sizeof (struct rmtcallfd_list));
+       rmt = malloc(sizeof(*rmt));
        if (rmt == NULL) {
-               syslog(LOG_ERR, "create_rmtcall_fd: no memory!");
+               syslog(LOG_ERR, "%s: %m", __func__);
                return (-1);
        }
        rmt->xprt = xprt;
@@ -591,16 +594,16 @@ find_rmtcallxprt_by_fd(int fd)
 
 void
 rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
-                   rpcproc_t reply_type, rpcvers_t versnum)
+    rpcproc_t reply_type, rpcvers_t versnum)
 {
-       register rpcblist_ptr rbl;
+       rpcblist_ptr rbl;
        struct netconfig *nconf;
        struct netbuf *caller;
        struct r_rmtcall_args a;
        char *buf_alloc = NULL, *outbufp;
        char *outbuf_alloc = NULL;
        char buf[RPC_BUF_MAX], outbuf[RPC_BUF_MAX];
-       struct netbuf *na = (struct netbuf *) NULL;
+       struct netbuf *na = NULL;
        struct rpc_msg call_msg;
        int outlen;
        u_int sendsz;
@@ -638,8 +641,7 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
 #endif /* notyet */
                if (buf_alloc == NULL) {
                        if (debugging)
-                               fprintf(stderr,
-                                       "rpcbproc_callit_com:  No Memory!\n");
+                               fprintf(stderr, "%s: %m\n", __func__);
                        if (reply_type == RPCBPROC_INDIRECT)
                                svcerr_systemerr(transp);
                        return;
@@ -650,12 +652,11 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT 
*transp,
        }
 
        call_msg.rm_xid = 0;    /* For error checking purposes */
-       if (!svc_getargs(transp, (xdrproc_t) xdr_rmtcall_args, (char *) &a)) {
+       if (!svc_getargs(transp, (xdrproc_t)xdr_rmtcall_args, (char *) &a)) {
                if (reply_type == RPCBPROC_INDIRECT)
                        svcerr_decode(transp);
                if (debugging)
-                       fprintf(stderr,
-                       "rpcbproc_callit_com:  svc_getargs failed\n");
+                       fprintf(stderr, "%s: svc_getargs failed\n", __func__);
                goto error;
        }
 
@@ -668,14 +669,15 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT 
*transp,
 #ifdef RPCBIND_DEBUG
        if (debugging) {
                uaddr = taddr2uaddr(rpcbind_get_conf(transp->xp_netid), caller);
-               fprintf(stderr, "%s %s req for (%lu, %lu, %lu, %s) from %s : ",
-                       versnum == PMAPVERS ? "pmap_rmtcall" :
-                       versnum == RPCBVERS ? "rpcb_rmtcall" :
-                       versnum == RPCBVERS4 ? "rpcb_indirect" : "unknown",
-                       reply_type == RPCBPROC_INDIRECT ? "indirect" : "callit",
-                       (unsigned long)a.rmt_prog, (unsigned long)a.rmt_vers,
-                       (unsigned long)a.rmt_proc, transp->xp_netid,
-                       uaddr ? uaddr : "unknown");
+               fprintf(stderr,
+                   "%s: %s %s req for (%lu, %lu, %lu, %s) from %s: ",
+                   __func__, versnum == PMAPVERS ? "pmap_rmtcall" :
+                   versnum == RPCBVERS ? "rpcb_rmtcall" :
+                   versnum == RPCBVERS4 ? "rpcb_indirect" : rpcbind_unknown,
+                   reply_type == RPCBPROC_INDIRECT ? "indirect" : "callit",
+                   (unsigned long)a.rmt_prog, (unsigned long)a.rmt_vers,
+                   (unsigned long)a.rmt_proc, transp->xp_netid,
+                   uaddr ? uaddr : rpcbind_unknown);
                free(uaddr);
        }
 #endif
@@ -685,7 +687,7 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
        rpcbs_rmtcall(versnum - 2, reply_type, a.rmt_prog, a.rmt_vers,
                        a.rmt_proc, transp->xp_netid, rbl);
 
-       if (rbl == (rpcblist_ptr)NULL) {
+       if (rbl == NULL) {
 #ifdef RPCBIND_DEBUG
                if (debugging)
                        fprintf(stderr, "not found\n");
@@ -726,19 +728,18 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT 
*transp,
                free(uaddr);
        }
        nconf = rpcbind_get_conf(transp->xp_netid);
-       if (nconf == (struct netconfig *)NULL) {
+       if (nconf == NULL) {
                if (reply_type == RPCBPROC_INDIRECT)
                        svcerr_systemerr(transp);
                if (debugging)
-                       fprintf(stderr,
-                       "rpcbproc_callit_com:  rpcbind_get_conf failed\n");
+                       fprintf(stderr, "%s: rpcbind_get_conf failed\n",
+                           __func__);
                goto error;
        }
        localsa = local_sa(((struct sockaddr *)caller->buf)->sa_family);
        if (localsa == NULL) {
                if (debugging)
-                       fprintf(stderr,
-                       "rpcbproc_callit_com: no local address\n");
+                       fprintf(stderr, "%s: no local address\n", __func__);
                goto error;
        }
        tbuf.len = tbuf.maxlen = localsa->sa_len;
@@ -749,7 +750,7 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
                        nconf->nc_netid);
 #ifdef RPCBIND_DEBUG
        if (debugging)
-               fprintf(stderr, "merged uaddr %s\n", m_uaddr);
+               fprintf(stderr, "%s: merged uaddr %s\n", __func__, m_uaddr);
 #endif
        if ((fd = find_rmtcallfd_by_netid(nconf->nc_netid)) == -1) {
                if (reply_type == RPCBPROC_INDIRECT)
@@ -769,22 +770,20 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT 
*transp,
                 * beat on it any more.
                 */
                if (debugging)
-                       fprintf(stderr,
-                       "rpcbproc_callit_com:  duplicate request\n");
+                       fprintf(stderr, "%s: duplicate request\n", __func__);
                goto error;
        case -1:
                /*  forward_register failed.  Perhaps no memory. */
                if (debugging)
-                       fprintf(stderr,
-                       "rpcbproc_callit_com:  forward_register failed\n");
+                       fprintf(stderr, "%s: forward_register failed\n",
+                           __func__);
                goto error;
        }
 
 #ifdef DEBUG_RMTCALL
        if (debugging)
-               fprintf(stderr,
-                       "rpcbproc_callit_com:  original XID %x, new XID %x\n",
-                               *xidp, call_msg.rm_xid);
+               fprintf(stderr, "%s: original XID %x, new XID %x\n", __func__,
+                   *xidp, call_msg.rm_xid);
 #endif
        call_msg.rm_direction = CALL;
        call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
@@ -797,11 +796,10 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT 
*transp,
                outbuf_alloc = malloc(sendsz);
 #endif /* notyet */
                if (outbuf_alloc == NULL) {
+                       if (debugging)
+                               fprintf(stderr, "%s: %m\n", __func__);
                        if (reply_type == RPCBPROC_INDIRECT)
                                svcerr_systemerr(transp);
-                       if (debugging)
-                               fprintf(stderr,
-                               "rpcbproc_callit_com:  No memory!\n");
                        goto error;
                }
                xdrmem_create(&outxdr, outbuf_alloc, sendsz, XDR_ENCODE);
@@ -812,16 +810,14 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT 
*transp,
                if (reply_type == RPCBPROC_INDIRECT)
                        svcerr_systemerr(transp);
                if (debugging)
-                       fprintf(stderr,
-                       "rpcbproc_callit_com:  xdr_callhdr failed\n");
+                       fprintf(stderr, "%s: xdr_callhdr failed\n", __func__);
                goto error;
        }
        if (!xdr_u_int32_t(&outxdr, &(a.rmt_proc))) {
                if (reply_type == RPCBPROC_INDIRECT)
                        svcerr_systemerr(transp);
                if (debugging)
-                       fprintf(stderr,
-                       "rpcbproc_callit_com:  xdr_u_long failed\n");
+                       fprintf(stderr, "%s: xdr_u_long failed\n", __func__);
                goto error;
        }
 
@@ -839,8 +835,8 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
        } else {
                /* we do not support any other authentication scheme */
                if (debugging)
-                       fprintf(stderr,
-"rpcbproc_callit_com:  oa_flavor != AUTH_NONE and oa_flavor != AUTH_SYS\n");
+                       fprintf(stderr, "%s: oa_flavor != AUTH_NONE and "
+                           "oa_flavor != AUTH_SYS\n", __func__);
                if (reply_type == RPCBPROC_INDIRECT)
                        svcerr_weakauth(transp); /* XXX too strong.. */
                goto error;
@@ -850,7 +846,8 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
                        svcerr_systemerr(transp);
                if (debugging)
                        fprintf(stderr,
-               "rpcbproc_callit_com:  authwhatever_create returned NULL\n");
+                           "%s: authwhatever_create returned NULL\n",
+                           __func__);
                goto error;
        }
        if (!AUTH_MARSHALL(auth, &outxdr)) {
@@ -858,8 +855,8 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
                        svcerr_systemerr(transp);
                AUTH_DESTROY(auth);
                if (debugging)
-                       fprintf(stderr,
-               "rpcbproc_callit_com:  AUTH_MARSHALL failed\n");
+                       fprintf(stderr, "%s: AUTH_MARSHALL failed\n",
+                           __func__);
                goto error;
        }
        AUTH_DESTROY(auth);
@@ -867,8 +864,8 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
                if (reply_type == RPCBPROC_INDIRECT)
                        svcerr_systemerr(transp);
                if (debugging)
-                       fprintf(stderr,
-               "rpcbproc_callit_com:  xdr_opaque_parms failed\n");
+                       fprintf(stderr, "%s: xdr_opaque_parms failed\n",
+                           __func__);
                goto error;
        }
        outlen = (int) XDR_GETPOS(&outxdr);
@@ -887,8 +884,7 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
        if (sendto(fd, outbufp, outlen, 0, (struct sockaddr *)na->buf, na->len)
            != outlen) {
                if (debugging)
-                       fprintf(stderr,
-       "rpcbproc_callit_com:  sendto failed:  errno %d\n", errno);
+                       fprintf(stderr, "%s:  sendto failed: %m\n", __func__);
                if (reply_type == RPCBPROC_INDIRECT)
                        svcerr_systemerr(transp);
                goto error;
@@ -897,7 +893,7 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
 
 error:
        if (call_msg.rm_xid != 0)
-               (void) free_slot_by_xid(call_msg.rm_xid);
+               (void)free_slot_by_xid(call_msg.rm_xid);
 out:
        free(local_uaddr);
        free(buf_alloc);
@@ -913,14 +909,12 @@ out:
  */
 static int
 forward_register(u_int32_t caller_xid, struct netbuf *caller_addr,
-                int forward_fd, char *uaddr, rpcproc_t reply_type,
-                rpcvers_t versnum, u_int32_t *callxidp)
+    int forward_fd, char *uaddr, rpcproc_t reply_type,
+    rpcvers_t versnum, u_int32_t *callxidp)
 {
-       int             i;
-       int             j = 0;
-       time_t          min_time, time_now;
-       static u_int32_t        lastxid;
-       int             entry = -1;
+       static u_int32_t lastxid;
+       time_t min_time, time_now;
+       int i, j = 0, entry = -1;
 
        min_time = FINFO[0].time;
        time_now = time((time_t *)0);
@@ -945,7 +939,7 @@ forward_register(u_int32_t caller_xid, struct netbuf 
*caller_addr,
                        } else {
                                /* Should we wait any longer */
                                if ((time_now - FINFO[i].time) > MAXTIME_OFF)
-                                       (void) free_slot_by_index(i);
+                                       (void)free_slot_by_index(i);
                        }
                }
                if (entry == -1) {
@@ -961,7 +955,7 @@ forward_register(u_int32_t caller_xid, struct netbuf 
*caller_addr,
                /* use this empty slot */
                j = entry;
        } else {
-               (void) free_slot_by_index(j);
+               (void)free_slot_by_index(j);
        }
*** 1037 LINES SKIPPED ***


Reply via email to