[PC-BSD Commits] r18001 - pcbsd/current/src-sh/pc-adctl/krb

svn at pcbsd.org svn at pcbsd.org
Mon Jul 30 14:12:21 PDT 2012


Author: johnh
Date: 2012-07-30 21:12:20 +0000 (Mon, 30 Jul 2012)
New Revision: 18001

Modified:
   pcbsd/current/src-sh/pc-adctl/krb/krbconf.c
Log:
Messy, but in working order. 



Modified: pcbsd/current/src-sh/pc-adctl/krb/krbconf.c
===================================================================
--- pcbsd/current/src-sh/pc-adctl/krb/krbconf.c	2012-07-30 20:42:13 UTC (rev 18000)
+++ pcbsd/current/src-sh/pc-adctl/krb/krbconf.c	2012-07-30 21:12:20 UTC (rev 18001)
@@ -468,6 +468,110 @@
 	return (0);
 }
 
+static int
+fentries_insert(struct krb_entry *kp, struct krb_entry *ke)
+{
+	struct krb_entry *last, *end = NULL, *entry = NULL;
+
+	if (kp == NULL || ke == NULL)
+		return (-1);
+
+	if (ke->type == KRB_ENTRY_BINDING_START) {
+		end = xalloc(sizeof(*end));
+		end->type = KRB_ENTRY_BINDING_END;
+		end->keb_name = end->keb_value = NULL;
+		end->keb_nbindings = 0;
+		TAILQ_INIT(&end->keb_bindings);
+	}
+
+	switch (kp->type) {
+		case KRB_ENTRY_SECTION:
+			if (kp->kes_nbindings > 0 && ke->type != KRB_ENTRY_BINDING_START) {
+				struct krb_entry *fe, *fetmp, *last = NULL;
+
+				TAILQ_FOREACH_SAFE(fe, &kp->kes_bindings, entries, fetmp) {
+					if (fe == ke)
+						break;
+					last = fe;
+				}
+
+				if (last != NULL) {
+					TAILQ_INSERT_AFTER(&fentries, last, ke, fentries);
+					if (end != NULL)
+						TAILQ_INSERT_AFTER(&fentries, ke, end, fentries);
+				}
+
+			} else if (kp->kes_nbindings > 0 && ke->type == KRB_ENTRY_BINDING_START) {
+				struct krb_entry *fe, *fetmp, *last = NULL;
+				int section = 0;
+
+				TAILQ_FOREACH_SAFE(fe, &fentries, fentries, fetmp) {
+					if (fe == kp) {
+						section = 1;
+						continue;
+					}
+
+					if (fe->type == KRB_ENTRY_SECTION && section > 0)
+						break;
+
+					last = fe;
+				}
+
+				if (section > 0) {
+					TAILQ_INSERT_AFTER(&fentries, last, ke, fentries);
+					if (end != NULL)
+						TAILQ_INSERT_AFTER(&fentries, ke, end, fentries);
+				}
+
+			} else {
+				TAILQ_INSERT_AFTER(&fentries, kp, ke, fentries);
+				if (end != NULL)
+					TAILQ_INSERT_AFTER(&fentries, ke, end, fentries);
+			}
+
+			break;
+
+		case KRB_ENTRY_BINDING:
+		case KRB_ENTRY_BINDING_START: 
+			if (kp->keb_nbindings > 1 && ke->type != KRB_ENTRY_BINDING_START) {
+				struct krb_entry *fe, *fetmp, *last = NULL;
+
+				TAILQ_FOREACH_SAFE(fe, &kp->keb_bindings, entries, fetmp) {
+					if (fe == ke)
+						break;
+					last = fe;
+				}
+
+				if (last != NULL) {
+					TAILQ_INSERT_AFTER(&fentries, last, ke, fentries);
+					if (end != NULL)
+						TAILQ_INSERT_AFTER(&fentries, ke, end, fentries);
+				}
+
+			} else if (kp->keb_nbindings > 1 && ke->type == KRB_ENTRY_BINDING_START) {
+				struct krb_entry *fe, *fetmp;
+
+				TAILQ_FOREACH_SAFE(fe, &fentries, fentries, fetmp) {
+					if (fe == kp) {
+						TAILQ_INSERT_AFTER(&fentries, fe, ke, fentries);
+						if (end != NULL)
+							TAILQ_INSERT_AFTER(&fentries, ke, end, fentries);
+						break;
+					}
+				}
+
+			} else {
+				TAILQ_INSERT_AFTER(&fentries, kp, ke, fentries);
+				if (end != NULL)
+					TAILQ_INSERT_AFTER(&fentries, ke, end, fentries);
+			}
+
+			break;
+	}
+
+	return (0);
+}
+
 static struct krb_entry *
 create_bindings(struct krb_entry *ke, int nbindings,
 	char *bindings[], int bmax, const char *value)
