ntlm_auth: eliminate "cast pointer from integer of different size" warnings on 64bit.
[tprouty/samba.git] / source / utils / ntlm_auth.c
index b224689d7073b78429df45891e6b97724c63adf8..6a6302837e400a770647f8d7776221f985a100e1 100644 (file)
@@ -30,6 +30,7 @@
 #include "auth/auth.h"
 #include "librpc/gen_ndr/ndr_netlogon.h"
 #include "auth/auth_sam.h"
+#include "auth/ntlm/ntlm_check.h"
 #include "pstring.h"
 #include "libcli/auth/libcli_auth.h"
 #include "libcli/security/security.h"
@@ -285,7 +286,7 @@ static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mod
        DATA_BLOB in;
        if (strlen(buf) < 2) {
                DEBUG(1, ("query [%s] invalid", buf));
-               mux_printf(mux_id, "BH\n");
+               mux_printf(mux_id, "BH Query invalid\n");
                return;
        }
 
@@ -302,7 +303,7 @@ static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mod
                
                if (*password == NULL) {
                        DEBUG(1, ("Out of memory\n"));
-                       mux_printf(mux_id, "BH\n");
+                       mux_printf(mux_id, "BH Out of memory\n");
                        data_blob_free(&in);
                        return;
                }
@@ -312,7 +313,7 @@ static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mod
                return;
        }
        DEBUG(1, ("Asked for (and expected) a password\n"));
-       mux_printf(mux_id, "BH\n");
+       mux_printf(mux_id, "BH Expected a password\n");
        data_blob_free(&in);
 }
 
@@ -327,7 +328,7 @@ static const char *get_password(struct cli_credentials *credentials)
        char *password = NULL;
        
        /* Ask for a password */
-       mux_printf((unsigned int)credentials->priv_data, "PW\n");
+       mux_printf((unsigned int)(uintptr_t)credentials->priv_data, "PW\n");
        credentials->priv_data = NULL;
 
        manage_squid_request(cmdline_lp_ctx, NUM_HELPER_MODES /* bogus */, manage_gensec_get_pw_request, (void **)&password);
@@ -339,16 +340,25 @@ static const char *get_password(struct cli_credentials *credentials)
 **/
 static bool in_list(const char *s, const char *list, bool casesensitive)
 {
-       pstring tok;
+       char *tok;
+       size_t tok_len = 1024;
        const char *p=list;
 
        if (!list)
                return false;
 
-       while (next_token(&p, tok, LIST_SEP, sizeof(tok))) {
-               if ((casesensitive?strcmp:strcasecmp_m)(tok,s) == 0)
+       tok = (char *)malloc(tok_len);
+       if (!tok) {
+               return false;
+       }
+
+       while (next_token(&p, tok, LIST_SEP, tok_len)) {
+               if ((casesensitive?strcmp:strcasecmp_m)(tok,s) == 0) {
+                       free(tok);
                        return true;
+               }
        }
+       free(tok);
        return false;
 }
 
@@ -411,7 +421,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
        
        if (strlen(buf) < 2) {
                DEBUG(1, ("query [%s] invalid", buf));
-               mux_printf(mux_id, "BH\n");
+               mux_printf(mux_id, "BH Query invalid\n");
                return;
        }
 
@@ -435,7 +445,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                }
        } else if ( (strncmp(buf, "OK", 2) == 0)) {
                /* Just return BH, like ntlm_auth from Samba 3 does. */
-               mux_printf(mux_id, "BH\n");
+               mux_printf(mux_id, "BH Command expected\n");
                data_blob_free(&in);
                return;
        } else if ( (strncmp(buf, "TT ", 3) != 0) &&
@@ -447,11 +457,15 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                    (strncmp(buf, "GK", 2) != 0) &&
                    (strncmp(buf, "GF", 2) != 0)) {
                DEBUG(1, ("SPNEGO request [%s] invalid\n", buf));
-               mux_printf(mux_id, "BH\n");
+               mux_printf(mux_id, "BH SPNEGO request invalid\n");
                data_blob_free(&in);
                return;
        }
 
+       ev = s4_event_context_init(state);
+       if (!ev) {
+               exit(1);
+       }
        /* setup gensec */
        if (!(state->gensec_state)) {
                switch (stdio_helper_mode) {
@@ -459,7 +473,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                case NTLMSSP_CLIENT_1:
                        /* setup the client side */
 
-                       nt_status = gensec_client_start(NULL, &state->gensec_state, NULL, lp_ctx);
+                       nt_status = gensec_client_start(NULL, &state->gensec_state, ev, lp_ctx);
                        if (!NT_STATUS_IS_OK(nt_status)) {
                                exit(1);
                        }
@@ -467,10 +481,6 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                        break;
                case GSS_SPNEGO_SERVER:
                case SQUID_2_5_NTLMSSP:
-                       ev = event_context_init(state);
-                       if (!ev) {
-                               exit(1);
-                       }
                        msg = messaging_client_init(state, lp_messaging_path(state, lp_ctx), 
                                                    lp_iconv_convenience(lp_ctx), ev);
                        if (!msg) {
@@ -496,7 +506,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                        cli_credentials_set_password(creds, state->set_password, CRED_SPECIFIED);
                } else {
                        cli_credentials_set_password_callback(creds, get_password);
-                       creds->priv_data = (void*)mux_id;
+                       creds->priv_data = (void*)(uintptr_t)mux_id;
                }
                if (opt_workstation) {
                        cli_credentials_set_workstation(creds, opt_workstation, CRED_SPECIFIED);
@@ -536,7 +546,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
 
                if (!NT_STATUS_IS_OK(nt_status)) {
                        DEBUG(1, ("GENSEC mech failed to start: %s\n", nt_errstr(nt_status)));
-                       mux_printf(mux_id, "BH\n");
+                       mux_printf(mux_id, "BH GENSEC mech failed to start\n");
                        return;
                }
 
@@ -646,11 +656,11 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
 
 
        } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCESS_DENIED)) {
-               reply_code = "BH";
+               reply_code = "BH NT_STATUS_ACCESS_DENIED";
                reply_arg = nt_errstr(nt_status);
                DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
        } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_UNSUCCESSFUL)) {
-               reply_code = "BH";
+               reply_code = "BH NT_STATUS_UNSUCCESSFUL";
                reply_arg = nt_errstr(nt_status);
                DEBUG(1, ("GENSEC login failed: %s\n", nt_errstr(nt_status)));
        } else if (!NT_STATUS_IS_OK(nt_status)) {
@@ -662,7 +672,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
 
                nt_status = gensec_session_info(state->gensec_state, &session_info);
                if (!NT_STATUS_IS_OK(nt_status)) {
-                       reply_code = "BH";
+                       reply_code = "BH Failed to retrive session info";
                        reply_arg = nt_errstr(nt_status);
                        DEBUG(1, ("GENSEC failed to retreive the session info: %s\n", nt_errstr(nt_status)));
                } else {