diff mbox series

[4/4] rpcinfo: try connecting using abstract address.

Message ID 20240225235628.12473-5-neilb@suse.de (mailing list archive)
State New
Headers show
Series Supprt abstract addresses and disable broadcast | expand

Commit Message

NeilBrown Feb. 25, 2024, 11:53 p.m. UTC
rpcinfo doesn't use library calls to set up the address for rpcbind.  So
to get to it try the new abstract address, we need to explicitly
teach it how.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 src/rpcinfo.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Petr Vorel March 4, 2024, 6:58 p.m. UTC | #1
Hi Neil, Steve,

...
>    sun.sun_family = AF_LOCAL;
> +
> +#ifdef _PATH_RPCBINDSOCK_ABSTRACT
> +  memcpy(sun.sun_path, _PATH_RPCBINDSOCK_ABSTRACT,
> +         sizeof(_PATH_RPCBINDSOCK_ABSTRACT));
> +  nbuf.len = SUN_LEN_A (&sun);
> +  nbuf.maxlen = sizeof (struct sockaddr_un);
> +  nbuf.buf = &sun;
> +
> +  clnt = clnt_vc_create (sock, &nbuf, prog, vers, 0, 0);
> +  if (clnt)
> +    return clnt;
> +#endif
> +
>    strcpy (sun.sun_path, _PATH_RPCBINDSOCK);
>    nbuf.len = SUN_LEN (&sun);
>    nbuf.maxlen = sizeof (struct sockaddr_un);
>    nbuf.buf = &sun;

> -  return clnt_vc_create (sock, &nbuf, prog, vers, 0, 0);
> +  clnt = clnt_vc_create (sock, &nbuf, prog, vers, 0, 0);
> +  return clnt;
nit: maybe keeping the original:
	 return clnt_vc_create (sock, &nbuf, prog, vers, 0, 0);

Otherwise LGTM.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Also it might be worth to remove '#if 0' part.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/src/rpcinfo.c b/src/rpcinfo.c
index 0e14f78ad2de..4464cbc0941b 100644
--- a/src/rpcinfo.c
+++ b/src/rpcinfo.c
@@ -311,6 +311,13 @@  main (int argc, char **argv)
   return (0);
 }
 
+/* Evaluate to actual length of the `sockaddr_un' structure, whether
+ * abstract or not.
+ */
+#include <stddef.h>
+#define SUN_LEN_A(ptr) (offsetof(struct sockaddr_un, sun_path)	\
+			+ 1 + strlen((ptr)->sun_path + 1))
+
 static CLIENT *
 local_rpcb (rpcprog_t prog, rpcvers_t vers)
 {
@@ -334,6 +341,7 @@  local_rpcb (rpcprog_t prog, rpcvers_t vers)
   endnetconfig(localhandle);
   return clnt;
 #else
+  CLIENT *clnt;
   struct netbuf nbuf;
   struct sockaddr_un sun;
   int sock;
@@ -344,12 +352,26 @@  local_rpcb (rpcprog_t prog, rpcvers_t vers)
     return NULL;
 
   sun.sun_family = AF_LOCAL;
+
+#ifdef _PATH_RPCBINDSOCK_ABSTRACT
+  memcpy(sun.sun_path, _PATH_RPCBINDSOCK_ABSTRACT,
+         sizeof(_PATH_RPCBINDSOCK_ABSTRACT));
+  nbuf.len = SUN_LEN_A (&sun);
+  nbuf.maxlen = sizeof (struct sockaddr_un);
+  nbuf.buf = &sun;
+
+  clnt = clnt_vc_create (sock, &nbuf, prog, vers, 0, 0);
+  if (clnt)
+    return clnt;
+#endif
+
   strcpy (sun.sun_path, _PATH_RPCBINDSOCK);
   nbuf.len = SUN_LEN (&sun);
   nbuf.maxlen = sizeof (struct sockaddr_un);
   nbuf.buf = &sun;
 
-  return clnt_vc_create (sock, &nbuf, prog, vers, 0, 0);
+  clnt = clnt_vc_create (sock, &nbuf, prog, vers, 0, 0);
+  return clnt;
 #endif
 }