svn commit: samba r26352 - in branches/SAMBA_4_0: . source/client source/lib/cmdline source/param source/scripting/ejs source/scripting/libjs source/torture source/utils

jelmer at samba.org jelmer at samba.org
Sat Dec 8 23:32:40 GMT 2007


Author: jelmer
Date: 2007-12-08 23:32:37 +0000 (Sat, 08 Dec 2007)
New Revision: 26352

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

Log:
Don't make lp_load create a new context.
Modified:
   branches/SAMBA_4_0/
   branches/SAMBA_4_0/source/client/smbmount.c
   branches/SAMBA_4_0/source/client/smbspool.c
   branches/SAMBA_4_0/source/lib/cmdline/popt_common.c
   branches/SAMBA_4_0/source/param/loadparm.c
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls_config.c
   branches/SAMBA_4_0/source/scripting/ejs/smbscript.c
   branches/SAMBA_4_0/source/scripting/libjs/provision.js
   branches/SAMBA_4_0/source/scripting/libjs/upgrade.js
   branches/SAMBA_4_0/source/torture/gentest.c
   branches/SAMBA_4_0/source/torture/locktest.c
   branches/SAMBA_4_0/source/torture/locktest2.c
   branches/SAMBA_4_0/source/torture/masktest.c
   branches/SAMBA_4_0/source/utils/testparm.c


Changeset:

Property changes on: branches/SAMBA_4_0
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/SAMBA_4_0/source/client/smbmount.c
===================================================================
--- branches/SAMBA_4_0/source/client/smbmount.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/client/smbmount.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -897,7 +897,9 @@
 		pstrcpy(username,getenv("LOGNAME"));
 	}
 
-	if (!lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx)) {
+	lp_ctx = global_loadparm = loadparm_init(talloc_autofree_context());
+
+	if (!lp_load(lp_ctx, dyn_CONFIGFILE)) {
 		fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
 			lp_config_file());
 	}
@@ -923,6 +925,6 @@
 	}
 	strupper(my_netbios_name);
 
-	init_mount(global_loadparm);
+	init_mount(lp_ctx);
 	return 0;
 }

Modified: branches/SAMBA_4_0/source/client/smbspool.c
===================================================================
--- branches/SAMBA_4_0/source/client/smbspool.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/client/smbspool.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -177,7 +177,9 @@
 
   setup_logging(argv[0], DEBUG_STDOUT);
 
