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

jelmer at samba.org jelmer at samba.org
Sat Dec 8 23:31:43 GMT 2007


Author: jelmer
Date: 2007-12-08 23:31:41 +0000 (Sat, 08 Dec 2007)
New Revision: 26339

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

Log:
Make loadparm talloc-allocated.
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/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-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/client/smbmount.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -897,7 +897,7 @@
 		pstrcpy(username,getenv("LOGNAME"));
 	}
 
-	if (!lp_load(dyn_CONFIGFILE, &lp_ctx)) {
+	if (!lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx)) {
 		fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
 			lp_config_file());
 	}

Modified: branches/SAMBA_4_0/source/client/smbspool.c
===================================================================
--- branches/SAMBA_4_0/source/client/smbspool.c	2007-12-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/client/smbspool.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -177,7 +177,7 @@
 
   setup_logging(argv[0], DEBUG_STDOUT);
 
-  if (!lp_load(dyn_CONFIGFILE, &lp_ctx)) {
+  if (!lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx)) {
 	  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-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/lib/cmdline/popt_common.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -64,9 +64,9 @@
 	if (reason == POPT_CALLBACK_REASON_POST) {
 		if (!lp_loaded()) {
 			if (getenv("SMB_CONF_PATH"))
-				lp_load(getenv("SMB_CONF_PATH"), NULL);
+				lp_load(talloc_autofree_context(), getenv("SMB_CONF_PATH"), NULL);
 			else
-				lp_load(dyn_CONFIGFILE, NULL);
+				lp_load(talloc_autofree_context(), dyn_CONFIGFILE, NULL);
 		}
 		/* Hook any 'every Samba program must do this, after
 		 * the smb.conf is setup' functions here */
@@ -120,7 +120,7 @@
 
 	case 's':
 		if (arg) {
-			lp_load(arg, NULL);
+			lp_load(talloc_autofree_context(), arg, NULL);
 		}
 		break;
 

Modified: branches/SAMBA_4_0/source/param/loadparm.c
===================================================================
--- branches/SAMBA_4_0/source/param/loadparm.c	2007-12-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/param/loadparm.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -259,7 +259,7 @@
 };
 
 /* local variables */
-static struct loadparm_context {
+struct loadparm_context {
 	struct loadparm_global Globals;
 	struct loadparm_service **ServicePtrs;
 	int iNumServices;
@@ -271,9 +271,9 @@
 		char *subfname;
 		time_t modtime;
 	} *file_lists;
-} loadparm;
+};
 
-struct loadparm_context *global_loadparm = &loadparm;
+struct loadparm_context *global_loadparm = NULL;
 
 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
 
@@ -1087,7 +1087,7 @@
 		lp_ctx->iNumServices++;
 	} 
 
