[PC-BSD Commits] r17978 - pcbsd-projects/AD_4_PCBSD/krb

svn at pcbsd.org svn at pcbsd.org
Fri Jul 27 17:58:55 PDT 2012


Author: johnh
Date: 2012-07-28 00:58:55 +0000 (Sat, 28 Jul 2012)
New Revision: 17978

Modified:
   pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y
   pcbsd-projects/AD_4_PCBSD/krb/krbconf.c
Log:
working add/modify/delete...  now for cleanup.



Modified: pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y
===================================================================
--- pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y	2012-07-27 22:14:02 UTC (rev 17977)
+++ pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y	2012-07-28 00:58:55 UTC (rev 17978)
@@ -144,6 +144,12 @@
 		ke->type = KRB_ENTRY_BINDING_END;
 		TAILQ_INSERT_TAIL(&fentries, ke, fentries);
 
+		/*
+		 *	Empty binding.
+		 */
+		if (tstack[tindex - 1] == B_OPEN)
+			ce->type = KRB_ENTRY_BINDING_START;
+
 		tstack[tindex++] = B_CLOSE;
 	}
 

Modified: pcbsd-projects/AD_4_PCBSD/krb/krbconf.c
===================================================================
--- pcbsd-projects/AD_4_PCBSD/krb/krbconf.c	2012-07-27 22:14:02 UTC (rev 17977)
+++ pcbsd-projects/AD_4_PCBSD/krb/krbconf.c	2012-07-28 00:58:55 UTC (rev 17978)
@@ -2,6 +2,8 @@
  *	krbconf.c
  *
  *	Configure kerberos
+ *
+ *	This can be better, but it works.
  */
 
 #include "krb5-parser.tab.h"
@@ -411,31 +413,20 @@
 	return (fel);
 }
 
-struct krb_entry *
-km2entry(struct krb_modification *km)
+static int
+parse_modstr(const char *modstr, char **section_pptr,
+	int *nbindingsptr, char *bindings[], int bmax, char **value)
 {
 	struct krb_entry *ke = NULL;
-	int i, bsize, nbindings, bmax = 128;
 	char *tmp, *ptr, *str, *save, *last, *buf, *bptr;
-	char *bindings[bmax];
-	char *section;
+	int i, nbindings, bsize;
 
-	if (km == NULL)
-		return (ke);
-
-	save = xstrdup(km->modstr);
+	save = xstrdup(modstr);
 	ptr = save;
 
-	/*
-	 *	+appdefaults.foo=bar
-	 *	+appdefaults.foo.bar=val
-	 *
-	 *	-appdefaults.foo
-	 *
-	 *	^appdefaults.foo=bar
-	 */
-
 	tmp = strsep(&ptr, "=");	
+	if (value != NULL && ptr != NULL && ptr[0] != 0)
+		*value = xstrdup(ptr);
 	last = str = tmp;
 
 	bsize = 8192;
@@ -457,11 +448,13 @@
 
 			switch (i) {
 				case 0:
-					section = xstrdup(buf);
+					*section_pptr = xstrdup(buf);
 					break;
 
 				default:
 					bindings[nbindings++] = xstrdup(buf);
+					if (nbindings >= bmax)
+						return (-1);
 					break;
 			}
 
@@ -478,10 +471,134 @@
 		tmp++;
 	}
 
