auth: Slightly simplify smb_pwd_check_ntlmv2()
authorVolker Lendecke <vl@samba.org>
Fri, 3 Jan 2020 13:10:00 +0000 (14:10 +0100)
committerGary Lockyer <gary@samba.org>
Mon, 6 Jan 2020 01:47:30 +0000 (01:47 +0000)
Do an early return for the failure case

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
libcli/auth/ntlm_check.c

index 6e25ca280efceaa8be032a4302998c8adab6151f..032888476280d8712b873ed93b8e555590fe2937 100644 (file)
@@ -98,6 +98,7 @@ static bool smb_pwd_check_ntlmv2(TALLOC_CTX *mem_ctx,
        uint8_t value_from_encryption[16];
        DATA_BLOB client_key_data;
        NTSTATUS status;
+       bool ok;
 
        if (part_passwd == NULL) {
                DEBUG(10,("No password set - DISALLOWING access\n"));
@@ -151,24 +152,25 @@ static bool smb_pwd_check_ntlmv2(TALLOC_CTX *mem_ctx,
        dump_data(100, value_from_encryption, 16);
 #endif
        data_blob_clear_free(&client_key_data);
-       if (memcmp(value_from_encryption, ntv2_response->data, 16) == 0) { 
-               if (user_sess_key != NULL) {
-                       *user_sess_key = data_blob_talloc(mem_ctx, NULL, 16);
-                       if (user_sess_key->data == NULL) {
-                               DBG_ERR("data_blob_talloc failed\n");
-                               return false;
-                       }
 
-                       status = SMBsesskeygen_ntv2(kr,
-                                                   value_from_encryption,
-                                                   user_sess_key->data);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               return false;
-                       }
+       ok = (memcmp(value_from_encryption, ntv2_response->data, 16) == 0);
+       if (!ok) {
+               return false;
+       }
+       if (user_sess_key != NULL) {
+               *user_sess_key = data_blob_talloc(mem_ctx, NULL, 16);
+               if (user_sess_key->data == NULL) {
+                       DBG_ERR("data_blob_talloc failed\n");
+                       return false;
+               }
+
+               status = SMBsesskeygen_ntv2(
+                       kr, value_from_encryption, user_sess_key->data);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return false;
                }
-               return true;
        }
-       return false;
+       return true;
 }
 
 /****************************************************************************