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

svn at pcbsd.org svn at pcbsd.org
Tue Jul 24 11:50:28 PDT 2012


Author: johnh
Date: 2012-07-24 18:50:27 +0000 (Tue, 24 Jul 2012)
New Revision: 17917

Modified:
   pcbsd-projects/AD_4_PCBSD/krb/krb5-lexer.l
   pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.tab.i
   pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y
   pcbsd-projects/AD_4_PCBSD/krb/krbconf.c
   pcbsd-projects/AD_4_PCBSD/krb/krbconf.h
Log:
Committing progress. Ugly but does the job, read to do bulk of work now
to add/modify/remove sections of the file then we will be good to roll
this out.



Modified: pcbsd-projects/AD_4_PCBSD/krb/krb5-lexer.l
===================================================================
--- pcbsd-projects/AD_4_PCBSD/krb/krb5-lexer.l	2012-07-24 18:20:04 UTC (rev 17916)
+++ pcbsd-projects/AD_4_PCBSD/krb/krb5-lexer.l	2012-07-24 18:50:27 UTC (rev 17917)
@@ -36,8 +36,6 @@
 	return (STRING);
 }
 
-
-
 %%
 
 int lineno = 0;

Modified: pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.tab.i
===================================================================
--- pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.tab.i	2012-07-24 18:20:04 UTC (rev 17916)
+++ pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.tab.i	2012-07-24 18:50:27 UTC (rev 17917)
@@ -15,14 +15,9 @@
 
 extern	FILE *yyin, *yyout;
 
-extern	struct krb_config fentries;
+extern	struct krb_entry_list fentries;
+extern	struct krb_entry_list krbconf;
 
-extern	struct krb_binding *new_krb_binding(void);
-extern	struct krb_section *new_krb_section(const char *);
-
-extern	void set_binding_name(struct krb_binding *, const char *);
-extern	void set_binding_value(struct krb_binding *, const char *);
-
 extern	int lineno;
 extern	int tindex;
 extern	int	*tstack;
@@ -47,12 +42,13 @@
 
 #define	ks_bindings		ks->bindings
 #define	ks_nbindings	ks->nbindings
+
 };
 
 extern	struct	_krbinfo bl;
 extern	struct	_krbinfo ll;
 
-#line 53 "krb5-parser.y"
+#line 49 "krb5-parser.y"
 #ifdef YYSTYPE
 #undef  YYSTYPE_IS_DECLARED
 #define YYSTYPE_IS_DECLARED 1

Modified: pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y
===================================================================
--- pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y	2012-07-24 18:20:04 UTC (rev 17916)
+++ pcbsd-projects/AD_4_PCBSD/krb/krb5-parser.y	2012-07-24 18:50:27 UTC (rev 17917)
@@ -11,14 +11,9 @@
 
 extern	FILE *yyin, *yyout;
 
-extern	struct krb_config fentries;
+extern	struct krb_entry_list fentries;
+extern	struct krb_entry_list krbconf;
 
-extern	struct krb_binding *new_krb_binding(void);
-extern	struct krb_section *new_krb_section(const char *);
-
-extern	void set_binding_name(struct krb_binding *, const char *);
-extern	void set_binding_value(struct krb_binding *, const char *);
-
 extern	int lineno;
 extern	int tindex;
 extern	int	*tstack;
@@ -43,6 +38,7 @@
 
 #define	ks_bindings		ks->bindings
 #define	ks_nbindings	ks->nbindings
+
 };
 
 extern	struct	_krbinfo bl;
@@ -67,7 +63,7 @@
 
 file:
 	|
-	lines
+	lines |
 
 lines:
 	lines line |
@@ -97,9 +93,19 @@
 section_name:
 	STRING
 	{
-		struct krb_section *ks = new_krb_section($1);
-		TAILQ_INSERT_TAIL(&fentries, ks, entries);
+		struct krb_entry *ke = xalloc(sizeof(*ke));
+		struct krb_section *ks;
 
+		ke->type = KRB_ENTRY_SECTION;
+		ke->kes_name = xstrdup($1);
+		ke->kes_nbindings = 0;
+
+		TAILQ_INIT(&ke->kes_bindings);
+		TAILQ_INSERT_TAIL(&krbconf, ke, entries);
+		TAILQ_INSERT_TAIL(&fentries, ke, fentries);
+
+		ks = &ke->kes;
+
 		xfree(&tstack);
 		tstack = xalloc(STOKENMAX);
 		tindex = 0;
@@ -108,17 +114,18 @@
 		bl.type = TYPE_SECTION;
 		bl.ks = ks;
 		cs = ks;
+		ce = ke;
 	}
 
 bindings:
 	binding bindings |
