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

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