-  if (!lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx)) {
+  global_loadparm = lp_ctx = loadparm_init(talloc_autofree_context());
+
+  if (!lp_load(lp_ctx, dyn_CONFIGFILE)) {
 	  fprintf(stderr, "ERROR: Can't load %s - run testparm to debug it\n", lp_config_file());
 	  return (1);
   }

Modified: branches/SAMBA_4_0/source/lib/cmdline/popt_common.c
===================================================================
--- branches/SAMBA_4_0/source/lib/cmdline/popt_common.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/lib/cmdline/popt_common.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -40,6 +40,7 @@
 enum {OPT_OPTION=1,OPT_LEAK_REPORT,OPT_LEAK_REPORT_FULL,OPT_DEBUG_STDERR};
 
 struct cli_credentials *cmdline_credentials = NULL;
+struct loadparm_context *cmdline_lp_ctx = NULL;
 
 static void popt_version_callback(poptContext con,
 			   enum poptCallbackReason reason,
@@ -59,14 +60,13 @@
 			   const char *arg, const void *data)
 {
 	const char *pname;
-	struct loadparm_context *lp_ctx = global_loadparm; /* FIXME: allow overriding */
 
 	if (reason == POPT_CALLBACK_REASON_POST) {
-		if (lp_ctx == NULL) {
+		if (lp_configfile(cmdline_lp_ctx) == NULL) {
 			if (getenv("SMB_CONF_PATH"))
-				lp_load(talloc_autofree_context(), getenv("SMB_CONF_PATH"), &lp_ctx);
+				lp_load(cmdline_lp_ctx, getenv("SMB_CONF_PATH"));
 			else
-				lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
+				lp_load(cmdline_lp_ctx, dyn_CONFIGFILE);
 		}
 		/* Hook any 'every Samba program must do this, after
 		 * the smb.conf is setup' functions here */
@@ -82,6 +82,11 @@
 		pname++;
 
 	if (reason == POPT_CALLBACK_REASON_PRE) {
+		if (global_loadparm != NULL) {
+			cmdline_lp_ctx = global_loadparm;
+		} else {
+			cmdline_lp_ctx = global_loadparm = loadparm_init(talloc_autofree_context());
+		}
 
 		/* Hook for 'almost the first thing to do in a samba program' here */
 		/* setup for panics */
@@ -104,14 +109,14 @@
 		break;
 
 	case OPT_OPTION:
-		if (!lp_set_option(lp_ctx, arg)) {
+		if (!lp_set_option(cmdline_lp_ctx, arg)) {
 			fprintf(stderr, "Error setting option '%s'\n", arg);
 			exit(1);
 		}
 		break;
 
 	case 'd':
-		lp_set_cmdline(lp_ctx, "log level", arg);
+		lp_set_cmdline(cmdline_lp_ctx, "log level", arg);
 		break;
 
 	case OPT_DEBUG_STDERR:
@@ -120,14 +125,14 @@
 
 	case 's':
 		if (arg) {
-			lp_load(talloc_autofree_context(), arg, NULL);
+			lp_load(cmdline_lp_ctx, arg);
 		}
 		break;
 
 	case 'l':
 		if (arg) {
 			char *new_logfile = talloc_asprintf(NULL, "%s/log.%s", arg, pname);
-			lp_set_cmdline(lp_ctx, "log file", new_logfile);
+			lp_set_cmdline(cmdline_lp_ctx, "log file", new_logfile);
 			talloc_free(new_logfile);
 		}
 		break;
@@ -143,7 +148,7 @@
 			   const struct poptOption *opt,
 			   const char *arg, const void *data)
 {
-	struct loadparm_context *lp_ctx = global_loadparm; /* FIXME: allow overriding */
+	struct loadparm_context *lp_ctx = cmdline_lp_ctx;
 
 	switch(opt->val) {
 	case 'O':

Modified: branches/SAMBA_4_0/source/param/loadparm.c
===================================================================
--- branches/SAMBA_4_0/source/param/loadparm.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/param/loadparm.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -88,7 +88,6 @@
 	char *szServerString;
 	char *szAutoServices;
 	char *szPasswdChat;
-	const char *szConfigFile;
 	char *szShareBackend;
 	char *szSAM_URL;
 	char *szSECRETS_URL;
@@ -356,8 +355,6 @@
 #define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
 
 static struct parm_struct parm_table[] = {
-	{"config file", P_STRING, P_GLOBAL, GLOBAL_VAR(szConfigFile), NULL, NULL},
-
 	{"server role", P_ENUM, P_GLOBAL, GLOBAL_VAR(server_role), NULL, enum_server_role},
 
 	{"dos charset", P_STRING, P_GLOBAL, GLOBAL_VAR(dos_charset), NULL, NULL},
@@ -521,6 +518,7 @@
 
 /* local variables */
 struct loadparm_context {
+	const char *szConfigFile;
 	struct loadparm_global *globals;
 	struct loadparm_service **services;
 	int iNumServices;
@@ -682,7 +680,6 @@
 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_support, bWINSsupport)
 _PUBLIC_ FN_GLOBAL_BOOL(lp_wins_dns_proxy, bWINSdnsProxy)
 _PUBLIC_ FN_GLOBAL_STRING(lp_wins_hook, szWINSHook)
-_PUBLIC_ FN_GLOBAL_STRING(lp_configfile, szConfigFile)
 _PUBLIC_ FN_GLOBAL_BOOL(lp_local_master, bLocalMaster)
 _PUBLIC_ FN_GLOBAL_BOOL(lp_readraw, bReadRaw)
 _PUBLIC_ FN_GLOBAL_BOOL(lp_large_readwrite, bLargeReadwrite)
@@ -2399,35 +2396,30 @@
 	return lp_ctx;
 }
 
+const char *lp_configfile(struct loadparm_context *lp_ctx)
+{
+	return lp_ctx->szConfigFile;
+}
+
 /**
  * Load the services array from the services file. 
  *
  * Return True on success, False on failure.
  */
-bool lp_load(TALLOC_CTX *mem_ctx, const char *filename, struct loadparm_context **ret_lp)
+bool lp_load(struct loadparm_context *lp_ctx, const char *filename)
 {
 	char *n2;
 	bool bRetval;
-	struct loadparm_context *lp_ctx;
 
-	if (ret_lp != NULL)
-		*ret_lp = NULL;
-
-	lp_ctx = loadparm_init(mem_ctx);
-	if (lp_ctx == NULL)
-		return false;
-
-	global_loadparm = lp_ctx;
-
 	filename = talloc_strdup(lp_ctx, filename);
 
-	lp_ctx->globals->szConfigFile = filename;
+	lp_ctx->szConfigFile = filename;
 	
 	lp_ctx->bInGlobalSection = true;
-	n2 = standard_sub_basic(lp_ctx, lp_ctx->globals->szConfigFile);
+	n2 = standard_sub_basic(lp_ctx, lp_ctx->szConfigFile);
 	DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
 	
-	add_to_file_list(lp_ctx, lp_ctx->globals->szConfigFile, n2);
+	add_to_file_list(lp_ctx, lp_ctx->szConfigFile, n2);
 
 	/* We get sections first, so have to start 'behind' to make up */
 	lp_ctx->currentService = NULL;
@@ -2452,9 +2444,6 @@
 
 	reload_charcnv();
 
-	if (ret_lp != NULL)
-		*ret_lp = lp_ctx;
-
 	return bRetval;
 }
 

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_config.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_config.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_config.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -161,6 +161,14 @@
 	return 0;
 }
 
+/*
+    v = lp.filename();         obtain filename
+*/
+static int ejs_lpFilename(MprVarHandle eid, int argc, char **argv)
+{
+	mpr_ReturnString(eid, lp_configfile(global_loadparm));
+	return 0;
+}
 
 /*
   set a smb.conf parameter. Only sets in memory, not permanent
@@ -188,8 +196,9 @@
 static int ejs_lpReload(MprVarHandle eid, int argc, char **argv)
 {
 	bool ret;
-	
-	ret = lp_load(talloc_autofree_context(), lp_configfile(global_loadparm), NULL);
+	const char *filename = lp_configfile(global_loadparm);
+
+	ret = lp_load(global_loadparm, filename);
 	if (ret) {
 		unload_interfaces();
 	}
@@ -208,6 +217,7 @@
 	mprSetStringCFunction(obj, "set", ejs_lpSet);
 	mprSetStringCFunction(obj, "reload", ejs_lpReload);
 	mprSetStringCFunction(obj, "services", ejs_lpServices);
+	mprSetStringCFunction(obj, "filename", ejs_lpFilename);
 	return 0;
 }
 

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbscript.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbscript.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbscript.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -53,10 +53,12 @@
 
 	fault_setup(argv[0]);
 
+	global_loadparm = lp_ctx = loadparm_init(talloc_autofree_context());
+
 	if (getenv("SMB_CONF_PATH")) {
-		lp_load(talloc_autofree_context(), getenv("SMB_CONF_PATH"), &lp_ctx);
+		lp_load(lp_ctx, getenv("SMB_CONF_PATH"));
 	} else {
-		lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
+		lp_load(lp_ctx, dyn_CONFIGFILE);
 	}
 
 	ldb_global_init();

Modified: branches/SAMBA_4_0/source/scripting/libjs/provision.js
===================================================================
--- branches/SAMBA_4_0/source/scripting/libjs/provision.js	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/scripting/libjs/provision.js	2007-12-08 23:32:37 UTC (rev 26352)
@@ -386,7 +386,7 @@
 	var dnsdomain = strlower(subobj.REALM);
 	var lp = loadparm_init();
 	var paths = new Object();
-	paths.smbconf = lp.get("config file");
+	paths.smbconf = lp.filename()
 	paths.shareconf = lp.get("private dir") + "/" + "share.ldb";
 	paths.samdb = lp.get("sam database");
 	paths.secrets = lp.get("secrets database");

Modified: branches/SAMBA_4_0/source/scripting/libjs/upgrade.js
===================================================================
--- branches/SAMBA_4_0/source/scripting/libjs/upgrade.js	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/scripting/libjs/upgrade.js	2007-12-08 23:32:37 UTC (rev 26352)
@@ -468,7 +468,6 @@
 	"wins support",
 	"csc policy",
 	"strict locking",
-	"config file",
 	"preload",
 	"auto services",
 	"lock dir",

Modified: branches/SAMBA_4_0/source/torture/gentest.c
===================================================================
--- branches/SAMBA_4_0/source/torture/gentest.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/torture/gentest.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -2197,7 +2197,8 @@
 	argc -= NSERVERS;
 	argv += NSERVERS;
 
-	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
+	global_loadparm = lp_ctx = loadparm_init(talloc_autofree_context());
+	lp_load(lp_ctx, dyn_CONFIGFILE);
 
 	servers[0].credentials = cli_credentials_init(talloc_autofree_context());
 	servers[1].credentials = cli_credentials_init(talloc_autofree_context());

Modified: branches/SAMBA_4_0/source/torture/locktest.c
===================================================================
--- branches/SAMBA_4_0/source/torture/locktest.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/torture/locktest.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -565,7 +565,8 @@
 	argc -= NSERVERS;
 	argv += NSERVERS;
 
-	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
+	global_loadparm = lp_ctx = loadparm_init(talloc_autofree_context());
+	lp_load(lp_ctx, dyn_CONFIGFILE);
 
 	servers[0] = cli_credentials_init(talloc_autofree_context());
 	servers[1] = cli_credentials_init(talloc_autofree_context());

Modified: branches/SAMBA_4_0/source/torture/locktest2.c
===================================================================
--- branches/SAMBA_4_0/source/torture/locktest2.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/torture/locktest2.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -484,7 +484,8 @@
 	argc -= 4;
 	argv += 4;
 
-	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
+	global_loadparm = lp_ctx = loadparm_init(talloc_autofree_context());
+	lp_load(lp_ctx, dyn_CONFIGFILE);
 
 	if (getenv("USER")) {
 		fstrcpy(username,getenv("USER"));

Modified: branches/SAMBA_4_0/source/torture/masktest.c
===================================================================
--- branches/SAMBA_4_0/source/torture/masktest.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/torture/masktest.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -303,7 +303,8 @@
 	argc -= 1;
 	argv += 1;
 
-	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
+	lp_ctx = global_loadparm = loadparm_init(talloc_autofree_context());
+	lp_load(lp_ctx, dyn_CONFIGFILE);
 
 	credentials = cli_credentials_init(talloc_autofree_context());
 	cli_credentials_guess(credentials, lp_ctx);

Modified: branches/SAMBA_4_0/source/utils/testparm.c
===================================================================
--- branches/SAMBA_4_0/source/utils/testparm.c	2007-12-08 23:32:33 UTC (rev 26351)
+++ branches/SAMBA_4_0/source/utils/testparm.c	2007-12-08 23:32:37 UTC (rev 26352)
@@ -141,7 +141,7 @@
 			if (!parameter_name) {
 				lp_dump_one(stdout, show_defaults, service);
 			} else {
-				ret = !lp_dump_a_parameter(lp_ctx, service, parameter_name, stdout, (service == NULL));
+				ret = !lp_dump_a_parameter(lp_ctx, service, parameter_name, stdout);
 			}
 		} else {
 			lp_dump(lp_ctx, stdout, show_defaults, lp_numservices(lp_ctx));
@@ -233,13 +233,15 @@
 		set_local_machine_name(new_local_machine, True);
 	}
 */
+
+	lp_ctx = global_loadparm;
 	
 	/* We need this to force the output */
-	lp_set_cmdline(global_loadparm, "log level", "2");
+	lp_set_cmdline(lp_ctx, "log level", "2");
 
-	fprintf(stderr, "Loaded smb config files from %s\n", lp_configfile(global_loadparm));
+	fprintf(stderr, "Loaded smb config files from %s\n", lp_configfile(lp_ctx));
 
-	if (!lp_load(talloc_autofree_context(), lp_configfile(global_loadparm), &lp_ctx)) {
+	if (!lp_load(lp_ctx, lp_configfile(lp_ctx))) {
 		fprintf(stderr,"Error loading services.\n");
 		return(1);
 	}



More information about the samba-cvs mailing list