Blame SOURCES/autofs-5.1.6-improve-sss-setautomntent-error-handling.patch

d702dc
autofs-5.1.6 - improve sss setautomntent() error handling
d702dc
d702dc
From: Ian Kent <raven@themaw.net>
d702dc
d702dc
Recent versions of the sss autofs access library will return EHOSTDOWN
d702dc
if the backend server is down.
d702dc
d702dc
The presence of this improvement in error handling is determined by an
d702dc
added function to get the sss autofs protocol version.
d702dc
d702dc
Update the setautomntent() function to use this.
d702dc
d702dc
Signed-off-by: Ian Kent <raven@themaw.net>
d702dc
---
d702dc
 CHANGELOG            |    1 +
d702dc
 modules/lookup_sss.c |   72 ++++++++++++++++++++++++++++++++++++++------------
d702dc
 2 files changed, 55 insertions(+), 18 deletions(-)
d702dc
d702dc
diff --git a/CHANGELOG b/CHANGELOG
d702dc
index 141658d..5ccd787 100644
d702dc
--- a/CHANGELOG
d702dc
+++ b/CHANGELOG
d702dc
@@ -99,6 +99,7 @@ xx/xx/2018 autofs-5.1.5
d702dc
 - add support for new sss autofs proto version call.
d702dc
 - fix retries check in setautomntent_wait().
d702dc
 - refactor sss setautomntent().
d702dc
+- improve sss setautomntent() error handling.
d702dc
 
d702dc
 19/12/2017 autofs-5.1.4
d702dc
 - fix spec file url.
d702dc
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
d702dc
index 011b232..e1ed83c 100644
d702dc
--- a/modules/lookup_sss.c
d702dc
+++ b/modules/lookup_sss.c
d702dc
@@ -259,16 +259,37 @@ static int setautomntent_wait(unsigned int logopt,
d702dc
 	*sss_ctxt = NULL;
d702dc
 
d702dc
 	retries = defaults_get_sss_master_map_wait();
d702dc
-	if (retries <= 0)
d702dc
-		return ENOENT;
d702dc
+
d702dc
+	/* If sss_master_map_wait is not set in the autofs
d702dc
+	 * configuration give it a sensible value since we
d702dc
+	 * want to wait for a host that's down in case it
d702dc
+	 * comes back up.
d702dc
+	 */
d702dc
+	if (retries <= 0) {
d702dc
+		/* Protocol version 0 cant't tell us about
d702dc
+		 * a host being down, return not found.
d702dc
+		 */
d702dc
+		if (proto_version(ctxt) == 0)
d702dc
+			return ENOENT;
d702dc
+		retries = 10;
d702dc
+	}
d702dc
+
d702dc
+	warn(logopt,
d702dc
+	     "can't connect to sssd, retry for %d seconds",
d702dc
+	     retries);
d702dc
 
d702dc
 	while (++retry <= retries) {
d702dc
 		struct timespec t = { SSS_WAIT_INTERVAL, 0 };
d702dc
 		struct timespec r;
d702dc
 
d702dc
 		ret = ctxt->setautomntent(ctxt->mapname, sss_ctxt);
d702dc
-		if (ret != ENOENT)
d702dc
-			break;
d702dc
+		if (proto_version(ctxt) == 0) {
d702dc
+			if (ret != ENOENT)
d702dc
+				break;
d702dc
+		} else {
d702dc
+			if (ret != EHOSTDOWN)
d702dc
+				break;
d702dc
+		}
d702dc
 
d702dc
 		if (*sss_ctxt) {
d702dc
 			free(*sss_ctxt);
d702dc
@@ -279,17 +300,17 @@ static int setautomntent_wait(unsigned int logopt,
d702dc
 			memcpy(&t, &r, sizeof(struct timespec));
d702dc
 	}
d702dc
 
d702dc
-
d702dc
-	if (ret) {
d702dc
+	if (!ret)
d702dc
+		info(logopt, "successfully connected to sssd");
d702dc
+	else {
d702dc
 		if (*sss_ctxt) {
d702dc
 			free(*sss_ctxt);
d702dc
 			*sss_ctxt = NULL;
d702dc
 		}
d702dc
 
d702dc
-		if (retry > retries)
d702dc
+		if (proto_version(ctxt) == 0 && retry > retries)
d702dc
 			ret = ETIMEDOUT;
d702dc
 	}
d702dc
-
d702dc
 	return ret;
d702dc
 }
d702dc
 
d702dc
@@ -298,35 +319,50 @@ static int setautomntent(unsigned int logopt,
d702dc
 {
d702dc
 	char buf[MAX_ERR_BUF];
d702dc
 	char *estr;
d702dc
+	int err = NSS_STATUS_UNAVAIL;
d702dc
 	int ret;
d702dc
 
d702dc
 	ret = ctxt->setautomntent(ctxt->mapname, sss_ctxt);
d702dc
 	if (ret) {
d702dc
-		if (ret == ECONNREFUSED)
d702dc
-			return NSS_STATUS_UNKNOWN;
d702dc
-
d702dc
-		if (ret != ENOENT)
d702dc
+		if (ret == ECONNREFUSED) {
d702dc
+			err = NSS_STATUS_UNKNOWN;
d702dc
 			goto error;
d702dc
+		}
d702dc
+
d702dc
+		if (proto_version(ctxt) == 0) {
d702dc
+			if (ret != ENOENT)
d702dc
+				goto error;
d702dc
+		} else {
d702dc
+			if (ret != ENOENT && ret != EHOSTDOWN)
d702dc
+				goto error;
d702dc
+		}
d702dc
 
d702dc
 		ret = setautomntent_wait(logopt, ctxt, sss_ctxt);
d702dc
 		if (ret) {
d702dc
-			if (ret == ECONNREFUSED)
d702dc
-				return NSS_STATUS_UNKNOWN;
d702dc
-			if (ret == ENOENT)
d702dc
-				return NSS_STATUS_NOTFOUND;
d702dc
+			if (ret == ECONNREFUSED) {
d702dc
+				err = NSS_STATUS_UNKNOWN;
d702dc
+				goto error;
d702dc
+			}
d702dc
+			if (ret == ETIMEDOUT)
d702dc
+				goto error;
d702dc
+			if (ret == ENOENT) {
d702dc
+				err = NSS_STATUS_NOTFOUND;
d702dc
+				goto free;
d702dc
+			}
d702dc
 			goto error;
d702dc
 		}
d702dc
 	}
d702dc
-	return ret;
d702dc
+	return NSS_STATUS_SUCCESS;
d702dc
 
d702dc
 error:
d702dc
 	estr = strerror_r(ret, buf, MAX_ERR_BUF);
d702dc
 	error(logopt, MODPREFIX "setautomntent: %s", estr);
d702dc
+free:
d702dc
 	if (*sss_ctxt) {
d702dc
 		free(*sss_ctxt);
d702dc
 		*sss_ctxt = NULL;
d702dc
 	}
d702dc
-	return NSS_STATUS_UNAVAIL;
d702dc
+	return err;
d702dc
 }
d702dc
 
d702dc
 static int endautomntent(unsigned int logopt,