[PATCH] Fix smbclient regression not printing session setup anymore

Stefan Metzmacher metze at samba.org
Wed Jun 7 15:27:46 UTC 2017


Hi Andreas,

I'm asking myself for a while if we really need to maintain printing
out this information at all. With SMB2 and Kerberos we're currently
not able to print anything.

Is this only used on the smbclient binary or do we trigger this
also via other code paths?

Would it be possible to skip this completely?
Or use wkssvc_NetWkstaInfo100 and/or srvsvc_NetSrvInfo101
to get these values more reliable?

https://git.samba.org/?p=samba.git;a=commitdiff;h=b6f87af427a1fa2bd39766
makes we a bit nervous as we can now have NULL pointers
in cli->server_{type,os,domain} and I guess not all code
is prepared for that see,
https://git.samba.org/?p=metze/samba/wip.git;a=commitdiff;h=a5fb0a4cac3a19b04

for where we make use of them.

That's why I created the attached change to restore the 4.5
behaviour.

metze

Am 06.06.2017 um 17:56 schrieb Andreas Schneider via samba-technical:
> On Tuesday, 6 June 2017 17:35:52 CEST Andreas Schneider via samba-technical 
> wrote:
>> Hi,
>>
>> with Samba 4.6 we have a regression. We do not get the information of the
>> session setup filled out so smbclient can't print it.
>>
>> Domain=[SAMBA-TEST] OS=[Windows 6.1] Server=[Samba 4.7.0pre1-DEVELOPERBUILD]
>> smb: \>
>>
>> The attached patchset addresses the issue. I've open a bug for this:
>>
>> https://bugzilla.samba.org/show_bug.cgi?id=12824
> 
> I've added a test to confirm that the message is actually printed so we do not 
> regress again ...



-------------- next part --------------
From fb01f9aa9309681b5bdaf0a8575bdd79b21badaf Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Wed, 15 Mar 2017 17:04:44 +0000
Subject: [PATCH] s3:libsmb: add cli_state_update_after_sesssetup() helper
 function

This function updates cli->server_{os,type,domain} to valid values
after a session setup.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12779

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 source3/libsmb/cliconnect.c | 74 +++++++++++++++++++++++++++++++--------------
 1 file changed, 52 insertions(+), 22 deletions(-)

diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index a28a582..200657a 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -372,6 +372,38 @@ NTSTATUS cli_session_creds_prepare_krb5(struct cli_state *cli,
 	return NT_STATUS_OK;
 }
 
+static NTSTATUS cli_state_update_after_sesssetup(struct cli_state *cli,
+						 const char *native_os,
+						 const char *native_lm,
+						 const char *primary_domain)
+{
+#define _VALID_STR(p) ((p) != NULL && (p)[0] != '\0')
+
+	if (!_VALID_STR(cli->server_os) && _VALID_STR(native_os)) {
+		cli->server_os = talloc_strdup(cli, native_os);
+		if (cli->server_os == NULL) {
+			return NT_STATUS_NO_MEMORY;
+		}
+	}
+
+	if (!_VALID_STR(cli->server_type) && _VALID_STR(native_lm)) {
+		cli->server_type = talloc_strdup(cli, native_lm);
+		if (cli->server_type == NULL) {
+			return NT_STATUS_NO_MEMORY;
+		}
+	}
+
+	if (!_VALID_STR(cli->server_domain) && _VALID_STR(primary_domain)) {
+		cli->server_domain = talloc_strdup(cli, primary_domain);
+		if (cli->server_domain == NULL) {
+			return NT_STATUS_NO_MEMORY;
+		}
+	}
+
+#undef _VALID_STRING
+	return NT_STATUS_OK;
+}
+
 /********************************************************
  Utility function to ensure we always return at least
  a valid char * pointer to an empty string for the
@@ -762,7 +794,6 @@ static void cli_sesssetup_blob_done(struct tevent_req *subreq)
 		subreq, struct tevent_req);
 	struct cli_sesssetup_blob_state *state = tevent_req_data(
 		req, struct cli_sesssetup_blob_state);
-	struct cli_state *cli = state->cli;
 	NTSTATUS status;
 
 	if (smbXcli_conn_protocol(state->cli->conn) >= PROTOCOL_SMB2_02) {
@@ -784,15 +815,16 @@ static void cli_sesssetup_blob_done(struct tevent_req *subreq)
 		return;
 	}
 
-	if (cli->server_os == NULL) {
-		cli->server_os = talloc_move(cli, &state->out_native_os);
-	}
-	if (cli->server_type == NULL) {
-		cli->server_type = talloc_move(cli, &state->out_native_lm);
-	}
-
 	state->status = status;
 
+	status = cli_state_update_after_sesssetup(state->cli,
+						  state->out_native_os,
+						  state->out_native_lm,
+						  NULL);
+	if (tevent_req_nterror(req, status)) {
+		return;
+	}
+
 	if (state->blob.length != 0) {
 		/*
 		 * More to send
@@ -1670,14 +1702,12 @@ static void cli_session_setup_creds_done_nt1(struct tevent_req *subreq)
 		return;
 	}
 
-	if (cli->server_os == NULL) {
-		cli->server_os = talloc_move(cli, &state->out_native_os);
-	}
-	if (cli->server_type == NULL) {
-		cli->server_type = talloc_move(cli, &state->out_native_lm);
-	}
-	if (cli->server_domain == NULL) {
-		cli->server_domain = talloc_move(cli, &state->out_primary_domain);
+	status = cli_state_update_after_sesssetup(state->cli,
+						  state->out_native_os,
+						  state->out_native_lm,
+						  state->out_primary_domain);
+	if (tevent_req_nterror(req, status)) {
+		return;
 	}
 
 	ok = smb1cli_conn_activate_signing(cli->conn,
@@ -1710,7 +1740,6 @@ static void cli_session_setup_creds_done_lm21(struct tevent_req *subreq)
 		subreq, struct tevent_req);
 	struct cli_session_setup_creds_state *state = tevent_req_data(
 		req, struct cli_session_setup_creds_state);
-	struct cli_state *cli = state->cli;
 	NTSTATUS status;
 
 	status = smb1cli_session_setup_lm21_recv(subreq, state,
@@ -1723,11 +1752,12 @@ static void cli_session_setup_creds_done_lm21(struct tevent_req *subreq)
 		return;
 	}
 
-	if (cli->server_os == NULL) {
-		cli->server_os = talloc_move(cli, &state->out_native_os);
-	}
-	if (cli->server_type == NULL) {
-		cli->server_type = talloc_move(cli, &state->out_native_lm);
+	status = cli_state_update_after_sesssetup(state->cli,
+						  state->out_native_os,
+						  state->out_native_lm,
+						  NULL);
+	if (tevent_req_nterror(req, status)) {
+		return;
 	}
 
 	tevent_req_done(req);
-- 
1.9.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20170607/9c644bc5/signature.sig>


More information about the samba-technical mailing list