svn commit: samba r23750 - in branches: SAMBA_3_0/source/utils SAMBA_3_0_26/source/utils

obnox at samba.org obnox at samba.org
Sat Jul 7 23:57:26 GMT 2007


Author: obnox
Date: 2007-07-07 23:57:25 +0000 (Sat, 07 Jul 2007)
New Revision: 23750

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23750

Log:
Change the behaviour of net conf import when there is a global section
in the current registry and there is no global section in the input
file (or only global options with default values):
In that case the existing global section is now not touched. Before, it
would have been deleted and recreated empty. The new behaviour is how
other shares are treated too.

Note that since the input file is parsed by lp_load, there is currently
no way to distinguish between a section with only default parameters
and a non-existing section in net conf import.

Michael

PS: A couple of trailing white-spaces have been eliminated
and a line was broken to be not longer than 80 chars, too.


Modified:
   branches/SAMBA_3_0/source/utils/net_conf.c
   branches/SAMBA_3_0_26/source/utils/net_conf.c


Changeset:
Modified: branches/SAMBA_3_0/source/utils/net_conf.c
===================================================================
--- branches/SAMBA_3_0/source/utils/net_conf.c	2007-07-07 22:33:45 UTC (rev 23749)
+++ branches/SAMBA_3_0/source/utils/net_conf.c	2007-07-07 23:57:25 UTC (rev 23750)
@@ -583,7 +583,20 @@
 	return ret;
 }
 
+/* return True iff there are nondefault globals */
+static BOOL globals_exist(void)
+{
+	int i = 0;
+	struct parm_struct *parm;
 
+	while ((parm = lp_next_parameter(GLOBAL_SECTION_SNUM, &i, 0)) != NULL) {
+		if (parm->type != P_SEP) {
+			return True;
+		}
+	}
+	return False;
+}
+
 /*
  * the conf functions 
  */
@@ -689,7 +702,7 @@
 	DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
 		filename));
 
-	if (!lp_load(filename, 
+	if (!lp_load(filename,
 		     False,     /* global_only */
 		     True,      /* save_defaults */
 		     False,     /* add_ipc */
@@ -700,10 +713,13 @@
 	}
 
 	if (opt_testmode) {
-		d_printf("\nTEST MODE - would import the following configuration:\n\n");
+		d_printf("\nTEST MODE - "
+			 "would import the following configuration:\n\n");
 	}
 
-	if ((servicename == NULL) || strequal(servicename, GLOBAL_NAME)) {
+	if (((servicename == NULL) && globals_exist()) ||
+	    strequal(servicename, GLOBAL_NAME))
+	{
 		service_found = True;
 		if (import_process_service(ctx, &global_share) != 0) {
 			goto done;
@@ -720,8 +736,8 @@
 		goto done;
 	}
 	while ((share = next_share(shares)) != NULL) {
-		if ((servicename == NULL) 
-		    || strequal(servicename, lp_servicename(share->service))) 
+		if ((servicename == NULL)
+		    || strequal(servicename, lp_servicename(share->service)))
 		{
 			service_found = True;
 			if (import_process_service(ctx, share)!= 0) {
@@ -729,16 +745,16 @@
 			}
 		}
 	}
-	
+
 	if ((servicename != NULL) && !service_found) {
-		d_printf("Share %s not found in file %s\n", 
+		d_printf("Share %s not found in file %s\n",
 			 servicename, filename);
 		goto done;
 
 	}
 
 	ret = 0;
-	
+
 done:
 	TALLOC_FREE(ctx);
 	return ret;

Modified: branches/SAMBA_3_0_26/source/utils/net_conf.c
===================================================================
--- branches/SAMBA_3_0_26/source/utils/net_conf.c	2007-07-07 22:33:45 UTC (rev 23749)
+++ branches/SAMBA_3_0_26/source/utils/net_conf.c	2007-07-07 23:57:25 UTC (rev 23750)
@@ -583,7 +583,20 @@
 	return ret;
 }
 
+/* return True iff there are nondefault globals */
+static BOOL globals_exist(void)
+{
+	int i = 0;
+	struct parm_struct *parm;
 
+	while ((parm = lp_next_parameter(GLOBAL_SECTION_SNUM, &i, 0)) != NULL) {
+		if (parm->type != P_SEP) {
+			return True;
+		}
+	}
+	return False;
+}
+
 /*
  * the conf functions 
  */
@@ -689,7 +702,7 @@
 	DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
 		filename));
 
-	if (!lp_load(filename, 
+	if (!lp_load(filename,
 		     False,     /* global_only */
 		     True,      /* save_defaults */
 		     False,     /* add_ipc */
@@ -700,10 +713,13 @@
 	}
 
 	if (opt_testmode) {
-		d_printf("\nTEST MODE - would import the following configuration:\n\n");
+		d_printf("\nTEST MODE - "
+			 "would import the following configuration:\n\n");
 	}
 
-	if ((servicename == NULL) || strequal(servicename, GLOBAL_NAME)) {
+	if (((servicename == NULL) && globals_exist()) ||
+	    strequal(servicename, GLOBAL_NAME))
+	{
 		service_found = True;
 		if (import_process_service(ctx, &global_share) != 0) {
 			goto done;
@@ -720,8 +736,8 @@
 		goto done;
 	}
 	while ((share = next_share(shares)) != NULL) {
-		if ((servicename == NULL) 
-		    || strequal(servicename, lp_servicename(share->service))) 
+		if ((servicename == NULL)
+		    || strequal(servicename, lp_servicename(share->service)))
 		{
 			service_found = True;
 			if (import_process_service(ctx, share)!= 0) {
@@ -729,16 +745,16 @@
 			}
 		}
 	}
-	
+
 	if ((servicename != NULL) && !service_found) {
-		d_printf("Share %s not found in file %s\n", 
+		d_printf("Share %s not found in file %s\n",
 			 servicename, filename);
 		goto done;
 
 	}
 
 	ret = 0;
-	
+
 done:
 	TALLOC_FREE(ctx);
 	return ret;



More information about the samba-cvs mailing list