1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-09 20:23:51 +03:00

r26339: Make loadparm talloc-allocated.

This commit is contained in:
Jelmer Vernooij
2007-12-08 23:31:41 +01:00
committed by Stefan Metzmacher
parent 2a005096dd
commit 1e02cd8db1
11 changed files with 64 additions and 56 deletions

View File

@@ -897,7 +897,7 @@ static void parse_mount_smb(int argc, char **argv)
pstrcpy(username,getenv("LOGNAME")); 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", fprintf(stderr, "Can't load %s - run testparm to debug it\n",
lp_config_file()); lp_config_file());
} }

View File

@@ -177,7 +177,7 @@ static int smb_print(struct smbcli_state *, char *, FILE *);
setup_logging(argv[0], DEBUG_STDOUT); 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()); fprintf(stderr, "ERROR: Can't load %s - run testparm to debug it\n", lp_config_file());
return (1); return (1);
} }

View File

@@ -64,9 +64,9 @@ static void popt_samba_callback(poptContext con,
if (reason == POPT_CALLBACK_REASON_POST) { if (reason == POPT_CALLBACK_REASON_POST) {
if (!lp_loaded()) { if (!lp_loaded()) {
if (getenv("SMB_CONF_PATH")) if (getenv("SMB_CONF_PATH"))
lp_load(getenv("SMB_CONF_PATH"), NULL); lp_load(talloc_autofree_context(), getenv("SMB_CONF_PATH"), NULL);
else else
lp_load(dyn_CONFIGFILE, NULL); lp_load(talloc_autofree_context(), dyn_CONFIGFILE, NULL);
} }
/* Hook any 'every Samba program must do this, after /* Hook any 'every Samba program must do this, after
* the smb.conf is setup' functions here */ * the smb.conf is setup' functions here */
@@ -120,7 +120,7 @@ static void popt_samba_callback(poptContext con,
case 's': case 's':
if (arg) { if (arg) {
lp_load(arg, NULL); lp_load(talloc_autofree_context(), arg, NULL);
} }
break; break;

View File

@@ -259,7 +259,7 @@ struct loadparm_service sDefault = {
}; };
/* local variables */ /* local variables */
static struct loadparm_context { struct loadparm_context {
struct loadparm_global Globals; struct loadparm_global Globals;
struct loadparm_service **ServicePtrs; struct loadparm_service **ServicePtrs;
int iNumServices; int iNumServices;
@@ -271,9 +271,9 @@ static struct loadparm_context {
char *subfname; char *subfname;
time_t modtime; time_t modtime;
} *file_lists; } *file_lists;
} loadparm; };
struct loadparm_context *global_loadparm = &loadparm; struct loadparm_context *global_loadparm = NULL;
#define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct)) #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
@@ -1087,7 +1087,7 @@ struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
lp_ctx->iNumServices++; 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) { if (lp_ctx->ServicePtrs[i] == NULL) {
DEBUG(0,("lp_add_service: out of memory!\n")); DEBUG(0,("lp_add_service: out of memory!\n"));
return NULL; return NULL;
@@ -1246,11 +1246,12 @@ void *lp_parm_ptr(struct loadparm_context *lp_ctx,
if (service == NULL) { if (service == NULL) {
if (parm->class == P_LOCAL) if (parm->class == P_LOCAL)
return ((char *)&sDefault)+parm->offset; return ((char *)&sDefault)+parm->offset;
else else if (parm->class == P_GLOBAL)
return ((char *)&lp_ctx->Globals)+parm->offset; 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 @@ static void copy_service(struct loadparm_service *pserviceDest,
strupper(*(char **)dest_ptr); strupper(*(char **)dest_ptr);
break; break;
case P_LIST: 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); *(const char ***)src_ptr);
break; break;
default: default:
@@ -1416,7 +1417,7 @@ static void add_to_file_list(struct loadparm_context *lp_ctx,
} }
if (!f) { if (!f) {
f = talloc(talloc_autofree_context(), struct file_lists); f = talloc(lp_ctx, struct file_lists);
if (!f) if (!f)
return; return;
f->next = lp_ctx->file_lists; f->next = lp_ctx->file_lists;
@@ -1452,7 +1453,7 @@ bool lp_file_list_changed(struct loadparm_context *lp_ctx)
char *n2; char *n2;
time_t mod_time; 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", DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
f->name, n2, ctime(&f->modtime))); f->name, n2, ctime(&f->modtime)));
@@ -1478,12 +1479,11 @@ bool lp_file_list_changed(struct loadparm_context *lp_ctx)
static bool handle_include(struct loadparm_context *lp_ctx, static bool handle_include(struct loadparm_context *lp_ctx,
const char *pszParmValue, char **ptr) const char *pszParmValue, char **ptr)
{ {
char *fname = standard_sub_basic(talloc_autofree_context(), char *fname = standard_sub_basic(lp_ctx, pszParmValue);
pszParmValue);
add_to_file_list(lp_ctx, pszParmValue, fname); 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)) if (file_exist(fname))
return pm_process(fname, do_section, do_parameter, lp_ctx); return pm_process(fname, do_section, do_parameter, lp_ctx);
@@ -1503,7 +1503,7 @@ static bool handle_copy(struct loadparm_context *lp_ctx,
bool bRetval; bool bRetval;
struct loadparm_service *serviceTemp; struct loadparm_service *serviceTemp;
string_set(talloc_autofree_context(), ptr, pszParmValue); string_set(lp_ctx, ptr, pszParmValue);
bRetval = false; bRetval = false;
@@ -1569,7 +1569,7 @@ static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
if (service == NULL) { if (service == NULL) {
data = lp_ctx->Globals.param_opt; data = lp_ctx->Globals.param_opt;
mem_ctx = talloc_autofree_context(); mem_ctx = lp_ctx;
} else { } else {
data = service->param_opt; data = service->param_opt;
mem_ctx = service; mem_ctx = service;
@@ -1732,7 +1732,7 @@ bool lp_do_global_parameter(struct loadparm_context *lp_ctx,
parm_ptr = lp_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]); 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); pszParmName, pszParmValue, lp_ctx);
} }
@@ -2240,14 +2240,38 @@ void lp_killunused(struct loadparm_context *lp_ctx,
} }
} }
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. Initialise the global parameter structure.
***************************************************************************/ ***************************************************************************/
bool loadparm_init(struct loadparm_context *lp_ctx) struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
{ {
int i; int i;
char *myname; 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; lp_ctx->bInGlobalSection = true;
DEBUG(3, ("Initialising global parameters\n")); DEBUG(3, ("Initialising global parameters\n"));
@@ -2257,7 +2281,7 @@ bool loadparm_init(struct loadparm_context *lp_ctx)
parm_table[i].type == P_USTRING) && parm_table[i].type == P_USTRING) &&
parm_table[i].offset != -1 && parm_table[i].offset != -1 &&
!(parm_table[i].flags & FLAG_CMDLINE)) { !(parm_table[i].flags & FLAG_CMDLINE)) {
string_set(talloc_autofree_context(), string_set(lp_ctx,
(char **)( (char **)(
(char *)((parm_table[i].class == P_LOCAL)?&sDefault:&(lp_ctx->Globals)) + (char *)((parm_table[i].class == P_LOCAL)?&sDefault:&(lp_ctx->Globals)) +
parm_table[i].offset), ""); parm_table[i].offset), "");
@@ -2400,50 +2424,34 @@ bool loadparm_init(struct loadparm_context *lp_ctx)
} }
} }
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, Load the services array from the services file. Return True on success,
False on failure. False on failure.
***************************************************************************/ ***************************************************************************/
bool lp_load(TALLOC_CTX *mem_ctx, const char *filename, struct loadparm_context **ret_lp)
bool lp_load(const char *filename, struct loadparm_context **ret_lp)
{ {
char *n2; char *n2;
bool bRetval; bool bRetval;
struct param_opt *data; struct loadparm_context *lp_ctx;
struct loadparm_context *lp_ctx = &loadparm;
if (ret_lp != NULL) if (ret_lp != NULL)
*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; global_loadparm = lp_ctx;
if (lp_ctx->Globals.param_opt != NULL) { filename = talloc_strdup(lp_ctx, filename);
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);
}
}
if (!loadparm_init(lp_ctx))
return false;
lp_ctx->Globals.szConfigFile = filename; lp_ctx->Globals.szConfigFile = filename;
lp_ctx->bInGlobalSection = true; 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)); 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->Globals.szConfigFile, n2);

