File 0001-rpcb_clnt.c-config-to-try-protocolversion-2-first.patch of Package libtirpc.10729

From 63c3ce3ffebb42793bb8971fc6665f0b99c77dd3 Mon Sep 17 00:00:00 2001
From: Thomas Blume <thomas.blume@suse.com>
Date: Thu, 17 Jan 2019 08:36:58 +0100
Subject: [PATCH] rpcb_clnt.c config to try protocolversion 2 first

In some setups, it is necessary to try rpc protocol version 2 first.
Creating the file  /etc/netconfig-try-2-first wil enforce this.
---
 man/Makefile.am             |  1 +
 man/netconfig-try-2-first.7 | 18 ++++++++++++++++++
 man/netconfig.5             |  1 +
 src/rpcb_clnt.c             | 22 ++++++++++++++++++++--
 4 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 man/netconfig-try-2-first.7

diff --git a/man/Makefile.am b/man/Makefile.am
index fa43bb4..2ecad64 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -16,6 +16,7 @@ RPCSEC_MANS		= rpcsec_gss.3t rpc_gss_get_error.3t \
 			  rpc_gss_get_principal_name.3t rpc_gss_set_callback.3t \
 			  rpc_gss_set_svc_name.3t rpc_gss_svc_max_data_length.3t
 
+dist_man7_MANS          = netconfig-try-2-first.7
 dist_man5_MANS		= netconfig.5
 dist_man3_MANS		= $(LOOKUP_MANS) $(NETCONFIG_MANS) \
 			  $(BIND_MANS) $(GENERIC_MANS) $(COMPAT_MANS) \
diff --git a/man/netconfig-try-2-first.7 b/man/netconfig-try-2-first.7
new file mode 100644
index 0000000..11a5027
--- /dev/null
+++ b/man/netconfig-try-2-first.7
@@ -0,0 +1,18 @@
+.Dd January 16, 2019
+.Dt NETCONFIG-TRY-2-FIRST 7
+.Os 
+.Sh NAME
+.Nm netconfig-try-2-first
+.Nd indicator to enfore tcp protocol version 2
+.Sh SYNOPSIS
+.Pa /etc/netconfig-try-2-first
+.Sh DESCRIPTION
+libtirpc tries per default for transport UDP and TCP the rpc protocol versions
+in the sequence 4, 3, 2.
+In some setups, it is necessary to try rpc protocol version 2 first.
+Creating the file
+.Nm
+will enforce this.
+.Ed
+.Sh FILES
+/etc/netconfig-try-2-first
diff --git a/man/netconfig.5 b/man/netconfig.5
index e8dcbb2..beaf27a 100644
--- a/man/netconfig.5
+++ b/man/netconfig.5
@@ -119,5 +119,6 @@ struct netconfig {
 .It Pa /etc/netconfig
 .El
 .Sh SEE ALSO
+.Xr netconfig-try-2-first 7 ,
 .Xr getnetconfig 3 ,
 .Xr getnetpath 3
diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c
index 1c9d565..2e59b9e 100644
--- a/src/rpcb_clnt.c
+++ b/src/rpcb_clnt.c
@@ -837,6 +837,9 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
 {
 #ifdef NOTUSED
 	static bool_t check_rpcbind = TRUE;
+#endif
+#ifdef PORTMAP
+	static bool_t portmap_first = FALSE;
 #endif
 	CLIENT *client = NULL;
 	RPCB parms;
@@ -846,6 +849,7 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
 	struct netbuf *address = NULL;
 	rpcvers_t start_vers = RPCBVERS4;
 	struct netbuf servaddr;
+	FILE *fp;
 
 	/* parameter checking */
 	if (nconf == NULL) {
@@ -893,8 +897,19 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
 		parms.r_addr = (char *) &nullstring[0];
 	}
 
-	/* First try from start_vers(4) and then version 3 (RPCBVERS) */
 
+#ifdef PORTMAP
+	/*enforce protocol version 2 if file exists */
+	fp = fopen ("/etc/netconfig-try-2-first", "r");
+	if (fp != NULL) {
+		portmap_first = TRUE;
+			goto portmap;
+	}
+#endif
+
+rpcbind:
+	/* First try from start_vers(4) and then version 3 (RPCBVERS) */
+	portmap_first = FALSE;
 	CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *) &rpcbrmttime);
 	for (vers = start_vers;  vers >= RPCBVERS; vers--) {
 		/* Set the version */
@@ -937,10 +952,13 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
 		}
 	}
 
+portmap:
 #ifdef PORTMAP 	/* Try version 2 for TCP or UDP */
 	if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
 		address = __try_protocol_version_2(program, version, nconf, host, tp);
-		if (address == NULL)
+		if (address == NULL && portmap_first)
+			goto rpcbind;
+		else
 			goto error;
 	}
 #endif		/* PORTMAP */
-- 
2.16.4

openSUSE Build Service is sponsored by