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

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