diff mbox series

[2/3] Change local_rpcb() to take a targaddr pointer.

Message ID 20240311014327.19692-3-neilb@suse.de (mailing list archive)
State New, archived
Headers show
Series Support abstract addresses for rpcbind in libtirpc | expand

Commit Message

NeilBrown March 11, 2024, 1:41 a.m. UTC
One caller of local_rpcb() wants the target-addr, and local_rcpb() has
easy access to it.  So accept a pointer and fill it in if not NULL.

This will simplify a future patch in which local_rpcb() makes a choice
between different possible socket paths.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 src/rpcb_clnt.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c
index 68fe69a320ff..2ed6ee65f8d6 100644
--- a/src/rpcb_clnt.c
+++ b/src/rpcb_clnt.c
@@ -89,7 +89,7 @@  static struct address_cache *copy_of_cached(const char *, char *);
 static void delete_cache(struct netbuf *);
 static void add_cache(const char *, const char *, struct netbuf *, char *);
 static CLIENT *getclnthandle(const char *, const struct netconfig *, char **);
-static CLIENT *local_rpcb(void);
+static CLIENT *local_rpcb(char **targaddr);
 #ifdef NOTUSED
 static struct netbuf *got_entry(rpcb_entry_list_ptr, const struct netconfig *);
 #endif
@@ -430,19 +430,12 @@  getclnthandle(host, nconf, targaddr)
 	    nconf->nc_netid, si.si_af, si.si_proto, si.si_socktype));
 
 	if (nconf->nc_protofmly != NULL && strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) {
-		client = local_rpcb();
+		client = local_rpcb(targaddr);
 		if (! client) {
 			LIBTIRPC_DEBUG(1, ("getclnthandle: %s", 
 				clnt_spcreateerror("local_rpcb failed")));
 			goto out_err;
 		} else {
-			struct sockaddr_un sun;
-
-			if (targaddr) {
-				*targaddr = malloc(sizeof(sun.sun_path));
-				strncpy(*targaddr, _PATH_RPCBINDSOCK,
-				    sizeof(sun.sun_path));
-			}
 			return (client);
 		}
 	} else {
@@ -492,6 +485,8 @@  getclnthandle(host, nconf, targaddr)
 	if (res)
 		freeaddrinfo(res);
 out_err:
+	if (client && targaddr &&!*targaddr)
+		fprintf(stderr, "No targaddr provided\n");
 	if (!client && targaddr)
 		free(*targaddr);
 	return (client);
@@ -541,7 +536,8 @@  getpmaphandle(nconf, hostname, tgtaddr)
  * rpcbind. Returns NULL on error and free's everything.
  */
 static CLIENT *
-local_rpcb()
+local_rpcb(targaddr)
+	char **targaddr;
 {
 	CLIENT *client;
 	static struct netconfig *loopnconf;
@@ -574,6 +570,8 @@  local_rpcb()
 	if (client != NULL) {
 		/* Mark the socket to be closed in destructor */
 		(void) CLNT_CONTROL(client, CLSET_FD_CLOSE, NULL);
+		if (targaddr)
+			*targaddr = strdup(sun.sun_path);
 		return client;
 	}
 
@@ -632,7 +630,7 @@  try_nconf:
 		endnetconfig(nc_handle);
 	}
 	mutex_unlock(&loopnconf_lock);
-	client = getclnthandle(hostname, loopnconf, NULL);
+	client = getclnthandle(hostname, loopnconf, targaddr);
 	return (client);
 }
 
@@ -661,7 +659,7 @@  rpcb_set(program, version, nconf, address)
 		rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
 		return (FALSE);
 	}
-	client = local_rpcb();
+	client = local_rpcb(NULL);
 	if (! client) {
 		return (FALSE);
 	}
@@ -712,7 +710,7 @@  rpcb_unset(program, version, nconf)
 	RPCB parms;
 	char uidbuf[32];
 
-	client = local_rpcb();
+	client = local_rpcb(NULL);
 	if (! client) {
 		return (FALSE);
 	}
@@ -1342,7 +1340,7 @@  rpcb_taddr2uaddr(nconf, taddr)
 		rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
 		return (NULL);
 	}
-	client = local_rpcb();
+	client = local_rpcb(NULL);
 	if (! client) {
 		return (NULL);
 	}
@@ -1376,7 +1374,7 @@  rpcb_uaddr2taddr(nconf, uaddr)
 		rpc_createerr.cf_stat = RPC_UNKNOWNADDR;
 		return (NULL);
 	}
-	client = local_rpcb();
+	client = local_rpcb(NULL);
 	if (! client) {
 		return (NULL);
 	}