-	binding |
+	binding
 
 binding:
 	|
 	comments |
 	name eq value |
-	name eq bopen bindings bclose 
+	name eq bopen bindings bclose
 
 eq:
 	EQ {
@@ -132,16 +139,25 @@
 
 bclose:
 	B_CLOSE {
+		struct krb_entry *ke = xalloc(sizeof(*ke));
+
+		ke->type = KRB_ENTRY_BINDING_END;
+		TAILQ_INSERT_TAIL(&fentries, ke, fentries);
+
 		tstack[tindex++] = B_CLOSE;
 	}
 
 name:
 	STRING
 	{
-		struct krb_binding *kb = new_krb_binding();
-		TAILQ_INIT(&kb->bindings);
-		kb->name = xstrdup($1);
+		struct krb_entry *ke = xalloc(sizeof(*ke));
 
+		ke->type = KRB_ENTRY_BINDING;
+		ke->keb_name = xstrdup($1);
+		ke->keb_value = NULL;
+		ke->keb_nbindings = 0;
+		TAILQ_INIT(&ke->keb_bindings);
+
 		/*
 		 *	Start of a section, set the binding list to a sectionk
 		 *	binding list.
@@ -162,6 +178,8 @@
 		 *	list.
 		 */
 		} else if (tstack[tindex - 1] == B_OPEN) {
+			ce->type = KRB_ENTRY_BINDING_START;
+
 			ll = bl;
 			bl.type = TYPE_BINDING;
 			bl.kb = cb;
@@ -178,15 +196,18 @@
 		}
 
 		if (bl.type == TYPE_SECTION) {
-			TAILQ_INSERT_TAIL(&bl.ks_bindings, kb, entries);
+			TAILQ_INSERT_TAIL(&bl.ks_bindings, ke, entries);
 			bl.ks_nbindings++;
 
 		} else {
-			TAILQ_INSERT_TAIL(&bl.kb_bindings, kb, entries);
+			TAILQ_INSERT_TAIL(&bl.kb_bindings, ke, entries);
 			bl.kb_nbindings++;
 		}
 
-		cb = kb;
+		TAILQ_INSERT_TAIL(&fentries, ke, fentries);
+
+		cb = &ke->keb;
+		ce = ke;
 		tstack[tindex++] = NAME;
 	}
 
@@ -199,7 +220,15 @@
 
 comment:
 	COMMENT
+	{
+		struct krb_entry *ke = xalloc(sizeof(*ke));
 
+		ke->type = KRB_ENTRY_COMMENT;
+		ke->kec_text = xstrdup($1);
+
+		TAILQ_INSERT_TAIL(&fentries, ke, fentries);
+	}
+
 %%
 
 int tindex;
@@ -207,37 +236,11 @@
 
 struct	krb_section *cs = NULL;
 struct	krb_binding *cb = NULL;
+struct	krb_entry *ce = NULL;
 
 struct	_krbinfo bl;
 struct	_krbinfo ll;
 
-struct krb_binding *
-new_krb_binding(void)
-{
-	struct krb_binding *kb = xalloc(sizeof(*kb));
-
-	kb->name = NULL;
-	kb->value = NULL;
-	kb->nbindings = 0;
-
-	TAILQ_INIT(&kb->bindings);
-
-	return (kb);
-}
-
-struct krb_section *
-new_krb_section(const char *name)
-{
-	struct krb_section *ks = xalloc(sizeof(*ks));
-
-	ks->name = xstrdup(name);
-	ks->nbindings = 0;
-
-	TAILQ_INIT(&ks->bindings);
-
-	return (ks);
-}
-
 void
 yyerror(const char *str)
 {

Modified: pcbsd-projects/AD_4_PCBSD/krb/krbconf.c
===================================================================
--- pcbsd-projects/AD_4_PCBSD/krb/krbconf.c	2012-07-24 18:20:04 UTC (rev 17916)
+++ pcbsd-projects/AD_4_PCBSD/krb/krbconf.c	2012-07-24 18:50:27 UTC (rev 17917)
@@ -35,7 +35,8 @@
 TAILQ_HEAD(krb_modification_list, krb_modification) krb_modifications = 
 	TAILQ_HEAD_INITIALIZER(krb_modifications);
 
-struct krb_config fentries = TAILQ_HEAD_INITIALIZER(fentries);
+struct krb_entry_list fentries = TAILQ_HEAD_INITIALIZER(fentries);
+struct krb_entry_list krbconf = TAILQ_HEAD_INITIALIZER(krbconf);
 
 void *
 xalloc(size_t size)
@@ -203,76 +204,112 @@
 }
 #endif
 
