Blame SOURCES/autofs-5.1.7-add-xdr_exports.patch

96dc52
autofs-5.1.7 - add xdr_exports()
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
Add an xdr_exports() function to get NFS exports from a server.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG              |    3 +
96dc52
 include/rpc_subs.h     |   14 ++++++
96dc52
 lib/rpc_subs.c         |  120 +++++++++++++++++++++++++++++++++++-------------
96dc52
 modules/lookup_hosts.c |   25 +++-------
96dc52
 4 files changed, 112 insertions(+), 50 deletions(-)
96dc52
96dc52
diff --git a/CHANGELOG b/CHANGELOG
96dc52
index 2c48484b..84050e91 100644
96dc52
--- a/CHANGELOG
96dc52
+++ b/CHANGELOG
96dc52
@@ -1,3 +1,6 @@
96dc52
+
96dc52
+- add xdr_exports().
96dc52
+
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
 - update ldap READMEs and schema definitions.
96dc52
diff --git a/include/rpc_subs.h b/include/rpc_subs.h
96dc52
index 7ba4b93f..080f19d9 100644
96dc52
--- a/include/rpc_subs.h
96dc52
+++ b/include/rpc_subs.h
96dc52
@@ -17,6 +17,7 @@
96dc52
 #define _RPC_SUBS_H
96dc52
 
96dc52
 #include <rpc/rpc.h>
96dc52
+#include <rpc/types.h>
96dc52
 #include <rpc/pmap_prot.h>
96dc52
 #include <linux/nfs.h>
96dc52
 #include <linux/nfs2.h>
96dc52
@@ -47,6 +48,17 @@
96dc52
 
96dc52
 #define HOST_ENT_BUF_SIZE       2048
96dc52
 
96dc52
+struct hostinfo {
96dc52
+	char *name;
96dc52
+	struct hostinfo *next;
96dc52
+};
96dc52
+
96dc52
+struct exportinfo {
96dc52
+	char *dir;
96dc52
+	struct hostinfo *hosts;
96dc52
+	struct exportinfo *next;
96dc52
+};
96dc52
+
96dc52
 struct conn_info {
96dc52
 	const char *host;
96dc52
 	struct sockaddr *addr;
96dc52
@@ -71,6 +83,8 @@ int rpc_portmap_getport(struct conn_info *, struct pmap *, unsigned short *);
96dc52
 int rpc_ping_proto(struct conn_info *);
96dc52
 int rpc_ping(const char *, int, unsigned int, long, long, unsigned int);
96dc52
 double monotonic_elapsed(struct timespec, struct timespec);
96dc52
+struct exportinfo *rpc_get_exports(const char *host, long seconds, long micros, unsigned int option);
96dc52
+void rpc_exports_free(struct exportinfo *exports);
96dc52
 const char *get_addr_string(struct sockaddr *, char *, socklen_t);
96dc52
 
96dc52
 #endif
96dc52
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
96dc52
index 643b7687..7b8162b4 100644
96dc52
--- a/lib/rpc_subs.c
96dc52
+++ b/lib/rpc_subs.c
96dc52
@@ -41,7 +41,6 @@ const rpcprog_t rpcb_prog = PMAPPROG;
96dc52
 const rpcvers_t rpcb_version = PMAPVERS;
96dc52
 #endif
96dc52
 
96dc52
-#include "mount.h"
96dc52
 #include "rpc_subs.h"
96dc52
 #include "replicated.h"
96dc52
 #include "automount.h"
96dc52
@@ -58,6 +57,17 @@ const rpcvers_t rpcb_version = PMAPVERS;
96dc52
 
96dc52
 #define MAX_NETWORK_LEN		255
96dc52
 
96dc52
+#define EXPPATHLEN 1024
96dc52
+#define EXPNAMELEN 255
96dc52
+
96dc52
+#define MOUNTPROG 100005
96dc52
+
96dc52
+#define MOUNTVERS	1
96dc52
+#define MOUNTVERS_NFSV3 3
96dc52
+#define MOUNTVERS_POSIX 2
96dc52
+
96dc52
+#define MOUNTPROC_EXPORT 5
96dc52
+
96dc52
 /* Get numeric value of the n bits starting at position p */
96dc52
 #define getbits(x, p, n)      ((x >> (p + 1 - n)) & ~(~0 << n))
96dc52
 
96dc52
@@ -1102,7 +1112,55 @@ double monotonic_elapsed(struct timespec start, struct timespec end)
96dc52
 	return t2 - t1;
96dc52
 }
96dc52
 
