s3:swat: hide "config backend" from swat
[ira/wip.git] / source3 / utils / ntlm_auth.c
index b94efc99cfa41fac8d015d1b095fa59ddd2544ce..50688bf6986b0a194313fb614e5fe62a98caf6da 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "includes.h"
 #include "utils/ntlm_auth.h"
+#include "../libcli/auth/libcli_auth.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -523,7 +524,7 @@ static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB
 {
        static const char zeros[16] = { 0, };
        NTSTATUS nt_status;
-       char *error_string;
+       char *error_string = NULL;
        uint8 lm_key[8]; 
        uint8 user_sess_key[16]; 
        char *unix_name = NULL;
@@ -558,6 +559,7 @@ static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB
                ntlmssp_state->auth_context = NULL;
        }
 
+       SAFE_FREE(error_string);
        SAFE_FREE(unix_name);
        return nt_status;
 }
@@ -565,19 +567,19 @@ static NTSTATUS winbind_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB
 static NTSTATUS local_pw_check(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key) 
 {
        NTSTATUS nt_status;
-       uint8 lm_pw[16], nt_pw[16];
+       struct samr_Password lm_pw, nt_pw;
 
-       nt_lm_owf_gen (opt_password, nt_pw, lm_pw);
+       nt_lm_owf_gen (opt_password, nt_pw.hash, lm_pw.hash);
        
        nt_status = ntlm_password_check(ntlmssp_state,
+                                       true, true, 0,
                                        &ntlmssp_state->chal,
                                        &ntlmssp_state->lm_resp,
                                        &ntlmssp_state->nt_resp, 
-                                       NULL, NULL,
                                        ntlmssp_state->user, 
                                        ntlmssp_state->user, 
                                        ntlmssp_state->domain,
-                                       lm_pw, nt_pw, user_session_key, lm_session_key);
+                                       &lm_pw, &nt_pw, user_session_key, lm_session_key);
        
        if (NT_STATUS_IS_OK(nt_status)) {
                ntlmssp_state->auth_context = talloc_asprintf(ntlmssp_state,
@@ -1250,8 +1252,6 @@ static void manage_gss_spnego_request(struct ntlm_auth_state *state,
                                                   &principal, &pac_data, &ap_rep,
                                                   &session_key, True);
 
-                       talloc_destroy(mem_ctx);
-
                        /* Now in "principal" we have the name we are
                            authenticated as. */
 
@@ -1273,9 +1273,9 @@ static void manage_gss_spnego_request(struct ntlm_auth_state *state,
                                user = SMB_STRDUP(principal);
 
                                data_blob_free(&ap_rep);
-
-                               SAFE_FREE(principal);
                        }
+
+                       TALLOC_FREE(mem_ctx);
                }
 #endif
 
@@ -1816,7 +1816,6 @@ static void manage_ntlm_server_1_request(struct ntlm_auth_state *state,
 
                                x_fprintf(x_stdout, "Authenticated: No\n");
                                x_fprintf(x_stdout, "Authentication-Error: %s\n.\n", error_string);
-                               SAFE_FREE(error_string);
                        } else {
                                static char zeros[16];
                                char *hex_lm_key;
@@ -1844,6 +1843,7 @@ static void manage_ntlm_server_1_request(struct ntlm_auth_state *state,
                                        TALLOC_FREE(hex_user_session_key);
                                }
                        }
+                       SAFE_FREE(error_string);
                }
                /* clear out the state */
                challenge = data_blob_null;
@@ -1978,7 +1978,7 @@ static void manage_ntlm_change_password_1_request(struct ntlm_auth_state *state,
                                encode_pw_buffer(new_lm_pswd.data, newpswd,
                                                 STR_UNICODE);
 
-                               SamOEMhash(new_lm_pswd.data, old_nt_hash, 516);
+                               arcfour_crypt(new_lm_pswd.data, old_nt_hash, 516);
                                E_old_pw_hash(new_nt_hash, old_lm_hash,
                                              old_lm_hash_enc.data);
                        } else {
@@ -1991,7 +1991,7 @@ static void manage_ntlm_change_password_1_request(struct ntlm_auth_state *state,
                        encode_pw_buffer(new_nt_pswd.data, newpswd,
                                         STR_UNICODE);
        
-                       SamOEMhash(new_nt_pswd.data, old_nt_hash, 516);
+                       arcfour_crypt(new_nt_pswd.data, old_nt_hash, 516);
                        E_old_pw_hash(new_nt_hash, old_nt_hash,
                                      old_nt_hash_enc.data);
                }
@@ -2276,7 +2276,7 @@ static bool check_auth_crap(void)
        if (request_lm_key 
            && (memcmp(zeros, lm_key, 
                       sizeof(lm_key)) != 0)) {
-               hex_lm_key = hex_encode_talloc(NULL, (const unsigned char *)lm_key,
+               hex_lm_key = hex_encode_talloc(talloc_tos(), (const unsigned char *)lm_key,
                                        sizeof(lm_key));
                x_fprintf(x_stdout, "LM_KEY: %s\n", hex_lm_key);
                TALLOC_FREE(hex_lm_key);
@@ -2284,7 +2284,7 @@ static bool check_auth_crap(void)
        if (request_user_session_key 
            && (memcmp(zeros, user_session_key, 
                       sizeof(user_session_key)) != 0)) {
-               hex_user_session_key = hex_encode_talloc(NULL, (const unsigned char *)user_session_key, 
+               hex_user_session_key = hex_encode_talloc(talloc_tos(), (const unsigned char *)user_session_key, 
                                                  sizeof(user_session_key));
                x_fprintf(x_stdout, "NT_KEY: %s\n", hex_user_session_key);
                TALLOC_FREE(hex_user_session_key);