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

svn at pcbsd.org svn at pcbsd.org
Mon Jul 30 21:24:58 PDT 2012


Author: johnh
Date: 2012-07-31 04:24:58 +0000 (Tue, 31 Jul 2012)
New Revision: 18010

Modified:
   pcbsd/current/src-sh/pc-adctl/krb/krbconf.c
Log:
Introduce a force create flag so modify operations can create a node if
it doesn't exist.



Modified: pcbsd/current/src-sh/pc-adctl/krb/krbconf.c
===================================================================
--- pcbsd/current/src-sh/pc-adctl/krb/krbconf.c	2012-07-31 03:49:38 UTC (rev 18009)
+++ pcbsd/current/src-sh/pc-adctl/krb/krbconf.c	2012-07-31 04:24:58 UTC (rev 18010)
@@ -16,6 +16,7 @@
 struct krb_modification {
 	TAILQ_ENTRY(krb_modification) entries;	
 	char *modstr;
+	int create;
 	int op;
 };
 TAILQ_HEAD(krb_modification_list, krb_modification) modifications = 
@@ -94,7 +95,7 @@
 }
 
 static int
-add_modification(const char *m)
+add_modification(const char *m, int create)
 {
 	struct krb_modification *km;
 
@@ -102,9 +103,12 @@
 		return (-1);
 
 	km = xalloc(sizeof(*km));
+	km->create = create;
+
 	switch (m[0]) {
 		case '+':
 			km->op = KRB_OP_ADD;
+			km->create = 1;
 			m += 1;
 			break;
 
@@ -115,6 +119,7 @@
 
 		case '^':
 			km->op = KRB_OP_MODIFY;
+			km->create = 0;
 			m += 1;
 			break;
 
@@ -670,7 +675,7 @@
 }
 
 static struct krb_entry *
-km2entry(struct krb_modification *km, int create, char **value)
+km2entry(struct krb_modification *km, char **value)
 {
 	struct krb_entry *ke = NULL;
 	int i, nbindings = 0, bmax = 1024;
@@ -686,7 +691,7 @@
 	if (section != NULL) {
 		ke = section2entry(section);
 
-		if (ke != NULL && nbindings > 0 && create == 0) {
+		if (ke != NULL && nbindings > 0 && km->create == 0) {
 			struct krb_entry_list *el = &ke->kes_bindings;
 
 			for (i = 0;i < nbindings;i++) {
@@ -697,11 +702,11 @@
 				el = &ke->keb_bindings;
 			}
 
-		} else if (ke != NULL && nbindings > 0 && create == 1) {
+		} else if (ke != NULL && nbindings > 0 && km->create == 1) {
 			ke = create_bindings(ke, nbindings, bindings, bmax,
 				value == NULL ? NULL : *value);
 
-		} else if (create == 1) {
+		} else if (km->create == 1) {
 			struct krb_entry *ns = xalloc(sizeof(*ns));
 
 			ns->type = KRB_ENTRY_SECTION;
@@ -908,7 +913,7 @@
 		switch (km->op) {
 			case KRB_OP_ADD: {
 				char *value = NULL;
-				struct krb_entry *ke = km2entry(km, 1, &value);
+				struct krb_entry *ke = km2entry(km, &value);
 
 				if (krb_op_add(ke) < 0)
 					warnx("KRB_OP_ADD: returned -1\n");
@@ -919,7 +924,7 @@
 
 			case KRB_OP_MODIFY: {
 				char *value = NULL;
-				struct krb_entry *ke = km2entry(km, 0, &value);
+				struct krb_entry *ke = km2entry(km, &value);
 				if (ke == NULL)
 					warnx("KRB_OP_MODIFY: km2entry() returned NULL\n");
 				if (ke != NULL)
@@ -930,7 +935,7 @@
 			}
 
 			case KRB_OP_REMOVE: {
-				struct krb_entry *ke = km2entry(km, 0, NULL);
+				struct krb_entry *ke = km2entry(km, NULL);
 				if (krb_op_remove(ke) < 0)
 					warnx("KRB_OP_REMOVE: returned -1\n");
 
@@ -948,10 +953,12 @@
 main(int argc, char **argv)
 {
 	int ch;
+	int create;
 	char *infile, *outfile;
 
+	create = 0;
 	infile = outfile = NULL;
-	while ((ch = getopt(argc, argv, "f:m:o:")) != -1) {
+	while ((ch = getopt(argc, argv, "f:m:co:")) != -1) {
 		switch (ch) {
 			case 'f':
 				xfree(&infile);
@@ -959,9 +966,14 @@
 				break;
 
 			case 'm':
-				add_modification(optarg);
+				add_modification(optarg, create);
+				create = 0;
 				break;
 
+			case 'c':
+				create++;
+				break;
+
 			case 'o':
 				xfree(&outfile);
 				outfile = xstrdup(optarg);



More information about the Commits mailing list