[PC-BSD Commits] r18146 - pcbsd/current/src-sh/pc-adctl/ldap

svn at pcbsd.org svn at pcbsd.org
Sat Aug 4 02:16:45 PDT 2012


Author: johnh
Date: 2012-08-04 09:16:44 +0000 (Sat, 04 Aug 2012)
New Revision: 18146

Modified:
   pcbsd/current/src-sh/pc-adctl/ldap/ldap-parser.y
   pcbsd/current/src-sh/pc-adctl/ldap/ldapconf.c
Log:
Modified parser to understand multiple ldap hosts, also have a working
delete now.



Modified: pcbsd/current/src-sh/pc-adctl/ldap/ldap-parser.y
===================================================================
--- pcbsd/current/src-sh/pc-adctl/ldap/ldap-parser.y	2012-08-03 21:47:22 UTC (rev 18145)
+++ pcbsd/current/src-sh/pc-adctl/ldap/ldap-parser.y	2012-08-04 09:16:44 UTC (rev 18146)
@@ -235,12 +235,13 @@
 	DEREF FINDING 	{ add_deref(FINDING);	} |
 	DEREF ALWAYS	{ add_deref(ALWAYS);	}
 
-host:
-	HOST WORD
+ldap_host:
+	WORD
 	{
 		struct ldap_host *lh = xalloc(sizeof(*lh));
 
-		lh->host = xstrdup(clean($2));
+		lh->host = xstrdup(clean($1));
+
 		if (lhl == NULL) {
 			struct ldap_entry *le = xalloc(sizeof(*le));
 
@@ -250,14 +251,21 @@
 			le->type = LDAP_ENTRY_HOST_LIST;
 			le->entry = lhl;
 
+			TAILQ_INSERT_TAIL(lhl, lh, entries);
 			TAILQ_INSERT_TAIL(&ldapconf, le, entries);
-			TAILQ_INSERT_TAIL(lhl, lh, entries);
 
 		} else {
 			TAILQ_INSERT_TAIL(lhl, lh, entries);
 		}
 	}
 
+ldap_hosts:
+	ldap_hosts ldap_host |
+	ldap_host
+
+host:
+	HOST ldap_hosts
+
 network_timeout:
 	NETWORK_TIMEOUT INTEGER
 	{

Modified: pcbsd/current/src-sh/pc-adctl/ldap/ldapconf.c
===================================================================
--- pcbsd/current/src-sh/pc-adctl/ldap/ldapconf.c	2012-08-03 21:47:22 UTC (rev 18145)
+++ pcbsd/current/src-sh/pc-adctl/ldap/ldapconf.c	2012-08-04 09:16:44 UTC (rev 18146)
@@ -77,6 +77,124 @@
 }
 
 static int
