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