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/ntvfs | |
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/ntvfs')
-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 |
8 files changed, 85 insertions, 26 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; |