-static int
-write_krb5_bindings(struct krb_binding *kb, int indent)
+
+static void
+do_indent(FILE *fp, int indent)
 {
-	if (kb == NULL)
-		return (-1);
+	int i = 0;
 
-	if (kb->nbindings > 0) {
-		struct krb_binding *kbtmp;
-		int i;
+	for (i = 0;i < indent;i++)
+		fprintf(fp, "\t");
+}
 
-		for (i = 0;i < indent;i++)
-			fprintf(yyout, "\t");
-		fprintf(yyout, "%s = { \n", kb->name, kb->nbindings);
+static void
+write_krb5_conf(void)
+{
+	int indent;
+	int section;
+	struct krb_entry *ke;
 
-		TAILQ_FOREACH(kbtmp, &kb->bindings, entries) {
+	indent = section = 0;
+	TAILQ_FOREACH(ke, &fentries, fentries) {
 
-			if (kbtmp->nbindings > 0) {
-				write_krb5_bindings(kbtmp, indent + 1);
+		if (ke->type == KRB_ENTRY_SECTION) {
+			fprintf(yyout, "\n");
+			do_indent(yyout, 0);
+			fprintf(yyout, "[%s]\n", ke->kes_name);
+			section = 1;
+			indent = 1;
 
-			} else {
-				int i;
+		} else if (ke->type == KRB_ENTRY_BINDING_START) {
+			if (section == 0)
+				fprintf(yyout, "\n");
 
-				for (i = 0;i < indent + 1;i++)
-					fprintf(yyout, "\t");
-				fprintf(yyout, "%s = %s\n", kbtmp->name, kbtmp->value);
-			}
-		}	
+			do_indent(yyout, indent);
+			fprintf(yyout, "%s = {\n", ke->keb_name);
+			section = 0;
+			indent++;
 
-		for (i = 0;i < indent;i++)
-			fprintf(yyout, "\t");
-		fprintf(yyout, "}\n");
+		} else if (ke->type == KRB_ENTRY_BINDING) {
+			do_indent(yyout, indent);
+			fprintf(yyout, "%s = %s\n", ke->keb_name, ke->keb_value);
 
-	} else {
-		int i;
+		} else if (ke->type == KRB_ENTRY_BINDING_END) {
+			indent--;
+			do_indent(yyout, indent);
+			fprintf(yyout, "}\n");
 
-		for (i = 0;i < indent;i++)
-			fprintf(yyout, "\t");
+		} else if (ke->type == KRB_ENTRY_COMMENT) {
+			do_indent(yyout, 0);
+			fprintf(yyout, "%s\n", ke->kec_text);
 
-		if (kb->value != NULL) {
-			fprintf(yyout, "%s = %s\n", kb->name, kb->value);
-
-		} else {
-			fprintf(yyout, "%s = { }\n", kb->name);
+		} else if (ke->type == KRB_ENTRY_NULL) {
+			fprintf(yyout, "\n");
 		}
 	}
 
-	return (0);
 }
 
 
 static void
-write_krb5_conf(void)
+krb5_bindings_unlink(struct krb_entry_list *el)
 {
-	struct krb_section *ks;
+	struct krb_entry *ke, *ketmp;
 
-	TAILQ_FOREACH(ks, &fentries, entries) {
-		fprintf(yyout, "[%s]\n", ks->name);
+	TAILQ_FOREACH_SAFE(ke, el, entries, ketmp) {
+		if (ke->type == KRB_ENTRY_BINDING && ke->keb_nbindings > 0)
+			krb5_bindings_unlink(&ke->keb_bindings);
 
-		if (ks->nbindings > 0) {
-			struct krb_binding *kb;
-
-			TAILQ_FOREACH(kb, &ks->bindings, entries)
-				write_krb5_bindings(kb, 1);
-		}
+		TAILQ_REMOVE(el, ke, entries);
 	}
 }
 
 static void
 krb5_conf_free(void)
 {
+	struct krb_entry *ke, *ketmp;
+
+	/*
+	 *	Unlink from krbconf list.
+	 */
+	TAILQ_FOREACH_SAFE(ke, &krbconf, entries, ketmp) {
+		if (ke->type == KRB_ENTRY_SECTION && ke->kes_nbindings > 0)
+			krb5_bindings_unlink(&ke->kes_bindings);
+		TAILQ_REMOVE(&krbconf, ke, entries);
+	}
+
+	/*
+	 *	Free everything from the fentries list.
+	 */
+	TAILQ_FOREACH_SAFE(ke, &fentries, fentries, ketmp) {
+		switch (ke->type) {
+			case KRB_ENTRY_SECTION:
+				xfree(&ke->kes_name);
+				break;
+
+			case KRB_ENTRY_BINDING:
+				xfree(&ke->keb_name);
+				xfree(&ke->keb_value);
+				break;
+
+			case KRB_ENTRY_COMMENT:
+				xfree(&ke->kec_text);
+				break;
+		}
+
+		TAILQ_REMOVE(&fentries, ke, fentries);
+		xfree(&ke);
+	}
 }
 
 int

Modified: pcbsd-projects/AD_4_PCBSD/krb/krbconf.h
===================================================================
--- pcbsd-projects/AD_4_PCBSD/krb/krbconf.h	2012-07-24 18:20:04 UTC (rev 17916)
+++ pcbsd-projects/AD_4_PCBSD/krb/krbconf.h	2012-07-24 18:50:27 UTC (rev 17917)
@@ -18,6 +18,14 @@
 #include <sysexits.h>
 #include <unistd.h>
 
+#define	KRB_ENTRY_NULL			0x0000
+#define	KRB_ENTRY_SECTION		0x0001
+#define	KRB_ENTRY_BINDING		0x0002
+#define	KRB_ENTRY_BINDING_START	0x0004
+#define	KRB_ENTRY_BINDING_END	0x0008
+#define	KRB_ENTRY_COMMENT		0x0010
+
+
 #define	KRB_S_APPDEFAULTS		"appdefaults"
 #define	KRB_S_LIBDEFAULTS		"libdefaults"
 #define	KRB_S_DOMAIN_REALM		"domain_realm"
@@ -28,28 +36,54 @@
 #define	KRB_S_KADMIN			"kadmin"
 #define	KRB_S_PASSWORD_QUALITY	"password_quality"
 
-#define	KRB_BINDING_LIST	0x00000001
+TAILQ_HEAD(krb_entry_list, krb_entry);
 
-TAILQ_HEAD(krb_binding_list, krb_binding);
+struct krb_comment {
+	char *text;
+};
 
 struct krb_binding {
 	char *name;
 	char *value;
-	unsigned int flags;
 	unsigned int nbindings;
-	struct krb_binding_list bindings;
-	TAILQ_ENTRY(krb_binding) entries;
+	struct krb_entry_list bindings;
 };
 
 struct krb_section {
 	char *name;  
 	unsigned int nbindings;
-	struct krb_binding_list bindings;
-	TAILQ_ENTRY(krb_section) entries;
+	struct krb_entry_list bindings;
 };
 
-TAILQ_HEAD(krb_config, krb_section);
+struct krb_entry {
+	unsigned int type;
+	union {
+		struct krb_section ks;
+		struct krb_binding kb;
+		struct krb_comment kc;
+	} ke;
 
+#define	kes	ke.ks
+#define	keb	ke.kb
+#define	kec	ke.kc
+
+#define	kes_name		kes.name
+#define	kes_nbindings	kes.nbindings
+#define	kes_bindings	kes.bindings
+#define	kes_entries		kes.entries
+
+#define	keb_name		keb.name
+#define	keb_value		keb.value
+#define	keb_nbindings	keb.nbindings
+#define	keb_bindings	keb.bindings
+#define	keb_entries		keb.entries
+
+#define	kec_text		kec.text
+
+	TAILQ_ENTRY(krb_entry) entries;
+	TAILQ_ENTRY(krb_entry) fentries;
+};
+
 extern	void *xalloc(size_t);
 extern	void _xfree(char **);
     



More information about the Commits mailing list