|
|
63b9c2 |
autofs-5.1.6 - refactor sss getautomntbyname()
|
|
|
63b9c2 |
|
|
|
63b9c2 |
From: Ian Kent <raven@themaw.net>
|
|
|
63b9c2 |
|
|
|
63b9c2 |
Refactor the sss getautomntbyname_r() to consolidate the error handling
|
|
|
63b9c2 |
in one location.
|
|
|
63b9c2 |
|
|
|
63b9c2 |
Also add the missing ECONREFUSED handling while we are at it.
|
|
|
63b9c2 |
|
|
|
63b9c2 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
63b9c2 |
---
|
|
|
63b9c2 |
CHANGELOG | 1
|
|
|
63b9c2 |
modules/lookup_sss.c | 110 +++++++++++++++++++++++++++++---------------------
|
|
|
63b9c2 |
2 files changed, 65 insertions(+), 46 deletions(-)
|
|
|
63b9c2 |
|
|
|
63b9c2 |
diff --git a/CHANGELOG b/CHANGELOG
|
|
|
63b9c2 |
index e48e2c0..8b662d7 100644
|
|
|
63b9c2 |
--- a/CHANGELOG
|
|
|
63b9c2 |
+++ b/CHANGELOG
|
|
|
63b9c2 |
@@ -106,6 +106,7 @@ xx/xx/2018 autofs-5.1.5
|
|
|
63b9c2 |
- move readall into struct master.
|
|
|
63b9c2 |
- sss introduce a flag to indicate map being read.
|
|
|
63b9c2 |
- update sss timeout documentation.
|
|
|
63b9c2 |
+- refactor sss getautomntbyname().
|
|
|
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 3c0ffde..1a56ea1 100644
|
|
|
63b9c2 |
--- a/modules/lookup_sss.c
|
|
|
63b9c2 |
+++ b/modules/lookup_sss.c
|
|
|
63b9c2 |
@@ -566,6 +566,39 @@ free:
|
|
|
63b9c2 |
return err;
|
|
|
63b9c2 |
}
|
|
|
63b9c2 |
|
|
|
63b9c2 |
+static int getautomntbyname(unsigned int logopt,
|
|
|
63b9c2 |
+ struct lookup_context *ctxt,
|
|
|
63b9c2 |
+ char *key, char **value, void *sss_ctxt)
|
|
|
63b9c2 |
+{
|
|
|
63b9c2 |
+ char buf[MAX_ERR_BUF];
|
|
|
63b9c2 |
+ char *estr;
|
|
|
63b9c2 |
+ int ret = NSS_STATUS_UNAVAIL;
|
|
|
63b9c2 |
+
|
|
|
63b9c2 |
+ ret = ctxt->getautomntbyname_r(key, value, sss_ctxt);
|
|
|
63b9c2 |
+ if (ret) {
|
|
|
63b9c2 |
+ /* Host has gone down */
|
|
|
63b9c2 |
+ if (ret == ECONNREFUSED)
|
|
|
63b9c2 |
+ return NSS_STATUS_UNKNOWN;
|
|
|
63b9c2 |
+
|
|
|
63b9c2 |
+ if (ret != ENOENT)
|
|
|
63b9c2 |
+ goto error;
|
|
|
63b9c2 |
+
|
|
|
63b9c2 |
+ ret = NSS_STATUS_NOTFOUND;
|
|
|
63b9c2 |
+ goto free;
|
|
|
63b9c2 |
+ }
|
|
|
63b9c2 |
+ return ret;
|
|
|
63b9c2 |
+
|
|
|
63b9c2 |
+error:
|
|
|
63b9c2 |
+ estr = strerror_r(ret, buf, MAX_ERR_BUF);
|
|
|
63b9c2 |
+ error(logopt, MODPREFIX "getautomntbyname: %s", estr);
|
|
|
63b9c2 |
+free:
|
|
|
63b9c2 |
+ if (*value) {
|
|
|
63b9c2 |
+ free(*value);
|
|
|
63b9c2 |
+ *value = NULL;
|
|
|
63b9c2 |
+ }
|
|
|
63b9c2 |
+ return ret;
|
|
|
63b9c2 |
+}
|
|
|
63b9c2 |
+
|
|
|
63b9c2 |
int lookup_read_master(struct master *master, time_t age, void *context)
|
|
|
63b9c2 |
{
|
|
|
63b9c2 |
struct lookup_context *ctxt = (struct lookup_context *) context;
|
|
|
63b9c2 |
@@ -755,7 +788,6 @@ static int lookup_one(struct autofs_point *ap,
|
|
|
63b9c2 |
struct mapent *we;
|
|
|
63b9c2 |
void *sss_ctxt = NULL;
|
|
|
63b9c2 |
time_t age = monotonic_time(NULL);
|
|
|
63b9c2 |
- char buf[MAX_ERR_BUF];
|
|
|
63b9c2 |
char *value = NULL;
|
|
|
63b9c2 |
char *s_key;
|
|
|
63b9c2 |
int ret;
|
|
|
63b9c2 |
@@ -770,61 +802,47 @@ static int lookup_one(struct autofs_point *ap,
|
|
|
63b9c2 |
if (ret)
|
|
|
63b9c2 |
return ret;
|
|
|
63b9c2 |
|
|
|
63b9c2 |
- ret = ctxt->getautomntbyname_r(qKey, &value, sss_ctxt);
|
|
|
63b9c2 |
- if (ret && ret != ENOENT) {
|
|
|
63b9c2 |
- char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
|
|
|
63b9c2 |
- error(ap->logopt,
|
|
|
63b9c2 |
- MODPREFIX "getautomntbyname_r: %s", estr);
|
|
|
63b9c2 |
+ ret = getautomntbyname(ap->logopt, ctxt, qKey, &value, sss_ctxt);
|
|
|
63b9c2 |
+ if (ret == NSS_STATUS_NOTFOUND)
|
|
|
63b9c2 |
+ goto wild;
|
|
|
63b9c2 |
+ if (ret) {
|
|
|
63b9c2 |
endautomntent(ap->logopt, ctxt, &sss_ctxt);
|
|
|
63b9c2 |
- if (value)
|
|
|
63b9c2 |
- free(value);
|
|
|
63b9c2 |
- return NSS_STATUS_UNAVAIL;
|
|
|
63b9c2 |
+ return ret;
|
|
|
63b9c2 |
}
|
|
|
63b9c2 |
- if (ret != ENOENT) {
|
|
|
63b9c2 |
- /*
|
|
|
63b9c2 |
- * TODO: implement sun % hack for key translation for
|
|
|
63b9c2 |
- * mixed case keys in schema that are single case only.
|
|
|
63b9c2 |
- */
|
|
|
63b9c2 |
- s_key = sanitize_path(qKey, qKey_len, ap->type, ap->logopt);
|
|
|
63b9c2 |
- if (!s_key) {
|
|
|
63b9c2 |
- free(value);
|
|
|
63b9c2 |
- value = NULL;
|
|
|
63b9c2 |
- goto wild;
|
|
|
63b9c2 |
- }
|
|
|
63b9c2 |
- cache_writelock(mc);
|
|
|
63b9c2 |
- ret = cache_update(mc, source, s_key, value, age);
|
|
|
63b9c2 |
- cache_unlock(mc);
|
|
|
63b9c2 |
- endautomntent(ap->logopt, ctxt, &sss_ctxt);
|
|
|
63b9c2 |
- free(s_key);
|
|
|
63b9c2 |
+
|
|
|
63b9c2 |
+ /*
|
|
|
63b9c2 |
+ * TODO: implement sun % hack for key translation for
|
|
|
63b9c2 |
+ * mixed case keys in schema that are single case only.
|
|
|
63b9c2 |
+ */
|
|
|
63b9c2 |
+ s_key = sanitize_path(qKey, qKey_len, ap->type, ap->logopt);
|
|
|
63b9c2 |
+ if (!s_key) {
|
|
|
63b9c2 |
free(value);
|
|
|
63b9c2 |
- return NSS_STATUS_SUCCESS;
|
|
|
63b9c2 |
+ value = NULL;
|
|
|
63b9c2 |
+ goto wild;
|
|
|
63b9c2 |
}
|
|
|
63b9c2 |
+ cache_writelock(mc);
|
|
|
63b9c2 |
+ ret = cache_update(mc, source, s_key, value, age);
|
|
|
63b9c2 |
+ cache_unlock(mc);
|
|
|
63b9c2 |
+ endautomntent(ap->logopt, ctxt, &sss_ctxt);
|
|
|
63b9c2 |
+ free(s_key);
|
|
|
63b9c2 |
+ free(value);
|
|
|
63b9c2 |
+ return NSS_STATUS_SUCCESS;
|
|
|
63b9c2 |
|
|
|
63b9c2 |
wild:
|
|
|
63b9c2 |
- ret = ctxt->getautomntbyname_r("/", &value, sss_ctxt);
|
|
|
63b9c2 |
- if (ret && ret != ENOENT) {
|
|
|
63b9c2 |
- char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
|
|
|
63b9c2 |
- error(ap->logopt,
|
|
|
63b9c2 |
- MODPREFIX "getautomntbyname_r: %s", estr);
|
|
|
63b9c2 |
- endautomntent(ap->logopt, ctxt, &sss_ctxt);
|
|
|
63b9c2 |
- if (value)
|
|
|
63b9c2 |
- free(value);
|
|
|
63b9c2 |
- return NSS_STATUS_UNAVAIL;
|
|
|
63b9c2 |
- }
|
|
|
63b9c2 |
- if (ret == ENOENT) {
|
|
|
63b9c2 |
- ret = ctxt->getautomntbyname_r("*", &value, sss_ctxt);
|
|
|
63b9c2 |
- if (ret && ret != ENOENT) {
|
|
|
63b9c2 |
- char *estr = strerror_r(ret, buf, MAX_ERR_BUF);
|
|
|
63b9c2 |
- error(ap->logopt,
|
|
|
63b9c2 |
- MODPREFIX "getautomntbyname_r: %s", estr);
|
|
|
63b9c2 |
+ ret = getautomntbyname(ap->logopt, ctxt, "/", &value, sss_ctxt);
|
|
|
63b9c2 |
+ if (ret) {
|
|
|
63b9c2 |
+ if (ret != NSS_STATUS_NOTFOUND) {
|
|
|
63b9c2 |
endautomntent(ap->logopt, ctxt, &sss_ctxt);
|
|
|
63b9c2 |
- if (value)
|
|
|
63b9c2 |
- free(value);
|
|
|
63b9c2 |
- return NSS_STATUS_UNAVAIL;
|
|
|
63b9c2 |
+ return ret;
|
|
|
63b9c2 |
+ }
|
|
|
63b9c2 |
+ ret = getautomntbyname(ap->logopt, ctxt, "*", &value, sss_ctxt);
|
|
|
63b9c2 |
+ if (ret && ret != NSS_STATUS_NOTFOUND) {
|
|
|
63b9c2 |
+ endautomntent(ap->logopt, ctxt, &sss_ctxt);
|
|
|
63b9c2 |
+ return ret;
|
|
|
63b9c2 |
}
|
|
|
63b9c2 |
}
|
|
|
63b9c2 |
|
|
|
63b9c2 |
- if (ret == ENOENT) {
|
|
|
63b9c2 |
+ if (ret == NSS_STATUS_NOTFOUND) {
|
|
|
63b9c2 |
/* Failed to find wild entry, update cache if needed */
|
|
|
63b9c2 |
cache_writelock(mc);
|
|
|
63b9c2 |
we = cache_lookup_distinct(mc, "*");
|