diff options
author | Garming Sam <garming@catalyst.net.nz> | 2014-01-17 10:16:12 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2014-02-20 10:11:00 +1300 |
commit | bce62e600085270f26053882c5a4e35f5fe4fb5e (patch) | |
tree | 36be15d3c9867498693ae247c119c18b933e835f /source4/param | |
parent | 497f0327a08fbfa444308c90a418ccb6b45b96d6 (diff) | |
download | samba-bce62e600085270f26053882c5a4e35f5fe4fb5e.tar.gz samba-bce62e600085270f26053882c5a4e35f5fe4fb5e.tar.xz samba-bce62e600085270f26053882c5a4e35f5fe4fb5e.zip |
s4: pass down a memory context when performing share_string_option, to allow substitutions
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Change-Id: I24b36db3ac11834c3268b2da929e214c10268b16
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Nadezhda Ivanova <nivanova@samba.org>
Diffstat (limited to 'source4/param')
-rw-r--r-- | source4/param/share.c | 4 | ||||
-rw-r--r-- | source4/param/share.h | 4 | ||||
-rw-r--r-- | source4/param/share_classic.c | 23 | ||||
-rw-r--r-- | source4/param/share_ldb.c | 24 |
4 files changed, 31 insertions, 24 deletions
diff --git a/source4/param/share.c b/source4/param/share.c index da0470d5606..2bf4b89c23c 100644 --- a/source4/param/share.c +++ b/source4/param/share.c @@ -24,9 +24,9 @@ #include "param/param.h" #include "lib/util/samba_modules.h" -const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval) +char *share_string_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name, const char *defval) { - return scfg->ctx->ops->string_option(scfg, opt_name, defval); + return scfg->ctx->ops->string_option(mem_ctx, scfg, opt_name, defval); } int share_int_option(struct share_config *scfg, const char *opt_name, int defval) diff --git a/source4/param/share.h b/source4/param/share.h index ab20c8a2441..9fa37289d28 100644 --- a/source4/param/share.h +++ b/source4/param/share.h @@ -54,7 +54,7 @@ struct share_ops { NTSTATUS (*init)(TALLOC_CTX *, const struct share_ops*, struct tevent_context *ev_ctx, struct loadparm_context *lp_ctx, struct share_context **); - const char *(*string_option)(struct share_config *, const char *, const char *); + char *(*string_option)(TALLOC_CTX *, struct share_config *, const char *, const char *); int (*int_option)(struct share_config *, const char *, int); bool (*bool_option)(struct share_config *, const char *, bool); const char **(*string_list_option)(TALLOC_CTX *, struct share_config *, const char *); @@ -67,7 +67,7 @@ struct share_ops { struct loadparm_context; -const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval); +char *share_string_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name, const char *defval); int share_int_option(struct share_config *scfg, const char *opt_name, int defval); bool share_bool_option(struct share_config *scfg, const char *opt_name, bool defval); const char **share_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name); diff --git a/source4/param/share_classic.c b/source4/param/share_classic.c index 9f00a6847ff..74a454e5e16 100644 --- a/source4/param/share_classic.c +++ b/source4/param/share_classic.c @@ -43,9 +43,10 @@ static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } -static const char *sclassic_string_option(struct share_config *scfg, - const char *opt_name, - const char *defval) +static char *sclassic_string_option(TALLOC_CTX *mem_ctx, + struct share_config *scfg, + const char *opt_name, + const char *defval) { struct loadparm_service *s = talloc_get_type(scfg->opaque, struct loadparm_service); @@ -68,11 +69,11 @@ static const char *sclassic_string_option(struct share_config *scfg, ret = defval; } talloc_free(parm); - return ret; + return talloc_strdup(mem_ctx, ret); } if (strcmp(opt_name, SHARE_NAME) == 0) { - return scfg->name; + return talloc_strdup(mem_ctx, scfg->name); } if (strcmp(opt_name, SHARE_PATH) == 0) { @@ -84,27 +85,27 @@ static const char *sclassic_string_option(struct share_config *scfg, } if (strcmp(opt_name, SHARE_VOLUME) == 0) { - return lpcfg_volume_label(s, lpcfg_default_service(lp_ctx)); + return talloc_strdup(mem_ctx, lpcfg_volume_label(s, lpcfg_default_service(lp_ctx))); } if (strcmp(opt_name, SHARE_TYPE) == 0) { if (lpcfg_printable(s, lpcfg_default_service(lp_ctx))) { - return "PRINTER"; + return talloc_strdup(mem_ctx, "PRINTER"); } if (strcmp("NTFS", lpcfg_fstype(s, lpcfg_default_service(lp_ctx))) == 0) { - return "DISK"; + return talloc_strdup(mem_ctx, "DISK"); } - return lpcfg_fstype(s, lpcfg_default_service(lp_ctx)); + return talloc_strdup(mem_ctx, lpcfg_fstype(s, lpcfg_default_service(lp_ctx))); } if (strcmp(opt_name, SHARE_PASSWORD) == 0) { - return defval; + return talloc_strdup(mem_ctx, defval); } DEBUG(0,("request for unknown share string option '%s'\n", opt_name)); - return defval; + return talloc_strdup(mem_ctx, defval); } static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval) diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 0e27376e96d..0257cd1b937 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -58,13 +58,13 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, return NT_STATUS_OK; } -static const char *sldb_string_option(struct share_config *scfg, const char *opt_name, const char *defval) +static char *sldb_string_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name, const char *defval) { struct ldb_message *msg; struct ldb_message_element *el; const char *colon; - if (scfg == NULL) return defval; + if (scfg == NULL) return talloc_strdup(mem_ctx, defval); msg = talloc_get_type(scfg->opaque, struct ldb_message); @@ -85,22 +85,24 @@ static const char *sldb_string_option(struct share_config *scfg, const char *opt } if (el == NULL) { - return defval; + return talloc_strdup(mem_ctx, defval); } - return (const char *)(el->values[0].data); + return (char *)(el->values[0].data); } static int sldb_int_option(struct share_config *scfg, const char *opt_name, int defval) { - const char *val; + char *val; int ret; - val = sldb_string_option(scfg, opt_name, NULL); + val = sldb_string_option(scfg, scfg, opt_name, NULL); if (val == NULL) return defval; errno = 0; ret = (int)strtol(val, NULL, 10); + TALLOC_FREE(val); + if (errno) return -1; return ret; @@ -108,13 +110,17 @@ static int sldb_int_option(struct share_config *scfg, const char *opt_name, int static bool sldb_bool_option(struct share_config *scfg, const char *opt_name, bool defval) { - const char *val; + char *val; - val = sldb_string_option(scfg, opt_name, NULL); + val = sldb_string_option(scfg, scfg, opt_name, NULL); if (val == NULL) return defval; - if (strcasecmp(val, "true") == 0) return true; + if (strcasecmp(val, "true") == 0) { + TALLOC_FREE(val); + return true; + } + TALLOC_FREE(val); return false; } |