From 664b2ed36b90f0d6f081ca6889c66d2c515fe021 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 14 Jun 2017 23:33:04 +0200 Subject: [PATCH] s4:libcli/smb_composite: add early returns to sesssetup.c:request_handler() This makes it much clearer under which condutions the following code operates. Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- source4/libcli/smb_composite/sesssetup.c | 34 ++++++++++++++++-------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/source4/libcli/smb_composite/sesssetup.c b/source4/libcli/smb_composite/sesssetup.c index 0c222d6bc35..2f1ce4c5db7 100644 --- a/source4/libcli/smb_composite/sesssetup.c +++ b/source4/libcli/smb_composite/sesssetup.c @@ -125,6 +125,10 @@ static void request_handler(struct smbcli_request *req) } } } + if (!NT_STATUS_IS_OK(c->status)) { + composite_error(c, c->status); + return; + } os = state->setup.old.out.os; lanman = state->setup.old.out.lanman; break; @@ -146,6 +150,10 @@ static void request_handler(struct smbcli_request *req) } } } + if (!NT_STATUS_IS_OK(c->status)) { + composite_error(c, c->status); + return; + } os = state->setup.nt1.out.os; lanman = state->setup.nt1.out.lanman; break; @@ -191,9 +199,9 @@ static void request_handler(struct smbcli_request *req) return; } } - if (!NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED) && - !NT_STATUS_IS_OK(c->status)) { - break; + if (GENSEC_UPDATE_IS_NTERROR(c->status)) { + composite_error(c, c->status); + return; } if (NT_STATUS_EQUAL(state->gensec_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { @@ -208,9 +216,9 @@ static void request_handler(struct smbcli_request *req) state->setup.spnego.out.secblob, &state->setup.spnego.in.secblob); c->status = state->gensec_status; - if (!NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED) && - !NT_STATUS_IS_OK(c->status)) { - break; + if (GENSEC_UPDATE_IS_NTERROR(c->status)) { + composite_error(c, c->status); + return; } } else { state->setup.spnego.in.secblob = data_blob(NULL, 0); @@ -225,7 +233,8 @@ static void request_handler(struct smbcli_request *req) if (state->setup.spnego.in.secblob.length) { c->status = NT_STATUS_INTERNAL_ERROR; - break; + composite_error(c, c->status); + return; } session_key_err = gensec_session_key(session->gensec, session, &session_key); if (NT_STATUS_IS_OK(session_key_err)) { @@ -238,7 +247,8 @@ static void request_handler(struct smbcli_request *req) session_key); data_blob_free(&session_key); if (!NT_STATUS_IS_OK(c->status)) { - break; + composite_error(c, c->status); + return; } } @@ -264,7 +274,8 @@ static void request_handler(struct smbcli_request *req) case RAW_SESSSETUP_SMB2: c->status = NT_STATUS_INTERNAL_ERROR; - break; + composite_error(c, c->status); + return; } if (check_req) { @@ -274,11 +285,12 @@ static void request_handler(struct smbcli_request *req) ok = smb1cli_conn_check_signing(check_req->transport->conn, check_req->in.buffer, 1); + TALLOC_FREE(check_req); if (!ok) { c->status = NT_STATUS_ACCESS_DENIED; + composite_error(c, c->status); + return; } - talloc_free(check_req); - check_req = NULL; } if (!NT_STATUS_IS_OK(c->status)) {