Blame SOURCES/autofs-5.1.6-refactor-sss-setautomntent.patch

63b9c2
autofs-5.1.6 - refactor sss setautomntent()
63b9c2
63b9c2
From: Ian Kent <raven@themaw.net>
63b9c2
63b9c2
Refactor the sss setautomntent() to consolidate the error handling in
63b9c2
one location.
63b9c2
63b9c2
Also move the number of retries calculation into the wait function
63b9c2
as it's a much more sensible place for it.
63b9c2
63b9c2
Signed-off-by: Ian Kent <raven@themaw.net>
63b9c2
---
63b9c2
 CHANGELOG            |    1 
63b9c2
 modules/lookup_sss.c |  106 +++++++++++++++++++++++---------------------------
63b9c2
 2 files changed, 49 insertions(+), 58 deletions(-)
63b9c2
63b9c2
diff --git a/CHANGELOG b/CHANGELOG
63b9c2
index b3ffbb6..141658d 100644
63b9c2
--- a/CHANGELOG
63b9c2
+++ b/CHANGELOG
63b9c2
@@ -98,6 +98,7 @@ xx/xx/2018 autofs-5.1.5
63b9c2
 - use mapname in sss context for setautomntent().
63b9c2
 - add support for new sss autofs proto version call.
63b9c2
 - fix retries check in setautomntent_wait().
63b9c2
+- refactor sss setautomntent().
63b9c2
 
63b9c2
 19/12/2017 autofs-5.1.4
63b9c2
 - fix spec file url.
63b9c2
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
63b9c2
index d65e71c..011b232 100644
63b9c2
--- a/modules/lookup_sss.c
63b9c2
+++ b/modules/lookup_sss.c
63b9c2
@@ -232,20 +232,6 @@ int lookup_reinit(const char *mapfmt,
63b9c2
 	return 0;
63b9c2
 }
63b9c2
 
63b9c2
-static int setautomntent(unsigned int logopt,
63b9c2
-			 struct lookup_context *ctxt, void **sss_ctxt)
63b9c2
-{
63b9c2
-	int ret = ctxt->setautomntent(ctxt->mapname, sss_ctxt);
63b9c2
-	if (ret) {
63b9c2
-		char buf[MAX_ERR_BUF];
63b9c2
-		char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
63b9c2
-		error(logopt, MODPREFIX "setautomntent: %s", estr);
63b9c2
-		if (*sss_ctxt)
63b9c2
-			free(*sss_ctxt);
63b9c2
-	}
63b9c2
-	return ret;
63b9c2
-}
63b9c2
-
63b9c2
 static unsigned int proto_version(struct lookup_context *ctxt)
63b9c2
 {
63b9c2
 	unsigned int proto_version = 0;
63b9c2
@@ -264,14 +250,18 @@ static unsigned int proto_version(struct lookup_context *ctxt)
63b9c2
 }
63b9c2
 
