[PC-BSD Commits] r18306 - pcbsd/current/src-sh/pc-adctl/nssldap

svn at pcbsd.org svn at pcbsd.org
Tue Aug 7 11:09:42 PDT 2012


Author: johnh
Date: 2012-08-07 18:09:42 +0000 (Tue, 07 Aug 2012)
New Revision: 18306

Modified:
   pcbsd/current/src-sh/pc-adctl/nssldap/nssldap-parser.y
   pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.c
   pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.h
Log:
Added support for triplets that I had overlooked previously.



Modified: pcbsd/current/src-sh/pc-adctl/nssldap/nssldap-parser.y
===================================================================
--- pcbsd/current/src-sh/pc-adctl/nssldap/nssldap-parser.y	2012-08-07 17:59:19 UTC (rev 18305)
+++ pcbsd/current/src-sh/pc-adctl/nssldap/nssldap-parser.y	2012-08-07 18:09:42 UTC (rev 18306)
@@ -47,6 +47,7 @@
 	newline |
 	comment |
 	pair |
+	triplet |
 	empty |
 	space
 
@@ -71,6 +72,18 @@
 		TAILQ_INSERT_TAIL(&nssldapconf, ne, entries);
 	}
 
+triplet:
+	WORD SPACE WORD SPACE WORD {
+		struct nssldap_entry *ne = xalloc(sizeof(*ne));
+
+		ne->type = NSSLDAP_ENTRY_TRIPLET;
+		ne->net_name = xstrdup(clean($1));
+		ne->net_attr = xstrdup(clean($3));
+		ne->net_value = xstrdup(clean($5));
+
+		TAILQ_INSERT_TAIL(&nssldapconf, ne, entries);
+	}
+
 newline:
 	NEWLINE {
 		lineno++;

Modified: pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.c
===================================================================
--- pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.c	2012-08-07 17:59:19 UTC (rev 18305)
+++ pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.c	2012-08-07 18:09:42 UTC (rev 18306)
@@ -14,6 +14,7 @@
 struct nssldap_modification {
 	TAILQ_ENTRY(nssldap_modification) entries;
 	char *name;
+	char *attr;
 	char *value;
 	int create;
 	int op;
@@ -86,6 +87,8 @@
 		return (-1);
 
 	nm = xalloc(sizeof(*nm));
+	nm->name = nm->attr = nm->value = NULL;
+
 	switch (m[0]) {
 		case '+':
 			nm->op = NSSLDAP_OP_ADD;
@@ -121,9 +124,17 @@
 
 	if (tmp != NULL)
 		nm->name = xstrdup(clean(tmp));
-	if (ptr != NULL)
-		nm->value = xstrdup(clean(ptr));
+	if (ptr != NULL) {
+		tmp = strsep(&ptr, "=");
+		if (ptr != NULL) {
+			nm->attr = xstrdup(clean(tmp));
+			nm->value = xstrdup(clean(ptr));
 
+		} else {
+			nm->value = xstrdup(clean(tmp));
+		}
+	}
+
 	TAILQ_INSERT_TAIL(&modifications, nm, entries);
 
 	xfree(&save);
@@ -133,26 +144,48 @@
 static int
 nssldap_op_add(struct nssldap_modification *nm)
 {
+	int type;
 	int exists = 0;
 	struct nssldap_entry *ne;
 
 	if (nm == NULL)
 		return (-1);
 
+	type = NSSLDAP_ENTRY_PAIR;	
+	if (nm->attr != NULL)
+		type = NSSLDAP_ENTRY_TRIPLET;
+
 	TAILQ_FOREACH(ne, &nssldapconf, entries) {
-		if (ne->type == NSSLDAP_ENTRY_PAIR &&
+		if (ne->type == type && type == NSSLDAP_ENTRY_PAIR &&
 			strcasecmp(ne->nep_name, nm->name) == 0) {
 			exists = 1;
 			break;
+
+		} else if (ne->type == type && type == NSSLDAP_ENTRY_TRIPLET &&
+			strcasecmp(ne->net_name, nm->name) == 0) {
+			exists = 1;
+			break;
 		}
 	}
 
 	if (exists == 0) {
 		ne = xalloc(sizeof(*ne));
 
-		ne->type = NSSLDAP_ENTRY_PAIR;
-		ne->nep_name = xstrdup(nm->name);
-		ne->nep_value = xstrdup(nm->value);
+		ne->type = type;
+		switch (type) {
+			case NSSLDAP_ENTRY_PAIR: {
+				ne->nep_name = xstrdup(nm->name);
+				ne->nep_value = xstrdup(nm->value);
+				break;
+			}
+				
+			case NSSLDAP_ENTRY_TRIPLET: {
+				ne->net_name = xstrdup(nm->name);
+				ne->net_attr = xstrdup(nm->attr);
+				ne->net_value = xstrdup(nm->value);
+				break;
+			}
+		}
 
 		TAILQ_INSERT_TAIL(&nssldapconf, ne, entries);
 	}
@@ -163,19 +196,33 @@
 static int
 nssldap_op_modify(struct nssldap_modification *nm)
 {
+	int type;
 	int exists = 0;
 	struct nssldap_entry *ne, *netmp;
 
 	if (nm == NULL)
 		return (-1);
 
+	type = NSSLDAP_ENTRY_PAIR;	
+	if (nm->attr != NULL)
+		type = NSSLDAP_ENTRY_TRIPLET;
+
 	TAILQ_FOREACH_SAFE(ne, &nssldapconf, entries, netmp) {
-		if (ne->type == NSSLDAP_ENTRY_PAIR &&
+		if (ne->type == type && type == NSSLDAP_ENTRY_PAIR &&
 			strcasecmp(ne->nep_name, nm->name) == 0) {
 			xfree(&ne->nep_value);
 			ne->nep_value = xstrdup(nm->value);
 			exists = 1;
 			break;
+
+		} else if (ne->type == type && type == NSSLDAP_ENTRY_TRIPLET &&
+			strcasecmp(ne->net_name, nm->name) == 0) {
+			xfree(&ne->net_attr);
+			xfree(&ne->net_value);
+			ne->net_attr = xstrdup(nm->attr);
+			ne->net_value = xstrdup(nm->value);
+			exists = 1;
+			break;
 		}
 	}
 
@@ -188,19 +235,33 @@
 static int
 nssldap_op_remove(struct nssldap_modification *nm)
 {
+	int type;
 	struct nssldap_entry *ne, *netmp;
 
 	if (nm == NULL)
 		return (-1);
 
+	type = NSSLDAP_ENTRY_PAIR;	
+	if (nm->attr != NULL)
+		type = NSSLDAP_ENTRY_TRIPLET;
+
 	TAILQ_FOREACH_SAFE(ne, &nssldapconf, entries, netmp) {
-		if (ne->type == NSSLDAP_ENTRY_PAIR &&
+		if (ne->type == type && type == NSSLDAP_ENTRY_PAIR &&
 			strcasecmp(ne->nep_name, nm->name) == 0) {
 			TAILQ_REMOVE(&nssldapconf, ne, entries);
 			xfree(&ne->nep_name);
 			xfree(&ne->nep_value);
 			xfree(&ne);
 			break;
+
+		} else if (ne->type == type && type == NSSLDAP_ENTRY_TRIPLET &&
+			strcasecmp(ne->net_name, nm->name) == 0) {
+			TAILQ_REMOVE(&nssldapconf, ne, entries);
+			xfree(&ne->net_name);
+			xfree(&ne->net_attr);
+			xfree(&ne->net_value);
+			xfree(&ne);
+			break;
 		}
 	}
 
@@ -252,6 +313,11 @@
 				fprintf(yyout, "%s\t%s\n", ne->nep_name, ne->nep_value);
 				break;
 
+			case NSSLDAP_ENTRY_TRIPLET:
+				fprintf(yyout, "%s\t%s\t%s\n", ne->net_name,
+					ne->net_attr, ne->net_value);
+				break;
+
 			case NSSLDAP_ENTRY_COMMENT:
 				fprintf(yyout, "%s\n", ne->nec_text);
 				break;
@@ -276,6 +342,12 @@
 				xfree(&ne->nep_value);
 				break;
 
+			case NSSLDAP_ENTRY_TRIPLET:
+				xfree(&ne->net_name);
+				xfree(&ne->net_attr);
+				xfree(&ne->net_value);
+				break;
+
 			case NSSLDAP_ENTRY_COMMENT:
 				xfree(&ne->nec_text);
 				break;
@@ -293,7 +365,7 @@
 		"Where options in:\n\n"
 		"\t-f <input file>\n"
 		"\t-o <output file>\n"
-		"\t-m <(+|-|^)name=value>\n\n"
+		"\t-m <(+|-|^)name=(value|attr=value)>\n\n"
 	);
 
 	exit (1);

Modified: pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.h
===================================================================
--- pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.h	2012-08-07 17:59:19 UTC (rev 18305)
+++ pcbsd/current/src-sh/pc-adctl/nssldap/nssldapconf.h	2012-08-07 18:09:42 UTC (rev 18306)
@@ -20,12 +20,19 @@
 
 #define	NSSLDAP_ENTRY_NULL		0x00
 #define	NSSLDAP_ENTRY_PAIR		0x01
-#define	NSSLDAP_ENTRY_COMMENT	0x02
+#define	NSSLDAP_ENTRY_TRIPLET	0x02
+#define	NSSLDAP_ENTRY_COMMENT	0x04
 
 struct nssldap_comment {
 	char *text;
 };
 
+struct nssldap_triplet {
+	char *name;
+	char *attr;
+	char *value;
+};
+
 struct nssldap_pair {
 	char *name;
 	char *value;
@@ -35,15 +42,21 @@
 	unsigned int type;
 	union {
 		struct nssldap_pair ne_pair;
+		struct nssldap_triplet ne_triplet;
 		struct nssldap_comment ne_comment;
 	} ne;
 
 #define	nep	ne.ne_pair
+#define	net	ne.ne_triplet
 #define	nec	ne.ne_comment
 
 #define	nep_name	nep.name
 #define	nep_value	nep.value
 
+#define	net_name	net.name
+#define	net_attr	net.attr
+#define	net_value	net.value
+
 #define	nec_text	nec.text
 
 	TAILQ_ENTRY(nssldap_entry) entries;



More information about the Commits mailing list