Blame SOURCES/autofs-5.0.9-amd-lookup-add-selector-handling-functions.patch

306fa1
autofs-5.0.999999999 - amd lookup add selector handling functions
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
306fa1
---
306fa1
 include/parse_subs.h |   77 +++++++++++++++++++++++++++++++++
306fa1
 lib/parse_subs.c     |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++
306fa1
 2 files changed, 194 insertions(+)
306fa1
306fa1
diff --git a/include/parse_subs.h b/include/parse_subs.h
306fa1
index 675411d..a416c59 100644
306fa1
--- a/include/parse_subs.h
306fa1
+++ b/include/parse_subs.h
306fa1
@@ -25,6 +25,83 @@
306fa1
 #define PROXIMITY_OTHER         0x0008
306fa1
 #define PROXIMITY_UNSUPPORTED   0x0010
306fa1
 
306fa1
+#define SEL_ARCH		0x00000001
306fa1
+#define SEL_KARCH		0x00000002
306fa1
+#define SEL_OS			0x00000004
306fa1
+#define SEL_OSVER		0x00000008
306fa1
+#define SEL_FULL_OS		0x00000010
306fa1
+#define SEL_VENDOR		0x00000020
306fa1
+#define SEL_HOST		0x00000040
306fa1
+#define SEL_HOSTD		0x00000080
306fa1
+#define SEL_XHOST		0x00000100
306fa1
+#define SEL_DOMAIN		0x00000200
306fa1
+#define SEL_BYTE		0x00000400
306fa1
+#define SEL_CLUSTER		0x00000800
306fa1
+#define SEL_NETGRP		0x00001000
306fa1
+#define SEL_NETGRPD		0x00002000
306fa1
+#define SEL_IN_NETWORK		0x00004000
306fa1
+#define SEL_UID			0x00008000
306fa1
+#define SEL_GID			0x00010000
306fa1
+#define SEL_KEY			0x00020000
306fa1
+#define SEL_MAP			0x00040000
306fa1
+#define SEL_PATH		0x00080000
306fa1
+#define SEL_EXISTS		0x00100000
306fa1
+#define SEL_AUTODIR		0x00200000
306fa1
+#define SEL_DOLLAR		0x00400000
306fa1
+#define SEL_TRUE		0x00800000
306fa1
+#define SEL_FALSE		0x01000000
306fa1
+
306fa1
+#define SEL_COMP_NONE		0x0000
306fa1
+#define SEL_COMP_EQUAL		0x0001
306fa1
+#define SEL_COMP_NOTEQUAL	0x0002
306fa1
+#define SEL_COMP_NOT		0x0004
306fa1
+
306fa1
+#define SEL_FLAG_MACRO		0x0001
306fa1
+#define SEL_FLAG_FUNC1		0x0002
306fa1
+#define SEL_FLAG_FUNC2		0x0004
306fa1
+#define SEL_FLAG_STR		0x0100
306fa1
+#define SEL_FLAG_NUM		0x0200
306fa1
+#define SEL_FLAG_BOOL		0x0400
306fa1
+
306fa1
+#define SEL_FLAGS_TYPE_MASK	0x00FF
306fa1
+#define SEL_FLAGS_VALUE_MASK	0xFF00
306fa1
+#define SEL_FREE_VALUE_MASK	(SEL_FLAG_MACRO|SEL_FLAG_STR|SEL_FLAG_NUM)
306fa1
+#define SEL_FREE_ARG1_MASK	(SEL_FLAG_FUNC1)
306fa1
+#define SEL_FREE_ARG2_MASK	(SEL_FLAG_FUNC2)
306fa1
+
306fa1
+struct type_compare {
306fa1
+	char	*value;
306fa1
+};
306fa1
+
306fa1
+struct type_function {
306fa1
+	char *arg1;
306fa1
+	char *arg2;
306fa1
+};
306fa1
+
306fa1
+struct sel {
306fa1
+	unsigned long selector;
306fa1
+	const char *name;
306fa1
+	unsigned int flags;
306fa1
+	struct sel *next;
306fa1
+};
306fa1
+
306fa1
+struct selector {
306fa1
+	struct sel *sel;
306fa1
+	unsigned int compare;
306fa1
+
306fa1
+	union {
306fa1
+		struct type_compare	comp;
306fa1
+		struct type_function	func;
306fa1
+	};
306fa1
+
306fa1
+	struct selector *next;
306fa1
+};
306fa1
+
306fa1
+void sel_hash_init(void);
306fa1
+struct sel *sel_lookup(const char *);
306fa1
+struct selector *get_selector(char *);
306fa1
+void free_selector(struct selector *);
306fa1
+
306fa1
 struct mapent;
306fa1
 
