s4:auth: Add FALL_THROUGH statements in auth_util.c
[sfrench/samba-autobuild/.git] / source4 / auth / ntlm / auth_util.c
index 64ceb437ad6dc4b9a3ba71ab23811ef52144a3fb..5084cc4a929b01ad6055ffafe84ebe2f4696eb99 100644 (file)
 
 #include "includes.h"
 #include "auth/auth.h"
 
 #include "includes.h"
 #include "auth/auth.h"
-#include "auth/auth_proto.h"
-#include "libcli/security/security.h"
 #include "libcli/auth/libcli_auth.h"
 #include "libcli/auth/libcli_auth.h"
-#include "dsdb/samdb/samdb.h"
-#include "auth/credentials/credentials.h"
 #include "param/param.h"
 #include "param/param.h"
+#include "auth/ntlm/auth_proto.h"
+#include "librpc/gen_ndr/drsuapi.h"
+#include "dsdb/samdb/samdb.h"
 
 /* this default function can be used by mostly all backends
  * which don't want to set a challenge
  */
 
 /* this default function can be used by mostly all backends
  * which don't want to set a challenge
  */
-NTSTATUS auth_get_challenge_not_implemented(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, DATA_BLOB *challenge)
+NTSTATUS auth_get_challenge_not_implemented(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, uint8_t chal[8])
 {
        /* we don't want to set a challenge */
        return NT_STATUS_NOT_IMPLEMENTED;
 {
        /* we don't want to set a challenge */
        return NT_STATUS_NOT_IMPLEMENTED;
@@ -43,66 +42,7 @@ NTSTATUS auth_get_challenge_not_implemented(struct auth_method_context *ctx, TAL
  Create an auth_usersupplied_data structure after appropriate mapping.
 ****************************************************************************/
 
  Create an auth_usersupplied_data structure after appropriate mapping.
 ****************************************************************************/
 
-NTSTATUS map_user_info(TALLOC_CTX *mem_ctx,
-                      const char *default_domain,
-                      const struct auth_usersupplied_info *user_info,
-                      struct auth_usersupplied_info **user_info_mapped)
-{
-       const char *domain;
-       char *account_name;
-       char *d;
-       DEBUG(5,("map_user_info: Mapping user [%s]\\[%s] from workstation [%s]\n",
-               user_info->client.domain_name, user_info->client.account_name, user_info->workstation_name));
-
-       account_name = talloc_strdup(mem_ctx, user_info->client.account_name);
-       if (!account_name) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       
-       /* don't allow "" as a domain, fixes a Win9X bug 
-          where it doesn't supply a domain for logon script
-          'net use' commands.                                 */
-
-       /* Split user@realm names into user and realm components.  This is TODO to fix with proper userprincipalname support */
-       if (user_info->client.domain_name && *user_info->client.domain_name) {
-               domain = user_info->client.domain_name;
-       } else if (strchr_m(user_info->client.account_name, '@')) {
-               d = strchr_m(account_name, '@');
-               if (!d) {
-                       return NT_STATUS_INTERNAL_ERROR;
-               }
-               d[0] = '\0';
-               d++;
-               domain = d;
-       } else {
-               domain = default_domain;
-       }
-
-       *user_info_mapped = talloc(mem_ctx, struct auth_usersupplied_info);
-       if (!*user_info_mapped) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       if (!talloc_reference(*user_info_mapped, user_info)) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       **user_info_mapped = *user_info;
-       (*user_info_mapped)->mapped_state = true;
-       (*user_info_mapped)->mapped.domain_name = talloc_strdup(*user_info_mapped, domain);
-       (*user_info_mapped)->mapped.account_name = talloc_strdup(*user_info_mapped, account_name);
-       talloc_free(account_name);
-       if (!(*user_info_mapped)->mapped.domain_name 
-           || !(*user_info_mapped)->mapped.account_name) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       return NT_STATUS_OK;
-}
-
-/****************************************************************************
- Create an auth_usersupplied_data structure after appropriate mapping.
-****************************************************************************/
-
-NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_context, 
+NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth4_context *auth_context, 
                           enum auth_password_state to_state,
                           const struct auth_usersupplied_info *user_info_in,
                           const struct auth_usersupplied_info **user_info_encrypted)
                           enum auth_password_state to_state,
                           const struct auth_usersupplied_info *user_info_in,
                           const struct auth_usersupplied_info **user_info_encrypted)
@@ -122,13 +62,14 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex
                                return nt_status;
                        }
                        user_info_in = user_info_temp2;
                                return nt_status;
                        }
                        user_info_in = user_info_temp2;
