From c92efb4081d8be7b25161c3a988fb43867ed5ace Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 6 Jun 2017 17:27:44 +0200 Subject: [PATCH 1/3] libcli:smb: Fix pulling strings from the wire BUG: https://bugzilla.samba.org/show_bug.cgi?id=12824 Signed-off-by: Andreas Schneider Reviewed-by: Jeremy Allison (cherry picked from commit a4efe647c51700cee93b7574e5955e264aa96893) --- libcli/smb/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcli/smb/util.c b/libcli/smb/util.c index ef8c9fafa35..80d34281adf 100644 --- a/libcli/smb/util.c +++ b/libcli/smb/util.c @@ -372,6 +372,6 @@ NTSTATUS smb_bytes_pull_str(TALLOC_CTX *mem_ctx, char **_str, bool ucs2, const uint8_t *buf, size_t buf_len, size_t *_buf_consumed) { - return internal_bytes_pull_str(mem_ctx, _str, ucs2, true, + return internal_bytes_pull_str(mem_ctx, _str, ucs2, false, buf, buf_len, _buf_consumed); } -- 2.13.0 From d116399b13499b6cc8e0dab46cb92da3b6346a05 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 6 Jun 2017 17:29:16 +0200 Subject: [PATCH 2/3] s3:libsmb: Fix printing the session setup information This fixes a regression and prints the session setup on connect again: Domain=[SAMBA-TEST] OS=[Windows 6.1] Server=[Samba 4.7.0pre1-DEVELOPERBUILD] smb: \> BUG: https://bugzilla.samba.org/show_bug.cgi?id=12824 Signed-off-by: Andreas Schneider Reviewed-by: Jeremy Allison (cherry picked from commit b6f87af427a1fa2bd397668d9f14cb0cf8ec5015) --- source3/libsmb/cliconnect.c | 3 ++- source3/libsmb/clidfs.c | 32 +++++++++++++++++++++++++------- source3/libsmb/clientgen.c | 13 ------------- source3/torture/masktest.c | 4 +++- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index a2362ceb863..90fc80f92a9 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -1119,7 +1119,8 @@ static void cli_session_setup_gensec_ready(struct tevent_req *req) server_domain = gensec_ntlmssp_server_domain( state->auth_generic->gensec_security); - if (state->cli->server_domain[0] == '\0' && server_domain != NULL) { + if ((state->cli->server_domain == NULL || + state->cli->server_domain[0] == '\0') && server_domain != NULL) { TALLOC_FREE(state->cli->server_domain); state->cli->server_domain = talloc_strdup(state->cli, server_domain); diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index c477d7c6a46..09e21ac7f8d 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -259,13 +259,31 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx, return status; } - if ( show_sessetup ) { - if (*c->server_domain) { - DEBUG(0,("Domain=[%s] OS=[%s] Server=[%s]\n", - c->server_domain,c->server_os,c->server_type)); - } else if (*c->server_os || *c->server_type) { - DEBUG(0,("OS=[%s] Server=[%s]\n", - c->server_os,c->server_type)); + if (show_sessetup) { + const char *server_os = "unknown"; + const char *server_type = "unknown"; + bool do_print = false; + + if (c->server_os != NULL && c->server_os[0] != '\0') { + server_os = c->server_os; + do_print = true; + } + if (c->server_type != NULL && c->server_type[0] != '\0') { + server_type = c->server_type; + do_print = true; + } + + if (c->server_domain != NULL && c->server_domain[0] != '\0') { + DEBUG(0, ("Domain=[%s] OS=[%s] Server=[%s]\n", + c->server_domain, + server_os, + server_type)); + } else { + if (do_print) { + DEBUG(0, ("OS=[%s] Server=[%s]\n", + server_os, + server_type)); + } } } DEBUG(4,(" session setup ok\n")); diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index bc5c1b1ce3c..2c0b8c5f081 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -104,19 +104,6 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx, return NULL; } - cli->server_domain = talloc_strdup(cli, ""); - if (!cli->server_domain) { - goto error; - } - cli->server_os = talloc_strdup(cli, ""); - if (!cli->server_os) { - goto error; - } - cli->server_type = talloc_strdup(cli, ""); - if (!cli->server_type) { - goto error; - } - cli->dfs_mountpoint = talloc_strdup(cli, ""); if (!cli->dfs_mountpoint) { goto error; diff --git a/source3/torture/masktest.c b/source3/torture/masktest.c index 95e0b04b040..57607b069a8 100644 --- a/source3/torture/masktest.c +++ b/source3/torture/masktest.c @@ -212,7 +212,9 @@ static struct cli_state *connect_one(char *share) * mode to turn these on/off ? JRA. */ - if (*c->server_domain || *c->server_os || *c->server_type) + if (c->server_domain != NULL || + c->server_os != NULL || + c->server_type != NULL) DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n", c->server_domain,c->server_os,c->server_type)); -- 2.13.0 From 5efc32f0725ada379280f2fb750a5042f5a97e9b Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 6 Jun 2017 17:54:18 +0200 Subject: [PATCH 3/3] s3:tests: Add a test which checks that the smbclient session setup works BUG: https://bugzilla.samba.org/show_bug.cgi?id=12824 Signed-off-by: Andreas Schneider Reviewed-by: Jeremy Allison (cherry picked from commit d3c4c1e263f187d38a4b25ef63d9e1d8833822b5) --- source3/script/tests/test_smbclient_s3.sh | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh index be7aafbed7c..9c12322ddda 100755 --- a/source3/script/tests/test_smbclient_s3.sh +++ b/source3/script/tests/test_smbclient_s3.sh @@ -1215,6 +1215,36 @@ EOF fi } +test_server_os_message() +{ + tmpfile=$PREFIX/smbclient_interactive_prompt_commands + cat > $tmpfile <