+	*nbindingsptr = nbindings;
+	xfree(&save);
+	return (0);
+}
+
+static struct krb_entry *
+create_bindings(struct krb_entry *ke, int nbindings,
+	char *bindings[], int bmax, const char *value)
+{
+	int i;
+	struct krb_entry *ep = ke;
+	struct krb_entry *re = NULL;
+	struct krb_entry_list *el = &ke->kes_bindings;
+
+	for (i = 0;i < nbindings;i++) {
+		struct krb_entry *kb = binding2entry(el, bindings[i]);
+		if (kb != NULL) {
+			el = &kb->keb_bindings;
+			ep = kb;
+			re = kb;
+
+		} else {
+			struct krb_entry *new = xalloc(sizeof(*new));
+			struct krb_entry *end = NULL;
+
+			re = new;
+			new->keb_name = xstrdup(bindings[i]);
+
+			if (i + 1 == nbindings && value == NULL)
+				new->type = KRB_ENTRY_BINDING_START;
+			else if (i + 1 == nbindings && value != NULL)
+				new->type = KRB_ENTRY_BINDING;
+			else
+				new->type = KRB_ENTRY_BINDING_START;
+
+			new->keb_value = NULL;
+			TAILQ_INIT(&new->keb_bindings);
+			new->keb_nbindings = 0;
+
+			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;
+			}
+		}
+	}
+
+	return (re);
+}
+
+static struct krb_entry *
+km2entry(struct krb_modification *km, int create, char **value)
+{
+	struct krb_entry *ke = NULL;
+	int i, nbindings = 0, bmax = 1024;
+	char *section = NULL;
+	char *bindings[bmax];
+
+	if (km == NULL)
+		return (NULL);
+
+	if (parse_modstr(km->modstr, &section, &nbindings, bindings, bmax, value) < 0)
+		return (NULL);
+
 	if (section != NULL) {
 		ke = section2entry(section);
 
-		if (ke != NULL && nbindings > 0) {
+		if (ke != NULL && nbindings > 0 && create == 0) {
 			struct krb_entry_list *el = &ke->kes_bindings;
 
 			for (i = 0;i < nbindings;i++) {
@@ -491,10 +608,28 @@
 
 				el = &ke->keb_bindings;
 			}
+
+		} else if (ke != NULL && nbindings > 0 && create == 1) {
+			ke = create_bindings(ke, nbindings, bindings, bmax,
+				value == NULL ? NULL : *value);
+
+		} else {
+			struct krb_entry *ns = xalloc(sizeof(*ns));
+
+			ns->type = KRB_ENTRY_SECTION;
+			ns->kes_name = xstrdup(section);
+			TAILQ_INIT(&ns->kes_bindings);
+			ns->kes_nbindings = 0;
+
+			TAILQ_INSERT_TAIL(&krbconf, ns, entries);
+			TAILQ_INSERT_TAIL(&fentries, ns, fentries);
+
+			if (nbindings > 0)
+				ke = create_bindings(ns, nbindings, bindings, bmax,
+					value == NULL ? NULL : *value);
 		}
 	}
 
-	xfree(&save);
 	return (ke);
 }
 
@@ -505,12 +640,6 @@
 }
 
 static int
-krb_op_modify(struct krb_entry *ke)
-{
-	return (0);
-}
-
-static int
 krb_fentries_remove_section(struct krb_entry *ke)
 {
 	int delete = 0;
@@ -687,24 +816,38 @@
 	struct krb_modification *km, *kmtmp;
 
 	TAILQ_FOREACH_SAFE(km, &modifications, entries, kmtmp) {
-		struct krb_entry *ke = km2entry(km);
 
-		if (ke != NULL) {
-			int res = -1;
+		switch (km->op) {
+			case KRB_OP_ADD: {
+				char *value = NULL;
+				struct krb_entry *ke = km2entry(km, 1, &value);
 
-			switch (km->op) {
-				case KRB_OP_ADD:
-					res = krb_op_add(ke);
-					break;
+				if (krb_op_add(ke) < 0)
+					warnx("KRB_OP_ADD: returned -1\n");
 
-				case KRB_OP_MODIFY:
-					res = krb_op_modify(ke);
-					break;
+				xfree(&value);
+				break;
+			}
 
-				case KRB_OP_REMOVE:
-					res = krb_op_remove(ke);
-					break;
+			case KRB_OP_MODIFY: {
+				char *value = NULL;
+				struct krb_entry *ke = km2entry(km, 0, &value);
+				if (ke == NULL)
+					warnx("KRB_OP_MODIFY: km2entry() returned NULL\n");
+				if (ke != NULL)
+					ke->keb_value = xstrdup(value);
+			
+				xfree(&value);
+				break;
 			}
+
+			case KRB_OP_REMOVE: {
+				struct krb_entry *ke = km2entry(km, 0, NULL);
+				if (krb_op_remove(ke) < 0)
+					warnx("KRB_OP_REMOVE: returned -1\n");
+
+				break;
+			}
 		}
 
 		TAILQ_REMOVE(&modifications, km, entries);



More information about the Commits mailing list