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