diff options
author | Garming Sam <garming@catalyst.net.nz> | 2014-02-18 12:06:57 +1300 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-05-07 19:49:15 +0200 |
commit | be0851f7542c5d07077285567b6f6691af172b1b (patch) | |
tree | 1853b4618a015383c1140adba31903e9c31a105c /lib/param/loadparm.c | |
parent | 5a9cef48df0e87caa318dc147c41f6b55104a6ec (diff) | |
download | samba-be0851f7542c5d07077285567b6f6691af172b1b.tar.gz samba-be0851f7542c5d07077285567b6f6691af172b1b.tar.xz samba-be0851f7542c5d07077285567b6f6691af172b1b.zip |
param: move set_param_opt to lib/param
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-on: https://gerrit.samba.org/109
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/param/loadparm.c')
-rw-r--r-- | lib/param/loadparm.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c index 636c41bd201..63be8c4bc0d 100644 --- a/lib/param/loadparm.c +++ b/lib/param/loadparm.c @@ -856,6 +856,63 @@ static struct loadparm_service *getservicebyname(struct loadparm_context *lp_ctx } /** + * Add a parametric option to a parmlist_entry, + * replacing old value, if already present. + */ +void set_param_opt(TALLOC_CTX *mem_ctx, + struct parmlist_entry **opt_list, + const char *opt_name, + const char *opt_value, + unsigned priority) +{ + struct parmlist_entry *new_opt, *opt; + bool not_added; + + opt = *opt_list; + not_added = true; + + /* Traverse destination */ + while (opt) { + /* If we already have same option, override it */ + if (strwicmp(opt->key, opt_name) == 0) { + if ((opt->priority & FLAG_CMDLINE) && + !(priority & FLAG_CMDLINE)) { + /* it's been marked as not to be + overridden */ + return; + } + TALLOC_FREE(opt->value); + TALLOC_FREE(opt->list); + opt->value = talloc_strdup(opt, opt_value); + opt->priority = priority; + not_added = false; + break; + } + opt = opt->next; + } + if (not_added) { + new_opt = talloc(mem_ctx, struct parmlist_entry); + if (new_opt == NULL) { + smb_panic("OOM"); + } + + new_opt->key = talloc_strdup(new_opt, opt_name); + if (new_opt->key == NULL) { + smb_panic("talloc_strdup failed"); + } + + new_opt->value = talloc_strdup(new_opt, opt_value); + if (new_opt->value == NULL) { + smb_panic("talloc_strdup failed"); + } + + new_opt->list = NULL; + new_opt->priority = priority; + DLIST_ADD(*opt_list, new_opt); + } +} + +/** * Copy a service structure to another. * If pcopymapDest is NULL then copy all fields */ |