96dc52
-static int rpc_get_exports_proto(struct conn_info *info, exports *exp)
96dc52
+static bool_t xdr_host(XDR *xdrs, struct hostinfo *host)
96dc52
+{
96dc52
+	if (!xdr_string(xdrs, &host->name, EXPNAMELEN))
96dc52
+		return FALSE;
96dc52
+	return TRUE;
96dc52
+}
96dc52
+
96dc52
+static bool_t xdr_hosts(XDR *xdrs, struct hostinfo **hosts)
96dc52
+{
96dc52
+	unsigned int size = sizeof(struct hostinfo);
96dc52
+	char **host;
96dc52
+
96dc52
+	host = (char **) hosts;
96dc52
+	while (1) {
96dc52
+		if (!xdr_pointer(xdrs, host, size, (xdrproc_t) xdr_host))
96dc52
+			return FALSE;
96dc52
+		if (!*host)
96dc52
+			break;
96dc52
+		host = (char **) &((struct hostinfo *) *host)->next;
96dc52
+	}
96dc52
+	return TRUE;
96dc52
+}
96dc52
+
96dc52
+static bool_t xdr_export(XDR *xdrs, struct exportinfo *export)
96dc52
+{
96dc52
+	if (!xdr_string(xdrs, &export->dir, EXPPATHLEN))
96dc52
+		return FALSE;
96dc52
+	if (!xdr_hosts(xdrs, &export->hosts))
96dc52
+		return FALSE;
96dc52
+	return TRUE;
96dc52
+}
96dc52
+
96dc52
+bool_t xdr_exports(XDR *xdrs, struct exportinfo **exports)
96dc52
+{
96dc52
+	unsigned int size = sizeof(struct exportinfo);
96dc52
+	char **export;
96dc52
+
96dc52
+	export = (char **) exports;
96dc52
+	while (1) {
96dc52
+		if (!xdr_pointer(xdrs, export, size, (xdrproc_t) xdr_export))
96dc52
+			return FALSE;
96dc52
+		if (!*export)
96dc52
+			break;
96dc52
+		export = (char **) &((struct exportinfo *) *export)->next;
96dc52
+	}
96dc52
+	return TRUE;
96dc52
+}
96dc52
+
96dc52
+static int rpc_get_exports_proto(struct conn_info *info, struct exportinfo **exports)
96dc52
 {
96dc52
 	CLIENT *client;
96dc52
 	enum clnt_stat status;
96dc52
@@ -1133,7 +1191,7 @@ static int rpc_get_exports_proto(struct conn_info *info, exports *exp)
96dc52
 	while (1) {
96dc52
 		status = clnt_call(client, MOUNTPROC_EXPORT,
96dc52
 				 (xdrproc_t) xdr_void, NULL,
96dc52
-				 (xdrproc_t) xdr_exports, (caddr_t) exp,
96dc52
+				 (xdrproc_t) xdr_exports, (caddr_t) exports,
96dc52
 				 info->timeout);
96dc52
 		if (status == RPC_SUCCESS)
96dc52
 			break;
96dc52
@@ -1168,41 +1226,43 @@ static int rpc_get_exports_proto(struct conn_info *info, exports *exp)
96dc52
 	return 1;
96dc52
 }
96dc52
 
96dc52
-static void rpc_export_free(exports item)
96dc52
+static void rpc_export_free(struct exportinfo *export)
96dc52
 {
96dc52
-	groups grp;
96dc52
-	groups tmp;
96dc52
-
96dc52
-	if (item->ex_dir)
96dc52
-		free(item->ex_dir);
96dc52
-
96dc52
-	grp = item->ex_groups;
96dc52
-	while (grp) {
96dc52
-		if (grp->gr_name)
96dc52
-			free(grp->gr_name);
96dc52
-		tmp = grp;
96dc52
-		grp = grp->gr_next;
96dc52
+	struct hostinfo *host, *tmp;
96dc52
+
96dc52
+	if (export->dir)
96dc52
+		free(export->dir);
96dc52
+
96dc52
+	host = export->hosts;
96dc52
+	while (host) {
96dc52
+		if (host->name)
96dc52
+			free(host->name);
96dc52
+		tmp = host;
96dc52
+		host = host->next;
96dc52
 		free(tmp);
96dc52
 	}
96dc52
-	free(item);
96dc52
+	free(export);
96dc52
 }
96dc52
 
96dc52
-void rpc_exports_free(exports list)
96dc52
+void rpc_exports_free(struct exportinfo *exports)
96dc52
 {
96dc52
-	exports tmp;
96dc52
+	struct exportinfo *export, *tmp;
96dc52
 
96dc52
-	while (list) {
96dc52
-		tmp = list;
96dc52
-		list = list->ex_next;
96dc52
+	export = exports;
96dc52
+	while (export) {
96dc52
+		tmp = export;
96dc52
+		export = export->next;
96dc52
 		rpc_export_free(tmp);
96dc52
 	}
96dc52
 	return;
96dc52
 }
96dc52
 
96dc52
-exports rpc_get_exports(const char *host, long seconds, long micros, unsigned int option)
96dc52
+struct exportinfo *rpc_get_exports(const char *host,
96dc52
+				   long seconds, long micros,
96dc52
+				   unsigned int option)
96dc52
 {
96dc52
 	struct conn_info info;
96dc52
-	exports exportlist;
96dc52
+	struct exportinfo *exports = NULL;
96dc52
 	struct pmap parms;
96dc52
 	int status;
96dc52
 
96dc52
@@ -1231,11 +1291,9 @@ exports rpc_get_exports(const char *host, long seconds, long micros, unsigned in
96dc52
 	if (status < 0)
96dc52
 		goto try_tcp;
96dc52
 
96dc52
-	memset(&exportlist, '\0', sizeof(exportlist));
96dc52
-
96dc52
-	status = rpc_get_exports_proto(&info, &exportlist);
96dc52
+	status = rpc_get_exports_proto(&info, &exports);
96dc52
 	if (status)
96dc52
-		return exportlist;
96dc52
+		return exports;
96dc52
 
96dc52
 try_tcp:
96dc52
 	info.proto = IPPROTO_TCP;
96dc52
@@ -1246,13 +1304,11 @@ try_tcp:
96dc52
 	if (status < 0)
96dc52
 		return NULL;
96dc52
 
96dc52
-	memset(&exportlist, '\0', sizeof(exportlist));
96dc52
-
96dc52
-	status = rpc_get_exports_proto(&info, &exportlist);
96dc52
+	status = rpc_get_exports_proto(&info, &exports);
96dc52
 	if (!status)
96dc52
 		return NULL;
96dc52
 
96dc52
-	return exportlist;
96dc52
+	return exports;
96dc52
 }
96dc52
 
96dc52
 const char *get_addr_string(struct sockaddr *sa, char *name, socklen_t len)
96dc52
diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c
96dc52
index 744062e2..81a4eb18 100644
96dc52
--- a/modules/lookup_hosts.c
96dc52
+++ b/modules/lookup_hosts.c
96dc52
@@ -20,14 +20,6 @@
96dc52
 #include <sys/stat.h>
96dc52
 #include <netdb.h>
96dc52
 
96dc52
-/* 
96dc52
- * Avoid annoying compiler noise by using an alternate name for
96dc52
- * typedef name in mount.h
96dc52
- */
96dc52
-#define name __dummy_type_name
96dc52
-#include "mount.h"
96dc52
-#undef name
96dc52
-
96dc52
 #define MODULE_LOOKUP
96dc52
 #include "automount.h"
96dc52
 #include "nsswitch.h"
96dc52
@@ -43,9 +35,6 @@ struct lookup_context {
96dc52
 
96dc52
 int lookup_version = AUTOFS_LOOKUP_VERSION;	/* Required by protocol */
96dc52
 
96dc52
-exports rpc_get_exports(const char *host, long seconds, long micros, unsigned int option);
96dc52
-void rpc_exports_free(exports list);
96dc52
-
96dc52
 int lookup_init(const char *mapfmt,
96dc52
 		int argc, const char *const *argv, void **context)
96dc52
 {
96dc52
@@ -99,7 +88,7 @@ static char *get_exports(struct autofs_point *ap, const char *host)
96dc52
 {
96dc52
 	char buf[MAX_ERR_BUF];
96dc52
 	char *mapent;
96dc52
-	exports exp, this;
96dc52
+	struct exportinfo *exp, *this;
96dc52
 
96dc52
 	debug(ap->logopt, MODPREFIX "fetchng export list for %s", host);
96dc52
 
96dc52
@@ -111,7 +100,7 @@ static char *get_exports(struct autofs_point *ap, const char *host)
96dc52
 		if (mapent) {
96dc52
 			int len = strlen(mapent) + 1;
96dc52
 
96dc52
-			len += strlen(host) + 2*(strlen(this->ex_dir) + 2) + 3;
96dc52
+			len += strlen(host) + 2*(strlen(this->dir) + 2) + 3;
96dc52
 			mapent = realloc(mapent, len);
96dc52
 			if (!mapent) {
96dc52
 				char *estr;
96dc52
@@ -121,10 +110,10 @@ static char *get_exports(struct autofs_point *ap, const char *host)
96dc52
 				return NULL;
96dc52
 			}
96dc52
 			strcat(mapent, " \"");
96dc52
-			strcat(mapent, this->ex_dir);
96dc52
+			strcat(mapent, this->dir);
96dc52
 			strcat(mapent, "\"");
96dc52
 		} else {
96dc52
-			int len = 2*(strlen(this->ex_dir) + 2) + strlen(host) + 3;
96dc52
+			int len = 2*(strlen(this->dir) + 2) + strlen(host) + 3;
96dc52
 
96dc52
 			mapent = malloc(len);
96dc52
 			if (!mapent) {
96dc52
@@ -135,16 +124,16 @@ static char *get_exports(struct autofs_point *ap, const char *host)
96dc52
 				return NULL;
96dc52
 			}
96dc52
 			strcpy(mapent, "\"");
96dc52
-			strcat(mapent, this->ex_dir);
96dc52
+			strcat(mapent, this->dir);
96dc52
 			strcat(mapent, "\"");
96dc52
 		}
96dc52
 		strcat(mapent, " \"");
96dc52
 		strcat(mapent, host);
96dc52
 		strcat(mapent, ":");
96dc52
-		strcat(mapent, this->ex_dir);
96dc52
+		strcat(mapent, this->dir);
96dc52
 		strcat(mapent, "\"");
96dc52
 
96dc52
-		this = this->ex_next;
96dc52
+		this = this->next;
96dc52
 	}
96dc52
 	rpc_exports_free(exp);
96dc52