From 317054f6eb7c485d8a5476df6df7dbc05a51c4a4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 11 Jun 2019 17:42:38 +0200 Subject: [PATCH] libcli/smb: s/smbXcli_session_copy/smbXcli_session_shallow_copy We should make clear that this is a function for testing only, with possible strange side effects. Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- libcli/smb/smbXcli_base.c | 7 ++++++- libcli/smb/smbXcli_base.h | 2 +- source4/torture/smb2/compound.c | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c index 79e6658182e..3d7a0625ccc 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -5558,7 +5558,7 @@ struct smbXcli_session *smbXcli_session_create(TALLOC_CTX *mem_ctx, return session; } -struct smbXcli_session *smbXcli_session_copy(TALLOC_CTX *mem_ctx, +struct smbXcli_session *smbXcli_session_shallow_copy(TALLOC_CTX *mem_ctx, struct smbXcli_session *src) { struct smbXcli_session *session; @@ -5573,6 +5573,11 @@ struct smbXcli_session *smbXcli_session_copy(TALLOC_CTX *mem_ctx, return NULL; } + /* + * Note we keep a pointer to the session keys of the + * main session and rely on the caller to free the + * shallow copy first! + */ session->conn = src->conn; *session->smb2 = *src->smb2; session->smb2_channel = src->smb2_channel; diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h index a132fbe95af..2afc7165cd9 100644 --- a/libcli/smb/smbXcli_base.h +++ b/libcli/smb/smbXcli_base.h @@ -466,7 +466,7 @@ NTSTATUS smb2cli_validate_negotiate_info_recv(struct tevent_req *req); struct smbXcli_session *smbXcli_session_create(TALLOC_CTX *mem_ctx, struct smbXcli_conn *conn); -struct smbXcli_session *smbXcli_session_copy(TALLOC_CTX *mem_ctx, +struct smbXcli_session *smbXcli_session_shallow_copy(TALLOC_CTX *mem_ctx, struct smbXcli_session *src); bool smbXcli_session_is_guest(struct smbXcli_session *session); bool smbXcli_session_is_authenticated(struct smbXcli_session *session); diff --git a/source4/torture/smb2/compound.c b/source4/torture/smb2/compound.c index a84efc20186..fd657a4a16e 100644 --- a/source4/torture/smb2/compound.c +++ b/source4/torture/smb2/compound.c @@ -262,7 +262,7 @@ static bool test_compound_related1(struct torture_context *tctx, 0, /* capabilities */ 0 /* maximal_access */); - tree->session->smbXcli = smbXcli_session_copy(tree->session, + tree->session->smbXcli = smbXcli_session_shallow_copy(tree->session, tree->session->smbXcli); smb2cli_session_set_id_and_flags(tree->session->smbXcli, UINT64_MAX, 0); @@ -341,7 +341,7 @@ static bool test_compound_related2(struct torture_context *tctx, 0, /* capabilities */ 0 /* maximal_access */); - tree->session->smbXcli = smbXcli_session_copy(tree->session, + tree->session->smbXcli = smbXcli_session_shallow_copy(tree->session, tree->session->smbXcli); smb2cli_session_set_id_and_flags(tree->session->smbXcli, UINT64_MAX, 0); @@ -930,7 +930,7 @@ static bool test_compound_invalid2(struct torture_context *tctx, 0, /* capabilities */ 0 /* maximal_access */); - tree->session->smbXcli = smbXcli_session_copy(tree->session, + tree->session->smbXcli = smbXcli_session_shallow_copy(tree->session, tree->session->smbXcli); smb2cli_session_set_id_and_flags(tree->session->smbXcli, UINT64_MAX, 0);