diff options
author | Garming Sam <garming@catalyst.net.nz> | 2014-02-25 16:45:43 +1300 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-05-07 19:49:17 +0200 |
commit | 66338032c243e4fe49a3b7cd71c74b14d7b2c784 (patch) | |
tree | 2f5b7cdcb4bf28f296b0c09720375351dce70b44 /source3/param/loadparm.c | |
parent | 687b35931db026779688891aa10e49ae2d05c4a9 (diff) | |
download | samba-66338032c243e4fe49a3b7cd71c74b14d7b2c784.tar.gz samba-66338032c243e4fe49a3b7cd71c74b14d7b2c784.tar.xz samba-66338032c243e4fe49a3b7cd71c74b14d7b2c784.zip |
param: tidy up get_parametrics_by_service
Reorders the search to check the service first, then check the globals
if it fails, or if none is specified, for better clarity.
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/param/loadparm.c')
-rw-r--r-- | source3/param/loadparm.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 9fa3030928..459528f237 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -1172,20 +1172,12 @@ static bool is_synonym_of(int parm1, int parm2, bool *inverse); * parametrical functions are quite simple */ static struct parmlist_entry *get_parametrics_by_service(struct loadparm_service *service, const char *type, - const char *option) + const char *option, struct parmlist_entry *global_opts) { - bool global_section = false; char* param_key; struct parmlist_entry *data; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (service == NULL) { - data = Globals.param_opt; - global_section = true; - } else { - data = service->param_opt; - } - param_key = talloc_asprintf(mem_ctx, "%s:%s", type, option); if (param_key == NULL) { DEBUG(0,("asprintf failed!\n")); @@ -1193,18 +1185,11 @@ static struct parmlist_entry *get_parametrics_by_service(struct loadparm_service return NULL; } - while (data) { - if (strwicmp(data->key, param_key) == 0) { - TALLOC_FREE(mem_ctx); - return data; - } - data = data->next; - } - - if (!global_section) { - /* Try to fetch the same option but from globals */ - /* but only if we are not already working with Globals */ - data = Globals.param_opt; + /* + * Try to fetch the option from the service. + */ + if (service != NULL) { + data = service->param_opt; while (data) { if (strwicmp(data->key, param_key) == 0) { TALLOC_FREE(mem_ctx); @@ -1214,6 +1199,19 @@ static struct parmlist_entry *get_parametrics_by_service(struct loadparm_service } } + /* + * Fall back to fetching from the globals. + */ + data = global_opts; + while (data) { + if (strwicmp(data->key, param_key) == 0) { + TALLOC_FREE(mem_ctx); + return data; + } + data = data->next; + } + + TALLOC_FREE(mem_ctx); return NULL; @@ -1230,9 +1228,10 @@ static struct parmlist_entry *get_parametrics(int snum, const char *type, if (snum >= iNumServices) return NULL; if (snum < 0) { - return get_parametrics_by_service(NULL, type, option); + return get_parametrics_by_service(NULL, type, option, Globals.param_opt); } else { - return get_parametrics_by_service(ServicePtrs[snum], type, option); + return get_parametrics_by_service(ServicePtrs[snum], + type, option, Globals.param_opt); } } @@ -1296,7 +1295,7 @@ const char *lp_parm_const_string_service(struct loadparm_service *service, const char *type, const char *option, const char *def) { - struct parmlist_entry *data = get_parametrics_by_service(service, type, option); + struct parmlist_entry *data = get_parametrics_by_service(service, type, option, Globals.param_opt); if (data == NULL||data->value==NULL) return def; |