Blame SOURCES/autofs-5.0.9-amd-lookup-add-cache-partial-match-functions.patch

306fa1
autofs-5.0.9 - amd lookup add cache partial match functions
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
Partial key matching is used for amd. A prefix is possibly added to the key
306fa1
and if the map entry key has a trailing /* and matches the initial part of
306fa1
the key+prefix the match succeeds.
306fa1
306fa1
Update the existing partial match functions to help with this.
306fa1
---
306fa1
 include/automount.h |    1 +
306fa1
 lib/cache.c         |   38 +++++++++++++++++++++++++++++++++-----
306fa1
 2 files changed, 34 insertions(+), 5 deletions(-)
306fa1
306fa1
diff --git a/include/automount.h b/include/automount.h
306fa1
index 37133fe..ac6c4e3 100644
306fa1
--- a/include/automount.h
306fa1
+++ b/include/automount.h
306fa1
@@ -215,6 +215,7 @@ struct mapent *cache_lookup(struct mapent_cache *mc, const char *key);
306fa1
 struct mapent *cache_lookup_distinct(struct mapent_cache *mc, const char *key);
306fa1
 struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int start, struct list_head *head);
306fa1
 struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix);
306fa1
+struct mapent *cache_partial_match_wild(struct mapent_cache *mc, const char *prefix);
306fa1
 int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
306fa1
 int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
306fa1
 void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
306fa1
diff --git a/lib/cache.c b/lib/cache.c
306fa1
index 9af1709..8d08094 100644
306fa1
--- a/lib/cache.c
306fa1
+++ b/lib/cache.c
306fa1
@@ -566,7 +566,9 @@ struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int s
306fa1
 }
306fa1
 
306fa1
 /* cache must be read locked by caller */
306fa1
-struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix)
306fa1
+static struct mapent *__cache_partial_match(struct mapent_cache *mc,
306fa1
+					    const char *prefix,
306fa1
+					    unsigned int type)
306fa1
 {
306fa1
 	struct mapent *me = NULL;
306fa1
 	size_t len = strlen(prefix);
306fa1
@@ -578,20 +580,46 @@ struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix)
306fa1
 			continue;
306fa1
 
306fa1
 		if (len < strlen(me->key) &&
306fa1
-		    (strncmp(prefix, me->key, len) == 0) && me->key[len] == '/')
306fa1
-			return me;
306fa1
+		    (strncmp(prefix, me->key, len) == 0) &&
306fa1
+		     me->key[len] == '/') {
306fa1
+			if (type == LKP_NORMAL)
306fa1
+				return me;
306fa1
+			if (type == LKP_WILD &&
306fa1
+			    me->key[len] != '\0' &&
306fa1
+			    me->key[len + 1] == '*')
306fa1
+				return me;
306fa1
+		}
306fa1
 
306fa1
 		me = me->next;
306fa1
 		while (me != NULL) {
306fa1
 			if (len < strlen(me->key) &&
306fa1
-			    strncmp(prefix, me->key, len) == 0 && me->key[len] == '/')
306fa1
-				return me;
306fa1
+			    (strncmp(prefix, me->key, len) == 0 &&
306fa1
+			    me->key[len] == '/')) {
306fa1
+				if (type == LKP_NORMAL)
306fa1
+					return me;
306fa1
+				if (type == LKP_WILD &&
306fa1
+				    me->key[len] != '\0' &&
306fa1
+				    me->key[len + 1] == '*')
306fa1
+					return me;
306fa1
+			}
306fa1
 			me = me->next;
306fa1
 		}
306fa1
 	}
306fa1
 	return NULL;
306fa1
 }
306fa1
 
306fa1
+/* cache must be read locked by caller */
306fa1
+struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix)
306fa1
+{
306fa1
+	return __cache_partial_match(mc, prefix, LKP_NORMAL);
306fa1
+}
306fa1
+
306fa1
+/* cache must be read locked by caller */
306fa1
+struct mapent *cache_partial_match_wild(struct mapent_cache *mc, const char *prefix)
306fa1
+{
306fa1
+	return __cache_partial_match(mc, prefix, LKP_WILD);
306fa1
+}
306fa1
+
306fa1
 /* cache must be write locked by caller */
306fa1
 int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age)
306fa1
 {