1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-02 00:22:11 +03:00

r26352: Don't make lp_load create a new context.

(This used to be commit d0d5c1a823)
This commit is contained in:
Jelmer Vernooij
2007-12-08 23:32:37 +01:00
committed by Stefan Metzmacher
parent 75ac6cd318
commit dd7e5ed88c
13 changed files with 62 additions and 47 deletions

View 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;
}

View 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);
}

View 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':

View 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;
}

View 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;
}

View 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();

View 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");

View File

@ -468,7 +468,6 @@ smbconf_keep = new Array(
"wins support",
"csc policy",
"strict locking",
"config file",
"preload",
"auto services",
"lock dir",

View 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());

View 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());

View 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"));

View 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);

View 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);
}