r26260: Store loadparm context in gensec context.
[samba.git] / source4 / utils / ntlm_auth.c
index c51b35aa0309aab4272a9ca0945ee1eba282a9cd..cb2fbd63c157d6ce93aa17394bccac2b75cfbe5c 100644 (file)
@@ -58,18 +58,22 @@ enum stdio_helper_mode {
 
 
 typedef void (*stdio_helper_function)(enum stdio_helper_mode stdio_helper_mode, 
+                                     struct loadparm_context *lp_ctx,
                                      char *buf, int length, void **private,
                                      unsigned int mux_id, void **private2);
 
 static void manage_squid_basic_request (enum stdio_helper_mode stdio_helper_mode, 
+                                       struct loadparm_context *lp_ctx,
                                        char *buf, int length, void **private,
                                        unsigned int mux_id, void **private2);
 
 static void manage_gensec_request (enum stdio_helper_mode stdio_helper_mode, 
+                                  struct loadparm_context *lp_ctx,
                                   char *buf, int length, void **private,
                                   unsigned int mux_id, void **private2);
 
 static void manage_ntlm_server_1_request (enum stdio_helper_mode stdio_helper_mode, 
+                                         struct loadparm_context *lp_ctx,
                                          char *buf, int length, void **private,
                                          unsigned int mux_id, void **private2);
 
@@ -122,10 +126,10 @@ static void mux_printf(unsigned int mux_id, const char *format, ...)
    form DOMAIN/user into a domain and a user */
 
 static bool parse_ntlm_auth_domain_user(const char *domuser, fstring domain, 
-                                       fstring user)
+                                       fstring user, char winbind_separator)
 {
 
-       char *p = strchr(domuser,*lp_winbind_separator(global_loadparm));
+       char *p = strchr(domuser, winbind_separator);
 
        if (!p) {
                return false;
@@ -176,7 +180,8 @@ static bool check_plaintext_auth(const char *user, const char *pass,
 
 /* authenticate a user with an encrypted username/password */
 
-static NTSTATUS local_pw_check_specified(const char *username, 
+static NTSTATUS local_pw_check_specified(struct loadparm_context *lp_ctx,
+                                        const char *username, 
                                         const char *domain, 
                                         const char *workstation,
                                         const DATA_BLOB *challenge, 
@@ -206,6 +211,7 @@ static NTSTATUS local_pw_check_specified(const char *username,
                
                
                nt_status = ntlm_password_check(mem_ctx, 
+                                               lp_ctx,
                                                MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
                                                MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT,
                                                challenge,
@@ -220,7 +226,7 @@ static NTSTATUS local_pw_check_specified(const char *username,
                        if (unix_name) {
                                asprintf(unix_name, 
                                         "%s%c%s", domain,
-                                        *lp_winbind_separator(global_loadparm), 
+                                        *lp_winbind_separator(lp_ctx), 
                                         username);
                        }
                } else {
@@ -239,6 +245,7 @@ static NTSTATUS local_pw_check_specified(const char *username,
 }
 
 static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode, 
+                                      struct loadparm_context *lp_ctx,
                                       char *buf, int length, void **private,
                                       unsigned int mux_id, void **private2) 
 {
@@ -270,6 +277,7 @@ static void manage_squid_basic_request(enum stdio_helper_mode stdio_helper_mode,
    to the calling application.  The callback comes from within gensec */
 
 static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mode, 
+                                        struct loadparm_context *lp_ctx,
                                         char *buf, int length, void **private,
                                         unsigned int mux_id, void **password)  
 {
@@ -308,8 +316,8 @@ static void manage_gensec_get_pw_request(enum stdio_helper_mode stdio_helper_mod
 }
 
 /** 
- * Callback for password credentails.  This is not async, and when
- * GENSEC and the credentails code is made async, it will look rather
+ * Callback for password credentials.  This is not async, and when
+ * GENSEC and the credentials code is made async, it will look rather
  * different.
  */
 
@@ -360,6 +368,7 @@ static void gensec_want_feature_list(struct gensec_security *state, char* featur
 }
 
 static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode, 
+                                 struct loadparm_context *lp_ctx,
                                  char *buf, int length, void **private,
                                  unsigned int mux_id, void **private2) 
 {
@@ -449,7 +458,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);
+                       nt_status = gensec_client_start(NULL, &state->gensec_state, NULL, lp_ctx);
                        if (!NT_STATUS_IS_OK(nt_status)) {
                                exit(1);
                        }
@@ -461,11 +470,11 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                        if (!ev) {
                                exit(1);
                        }
-                       msg = messaging_client_init(state, lp_messaging_path(state, global_loadparm), ev);
+                       msg = messaging_client_init(state, lp_messaging_path(state, lp_ctx), ev);
                        if (!msg) {
                                exit(1);
                        }
-                       if (!NT_STATUS_IS_OK(gensec_server_start(state, ev, msg, &state->gensec_state))) {
+                       if (!NT_STATUS_IS_OK(gensec_server_start(state, ev, lp_ctx, msg, &state->gensec_state))) {
                                exit(1);
                        }
                        break;
@@ -474,7 +483,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                }
 
                creds = cli_credentials_init(state->gensec_state);
-               cli_credentials_set_conf(creds, global_loadparm);
+               cli_credentials_set_conf(creds, lp_ctx);
                if (opt_username) {
                        cli_credentials_set_username(creds, opt_username, CRED_SPECIFIED);
                }
@@ -659,7 +668,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                        reply_code = "AF";
                        reply_arg = talloc_asprintf(state->gensec_state, 
                                                    "%s%s%s", session_info->server_info->domain_name, 
-                                                   lp_winbind_separator(global_loadparm), session_info->server_info->account_name);
+                                                   lp_winbind_separator(lp_ctx), session_info->server_info->account_name);
                        talloc_free(session_info);
                }
        } else if (state->gensec_state->gensec_role == GENSEC_CLIENT) {
@@ -690,6 +699,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
 }
 
 static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mode, 
+                                        struct loadparm_context *lp_ctx,
                                         char *buf, int length, void **private,
                                         unsigned int mux_id, void **private2) 
 {
@@ -710,7 +720,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
                } else if (plaintext_password) {
                        /* handle this request as plaintext */
                        if (!full_username) {
-                               if (asprintf(&full_username, "%s%c%s", domain, *lp_winbind_separator(global_loadparm), username) == -1) {
+                               if (asprintf(&full_username, "%s%c%s", domain, *lp_winbind_separator(lp_ctx), username) == -1) {
                                        mux_printf(mux_id, "Error: Out of memory in asprintf!\n.\n");
                                        return;
                                }
@@ -734,7 +744,8 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
                                fstring fstr_user;
                                fstring fstr_domain;
                                
-                               if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain)) {
+                               if (!parse_ntlm_auth_domain_user(full_username, fstr_user, fstr_domain, 
+                                                                *lp_winbind_separator(lp_ctx))) {
                                        /* username might be 'tainted', don't print into our new-line deleimianted stream */
                                        mux_printf(mux_id, "Error: Could not parse into domain and username\n");
                                }
@@ -745,7 +756,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
                        }
 
                        if (!domain) {
-                               domain = smb_xstrdup(lp_workgroup(global_loadparm));
+                               domain = smb_xstrdup(lp_workgroup(lp_ctx));
                        }
 
                        if (ntlm_server_1_lm_session_key) 
@@ -755,9 +766,10 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
                                flags |= NTLM_AUTH_FLAG_USER_SESSION_KEY;
 
                        if (!NT_STATUS_IS_OK(
-                                   local_pw_check_specified(username, 
+                                   local_pw_check_specified(lp_ctx,
+                                                            username, 
                                                              domain, 
-                                                             lp_netbios_name(global_loadparm),
+                                                             lp_netbios_name(lp_ctx),
                                                              &challenge, 
                                                              &lm_response, 
                                                              &nt_response, 
@@ -988,7 +1000,7 @@ static void manage_squid_request(enum stdio_helper_mode helper_mode,
                private = &normal_private;
        }
 
-       fn(helper_mode, c, length, private, mux_id, private2);
+       fn(helper_mode, global_loadparm, c, length, private, mux_id, private2);
        talloc_free(buf);
 }
 
@@ -1081,7 +1093,7 @@ int main(int argc, const char **argv)
                return 1;
        }
 
-       gensec_init();
+       gensec_init(global_loadparm);
 
        if (opt_domain == NULL) {
                opt_domain = lp_workgroup(global_loadparm);