rpcbind/0008-Fix-the-behavior-when-specifying-the-h-option.patch

142 lines
3.9 KiB
Diff

From 2a825515a2b6304e27f0e28fd5da562d44d6cbfe Mon Sep 17 00:00:00 2001
From: Olaf Kirch <okir@suse.de>
Date: Tue, 20 Aug 2013 09:58:51 +0200
Subject: [PATCH 08/13] Fix the behavior when specifying the -h option
Currently, when specifying the "-h" option, rpcbind will try to create
sockets for all specified addresses, plus the loopback address. However,
it will only register its programs on the last SVCXPRT created, which
will usually be the first address specified via -h.
This patch fixes this problem by introducing a new function that creates
the socket *and* registers all programs, and use that from the while
loop.
Signed-off-by: Olaf Kirch <okir@suse.de>
---
src/rpcbind.c | 79 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 43 insertions(+), 36 deletions(-)
diff --git a/src/rpcbind.c b/src/rpcbind.c
index 25d12c9..c3679e2 100644
--- a/src/rpcbind.c
+++ b/src/rpcbind.c
@@ -562,6 +562,43 @@ rpcbind_register_transport(struct netconfig *nconf, SVCXPRT *xprt, struct netbuf
}
/*
+ * This will create a server socket for the given netid, bound to the
+ * address specified by @hostname
+ *
+ * Return value:
+ * 1: success
+ * 0: error - ignore this hostname
+ * <0: error - ignore this netid
+ */
+static int
+rpcbind_init_endpoint(struct netconfig *nconf, const char *hostname)
+{
+ struct t_bind taddr;
+ SVCXPRT *my_xprt = NULL;
+ int r, fd = -1;
+
+ memset(&taddr, 0, sizeof(taddr));
+
+ r = create_transport_socket(nconf, hostname, &taddr.addr, &fd);
+ if (r <= 0)
+ return r;
+
+ my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
+ if (my_xprt == (SVCXPRT *)NULL) {
+ syslog(LOG_ERR, "%s: could not create service", nconf->nc_netid);
+ close(fd);
+ return 0;
+ }
+
+ if (!rpcbind_register_transport(nconf, my_xprt, &taddr.addr)) {
+ svc_destroy(my_xprt);
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
* Adds the entry into the rpcbind database.
* If PORTMAP, then for UDP and TCP, it adds the entries for version 2 also
* Returns 0 if succeeds, else fails
@@ -569,10 +606,7 @@ rpcbind_register_transport(struct netconfig *nconf, SVCXPRT *xprt, struct netbuf
static int
init_transport(struct netconfig *nconf)
{
- int fd = -1;
- struct t_bind taddr;
struct __rpc_sockinfo si;
- SVCXPRT *my_xprt = NULL;
int status; /* bound checking ? */
if ((nconf->nc_semantics != NC_TPI_CLTS) &&
@@ -635,42 +669,19 @@ init_transport(struct netconfig *nconf)
if (strcmp("*", hosts[nhostsbak]) == 0)
hosts[nhostsbak] = NULL;
- memset(&taddr, 0, sizeof(taddr));
-
- r = create_transport_socket(nconf, hosts[nhostsbak], &taddr.addr, &fd);
+ r = rpcbind_init_endpoint(nconf, hosts[nhostsbak]);
if (r < 0)
- goto error;
- if (r == 0)
- continue;
-
- my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr,
- RPC_MAXDATASIZE, RPC_MAXDATASIZE);
- if (my_xprt == (SVCXPRT *)NULL) {
- syslog(LOG_ERR, "%s: could not create service",
- nconf->nc_netid);
- goto error;
- }
- checkbind = 1;
- fd = -1;
+ return 1;
+ if (r > 0)
+ checkbind = 1;
}
if (!checkbind)
return 1;
} else { /* NC_TPI_COTS */
- memset(&taddr, 0, sizeof(taddr));
- if (create_transport_socket(nconf, NULL, &taddr.addr, &fd) <= 0)
- goto error;
-
- my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
- if (my_xprt == (SVCXPRT *)NULL) {
- syslog(LOG_ERR, "%s: could not create service",
- nconf->nc_netid);
- goto error;
- }
+ if (rpcbind_init_endpoint(nconf, NULL) <= 0)
+ return 1;
}
- if (!rpcbind_register_transport(nconf, my_xprt, &taddr.addr))
- return (1);
-
/*
* rmtcall only supported on CLTS transports for now.
*/
@@ -691,10 +702,6 @@ init_transport(struct netconfig *nconf)
#endif
}
return (0);
-error:
- if (fd >= 0)
- close(fd);
- return (1);
}
static void
--
1.7.12.4