[PC-BSD Commits] r17784 - pcbsd-projects/AD_4_PCBSD/samba

svn at pcbsd.org svn at pcbsd.org
Mon Jul 16 13:19:27 PDT 2012


Author: johnh
Date: 2012-07-16 20:19:27 +0000 (Mon, 16 Jul 2012)
New Revision: 17784

Modified:
   pcbsd-projects/AD_4_PCBSD/samba/sambaconf.c
Log:
Add overwrite support



Modified: pcbsd-projects/AD_4_PCBSD/samba/sambaconf.c
===================================================================
--- pcbsd-projects/AD_4_PCBSD/samba/sambaconf.c	2012-07-16 20:09:58 UTC (rev 17783)
+++ pcbsd-projects/AD_4_PCBSD/samba/sambaconf.c	2012-07-16 20:19:27 UTC (rev 17784)
@@ -16,6 +16,7 @@
 	char *section;
 	char *name;
 	char *value;
+	int overwrite;
 	int op;
 };
 TAILQ_HEAD(smb_modification_list, smb_modification) modifications = 
@@ -65,7 +66,8 @@
 		"Where option in:\n\n"
 		"\t-f <input file>\n"
 		"\t-o <output file>\n"
-		"\t-m <(+|^|-)section:name:value)>\n\n"
+		"\t-m <(+|^|-)section:name=value)>\n"
+		"\t-w\n\n"
 	);
 
 	exit(1);
@@ -144,7 +146,7 @@
 }
 
 static int
-add_modification(const char *m)
+add_modification(const char *m, int overwrite)
 {
 	int i;
 	char *ptr, *eptr, *save;
@@ -176,6 +178,7 @@
 	sm->section = NULL;
 	sm->name = NULL;
 	sm->value = NULL;
+	sm->overwrite = overwrite;
 
 	save = ptr = xstrdup(&m[1]);
 	section = strsep(&ptr, ":");
@@ -226,6 +229,22 @@
 			node = se;
 	}
 
+	if (sm->overwrite) {
+		struct smb_entry *save;
+
+		save = node;
+		TAILQ_FOREACH(se, &fentries, entries) {
+			if (se->type == SMB_ENTRY_PARAMETERS &&
+				strcmp(se->sep_name, sm->name) == 0) {
+				xfree(&se->sep_value);
+				se->sep_value = xstrdup(sm->value);
+				return (0);
+			}
+		}
+
+		node = save;
+	}
+
 	if (node != NULL) {
 		struct smb_entry *new = xalloc(sizeof(*new));
 		new->type = SMB_ENTRY_PARAMETERS;
@@ -352,14 +371,15 @@
 int
 main(int argc, char **argv)
 {
-	int ch;
+	int ch, overwrite;
 	char *infile, *outfile;
 
 	if (argc <= 1)
 		usage();
 
+	overwrite = 0;
 	infile = outfile = NULL;
-	while ((ch = getopt(argc, argv, "f:m:o:")) != -1) {
+	while ((ch = getopt(argc, argv, "f:m:o:w")) != -1) {
 		switch (ch) {
 			case 'f':
 				xfree(&infile);
@@ -367,13 +387,18 @@
 				break;
 
 			case 'm':
-				add_modification(optarg);
+				add_modification(optarg, overwrite);
+				overwrite = 0;
 				break;
 
 			case 'o':
 				xfree(&outfile);
 				outfile = xstrdup(optarg);
 				break;
+	
+			case 'w':
+				overwrite = 1;
+				break;
 
 			case '?':
 			default:



More information about the Commits mailing list