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