+ldap_entry_free(struct ldap_entry **le_pptr)
+{
+	struct ldap_entry *le;
+
+	if (le_pptr == NULL)
+		return (-1);
+
+	le = *le_pptr;
+	switch (le->type) {
+
+		case LDAP_ENTRY_URI_LIST: {
+			struct ldap_uri *lu, *lutmp;
+			struct ldap_uri_list *lul = le->entry;
+
+			TAILQ_FOREACH_SAFE(lu, lul, entries, lutmp) {
+				TAILQ_REMOVE(lul, lu, entries);
+				xfree(&lu->uri);
+				xfree(&lu);
+			}
+
+			break;
+		}
+
+		case LDAP_ENTRY_HOST_LIST: {
+			struct ldap_host *lh, *lhtmp;
+			struct ldap_host_list *lhl = le->entry;
+
+			TAILQ_FOREACH_SAFE(lh, lhl, entries, lhtmp) {
+				TAILQ_REMOVE(lhl, lh, entries);
+				xfree(&lh->host);
+				xfree(&lh);
+			}
+
+			break;
+		}
+
+		case LDAP_ENTRY_SASL_SECPROPS_LIST: {
+			struct sasl_secprops *ss, *sstmp;
+			struct sasl_secprops_list *lsl = le->entry;
+
+			TAILQ_FOREACH_SAFE(ss, lsl, entries, sstmp) {
+				TAILQ_REMOVE(lsl, ss, entries);
+				xfree(&ss);
+			}
+
+			break;
+		}
+
+		case LDAP_ENTRY_COMMENT:
+			xfree(&((struct ldap_comment *)le->entry)->text);
+			break;
+
+		case BASE:
+			xfree(&((struct ldap_base *)le->entry)->base);
+			break;
+
+		case BINDDN:
+			xfree(&((struct ldap_binddn *)le->entry)->dn);
+			break;
+
+		case SASL_MECH:
+			xfree(&((struct sasl_mech *)le->entry)->mechanism);
+			break;
+
+		case SASL_REALM:
+			xfree(&((struct sasl_realm *)le->entry)->realm);
+			break;
+
+		case SASL_AUTHCID:
+			xfree(&((struct sasl_authcid *)le->entry)->authcid);
+			break;
+
+		case SASL_AUTHZID:
+			xfree(&((struct sasl_authzid *)le->entry)->authzid);
+			break;
+
+		case SASL_SECPROPS: {
+			/* XXX get back to this later XXX */
+			break;
+		}
+
+		case TLS_CACERT:
+			xfree(&((struct tls_cacert *)le->entry)->filename);
+			break;
+
+		case TLS_CACERTDIR:
+			xfree(&((struct tls_cacertdir *)le->entry)->path);
+			break;
+
+		case TLS_CERT:
+			xfree(&((struct tls_cert *)le->entry)->filename);
+			break;
+
+		case TLS_KEY:
+			xfree(&((struct tls_key *)le->entry)->filename);
+			break;
+
+		case TLS_CIPHER_SUITE:
+			xfree(&((struct tls_cipher_suite *)le->entry)->cipher_suite_spec);
+			break;
+
+		case TLS_RANDFILE:
+			xfree(&((struct tls_randfile *)le->entry)->filename);
+			break;
+
+		case TLS_CRLFILE:
+			xfree(&((struct tls_crlfile *)le->entry)->filename);
+			break;
+	}
+
+	xfree(&le->entry);
+	xfree(&le);
+	*le_pptr = NULL;
+
+	return (0);
+}
+
+static int
 add_modification(const char *m, int create)
 {
 	char *tmp, *save, *ptr;
@@ -501,23 +619,142 @@
 static int
 ldap_op_remove(struct ldap_modification *lm)
 {
-#if 0
+	unsigned long type;
 	struct ldap_entry *le, *letmp;
 
 	if (lm == NULL)
 		return (-1);
 
+	type = str2type(lm->name);
 	TAILQ_FOREACH_SAFE(le, &ldapconf, entries, letmp) {
-		if (le->type == LDAP_ENTRY_PAIR &&
-			strcasecmp(le->lep_name, lm->name) == 0) {
-			TAILQ_REMOVE(&ldapconf, le, entries);
-			xfree(&le->lep_name);
-			xfree(&le->lep_value);
-			xfree(&le);
-			break;
+		switch (le->type) {
+			case LDAP_ENTRY_URI_LIST: {
+				if (type == URI) {
+					long count = 0;
+					struct ldap_uri *lu, *lutmp;
+					struct ldap_uri_list *lul = le->entry;
+
+					TAILQ_FOREACH(lu, lul, entries)
+						count++;
+
+					if (lm->value == NULL) {
+						TAILQ_FOREACH_SAFE(lu, lul, entries, lutmp) {
+							TAILQ_REMOVE(lul, lu, entries);
+							xfree(&lu->uri);
+							xfree(&lu);
+							count--;
+						}
+
+					} else {
+						TAILQ_FOREACH_SAFE(lu, lul, entries, lutmp) {
+							if (strcasecmp(lu->uri, lm->value) == 0) {
+								TAILQ_REMOVE(lul, lu, entries);
+								xfree(&lu->uri);
+								xfree(&lu);
+								count--;
+								break;
+							}
+						}
+					}
+
+					if (count <= 0) {
+						TAILQ_REMOVE(&ldapconf, le, entries);
+						xfree(&le->entry);
+						xfree(&le);
+					}
+				}
+
+				break;
+			}
+
+			case LDAP_ENTRY_HOST_LIST: {
+				if (type == HOST) {
+					long count = 0;
+					struct ldap_host *lh, *lhtmp;
+					struct ldap_host_list *lhl = le->entry;
+
+					TAILQ_FOREACH(lh, lhl, entries)
+						count++;
+
+					if (lm->value == NULL) {
+						TAILQ_FOREACH_SAFE(lh, lhl, entries, lhtmp) {
+							TAILQ_REMOVE(lhl, lh, entries);
+							xfree(&lh->host);
+							xfree(&lh);
+							count--;
+						}
+
+					} else {
+						TAILQ_FOREACH_SAFE(lh, lhl, entries, lhtmp) {
+							if (strcasecmp(lh->host, lm->value) == 0) {
+								TAILQ_REMOVE(lhl, lh, entries);
+								xfree(&lh->host);
+								xfree(&lh);
+								count--;
+								break;
+							}
+						}
+					}
+
+					if (count <= 0) {
+						TAILQ_REMOVE(&ldapconf, le, entries);
+						xfree(&le->entry);
+						xfree(&le);
+					}
+				}
+
+				break;
+			}
+
+			case LDAP_ENTRY_SASL_SECPROPS_LIST: {
+				if (type == SASL_SECPROPS) {
+					long count = 0;
+					struct sasl_secprops *ss , *sstmp;
+					struct sasl_secprops_list *lsl = le->entry;
+
+					TAILQ_FOREACH(ss, lsl, entries)
+						count++;
+
+					if (lm->value == NULL) {
+						TAILQ_FOREACH_SAFE(ss, lsl, entries, sstmp) {
+							TAILQ_REMOVE(lsl, ss, entries);
+							xfree(&ss);
+							count--;
+						}
+
+					} else {
+						unsigned long properties = str2properties(lm->value, NONE);
+
+						TAILQ_FOREACH_SAFE(ss, lsl, entries, sstmp) {
+							if (ss->properties == properties) {
+								TAILQ_REMOVE(lsl, ss, entries);
+								xfree(&ss);
+								count--;
+								break;
+							}
+						}
+					}
+
+					if (count <= 0) {
+						TAILQ_REMOVE(&ldapconf, le, entries);
+						xfree(&le->entry);
+						xfree(&le);
+					}
+				}
+
+				break;
+			}
+
+			default: {
+				if (le->type == type) {
+					TAILQ_REMOVE(&ldapconf, le, entries);
+					ldap_entry_free(&le);
+				}
+
+				break;
+			}
 		}
 	}
-#endif
 
 	return (0);
 }
@@ -1240,100 +1477,7 @@
 
 	TAILQ_FOREACH_SAFE(le, &ldapconf, entries, letmp) {
 		TAILQ_REMOVE(&ldapconf, le, entries);
-
-		switch (le->type) {
-
-			case LDAP_ENTRY_URI_LIST: {
-				struct ldap_uri *lu, *lutmp;
-				struct ldap_uri_list *lul = le->entry;
-
-				TAILQ_FOREACH_SAFE(lu, lul, entries, lutmp) {
-					TAILQ_REMOVE(lul, lu, entries);
-					xfree(&lu->uri);
-					xfree(&lu);
-				}
-
-				break;
-			}
-
-			case LDAP_ENTRY_HOST_LIST: {
-				struct ldap_host *lh, *lhtmp;
-				struct ldap_host_list *lhl = le->entry;
-
-				TAILQ_FOREACH_SAFE(lh, lhl, entries, lhtmp) {
-					TAILQ_REMOVE(lhl, lh, entries);
-					xfree(&lh->host);
-					xfree(&lh);
-				}
-
-				break;
-			}
-
-			case LDAP_ENTRY_SASL_SECPROPS_LIST: {
-				struct sasl_secprops *ss, *sstmp;
-				struct sasl_secprops_list *lsl = le->entry;
-
-				TAILQ_FOREACH_SAFE(ss, lsl, entries, sstmp) {
-					TAILQ_REMOVE(lsl, ss, entries);
-					xfree(&ss);
-				}
-
-				break;
-			}
-
-			case LDAP_ENTRY_COMMENT:
-				xfree(&((struct ldap_comment *)le->entry)->text);
-				break;
-
-			case BASE:
-				xfree(&((struct ldap_base *)le->entry)->base);
-				break;
-			case BINDDN:
-				xfree(&((struct ldap_binddn *)le->entry)->dn);
-				break;
-
-			case SASL_MECH:
-				xfree(&((struct sasl_mech *)le->entry)->mechanism);
-				break;
-			case SASL_REALM:
-				xfree(&((struct sasl_realm *)le->entry)->realm);
-				break;
-			case SASL_AUTHCID:
-				xfree(&((struct sasl_authcid *)le->entry)->authcid);
-				break;
-			case SASL_AUTHZID:
-				xfree(&((struct sasl_authzid *)le->entry)->authzid);
-				break;
-			case SASL_SECPROPS: {
-				/* XXX get back to this later XXX */
-				break;
-			}
-
-			case TLS_CACERT:
-				xfree(&((struct tls_cacert *)le->entry)->filename);
-				break;
-			case TLS_CACERTDIR:
-				xfree(&((struct tls_cacertdir *)le->entry)->path);
-				break;
-			case TLS_CERT:
-				xfree(&((struct tls_cert *)le->entry)->filename);
-				break;
-			case TLS_KEY:
-				xfree(&((struct tls_key *)le->entry)->filename);
-				break;
-			case TLS_CIPHER_SUITE:
-				xfree(&((struct tls_cipher_suite *)le->entry)->cipher_suite_spec);
-				break;
-			case TLS_RANDFILE:
-				xfree(&((struct tls_randfile *)le->entry)->filename);
-				break;
-			case TLS_CRLFILE:
-				xfree(&((struct tls_crlfile *)le->entry)->filename);
-				break;
-		}
-
-		xfree(&le->entry);
-		xfree(&le);
+		ldap_entry_free(&le);
 	}
 }
 



More information about the Commits mailing list