Blame SOURCES/autofs-5.1.1-implement-reinit-in-nisplus-lookup-module.patch

306fa1
autofs-5.1.1 - implement reinit in nisplus lookup module
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
Refactor the nisplus lookup module to add an implementation for the newly
306fa1
added reinit entry point.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 modules/lookup_nisplus.c |   83 +++++++++++++++++++++++++++++++++++-----------
306fa1
 1 file changed, 63 insertions(+), 20 deletions(-)
306fa1
306fa1
diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
306fa1
index 0c66152..5fd1d89 100644
306fa1
--- a/modules/lookup_nisplus.c
306fa1
+++ b/modules/lookup_nisplus.c
306fa1
@@ -30,25 +30,16 @@ struct lookup_context {
306fa1
 
306fa1
 int lookup_version = AUTOFS_LOOKUP_VERSION;	/* Required by protocol */
306fa1
 
306fa1
-int lookup_init(const char *mapfmt,
306fa1
-		int argc, const char *const *argv, void **context)
306fa1
+static int do_init(const char *mapfmt,
306fa1
+		   int argc, const char *const *argv,
306fa1
+		   struct lookup_context *ctxt, unsigned int reinit)
306fa1
 {
306fa1
-	struct lookup_context *ctxt;
306fa1
-	char buf[MAX_ERR_BUF];
306fa1
-
306fa1
-	*context = NULL;
306fa1
-
306fa1
-	ctxt = malloc(sizeof(struct lookup_context));
306fa1
-	if (!ctxt) {
306fa1
-		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
-		logerr(MODPREFIX "%s", estr);
306fa1
-		return 1;
306fa1
-	}
306fa1
+	int ret = 0;
306fa1
 
306fa1
 	if (argc < 1) {
306fa1
-		free(ctxt);
306fa1
 		logmsg(MODPREFIX "No map name");
306fa1
-		return 1;
306fa1
+		ret = 1;
306fa1
+		goto out;
306fa1
 	}
306fa1
 	ctxt->mapname = argv[0];
306fa1
 
306fa1
@@ -58,20 +49,50 @@ int lookup_init(const char *mapfmt,
306fa1
 	 */
306fa1
 	ctxt->domainname = nis_local_directory();
306fa1
 	if (!ctxt->domainname) {
306fa1
-		free(ctxt);
306fa1
 		logmsg(MODPREFIX "NIS+ domain not set");
306fa1
-		return 1;
306fa1
+		ret = 1;
306fa1
+		goto out;
306fa1
 	}
306fa1
 
306fa1
 	if (!mapfmt)
306fa1
 		mapfmt = MAPFMT_DEFAULT;
306fa1
 
306fa1
-	ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
306fa1
-	if (!ctxt->parse) {
306fa1
+	if (reinit) {
306fa1
+		ret = reinit_parse(ctxt->parse, mapfmt, MODPREFIX, argc, argv);
306fa1
+		if (ret)
306fa1
+			logmsg(MODPREFIX "failed to reinit parse context");
306fa1
+	} else {
306fa1
+		ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
306fa1
+		if (!ctxt->parse) {
306fa1
+			logerr(MODPREFIX "failed to open parse context");
306fa1
+			ret = 1;
306fa1
+		}
306fa1
+	}
306fa1
+out:
306fa1
+	return ret;
306fa1
+}
306fa1
+
306fa1
+int lookup_init(const char *mapfmt,
306fa1
+		int argc, const char *const *argv, void **context)
306fa1
+{
306fa1
+	struct lookup_context *ctxt;
306fa1
+	char buf[MAX_ERR_BUF];
306fa1
+
306fa1
+	*context = NULL;
306fa1
+
306fa1
+	ctxt = malloc(sizeof(struct lookup_context));
306fa1
+	if (!ctxt) {
306fa1
+		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
+		logerr(MODPREFIX "%s", estr);
306fa1
+		return 1;
306fa1
+	}
306fa1
+	memset(ctxt, 0, sizeof(struct lookup_context));
306fa1
+
306fa1
+	if (do_init(mapfmt, argc, argv, ctxt, 0)) {
306fa1
 		free(ctxt);
306fa1
-		logerr(MODPREFIX "failed to open parse context");
306fa1
 		return 1;
306fa1
 	}
306fa1
+
306fa1
 	*context = ctxt;
306fa1
 
306fa1
 	return 0;
306fa1
@@ -80,6 +101,28 @@ int lookup_init(const char *mapfmt,
306fa1
 int lookup_reinit(const char *mapfmt,
306fa1
 		  int argc, const char *const *argv, void **context)
306fa1
 {
306fa1
+	struct lookup_context *ctxt = (struct lookup_context *) *context;
306fa1
+	struct lookup_context *new;
306fa1
+	char buf[MAX_ERR_BUF];
306fa1
+	int ret;
306fa1
+
306fa1
+	new = malloc(sizeof(struct lookup_context));
306fa1
+	if (!new) {
306fa1
+		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306fa1
+		logerr(MODPREFIX "%s", estr);
306fa1
+		return 1;
306fa1
+	}
306fa1
+	memset(new, 0, sizeof(struct lookup_context));
306fa1
+
306fa1
+	new->parse = ctxt->parse;
306fa1
+	ret = do_init(mapfmt, argc, argv, new, 1);
306fa1
+	if (ret)
306fa1
+		return 1;
306fa1
+
306fa1
+	*context = new;
306fa1
+
306fa1
+	free(ctxt);
306fa1
+
306fa1
 	return 0;
306fa1
 }
306fa1