@@ -479,6 +583,7 @@
 
 	for (i = 0;i < nbindings;i++) {
 		struct krb_entry *kb = binding2entry(el, bindings[i]);
+
 		if (kb != NULL) {
 			el = &kb->keb_bindings;
 			ep = kb;
@@ -505,68 +610,21 @@
 			if (new->type == KRB_ENTRY_BINDING && value != NULL)
 				new->keb_value = xstrdup(value);
 
-			if (new->type == KRB_ENTRY_BINDING_START) {
-				end = xalloc(sizeof(*end));
-				end->type = KRB_ENTRY_BINDING_END;
-				end->keb_name = end->keb_value = NULL;
-				end->keb_nbindings = 0;
-				TAILQ_INIT(&end->keb_bindings);
-			}
-
 			switch (ep->type) {
 				case KRB_ENTRY_SECTION:
 					TAILQ_INSERT_TAIL(&ep->kes_bindings, new, entries);
-					if (ep->kes_nbindings > 0) {
-						struct krb_entry *fe, *fetmp, *last = NULL;
-
-						TAILQ_FOREACH_SAFE(fe, &ep->kes_bindings, entries, fetmp) {
-							if (fe == new)
-								break;
-							last = fe;
-						}
-
-						if (last != NULL) {
-							TAILQ_INSERT_AFTER(&fentries, last, new, fentries);
-							if (end != NULL)
-								TAILQ_INSERT_AFTER(&fentries, new, end, fentries);
-						}
-
-					} else {
-						TAILQ_INSERT_AFTER(&fentries, ep, new, fentries);
-						if (end != NULL)
-							TAILQ_INSERT_AFTER(&fentries, new, end, fentries);
-					}
-
 					ep->kes_nbindings++;
 					break;
-
 				case KRB_ENTRY_BINDING:
 				case KRB_ENTRY_BINDING_START:
 					TAILQ_INSERT_TAIL(&ep->keb_bindings, new, entries);
-					if (ep->keb_nbindings > 0) {
-						struct krb_entry *fe, *fetmp, *last = NULL;
-
-						TAILQ_FOREACH_SAFE(fe, &ep->keb_bindings, entries, fetmp) {
-							if (fe == new)
-								break;
-							last = fe;
-						}
-
-						if (last != NULL) {
-							TAILQ_INSERT_AFTER(&fentries, last, new, fentries);
-							if (end != NULL)
-								TAILQ_INSERT_AFTER(&fentries, new, end, fentries);
-						}
-
-					} else {
-						TAILQ_INSERT_AFTER(&fentries, ep, new, fentries);
-						if (end != NULL)
-							TAILQ_INSERT_AFTER(&fentries, new, end, fentries);
-					}
-
 					ep->keb_nbindings++;
 					break;
 			}
+
+			fentries_insert(ep, new);
+			ep = new;
+			re = new;
 		}
 	}
 



More information about the Commits mailing list