306fa1
 struct map_type_info {
306fa1
diff --git a/lib/parse_subs.c b/lib/parse_subs.c
306fa1
index 279f40e..f485a4c 100644
306fa1
--- a/lib/parse_subs.c
306fa1
+++ b/lib/parse_subs.c
306fa1
@@ -45,6 +45,44 @@ static int volatile ifc_last_len = 0;
306fa1
 #define EXPAND_LEADING_DOT	0x0004
306fa1
 #define EXPAND_TRAILING_DOT	0x0008
306fa1
 
306fa1
+#define SELECTOR_HASH_SIZE	20
306fa1
+
306fa1
+static struct sel sel_table[] = {
306fa1
+	{ SEL_ARCH,	  "arch",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_KARCH,	  "karch",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_OS,	  "os",		SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_OSVER,	  "osver",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_FULL_OS,	  "full_os",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_VENDOR,	  "vendor",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_HOST,	  "host",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_HOSTD,	  "hostd",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_XHOST,	  "xhost",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_DOMAIN,	  "domain",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_BYTE,	  "byte",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_CLUSTER,	  "cluster",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_NETGRP,	  "netgrp",	SEL_FLAG_FUNC2|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_NETGRPD,	  "netgrpd",	SEL_FLAG_FUNC2|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_IN_NETWORK, "in_network",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_IN_NETWORK, "netnumber",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_IN_NETWORK, "network",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_IN_NETWORK, "wire",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_UID,	  "uid",	SEL_FLAG_MACRO|SEL_FLAG_NUM, NULL },
306fa1
+	{ SEL_GID,	  "gid",	SEL_FLAG_MACRO|SEL_FLAG_NUM, NULL },
306fa1
+	{ SEL_KEY,	  "key",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_MAP,	  "map",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_PATH,	  "path",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_EXISTS,	  "exists",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_AUTODIR,	  "autodir",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_DOLLAR,	  "dollar",	SEL_FLAG_MACRO|SEL_FLAG_STR, NULL },
306fa1
+	{ SEL_TRUE,	  "true",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+	{ SEL_FALSE,	  "false",	SEL_FLAG_FUNC1|SEL_FLAG_BOOL, NULL },
306fa1
+};
306fa1
+static unsigned int sel_count = sizeof(sel_table)/sizeof(struct sel);
306fa1
+
306fa1
+static struct sel *sel_hash[SELECTOR_HASH_SIZE];
306fa1
+static unsigned int sel_hash_init_done = 0;
306fa1
+static pthread_mutex_t sel_hash_mutex = PTHREAD_MUTEX_INITIALIZER;
306fa1
+
306fa1
 struct types {
306fa1
 	char *type;
306fa1
 	unsigned int len;
306fa1
@@ -70,6 +108,85 @@ static struct types format_type[] = {
306fa1
 };
306fa1
 static unsigned int format_type_count = sizeof(format_type)/sizeof(struct types);
306fa1
 
306fa1
+static void sel_add(struct sel *sel)
306fa1
+{
306fa1
+	u_int32_t hval = hash(sel->name, SELECTOR_HASH_SIZE);
306fa1
+	struct sel *old;
306fa1
+
306fa1
+	old = sel_hash[hval];
306fa1
+	sel_hash[hval] = sel;
306fa1
+	sel_hash[hval]->next = old;
306fa1
+}
306fa1
+
306fa1
+void sel_hash_init(void)
306fa1
+{
306fa1
+	int i;
306fa1
+
306fa1
+	pthread_mutex_lock(&sel_hash_mutex);
306fa1
+	if (sel_hash_init_done) {
306fa1
+		pthread_mutex_unlock(&sel_hash_mutex);
306fa1
+		return;
306fa1
+	}
306fa1
+	for (i = 0; i < SELECTOR_HASH_SIZE; i++)
306fa1
+		sel_hash[i] = NULL;
306fa1
+
306fa1
+	for (i = 0; i < sel_count; i++)
306fa1
+		sel_add(&sel_table[i]);
306fa1
+
306fa1
+	sel_hash_init_done = 1;
306fa1
+	pthread_mutex_unlock(&sel_hash_mutex);
306fa1
+}
306fa1
+
306fa1
+struct sel *sel_lookup(const char *name)
306fa1
+{
306fa1
+	u_int32_t hval = hash(name, SELECTOR_HASH_SIZE);
306fa1
+	struct sel *sel;
306fa1
+
306fa1
+	pthread_mutex_lock(&sel_hash_mutex);
306fa1
+	for (sel = sel_hash[hval]; sel != NULL; sel = sel->next) {
306fa1
+		if (strcmp(name, sel->name) == 0) {
306fa1
+			pthread_mutex_unlock(&sel_hash_mutex);
306fa1
+			return sel;
306fa1
+		}
306fa1
+	}
306fa1
+	pthread_mutex_unlock(&sel_hash_mutex);
306fa1
+	return NULL;
306fa1
+}
306fa1
+
306fa1
+struct selector *get_selector(char *name)
306fa1
+{
306fa1
+	struct sel *sel;
306fa1
+
306fa1
+	sel = sel_lookup(name);
306fa1
+	if (sel) {
306fa1
+		struct selector *new = malloc(sizeof(struct selector));
306fa1
+		if (!new)
306fa1
+			return NULL;
306fa1
+		memset(new, 0, sizeof(*new));
306fa1
+		new->sel = sel;
306fa1
+		return new;
306fa1
+	}
306fa1
+	return NULL;
306fa1
+}
306fa1
+
306fa1
+void free_selector(struct selector *selector)
306fa1
+{
306fa1
+	struct selector *s = selector;
306fa1
+	struct selector *next = s;
306fa1
+
306fa1
+	while (s) {
306fa1
+		next = s->next;
306fa1
+		if (s->sel->flags & SEL_FREE_VALUE_MASK)
306fa1
+			free(s->comp.value);
306fa1
+		if (s->sel->flags & SEL_FREE_ARG1_MASK)
306fa1
+			free(s->func.arg1);
306fa1
+		if (s->sel->flags & SEL_FREE_ARG2_MASK)
306fa1
+			free(s->func.arg2);
306fa1
+		s = next;
306fa1
+	}
306fa1
+	return;
306fa1
+}
306fa1
+
306fa1
 static unsigned int ipv6_mask_cmp(uint32_t *host, uint32_t *iface, uint32_t *mask)
306fa1
 {
306fa1
 	unsigned int ret = 1;