-	lp_ctx->ServicePtrs[i] = init_service(talloc_autofree_context());
+	lp_ctx->ServicePtrs[i] = init_service(lp_ctx);
 	if (lp_ctx->ServicePtrs[i] == NULL) {
 		DEBUG(0,("lp_add_service: out of memory!\n"));
 		return NULL;
@@ -1246,11 +1246,12 @@
 	if (service == NULL) {
 		if (parm->class == P_LOCAL)
 			return ((char *)&sDefault)+parm->offset;
-		else
-			return ((char *)&lp_ctx->Globals)+parm->offset;
+		else if (parm->class == P_GLOBAL)
+			return ((char *)&(lp_ctx->Globals))+parm->offset;
+		else return NULL;
+	} else {
+		return ((char *)service) + parm->offset;
 	}
-
-	return ((char *)service) + parm->offset;
 }
 
 /***************************************************************************
@@ -1317,7 +1318,7 @@
 					strupper(*(char **)dest_ptr);
 					break;
 				case P_LIST:
-					*(const char ***)dest_ptr = str_list_copy(talloc_autofree_context(), 
+					*(const char ***)dest_ptr = str_list_copy(pserviceDest, 
 										  *(const char ***)src_ptr);
 					break;
 				default:
@@ -1416,7 +1417,7 @@
 	}
 
 	if (!f) {
-		f = talloc(talloc_autofree_context(), struct file_lists);
+		f = talloc(lp_ctx, struct file_lists);
 		if (!f)
 			return;
 		f->next = lp_ctx->file_lists;
@@ -1452,7 +1453,7 @@
 		char *n2;
 		time_t mod_time;
 
-		n2 = standard_sub_basic(talloc_autofree_context(), f->name);
+		n2 = standard_sub_basic(lp_ctx, f->name);
 
 		DEBUGADD(6, ("file %s -> %s  last mod_time: %s\n",
 			     f->name, n2, ctime(&f->modtime)));
@@ -1478,12 +1479,11 @@
 static bool handle_include(struct loadparm_context *lp_ctx, 
 			   const char *pszParmValue, char **ptr)
 {
-	char *fname = standard_sub_basic(talloc_autofree_context(), 
-					 pszParmValue);
+	char *fname = standard_sub_basic(lp_ctx, pszParmValue);
 
 	add_to_file_list(lp_ctx, pszParmValue, fname);
 
-	string_set(talloc_autofree_context(), ptr, fname);
+	string_set(lp_ctx, ptr, fname);
 
 	if (file_exist(fname))
 		return pm_process(fname, do_section, do_parameter, lp_ctx);
@@ -1503,7 +1503,7 @@
 	bool bRetval;
 	struct loadparm_service *serviceTemp;
 
-	string_set(talloc_autofree_context(), ptr, pszParmValue);
+	string_set(lp_ctx, ptr, pszParmValue);
 
 	bRetval = false;
 
@@ -1569,7 +1569,7 @@
 
 	if (service == NULL) {
 		data = lp_ctx->Globals.param_opt;
-		mem_ctx = talloc_autofree_context();
+		mem_ctx = lp_ctx;
 	} else {
 		data = service->param_opt;
 		mem_ctx = service;
@@ -1732,7 +1732,7 @@
 
 	parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
 
-	return set_variable(talloc_autofree_context(), parmnum, parm_ptr, 
+	return set_variable(lp_ctx, parmnum, parm_ptr, 
 			    pszParmName, pszParmValue, lp_ctx);
 }
 
@@ -2240,14 +2240,38 @@
 	}
 }
 
+
+static int lp_destructor(struct loadparm_context *lp_ctx)
+{
+	struct param_opt *data;
+
+	if (lp_ctx->Globals.param_opt != NULL) {
+		struct param_opt *next;
+		for (data = lp_ctx->Globals.param_opt; data; data=next) {
+			next = data->next;
+			if (data->flags & FLAG_CMDLINE) continue;
+			DLIST_REMOVE(lp_ctx->Globals.param_opt, data);
+			talloc_free(data);
+		}
+	}
+
+	return 0;
+}
+
 /***************************************************************************
  Initialise the global parameter structure.
 ***************************************************************************/
-bool loadparm_init(struct loadparm_context *lp_ctx)
+struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
 {
 	int i;
 	char *myname;
+	struct loadparm_context *lp_ctx;
 
+	lp_ctx = talloc(mem_ctx, struct loadparm_context);
+	if (lp_ctx == NULL)
+		return NULL;
+
+	talloc_set_destructor(lp_ctx, lp_destructor);
 	lp_ctx->bInGlobalSection = true;
 
 	DEBUG(3, ("Initialising global parameters\n"));
@@ -2257,7 +2281,7 @@
 		     parm_table[i].type == P_USTRING) &&
 		    parm_table[i].offset != -1 &&
 		    !(parm_table[i].flags & FLAG_CMDLINE)) {
-			string_set(talloc_autofree_context(), 
+			string_set(lp_ctx, 
 				   (char **)(
 				   (char *)((parm_table[i].class == P_LOCAL)?&sDefault:&(lp_ctx->Globals)) +
 				   parm_table[i].offset), "");
@@ -2400,50 +2424,34 @@
 		}
 	}
 
-	return true;
+	return lp_ctx;
 }
 
-_PUBLIC_ _DEPRECATED_ bool lp_load_default(void)
-{
-	return lp_load(dyn_CONFIGFILE, NULL);
-}
-
 /***************************************************************************
  Load the services array from the services file. Return True on success, 
  False on failure.
 ***************************************************************************/
