From e0069bd2a4820eca17c59d91bd1853f2f053a7a3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher 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 Reviewed-by: Andreas Schneider --- 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 a28a5824dc2..200657aff09 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);