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 | |
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>
-rw-r--r-- | source4/ntvfs/cifs/vfs_cifs.c | 38 | ||||
-rw-r--r-- | source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c | 2 | ||||
-rw-r--r-- | source4/ntvfs/ipc/rap_server.c | 2 | ||||
-rw-r--r-- | source4/ntvfs/posix/vfs_posix.c | 12 | ||||
-rw-r--r-- | source4/ntvfs/simple/vfs_simple.c | 2 | ||||
-rw-r--r-- | source4/ntvfs/smb2/vfs_smb2.c | 44 | ||||
-rw-r--r-- | source4/ntvfs/sysdep/sys_lease.c | 9 | ||||
-rw-r--r-- | source4/ntvfs/sysdep/sys_notify.c | 2 | ||||
-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 | ||||
-rw-r--r-- | source4/rpc_server/common/share_info.c | 23 | ||||
-rw-r--r-- | source4/rpc_server/srvsvc/dcesrv_srvsvc.c | 18 | ||||
-rw-r--r-- | source4/rpc_server/srvsvc/srvsvc_ntvfs.c | 6 | ||||
-rw-r--r-- | source4/smb_server/smb/service.c | 5 | ||||
-rw-r--r-- | source4/smb_server/smb2/tcon.c | 5 |
17 files changed, 151 insertions, 72 deletions
diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c index 552f664d8a1..16bbf970b49 100644 --- a/source4/ntvfs/cifs/vfs_cifs.c +++ b/source4/ntvfs/cifs/vfs_cifs.c @@ -155,6 +155,12 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, bool machine_account; bool s4u2proxy; const char* sharename; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(req); + if (tmp_ctx == NULL) { + return NT_STATUS_NO_MEMORY; + } switch (tcon->generic.level) { case RAW_TCON_TCON: @@ -180,11 +186,11 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, /* Here we need to determine which server to connect to. * For now we use parametric options, type cifs. */ - host = share_string_option(scfg, CIFS_SERVER, NULL); - user = share_string_option(scfg, CIFS_USER, NULL); - pass = share_string_option(scfg, CIFS_PASSWORD, NULL); - domain = share_string_option(scfg, CIFS_DOMAIN, NULL); - remote_share = share_string_option(scfg, CIFS_SHARE, NULL); + host = share_string_option(tmp_ctx, scfg, CIFS_SERVER, NULL); + user = share_string_option(tmp_ctx, scfg, CIFS_USER, NULL); + pass = share_string_option(tmp_ctx, scfg, CIFS_PASSWORD, NULL); + domain = share_string_option(tmp_ctx, scfg, CIFS_DOMAIN, NULL); + remote_share = share_string_option(tmp_ctx, scfg, CIFS_SHARE, NULL); if (!remote_share) { remote_share = sharename; } @@ -194,6 +200,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, p = talloc_zero(ntvfs, struct cvfs_private); if (!p) { + TALLOC_FREE(tmp_ctx); return NT_STATUS_NO_MEMORY; } @@ -208,6 +215,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, DEBUG(5, ("CIFS backend: Using specified password\n")); credentials = cli_credentials_init(p); if (!credentials) { + TALLOC_FREE(tmp_ctx); return NT_STATUS_NO_MEMORY; } cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx); @@ -225,6 +233,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, } status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx); if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(tmp_ctx); return status; } } else if (req->session_info->credentials) { @@ -256,6 +265,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, } status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx); if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(tmp_ctx); return status; } cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED); @@ -272,11 +282,13 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, status = NT_STATUS_CROSSREALM_DELEGATION_FAILURE; DEBUG(1,("S4U2Proxy: cli_credentials_get_ccache() gave: ret[%d] str[%s] - %s\n", ret, err_str, nt_errstr(status))); + TALLOC_FREE(tmp_ctx); return status; } } else { DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n")); + TALLOC_FREE(tmp_ctx); return NT_STATUS_INTERNAL_ERROR; } @@ -302,7 +314,10 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, lpcfg_resolve_context(ntvfs->ctx->lp_ctx), ntvfs->ctx->event_ctx); status = smb_composite_connect_recv(creq, p); - NT_STATUS_NOT_OK_RETURN(status); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(tmp_ctx); + return status; + } p->tree = io.out.tree; @@ -311,9 +326,15 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, p->ntvfs = ntvfs; ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS"); - NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type); + if (!ntvfs->ctx->fs_type) { + TALLOC_FREE(tmp_ctx); + return NT_STATUS_NO_MEMORY; + } ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:"); - NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type); + if (!ntvfs->ctx->dev_type) { + TALLOC_FREE(tmp_ctx); + return NT_STATUS_NO_MEMORY; + } if (tcon->generic.level == RAW_TCON_TCONX) { tcon->tconx.out.fs_type = ntvfs->ctx->fs_type; @@ -327,6 +348,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, p->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT); + TALLOC_FREE(tmp_ctx); return NT_STATUS_OK; } diff --git a/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c b/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c index 8c5a53b6f8e..d384dbbca05 100644 --- a/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c +++ b/source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c @@ -81,7 +81,7 @@ static NTSTATUS cifspsx_connect(struct ntvfs_module_context *ntvfs, NT_STATUS_HAVE_NO_MEMORY(p); p->ntvfs = ntvfs; p->next_search_handle = 0; - p->connectpath = talloc_strdup(p, share_string_option(scfg, SHARE_PATH, "")); + p->connectpath = share_string_option(p, scfg, SHARE_PATH, ""); p->open_files = NULL; p->search = NULL; diff --git a/source4/ntvfs/ipc/rap_server.c b/source4/ntvfs/ipc/rap_server.c index 8f36c09ebca..3a133f568da 100644 --- a/source4/ntvfs/ipc/rap_server.c +++ b/source4/ntvfs/ipc/rap_server.c @@ -72,7 +72,7 @@ NTSTATUS rap_netshareenum(TALLOC_CTX *mem_ctx, sizeof(r->out.info[0].info1.share_name)); r->out.info[i].info1.reserved1 = 0; r->out.info[i].info1.share_type = dcesrv_common_get_share_type(mem_ctx, NULL, scfg); - r->out.info[i].info1.comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); + r->out.info[i].info1.comment = share_string_option(mem_ctx, scfg, SHARE_COMMENT, ""); talloc_free(scfg); j++; } diff --git a/source4/ntvfs/posix/vfs_posix.c b/source4/ntvfs/posix/vfs_posix.c index 2ca024b6187..519ca98f39d 100644 --- a/source4/ntvfs/posix/vfs_posix.c +++ b/source4/ntvfs/posix/vfs_posix.c @@ -38,7 +38,8 @@ static void pvfs_setup_options(struct pvfs_state *pvfs) { struct share_config *scfg = pvfs->ntvfs->ctx->config; - const char *eadb; + char *eadb; + char *xattr_backend; bool def_perm_override = false; if (share_bool_option(scfg, SHARE_MAP_HIDDEN, SHARE_MAP_HIDDEN_DEFAULT)) @@ -117,11 +118,12 @@ static void pvfs_setup_options(struct pvfs_state *pvfs) FS_ATTR_SPARSE_FILES; /* allow xattrs to be stored in a external tdb */ - eadb = share_string_option(scfg, PVFS_EADB, NULL); + eadb = share_string_option(pvfs, scfg, PVFS_EADB, NULL); if (eadb != NULL) { pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000, TDB_DEFAULT, O_RDWR|O_CREAT, 0600, pvfs->ntvfs->ctx->lp_ctx); + TALLOC_FREE(eadb); if (pvfs->ea_db != NULL) { pvfs->flags |= PVFS_FLAG_XATTR_ENABLE; } else { @@ -147,7 +149,9 @@ static void pvfs_setup_options(struct pvfs_state *pvfs) } /* enable an ACL backend */ - pvfs->acl_ops = pvfs_acl_backend_byname(share_string_option(scfg, PVFS_ACL, "xattr")); + xattr_backend = share_string_option(pvfs, scfg, PVFS_ACL, "xattr"); + pvfs->acl_ops = pvfs_acl_backend_byname(xattr_backend); + TALLOC_FREE(xattr_backend); } static int pvfs_state_destructor(struct pvfs_state *pvfs) @@ -220,7 +224,7 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs, NT_STATUS_HAVE_NO_MEMORY(pvfs); /* for simplicity of path construction, remove any trailing slash now */ - base_directory = talloc_strdup(pvfs, share_string_option(ntvfs->ctx->config, SHARE_PATH, "")); + base_directory = share_string_option(pvfs, ntvfs->ctx->config, SHARE_PATH, ""); NT_STATUS_HAVE_NO_MEMORY(base_directory); if (strcmp(base_directory, "/") != 0) { trim_string(base_directory, NULL, "/"); diff --git a/source4/ntvfs/simple/vfs_simple.c b/source4/ntvfs/simple/vfs_simple.c index a652494dc17..38ecdfe66b3 100644 --- a/source4/ntvfs/simple/vfs_simple.c +++ b/source4/ntvfs/simple/vfs_simple.c @@ -80,7 +80,7 @@ static NTSTATUS svfs_connect(struct ntvfs_module_context *ntvfs, NT_STATUS_HAVE_NO_MEMORY(p); p->ntvfs = ntvfs; p->next_search_handle = 0; - p->connectpath = talloc_strdup(p, share_string_option(scfg, SHARE_PATH, "")); + p->connectpath = share_string_option(p, scfg, SHARE_PATH, ""); p->open_files = NULL; p->search = NULL; diff --git a/source4/ntvfs/smb2/vfs_smb2.c b/source4/ntvfs/smb2/vfs_smb2.c index 9447b2478c5..bb9a235e326 100644 --- a/source4/ntvfs/smb2/vfs_smb2.c +++ b/source4/ntvfs/smb2/vfs_smb2.c @@ -167,6 +167,12 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, struct cli_credentials *credentials; bool machine_account; struct smbcli_options options; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(req); + if (tmp_ctx == NULL) { + return NT_STATUS_NO_MEMORY; + } switch (tcon->generic.level) { case RAW_TCON_TCON: @@ -179,6 +185,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, sharename = tcon->smb2.in.path; break; default: + TALLOC_FREE(tmp_ctx); return NT_STATUS_INVALID_LEVEL; } @@ -192,11 +199,11 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, /* Here we need to determine which server to connect to. * For now we use parametric options, type cifs. */ - host = share_string_option(scfg, SMB2_SERVER, NULL); - user = share_string_option(scfg, SMB2_USER, NULL); - pass = share_string_option(scfg, SMB2_PASSWORD, NULL); - domain = share_string_option(scfg, SMB2_DOMAIN, NULL); - remote_share = share_string_option(scfg, SMB2_SHARE, NULL); + host = share_string_option(tmp_ctx, scfg, SMB2_SERVER, NULL); + user = share_string_option(tmp_ctx, scfg, SMB2_USER, NULL); + pass = share_string_option(tmp_ctx, scfg, SMB2_PASSWORD, NULL); + domain = share_string_option(tmp_ctx, scfg, SMB2_DOMAIN, NULL); + remote_share = share_string_option(tmp_ctx, scfg, SMB2_SHARE, NULL); if (!remote_share) { remote_share = sharename; } @@ -205,6 +212,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, p = talloc_zero(ntvfs, struct cvfs_private); if (!p) { + TALLOC_FREE(tmp_ctx); return NT_STATUS_NO_MEMORY; } @@ -212,6 +220,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, if (!host) { DEBUG(1,("CIFS backend: You must supply server\n")); + TALLOC_FREE(tmp_ctx); return NT_STATUS_INVALID_PARAMETER; } @@ -219,6 +228,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, DEBUG(5, ("CIFS backend: Using specified password\n")); credentials = cli_credentials_init(p); if (!credentials) { + TALLOC_FREE(tmp_ctx); return NT_STATUS_NO_MEMORY; } cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx); @@ -236,6 +246,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, } status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx); if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(tmp_ctx); return status; } } else if (req->session_info->credentials) { @@ -243,6 +254,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, credentials = req->session_info->credentials; } else { DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n")); + TALLOC_FREE(tmp_ctx); return NT_STATUS_INVALID_PARAMETER; } @@ -257,19 +269,31 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, ntvfs->ctx->event_ctx, &options, lpcfg_socket_options(ntvfs->ctx->lp_ctx), lpcfg_gensec_settings(p, ntvfs->ctx->lp_ctx)); - NT_STATUS_NOT_OK_RETURN(status); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(tmp_ctx); + return status; + } status = smb2_get_roothandle(tree, &p->roothandle); - NT_STATUS_NOT_OK_RETURN(status); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(tmp_ctx); + return status; + } p->tree = tree; p->transport = p->tree->session->transport; p->ntvfs = ntvfs; ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS"); - NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type); + if (!ntvfs->ctx->fs_type) { + TALLOC_FREE(tmp_ctx); + return NT_STATUS_NO_MEMORY; + } ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:"); - NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type); + if (!ntvfs->ctx->dev_type) { + TALLOC_FREE(tmp_ctx); + return NT_STATUS_NO_MEMORY; + } if (tcon->generic.level == RAW_TCON_TCONX) { tcon->tconx.out.fs_type = ntvfs->ctx->fs_type; @@ -280,6 +304,8 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, /* TODO: enable oplocks smbcli_oplock_handler(p->transport, oplock_handler, p); */ + + TALLOC_FREE(tmp_ctx); return NT_STATUS_OK; } diff --git a/source4/ntvfs/sysdep/sys_lease.c b/source4/ntvfs/sysdep/sys_lease.c index 9adb8982742..1c8c33f3cf1 100644 --- a/source4/ntvfs/sysdep/sys_lease.c +++ b/source4/ntvfs/sysdep/sys_lease.c @@ -48,6 +48,7 @@ _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config const char *bname; int i; NTSTATUS status; + TALLOC_CTX * tmp_ctx; if (num_backends == 0) { return NULL; @@ -62,11 +63,16 @@ _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config return NULL; } + tmp_ctx = talloc_new(ctx); + if (tmp_ctx == NULL) { + return NULL; + } + ctx->event_ctx = ev; ctx->msg_ctx = msg; ctx->break_send = break_send; - bname = share_string_option(scfg, LEASE_BACKEND, NULL); + bname = share_string_option(tmp_ctx, scfg, LEASE_BACKEND, NULL); if (!bname) { talloc_free(ctx); return NULL; @@ -90,6 +96,7 @@ _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config return NULL; } + TALLOC_FREE(tmp_ctx); return ctx; } diff --git a/source4/ntvfs/sysdep/sys_notify.c b/source4/ntvfs/sysdep/sys_notify.c index 00300cd25a6..dee3295de80 100644 --- a/source4/ntvfs/sysdep/sys_notify.c +++ b/source4/ntvfs/sysdep/sys_notify.c @@ -62,7 +62,7 @@ _PUBLIC_ struct sys_notify_context *sys_notify_context_create(struct share_confi ctx->ev = ev; - bname = share_string_option(scfg, NOTIFY_BACKEND, NULL); + bname = share_string_option(ctx, scfg, NOTIFY_BACKEND, NULL); if (!bname) { if (num_backends) { bname = backends[0].name; 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; } diff --git a/source4/rpc_server/common/share_info.c b/source4/rpc_server/common/share_info.c index 218901026f4..34330b92ca1 100644 --- a/source4/rpc_server/common/share_info.c +++ b/source4/rpc_server/common/share_info.c @@ -53,23 +53,26 @@ enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct d * this ones are hidden in NetShareEnum, but shown in NetShareEnumAll */ enum srvsvc_ShareType share_type = 0; - const char *sharetype; + char *sharetype; if (!share_bool_option(scfg, SHARE_BROWSEABLE, SHARE_BROWSEABLE_DEFAULT)) { share_type |= STYPE_HIDDEN; } - sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); + sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); if (sharetype && strcasecmp(sharetype, "IPC") == 0) { share_type |= STYPE_IPC; + TALLOC_FREE(sharetype); return share_type; } if (sharetype && strcasecmp(sharetype, "PRINTER") == 0) { share_type |= STYPE_PRINTQ; + TALLOC_FREE(sharetype); return share_type; } + TALLOC_FREE(sharetype); share_type |= STYPE_DISKTREE; return share_type; @@ -78,16 +81,20 @@ enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct d /* This hardcoded value should go into a ldb database! */ const char *dcesrv_common_get_share_path(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { - const char *sharetype; + char *sharetype; char *p; - - sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); + char *path; + + sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); if (sharetype && strcasecmp(sharetype, "IPC") == 0) { + TALLOC_FREE(sharetype); return talloc_strdup(mem_ctx, ""); } - p = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PATH, "")); + TALLOC_FREE(sharetype); + + p = share_string_option(mem_ctx, scfg, SHARE_PATH, ""); if (!p) { return NULL; } @@ -96,7 +103,9 @@ const char *dcesrv_common_get_share_path(TALLOC_CTX *mem_ctx, struct dcesrv_cont } all_string_sub(p, "/", "\\", 0); - return talloc_asprintf(mem_ctx, "C:%s", p); + path = talloc_asprintf(mem_ctx, "C:%s", p); + TALLOC_FREE(p); + return path; } /* This hardcoded value should go into a ldb database! */ diff --git a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c index 0ef676638bc..6521aea5039 100644 --- a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c +++ b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c @@ -622,7 +622,7 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T info->info1->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info1->name); info->info1->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); - info->info1->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); + info->info1->comment = share_string_option(mem_ctx, scfg, SHARE_COMMENT, ""); W_ERROR_HAVE_NO_MEMORY(info->info1->comment); return WERR_OK; @@ -632,14 +632,14 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T info->info2->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info2->name); info->info2->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); - info->info2->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); + info->info2->comment = share_string_option(mem_ctx, scfg, SHARE_COMMENT, ""); W_ERROR_HAVE_NO_MEMORY(info->info2->comment); info->info2->permissions = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, scfg); info->info2->max_users = share_int_option(scfg, SHARE_MAX_CONNECTIONS, SHARE_MAX_CONNECTIONS_DEFAULT); info->info2->current_users = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, scfg); info->info2->path = dcesrv_common_get_share_path(mem_ctx, dce_ctx, scfg); W_ERROR_HAVE_NO_MEMORY(info->info2->path); - info->info2->password = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PASSWORD, NULL)); + info->info2->password = share_string_option(mem_ctx, scfg, SHARE_PASSWORD, NULL); return WERR_OK; } @@ -648,7 +648,7 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T info->info501->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info501->name); info->info501->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); - info->info501->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); + info->info501->comment = share_string_option(mem_ctx, scfg, SHARE_COMMENT, ""); W_ERROR_HAVE_NO_MEMORY(info->info501->comment); info->info501->csc_policy = share_int_option(scfg, SHARE_CSC_POLICY, SHARE_CSC_POLICY_DEFAULT); @@ -659,14 +659,14 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T info->info502->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info502->name); info->info502->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); - info->info502->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); + info->info502->comment = share_string_option(mem_ctx, scfg, SHARE_COMMENT, ""); W_ERROR_HAVE_NO_MEMORY(info->info502->comment); info->info502->permissions = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, scfg); info->info502->max_users = share_int_option(scfg, SHARE_MAX_CONNECTIONS, SHARE_MAX_CONNECTIONS_DEFAULT); info->info502->current_users = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, scfg); info->info502->path = dcesrv_common_get_share_path(mem_ctx, dce_ctx, scfg); W_ERROR_HAVE_NO_MEMORY(info->info502->path); - info->info502->password = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PASSWORD, NULL)); + info->info502->password = share_string_option(mem_ctx, scfg, SHARE_PASSWORD, NULL); info->info502->sd_buf.sd = dcesrv_common_get_security_descriptor(mem_ctx, dce_ctx, scfg); return WERR_OK; @@ -1396,11 +1396,11 @@ static WERROR dcesrv_srvsvc_NetShareCheck(struct dcesrv_call_state *dce_call, TA if (!NT_STATUS_IS_OK(nterr)) { return ntstatus_to_werror(nterr); } - path = share_string_option(scfg, SHARE_PATH, NULL); + path = share_string_option(mem_ctx, scfg, SHARE_PATH, NULL); if (!path) continue; - if (strcmp(device, path) == 0) { - type = share_string_option(scfg, SHARE_TYPE, NULL); + if (strcmp(device, path) == 0) { + type = share_string_option(mem_ctx, scfg, SHARE_TYPE, NULL); if (!type) continue; if (strcmp(type, "DISK") == 0) { diff --git a/source4/rpc_server/srvsvc/srvsvc_ntvfs.c b/source4/rpc_server/srvsvc/srvsvc_ntvfs.c index 49beb50d869..5d6fc92859a 100644 --- a/source4/rpc_server/srvsvc/srvsvc_ntvfs.c +++ b/source4/rpc_server/srvsvc/srvsvc_ntvfs.c @@ -45,7 +45,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, enum ntvfs_type type; struct share_context *sctx; struct share_config *scfg; - const char *sharetype; + char *sharetype; union smb_tcon tcon; const struct tsocket_address *local_address; const struct tsocket_address *remote_address; @@ -71,7 +71,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, #endif /* work out what sort of connection this is */ - sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); + sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); if (sharetype && strcmp(sharetype, "IPC") == 0) { type = NTVFS_IPC; } else if (sharetype && strcmp(sharetype, "PRINTER")) { @@ -80,6 +80,8 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, type = NTVFS_DISK; } + TALLOC_FREE(sharetype); + c = talloc(mem_ctx, struct srvsvc_ntvfs_ctx); NT_STATUS_HAVE_NO_MEMORY(c); diff --git a/source4/smb_server/smb/service.c b/source4/smb_server/smb/service.c index 9ad0f3894ed..e25be1c382d 100644 --- a/source4/smb_server/smb/service.c +++ b/source4/smb_server/smb/service.c @@ -111,7 +111,7 @@ static NTSTATUS make_connection(struct smbsrv_request *req, enum ntvfs_type type; const char *type_str; struct share_config *scfg; - const char *sharetype; + char *sharetype; /* the service might be of the form \\SERVER\SHARE. Should we put the server name we get from this somewhere? */ @@ -138,7 +138,7 @@ static NTSTATUS make_connection(struct smbsrv_request *req, } /* work out what sort of connection this is */ - sharetype = share_string_option(scfg, "type", "DISK"); + sharetype = share_string_option(req, scfg, "type", "DISK"); if (sharetype && strcmp(sharetype, "IPC") == 0) { type = NTVFS_IPC; type_str = "IPC"; @@ -149,6 +149,7 @@ static NTSTATUS make_connection(struct smbsrv_request *req, type = NTVFS_DISK; type_str = "A:"; } + TALLOC_FREE(sharetype); if (strcmp(dev, "?????") != 0 && strcasecmp(type_str, dev) != 0) { /* the client gave us the wrong device type */ diff --git a/source4/smb_server/smb2/tcon.c b/source4/smb_server/smb2/tcon.c index 6ee2eb5f8ec..e7d28479c14 100644 --- a/source4/smb_server/smb2/tcon.c +++ b/source4/smb_server/smb2/tcon.c @@ -241,7 +241,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon enum ntvfs_type type; const char *service = io->smb2.in.path; struct share_config *scfg; - const char *sharetype; + char *sharetype; uint64_t ntvfs_caps = 0; if (strncmp(service, "\\\\", 2) == 0) { @@ -265,7 +265,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon } /* work out what sort of connection this is */ - sharetype = share_string_option(scfg, SHARE_TYPE, "DISK"); + sharetype = share_string_option(req, scfg, SHARE_TYPE, "DISK"); if (sharetype && strcmp(sharetype, "IPC") == 0) { type = NTVFS_IPC; } else if (sharetype && strcmp(sharetype, "PRINTER") == 0) { @@ -273,6 +273,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon } else { type = NTVFS_DISK; } + TALLOC_FREE(sharetype); tcon = smbsrv_smb2_tcon_new(req->session, scfg->name); if (!tcon) { |