Don't make lp_load create a new context.
authorjelmer <jelmer@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Sat, 8 Dec 2007 23:32:37 +0000 (23:32 +0000)
committerjelmer <jelmer@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Sat, 8 Dec 2007 23:32:37 +0000 (23:32 +0000)
git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@26352 0c0555d6-39d7-0310-84fc-f1cc0bd64818

13 files changed:
source/client/smbmount.c
source/client/smbspool.c
source/lib/cmdline/popt_common.c
source/param/loadparm.c
source/scripting/ejs/smbcalls_config.c
source/scripting/ejs/smbscript.c
source/scripting/libjs/provision.js
source/scripting/libjs/upgrade.js
source/torture/gentest.c
source/torture/locktest.c
source/torture/locktest2.c
source/torture/masktest.c
source/utils/testparm.c

index b32bcf5b68d609cde136130ba428cb2d393aa5e2..0c1c330104b954e179b84f095ff7b47b6f018c9b 100644 (file)
@@ -897,7 +897,9 @@ static void parse_mount_smb(int argc, char **argv)
                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 @@ static void parse_mount_smb(int argc, char **argv)
        }
        strupper(my_netbios_name);
 
-       init_mount(global_loadparm);
+       init_mount(lp_ctx);
        return 0;
 }
index 0951fb2befec5aa27b54c50c99e0e65782001b69..80a11d5f2d839df390a4d79e3867ddf2a555afa2 100644 (file)
@@ -177,7 +177,9 @@ static int          smb_print(struct smbcli_state *, char *, FILE *);
 
   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);
   }
index 2bbb59dbda823910ee7b01b06c96d770ff564aef..73b3eecfbfee0aad97d3cbbd61441212d3d31441 100644 (file)
@@ -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 @@ static void popt_samba_callback(poptContext con,
                           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 @@ static void popt_samba_callback(poptContext con,
                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 @@ static void popt_samba_callback(poptContext con,
                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 @@ static void popt_samba_callback(poptContext con,
 
        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 @@ static void popt_common_callback(poptContext con,
                           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':
index b045269192951483f8fd8cb7d756986724799852..564dede3a5ab3e0411e4a8edee0735dfa02ab4ec 100644 (file)
@@ -88,7 +88,6 @@ struct loadparm_global
        char *szServerString;
        char *szAutoServices;
        char *szPasswdChat;
-       const char *szConfigFile;
        char *szShareBackend;
        char *szSAM_URL;
        char *szSECRETS_URL;
@@ -356,8 +355,6 @@ static const struct enum_list enum_server_role[] = {
 #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 @@ static struct parm_struct parm_table[] = {
 
 /* 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_disable_netbios, bDisableNetbios)
 _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 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
        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 @@ bool lp_load(TALLOC_CTX *mem_ctx, const char *filename, struct loadparm_context
 
        reload_charcnv();
 
-       if (ret_lp != NULL)
-               *ret_lp = lp_ctx;
-
        return bRetval;
 }
 
index 157587186cd1274d040005111501d9c5d2d9143e..88c153ead3adc019c7f2dbcb4461bed341c08758 100644 (file)
@@ -161,6 +161,14 @@ static int ejs_lpGet(MprVarHandle eid, int argc, char **argv)
        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_lpSet(MprVarHandle eid, int argc, char **argv)
 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 @@ static int ejs_loadparm_init(MprVarHandle eid, int argc, struct MprVar **argv)
        mprSetStringCFunction(obj, "set", ejs_lpSet);
        mprSetStringCFunction(obj, "reload", ejs_lpReload);
        mprSetStringCFunction(obj, "services", ejs_lpServices);
+       mprSetStringCFunction(obj, "filename", ejs_lpFilename);
        return 0;
 }
 
index e00d52589adbedd782659e587cf1dd2929772008..a4f2e1cd431ddc03fc4a36c35167165a997e507d 100644 (file)
@@ -53,10 +53,12 @@ int main(int argc, const char **argv)
 
        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();
index 7d77bf78852b5631ab0367ba868cd5c543594f1d..f9814884f35edc87a34fedb3af2144ff48145ed4 100644 (file)
@@ -386,7 +386,7 @@ function provision_default_paths(subobj)
        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");
index 3504d850f26236e1e1318cd257d0477585f1c832..3a548fe34b3bb393a622a54802db0cede573b188 100644 (file)
@@ -468,7 +468,6 @@ smbconf_keep = new Array(
        "wins support",
        "csc policy",
        "strict locking",
-       "config file",
        "preload",
        "auto services",
        "lock dir",
index c1e33820af0bf4c51fd78adb37d7f14104df3dd5..e8e531a119efeb054b5e1ff8c680fb571e7c71fc 100644 (file)
@@ -2197,7 +2197,8 @@ static bool split_unc_name(const char *unc, char **server, char **share)
        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());
index a53422fb44bc2016c47b9b69680c13d61931795d..d51c2692d72f13a4e4314c46d8b43745e4c654f2 100644 (file)
@@ -565,7 +565,8 @@ static void usage(void)
        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());
index e8b0170f91f27566ddd741dc90c111b3f3468543..19629d87707bcc53d6e494a4fe8ed00017808f31 100644 (file)
@@ -484,7 +484,8 @@ static void usage(void)
        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"));
index 402ea4ae9c0522ab8bc7dbc651b9ee8699939843..612b96e4f7f9d6b3b7faeab1c2ba1f48140a59ff 100644 (file)
@@ -303,7 +303,8 @@ static void usage(void)
        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);
index bd4bc79240edd422d07115af176c18e3d1c889f6..fe8cc7124a08ff2346a1a3199d94897737f91f17 100644 (file)
@@ -141,7 +141,7 @@ static int do_share_checks(struct loadparm_context *lp_ctx, const char *cname, c
                        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 @@ static int do_share_checks(struct loadparm_context *lp_ctx, const char *cname, c
                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);
        }