63b9c2
 static int setautomntent_wait(unsigned int logopt,
63b9c2
-			      struct lookup_context *ctxt,
63b9c2
-			      void **sss_ctxt, unsigned int retries)
63b9c2
+			      struct lookup_context *ctxt, void **sss_ctxt)
63b9c2
 {
63b9c2
+	unsigned int retries;
63b9c2
 	unsigned int retry = 0;
63b9c2
 	int ret = 0;
63b9c2
 
63b9c2
 	*sss_ctxt = NULL;
63b9c2
 
63b9c2
+	retries = defaults_get_sss_master_map_wait();
63b9c2
+	if (retries <= 0)
63b9c2
+		return ENOENT;
63b9c2
+
63b9c2
 	while (++retry <= retries) {
63b9c2
 		struct timespec t = { SSS_WAIT_INTERVAL, 0 };
63b9c2
 		struct timespec r;
63b9c2
@@ -291,9 +281,6 @@ static int setautomntent_wait(unsigned int logopt,
63b9c2
 
63b9c2
 
63b9c2
 	if (ret) {
63b9c2
-		char buf[MAX_ERR_BUF];
63b9c2
-		char *estr;
63b9c2
-
63b9c2
 		if (*sss_ctxt) {
63b9c2
 			free(*sss_ctxt);
63b9c2
 			*sss_ctxt = NULL;
63b9c2
@@ -301,14 +288,47 @@ static int setautomntent_wait(unsigned int logopt,
63b9c2
 
63b9c2
 		if (retry > retries)
63b9c2
 			ret = ETIMEDOUT;
63b9c2
-
63b9c2
-		estr = strerror_r(ret, buf, MAX_ERR_BUF);
63b9c2
-		error(logopt, MODPREFIX "setautomntent: %s", estr);
63b9c2
 	}
63b9c2
 
63b9c2
 	return ret;
63b9c2
 }
63b9c2
 
63b9c2
+static int setautomntent(unsigned int logopt,
63b9c2
+			 struct lookup_context *ctxt, void **sss_ctxt)
63b9c2
+{
63b9c2
+	char buf[MAX_ERR_BUF];
63b9c2
+	char *estr;
63b9c2
+	int ret;
63b9c2
+
63b9c2
+	ret = ctxt->setautomntent(ctxt->mapname, sss_ctxt);
63b9c2
+	if (ret) {
63b9c2
+		if (ret == ECONNREFUSED)
63b9c2
+			return NSS_STATUS_UNKNOWN;
63b9c2
+
63b9c2
+		if (ret != ENOENT)
63b9c2
+			goto error;
63b9c2
+
63b9c2
+		ret = setautomntent_wait(logopt, ctxt, sss_ctxt);
63b9c2
+		if (ret) {
63b9c2
+			if (ret == ECONNREFUSED)
63b9c2
+				return NSS_STATUS_UNKNOWN;
63b9c2
+			if (ret == ENOENT)
63b9c2
+				return NSS_STATUS_NOTFOUND;
63b9c2
+			goto error;
63b9c2
+		}
63b9c2
+	}
63b9c2
+	return ret;
63b9c2
+
63b9c2
+error:
63b9c2
+	estr = strerror_r(ret, buf, MAX_ERR_BUF);
63b9c2
+	error(logopt, MODPREFIX "setautomntent: %s", estr);
63b9c2
+	if (*sss_ctxt) {
63b9c2
+		free(*sss_ctxt);
63b9c2
+		*sss_ctxt = NULL;
63b9c2
+	}
63b9c2
+	return NSS_STATUS_UNAVAIL;
63b9c2
+}
63b9c2
+
63b9c2
 static int endautomntent(unsigned int logopt,
63b9c2
 			 struct lookup_context *ctxt, void **sss_ctxt)
63b9c2
 {
63b9c2
@@ -336,28 +356,8 @@ int lookup_read_master(struct master *master, time_t age, void *context)
63b9c2
 	int count, ret;
63b9c2
 
63b9c2
 	ret = setautomntent(logopt, ctxt, &sss_ctxt);
63b9c2
-	if (ret) {
63b9c2
-		unsigned int retries;
63b9c2
-
63b9c2
-		if (ret == ECONNREFUSED)
63b9c2
-			return NSS_STATUS_UNKNOWN;
63b9c2
-
63b9c2
-		if (ret != ENOENT)
63b9c2
-			return NSS_STATUS_UNAVAIL;
63b9c2
-
63b9c2
-		retries = defaults_get_sss_master_map_wait();
63b9c2
-		if (retries <= 0)
63b9c2
-			return NSS_STATUS_NOTFOUND;
63b9c2
-
63b9c2
-		ret = setautomntent_wait(logopt, ctxt, &sss_ctxt, retries);
63b9c2
-		if (ret) {
63b9c2
-			if (ret == ECONNREFUSED)
63b9c2
-				return NSS_STATUS_UNKNOWN;
63b9c2
-			if (ret == ENOENT)
63b9c2
-				return NSS_STATUS_NOTFOUND;
63b9c2
-			return NSS_STATUS_UNAVAIL;
63b9c2
-		}
63b9c2
-	}
63b9c2
+	if (ret)
63b9c2
+		return ret;
63b9c2
 
63b9c2
 	count = 0;
63b9c2
 	while (1) {
63b9c2
@@ -459,13 +459,8 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
63b9c2
 	}
63b9c2
 
63b9c2
 	ret = setautomntent(ap->logopt, ctxt, &sss_ctxt);
63b9c2
-	if (ret) {
63b9c2
-		if (ret == ECONNREFUSED)
63b9c2
-			return NSS_STATUS_UNKNOWN;
63b9c2
-		if (ret == ENOENT)
63b9c2
-			return NSS_STATUS_NOTFOUND;
63b9c2
-		return NSS_STATUS_UNAVAIL;
63b9c2
-	}
63b9c2
+	if (ret)
63b9c2
+		return ret;
63b9c2
 
63b9c2
 	count = 0;
63b9c2
 	while (1) {
63b9c2
@@ -571,13 +566,8 @@ static int lookup_one(struct autofs_point *ap,
63b9c2
 	mc = source->mc;
63b9c2
 
63b9c2
 	ret = setautomntent(ap->logopt, ctxt, &sss_ctxt);
63b9c2
-	if (ret) {
63b9c2
-		if (ret == ECONNREFUSED)
63b9c2
-			return NSS_STATUS_UNKNOWN;
63b9c2
-		if (ret == ENOENT)
63b9c2
-			return NSS_STATUS_NOTFOUND;
63b9c2
-		return NSS_STATUS_UNAVAIL;
63b9c2
-	}
63b9c2
+	if (ret)
63b9c2
+		return ret;
63b9c2
 
63b9c2
 	ret = ctxt->getautomntbyname_r(qKey, &value, sss_ctxt);
63b9c2
 	if (ret && ret != ENOENT) {