-
-bool lp_load(const char *filename, struct loadparm_context **ret_lp)
+bool lp_load(TALLOC_CTX *mem_ctx, const char *filename, struct loadparm_context **ret_lp)
 {
 	char *n2;
 	bool bRetval;
-	struct param_opt *data;
-	struct loadparm_context *lp_ctx = &loadparm;
+	struct loadparm_context *lp_ctx;
 
 	if (ret_lp != NULL)
 		*ret_lp = NULL;
 
-	filename = talloc_strdup(talloc_autofree_context(), filename);
+	lp_ctx = loadparm_init(mem_ctx);
+	if (lp_ctx == NULL)
+		return false;
 
 	global_loadparm = lp_ctx;
 
-	if (lp_ctx->Globals.param_opt != NULL) {
-		struct param_opt *next;
-		for (data = lp_ctx->Globals.param_opt; data; data=next) {
-			next = data->next;
-			if (data->flags & FLAG_CMDLINE) continue;
-			DLIST_REMOVE(lp_ctx->Globals.param_opt, data);
-			talloc_free(data);
-		}
-	}
+	filename = talloc_strdup(lp_ctx, filename);
 
-	if (!loadparm_init(lp_ctx))
-		return false;
-
 	lp_ctx->Globals.szConfigFile = filename;
 	
 	lp_ctx->bInGlobalSection = true;
-	n2 = standard_sub_basic(talloc_autofree_context(), lp_ctx->Globals.szConfigFile);
+	n2 = standard_sub_basic(lp_ctx, lp_ctx->Globals.szConfigFile);
 	DEBUG(2, ("lp_load: refreshing parameters from %s\n", n2));
 	
 	add_to_file_list(lp_ctx, lp_ctx->Globals.szConfigFile, n2);

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_config.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_config.c	2007-12-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_config.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -189,7 +189,7 @@
 {
 	bool ret;
 	
-	ret = lp_load(lp_configfile(global_loadparm), NULL);
+	ret = lp_load(talloc_autofree_context(), lp_configfile(global_loadparm), NULL);
 	if (ret) {
 		unload_interfaces();
 	}

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbscript.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbscript.c	2007-12-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbscript.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -54,9 +54,9 @@
 	fault_setup(argv[0]);
 
 	if (getenv("SMB_CONF_PATH")) {
-		lp_load(getenv("SMB_CONF_PATH"), &lp_ctx);
+		lp_load(talloc_autofree_context(), getenv("SMB_CONF_PATH"), &lp_ctx);
 	} else {
-		lp_load(dyn_CONFIGFILE, &lp_ctx);
+		lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
 	}
 
 	ldb_global_init();

Modified: branches/SAMBA_4_0/source/torture/gentest.c
===================================================================
--- branches/SAMBA_4_0/source/torture/gentest.c	2007-12-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/torture/gentest.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -2197,7 +2197,7 @@
 	argc -= NSERVERS;
 	argv += NSERVERS;
 
-	lp_load(dyn_CONFIGFILE, &lp_ctx);
+	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
 
 	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-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/torture/locktest.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -565,7 +565,7 @@
 	argc -= NSERVERS;
 	argv += NSERVERS;
 
-	lp_load(dyn_CONFIGFILE, &lp_ctx);
+	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
 
 	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-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/torture/locktest2.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -484,7 +484,7 @@
 	argc -= 4;
 	argv += 4;
 
-	lp_load(dyn_CONFIGFILE, &lp_ctx);
+	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
 
 	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-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/torture/masktest.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -303,7 +303,7 @@
 	argc -= 1;
 	argv += 1;
 
-	lp_load(dyn_CONFIGFILE, &lp_ctx);
+	lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
 
 	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-07 23:56:53 UTC (rev 26338)
+++ branches/SAMBA_4_0/source/utils/testparm.c	2007-12-08 23:31:41 UTC (rev 26339)
@@ -239,7 +239,7 @@
 
 	fprintf(stderr, "Loaded smb config files from %s\n", lp_configfile(global_loadparm));
 
-	if (!lp_load(lp_configfile(global_loadparm), &lp_ctx)) {
+	if (!lp_load(talloc_autofree_context(), lp_configfile(global_loadparm), &lp_ctx)) {
 		fprintf(stderr,"Error loading services.\n");
 		return(1);
 	}



More information about the samba-cvs mailing list