|
|
6bbd11 |
autofs-5.0.9 - amd lookup add key matching helper function
|
|
|
6bbd11 |
|
|
|
6bbd11 |
From: Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
|
|
|
6bbd11 |
Add helper function and match_cached_key() that perform the progressive
|
|
|
6bbd11 |
key+prefix matching procedure.
|
|
|
6bbd11 |
---
|
|
|
6bbd11 |
include/parse_subs.h | 2 +
|
|
|
6bbd11 |
lib/parse_subs.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
6bbd11 |
2 files changed, 86 insertions(+)
|
|
|
6bbd11 |
|
|
|
6bbd11 |
diff --git a/include/parse_subs.h b/include/parse_subs.h
|
|
|
6bbd11 |
index 43da182..1e87716 100644
|
|
|
6bbd11 |
--- a/include/parse_subs.h
|
|
|
6bbd11 |
+++ b/include/parse_subs.h
|
|
|
6bbd11 |
@@ -113,6 +113,8 @@ struct map_type_info {
|
|
|
6bbd11 |
unsigned int get_proximity(struct sockaddr *);
|
|
|
6bbd11 |
unsigned int get_network_proximity(const char *);
|
|
|
6bbd11 |
unsigned int in_network(char *);
|
|
|
6bbd11 |
+struct mapent *match_cached_key(struct autofs_point *, const char *,
|
|
|
6bbd11 |
+ struct map_source *, const char *);
|
|
|
6bbd11 |
const char *skipspace(const char *);
|
|
|
6bbd11 |
int check_colon(const char *);
|
|
|
6bbd11 |
int chunklen(const char *, int);
|
|
|
6bbd11 |
diff --git a/lib/parse_subs.c b/lib/parse_subs.c
|
|
|
6bbd11 |
index 421d18c..1e4825d 100644
|
|
|
6bbd11 |
--- a/lib/parse_subs.c
|
|
|
6bbd11 |
+++ b/lib/parse_subs.c
|
|
|
6bbd11 |
@@ -498,6 +498,90 @@ unsigned int in_network(char *network)
|
|
|
6bbd11 |
return 1;
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
+struct mapent *match_cached_key(struct autofs_point *ap,
|
|
|
6bbd11 |
+ const char *err_prefix,
|
|
|
6bbd11 |
+ struct map_source *source,
|
|
|
6bbd11 |
+ const char *key)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char buf[MAX_ERR_BUF];
|
|
|
6bbd11 |
+ struct mapent_cache *mc;
|
|
|
6bbd11 |
+ struct mapent *me;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ mc = source->mc;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!(source->flags & MAP_FLAG_FORMAT_AMD)) {
|
|
|
6bbd11 |
+ int ret;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ me = cache_lookup(mc, key);
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * Stale mapent => check for entry in alternate source or
|
|
|
6bbd11 |
+ * wildcard. Note, plus included direct mount map entries
|
|
|
6bbd11 |
+ * are included as an instance (same map entry cache), not
|
|
|
6bbd11 |
+ * in a distinct source.
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ if (me && (!me->mapent ||
|
|
|
6bbd11 |
+ (me->source != source && *me->key != '/'))) {
|
|
|
6bbd11 |
+ while ((me = cache_lookup_key_next(me)))
|
|
|
6bbd11 |
+ if (me->source == source)
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+ if (!me)
|
|
|
6bbd11 |
+ me = cache_lookup_distinct(mc, "*");
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!me)
|
|
|
6bbd11 |
+ goto done;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * If this is a lookup add wildcard match for later validation
|
|
|
6bbd11 |
+ * checks and negative cache lookups.
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ if (!(ap->flags & MOUNT_FLAG_REMOUNT) &&
|
|
|
6bbd11 |
+ ap->type == LKP_INDIRECT && *me->key == '*') {
|
|
|
6bbd11 |
+ ret = cache_update(mc, source, key, me->mapent, me->age);
|
|
|
6bbd11 |
+ if (!(ret & (CHE_OK | CHE_UPDATED)))
|
|
|
6bbd11 |
+ me = NULL;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ char *lkp_key = strdup(key);
|
|
|
6bbd11 |
+ if (!lkp_key) {
|
|
|
6bbd11 |
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
6bbd11 |
+ error(ap->logopt, "%s strdup: %s", err_prefix, estr);
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /* If it's found we're done */
|
|
|
6bbd11 |
+ me = cache_lookup_distinct(mc, lkp_key);
|
|
|
6bbd11 |
+ if (me)
|
|
|
6bbd11 |
+ goto free;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * Otherwise strip successive directory components and try
|
|
|
6bbd11 |
+ * a match against map entries ending with a wildcard and
|
|
|
6bbd11 |
+ * finally try the wilcard entry itself.
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ while (!me) {
|
|
|
6bbd11 |
+ char *prefix;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ while ((prefix = strrchr(lkp_key, '/'))) {
|
|
|
6bbd11 |
+ *prefix = '\0';
|
|
|
6bbd11 |
+ me = cache_partial_match_wild(mc, lkp_key);
|
|
|
6bbd11 |
+ if (me)
|
|
|
6bbd11 |
+ goto free;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ me = cache_lookup_distinct(mc, "*");
|
|
|
6bbd11 |
+ if (me)
|
|
|
6bbd11 |
+ goto free;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+free:
|
|
|
6bbd11 |
+ free(lkp_key);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+done:
|
|
|
6bbd11 |
+ return me;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
/*
|
|
|
6bbd11 |
* Skip whitespace in a string; if we hit a #, consider the rest of the
|
|
|
6bbd11 |
* entry a comment.
|