View File

@@ -189,7 +189,7 @@ static int ejs_lpReload(MprVarHandle eid, int argc, char **argv)
{ {
bool ret; bool ret;
ret = lp_load(lp_configfile(global_loadparm), NULL); ret = lp_load(talloc_autofree_context(), lp_configfile(global_loadparm), NULL);
if (ret) { if (ret) {
unload_interfaces(); unload_interfaces();
} }

View File

@@ -54,9 +54,9 @@ int main(int argc, const char **argv)
fault_setup(argv[0]); fault_setup(argv[0]);
if (getenv("SMB_CONF_PATH")) { 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 { } else {
lp_load(dyn_CONFIGFILE, &lp_ctx); lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
} }
ldb_global_init(); ldb_global_init();

View File

@@ -2197,7 +2197,7 @@ static bool split_unc_name(const char *unc, char **server, char **share)
argc -= NSERVERS; argc -= NSERVERS;
argv += 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[0].credentials = cli_credentials_init(talloc_autofree_context());
servers[1].credentials = cli_credentials_init(talloc_autofree_context()); servers[1].credentials = cli_credentials_init(talloc_autofree_context());

View File

@@ -565,7 +565,7 @@ static void usage(void)
argc -= NSERVERS; argc -= NSERVERS;
argv += 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[0] = cli_credentials_init(talloc_autofree_context());
servers[1] = cli_credentials_init(talloc_autofree_context()); servers[1] = cli_credentials_init(talloc_autofree_context());

View File

@@ -484,7 +484,7 @@ static void usage(void)
argc -= 4; argc -= 4;
argv += 4; argv += 4;
lp_load(dyn_CONFIGFILE, &lp_ctx); lp_load(talloc_autofree_context(), dyn_CONFIGFILE, &lp_ctx);
if (getenv("USER")) { if (getenv("USER")) {
fstrcpy(username,getenv("USER")); fstrcpy(username,getenv("USER"));

View File

@@ -303,7 +303,7 @@ static void usage(void)
argc -= 1; argc -= 1;
argv += 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()); credentials = cli_credentials_init(talloc_autofree_context());
cli_credentials_guess(credentials, lp_ctx); cli_credentials_guess(credentials, lp_ctx);

View File

@@ -239,7 +239,7 @@ static int do_share_checks(struct loadparm_context *lp_ctx, const char *cname, c
fprintf(stderr, "Loaded smb config files from %s\n", lp_configfile(global_loadparm)); 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"); fprintf(stderr,"Error loading services.\n");
return(1); return(1);
} }