-                       /* fall through */
+
+                       FALL_THROUGH;
                }
                case AUTH_PASSWORD_HASH:
                {
                }
                case AUTH_PASSWORD_HASH:
                {
-                       const uint8_t *challenge;
+                       uint8_t chal[8];
                        DATA_BLOB chall_blob;
                        DATA_BLOB chall_blob;
-                       user_info_temp = talloc(mem_ctx, struct auth_usersupplied_info);
+                       user_info_temp = talloc_zero(mem_ctx, struct auth_usersupplied_info);
                        if (!user_info_temp) {
                                return NT_STATUS_NO_MEMORY;
                        }
                        if (!user_info_temp) {
                                return NT_STATUS_NO_MEMORY;
                        }
@@ -138,20 +79,22 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex
                        *user_info_temp = *user_info_in;
                        user_info_temp->mapped_state = to_state;
                        
                        *user_info_temp = *user_info_in;
                        user_info_temp->mapped_state = to_state;
                        
-                       nt_status = auth_get_challenge(auth_context, &challenge);
+                       nt_status = auth_get_challenge(auth_context, chal);
                        if (!NT_STATUS_IS_OK(nt_status)) {
                                return nt_status;
                        }
                        
                        if (!NT_STATUS_IS_OK(nt_status)) {
                                return nt_status;
                        }
                        
-                       chall_blob = data_blob_talloc(mem_ctx, challenge, 8);
-                       if (lp_client_ntlmv2_auth(auth_context->lp_ctx)) {
-                               DATA_BLOB names_blob = NTLMv2_generate_names_blob(mem_ctx, lp_iconv_convenience(auth_context->lp_ctx), lp_netbios_name(auth_context->lp_ctx), lp_workgroup(auth_context->lp_ctx));
+                       chall_blob = data_blob_talloc(mem_ctx, chal, 8);
+                       if (lpcfg_client_ntlmv2_auth(auth_context->lp_ctx)) {
+                               DATA_BLOB names_blob = NTLMv2_generate_names_blob(mem_ctx,  lpcfg_netbios_name(auth_context->lp_ctx), lpcfg_workgroup(auth_context->lp_ctx));
                                DATA_BLOB lmv2_response, ntlmv2_response, lmv2_session_key, ntlmv2_session_key;
                                
                                if (!SMBNTLMv2encrypt_hash(user_info_temp,
                                                           user_info_in->client.account_name, 
                                                           user_info_in->client.domain_name, 
                                DATA_BLOB lmv2_response, ntlmv2_response, lmv2_session_key, ntlmv2_session_key;
                                
                                if (!SMBNTLMv2encrypt_hash(user_info_temp,
                                                           user_info_in->client.account_name, 
                                                           user_info_in->client.domain_name, 
-                                                          user_info_in->password.hash.nt->hash, &chall_blob,
+                                                          user_info_in->password.hash.nt->hash,
+                                                          &chall_blob,
+                                                          NULL, /* server_timestamp */
                                                           &names_blob,
                                                           &lmv2_response, &ntlmv2_response, 
                                                           &lmv2_session_key, &ntlmv2_session_key)) {
                                                           &names_blob,
                                                           &lmv2_response, &ntlmv2_response, 
                                                           &lmv2_session_key, &ntlmv2_session_key)) {
@@ -166,12 +109,12 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex
                                data_blob_free(&ntlmv2_session_key);
                        } else {
                                DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, 24);
                                data_blob_free(&ntlmv2_session_key);
                        } else {
                                DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, 24);
-                               SMBOWFencrypt(user_info_in->password.hash.nt->hash, challenge, blob.data);
+                               SMBOWFencrypt(user_info_in->password.hash.nt->hash, chal, blob.data);
 
                                user_info_temp->password.response.nt = blob;
 
                                user_info_temp->password.response.nt = blob;
-                               if (lp_client_lanman_auth(auth_context->lp_ctx) && user_info_in->password.hash.lanman) {
+                               if (lpcfg_client_lanman_auth(auth_context->lp_ctx) && user_info_in->password.hash.lanman) {
                                        DATA_BLOB lm_blob = data_blob_talloc(mem_ctx, NULL, 24);
                                        DATA_BLOB lm_blob = data_blob_talloc(mem_ctx, NULL, 24);
-                                       SMBOWFencrypt(user_info_in->password.hash.lanman->hash, challenge, blob.data);
+                                       SMBOWFencrypt(user_info_in->password.hash.lanman->hash, chal, blob.data);
                                        user_info_temp->password.response.lanman = lm_blob;
                                } else {
                                        /* if not sending the LM password, send the NT password twice */
                                        user_info_temp->password.response.lanman = lm_blob;
                                } else {
                                        /* if not sending the LM password, send the NT password twice */
@@ -180,7 +123,8 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex
                        }
 
                        user_info_in = user_info_temp;
                        }
 
                        user_info_in = user_info_temp;
-                       /* fall through */
+
+                       FALL_THROUGH;
                }
                case AUTH_PASSWORD_RESPONSE:
                        *user_info_encrypted = user_info_in;
                }
                case AUTH_PASSWORD_RESPONSE:
                        *user_info_encrypted = user_info_in;
@@ -194,7 +138,7 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex
                        struct samr_Password lanman;
                        struct samr_Password nt;
                        
                        struct samr_Password lanman;
                        struct samr_Password nt;
                        
-                       user_info_temp = talloc(mem_ctx, struct auth_usersupplied_info);
+                       user_info_temp = talloc_zero(mem_ctx, struct auth_usersupplied_info);
                        if (!user_info_temp) {
                                return NT_STATUS_NO_MEMORY;
                        }
                        if (!user_info_temp) {
                                return NT_STATUS_NO_MEMORY;
                        }
@@ -218,7 +162,8 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex
                        *user_info_temp->password.hash.nt = nt;
                        
                        user_info_in = user_info_temp;
                        *user_info_temp->password.hash.nt = nt;
                        
                        user_info_in = user_info_temp;
-                       /* fall through */
+
+                       FALL_THROUGH;
                }
                case AUTH_PASSWORD_HASH:
                        *user_info_encrypted = user_info_in;
                }
                case AUTH_PASSWORD_HASH:
                        *user_info_encrypted = user_info_in;
@@ -235,27 +180,3 @@ NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_contex
 
        return NT_STATUS_OK;
 }
 
        return NT_STATUS_OK;
 }
-
-
-/**
- * Squash an NT_STATUS in line with security requirements.
- * In an attempt to avoid giving the whole game away when users
- * are authenticating, NT replaces both NT_STATUS_NO_SUCH_USER and 
- * NT_STATUS_WRONG_PASSWORD with NT_STATUS_LOGON_FAILURE in certain situations 
- * (session setups in particular).
- *
- * @param nt_status NTSTATUS input for squashing.
- * @return the 'squashed' nt_status
- **/
-_PUBLIC_ NTSTATUS auth_nt_status_squash(NTSTATUS nt_status)
-{
-       if NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_SUCH_USER) {
-               /* Match WinXP and don't give the game away */
-               return NT_STATUS_LOGON_FAILURE;
-       } else if NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD) {
-               /* Match WinXP and don't give the game away */
-               return NT_STATUS_LOGON_FAILURE;
-       }
-
-       return nt_status;
-}