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

1b50e3
autofs-5.1.6 - refactor sss getautomntent()
1b50e3
1b50e3
From: Ian Kent <raven@themaw.net>
1b50e3
1b50e3
Refactor the sss getautomntent_r() to consolidate the error handling in
1b50e3
one location.
1b50e3
1b50e3
Also add the missing ECONREFUSED handling while we are at it.
1b50e3
1b50e3
Signed-off-by: Ian Kent <raven@themaw.net>
1b50e3
---
1b50e3
 CHANGELOG            |    1 +
1b50e3
 modules/lookup_sss.c |   88 +++++++++++++++++++++++---------------------------
1b50e3
 2 files changed, 42 insertions(+), 47 deletions(-)
1b50e3
1b50e3
diff --git a/CHANGELOG b/CHANGELOG
1b50e3
index 5ccd787..ecd54e9 100644
1b50e3
--- a/CHANGELOG
1b50e3
+++ b/CHANGELOG
1b50e3
@@ -100,6 +100,7 @@ xx/xx/2018 autofs-5.1.5
1b50e3
 - fix retries check in setautomntent_wait().
1b50e3
 - refactor sss setautomntent().
1b50e3
 - improve sss setautomntent() error handling.
1b50e3
+- refactor sss getautomntent().
1b50e3
 
1b50e3
 19/12/2017 autofs-5.1.4
1b50e3
 - fix spec file url.
1b50e3
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
1b50e3
index e1ed83c..5addd87 100644
1b50e3
--- a/modules/lookup_sss.c
1b50e3
+++ b/modules/lookup_sss.c
1b50e3
@@ -377,6 +377,40 @@ static int endautomntent(unsigned int logopt,
1b50e3
 	return ret;
1b50e3
 }
1b50e3
 
1b50e3
+static int getautomntent(unsigned int logopt,
1b50e3
+			 struct lookup_context *ctxt,
1b50e3
+			 char **key, char **value, int count, void *sss_ctxt)
1b50e3
+{
1b50e3
+	char buf[MAX_ERR_BUF];
1b50e3
+	char *estr;
1b50e3
+	int ret = NSS_STATUS_UNAVAIL;
1b50e3
+
1b50e3
+	ret = ctxt->getautomntent_r(key, value, sss_ctxt);
1b50e3
+	if (ret) {
1b50e3
+		/* Host has gone down */
1b50e3
+		if (ret == ECONNREFUSED)
1b50e3
+			return NSS_STATUS_UNKNOWN;
1b50e3
+		if (ret != ENOENT)
1b50e3
+			goto error;
1b50e3
+		if (!count) {
1b50e3
+			ret = NSS_STATUS_NOTFOUND;
1b50e3
+			goto free;
1b50e3
+		}
1b50e3
+		goto error;
1b50e3
+	}
1b50e3
+	return ret;
1b50e3
+
1b50e3
+error:
1b50e3
+	estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
+	error(logopt, MODPREFIX "getautomntent: %s", estr);
1b50e3
+free:
1b50e3
+	if (*key)
1b50e3
+		free(*key);
1b50e3
+	if (*value)
1b50e3
+		free(*value);
1b50e3
+	return ret;
1b50e3
+}
1b50e3
+
1b50e3
 int lookup_read_master(struct master *master, time_t age, void *context)
1b50e3
 {
1b50e3
 	struct lookup_context *ctxt = (struct lookup_context *) context;
1b50e3
@@ -399,30 +433,12 @@ int lookup_read_master(struct master *master, time_t age, void *context)
1b50e3
 	while (1) {
1b50e3
 	        key = NULL;
1b50e3
 	        value = NULL;
1b50e3
-		ret = ctxt->getautomntent_r(&key, &value, sss_ctxt);
1b50e3
-		if (ret && ret != ENOENT) {
1b50e3
-			char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
-			error(logopt, MODPREFIX "getautomntent_r: %s", estr);
1b50e3
+		ret = getautomntent(logopt, ctxt, &key, &value, count, sss_ctxt);
1b50e3
+		if (ret) {
1b50e3
 			endautomntent(logopt, ctxt, &sss_ctxt);
1b50e3
-			if (key)
1b50e3
-				free(key);
1b50e3
-			if (value)
1b50e3
-				free(value);
1b50e3
-			return NSS_STATUS_UNAVAIL;
1b50e3
-		}
1b50e3
-		if (ret == ENOENT) {
1b50e3
-			if (!count) {
1b50e3
-				char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
-				error(logopt, MODPREFIX "getautomntent_r: %s", estr);
1b50e3
-				endautomntent(logopt, ctxt, &sss_ctxt);
1b50e3
-				if (key)
1b50e3
-					free(key);
1b50e3
-				if (value)
1b50e3
-					free(value);
1b50e3
-				return NSS_STATUS_NOTFOUND;
1b50e3
-			}
1b50e3
-			break;
1b50e3
+			return ret;
1b50e3
 		}
1b50e3
+
1b50e3
 		count++;
1b50e3
 
1b50e3
 		buffer_len = strlen(key) + 1 + strlen(value) + 2;
1b50e3
@@ -470,7 +486,6 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
1b50e3
 	struct map_source *source;
1b50e3
 	struct mapent_cache *mc;
1b50e3
 	void *sss_ctxt = NULL;
1b50e3
-	char buf[MAX_ERR_BUF];
1b50e3
 	char *key;
1b50e3
 	char *value = NULL;
1b50e3
 	char *s_key;
1b50e3
@@ -502,31 +517,10 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
1b50e3
 	while (1) {
1b50e3
 	        key = NULL;
1b50e3
 	        value = NULL;
1b50e3
-		ret = ctxt->getautomntent_r(&key, &value, sss_ctxt);
1b50e3
-		if (ret && ret != ENOENT) {
1b50e3
-			char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
-			error(ap->logopt,
1b50e3
-			      MODPREFIX "getautomntent_r: %s", estr);
1b50e3
+		ret = getautomntent(ap->logopt, ctxt, &key, &value, count, sss_ctxt);
1b50e3
+		if (ret) {
1b50e3
 			endautomntent(ap->logopt, ctxt, &sss_ctxt);
1b50e3
-			if (key)
1b50e3
-				free(key);
1b50e3
-			if (value)
1b50e3
-				free(value);
1b50e3
-			return NSS_STATUS_UNAVAIL;
1b50e3
-		}
1b50e3
-		if (ret == ENOENT) {
1b50e3
-			if (!count) {
1b50e3
-				char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
1b50e3
-				error(ap->logopt,
1b50e3
-				      MODPREFIX "getautomntent_r: %s", estr);
1b50e3
-				endautomntent(ap->logopt, ctxt, &sss_ctxt);
1b50e3
-				if (key)
1b50e3
-					free(key);
1b50e3
-				if (value)
1b50e3
-					free(value);
1b50e3
-				return NSS_STATUS_NOTFOUND;
1b50e3
-			}
1b50e3
-			break;
1b50e3
+			return ret;
1b50e3
 		}
1b50e3
 
1b50e3
 		/*