source: trunk/server/source3/auth/auth_ntlmssp.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 9.1 KB
Line 
1/*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 handle NLTMSSP, server side
5
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett 2001-2003
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "includes.h"
24#include "auth.h"
25#include "../libcli/auth/ntlmssp.h"
26#include "ntlmssp_wrap.h"
27#include "../librpc/gen_ndr/netlogon.h"
28#include "smbd/smbd.h"
29
30NTSTATUS auth_ntlmssp_steal_session_info(TALLOC_CTX *mem_ctx,
31 struct auth_ntlmssp_state *auth_ntlmssp_state,
32 struct auth_serversupplied_info **session_info)
33{
34 /* Free the current server_info user_session_key and reset it from the
35 * current ntlmssp_state session_key */
36 data_blob_free(&auth_ntlmssp_state->server_info->user_session_key);
37 /* Set up the final session key for the connection */
38 auth_ntlmssp_state->server_info->user_session_key =
39 data_blob_talloc(
40 auth_ntlmssp_state->server_info,
41 auth_ntlmssp_state->ntlmssp_state->session_key.data,
42 auth_ntlmssp_state->ntlmssp_state->session_key.length);
43 if (auth_ntlmssp_state->ntlmssp_state->session_key.length &&
44 !auth_ntlmssp_state->server_info->user_session_key.data) {
45 *session_info = NULL;
46 return NT_STATUS_NO_MEMORY;
47 }
48 /* Steal session_info away from auth_ntlmssp_state */
49 *session_info = talloc_move(mem_ctx, &auth_ntlmssp_state->server_info);
50 return NT_STATUS_OK;
51}
52
53/**
54 * Return the challenge as determined by the authentication subsystem
55 * @return an 8 byte random challenge
56 */
57
58static NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
59 uint8_t chal[8])
60{
61 struct auth_ntlmssp_state *auth_ntlmssp_state =
62 (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
63 auth_ntlmssp_state->auth_context->get_ntlm_challenge(
64 auth_ntlmssp_state->auth_context, chal);
65 return NT_STATUS_OK;
66}
67
68/**
69 * Some authentication methods 'fix' the challenge, so we may not be able to set it
70 *
71 * @return If the effective challenge used by the auth subsystem may be modified
72 */
73static bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
74{
75 struct auth_ntlmssp_state *auth_ntlmssp_state =
76 (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
77 struct auth_context *auth_context = auth_ntlmssp_state->auth_context;
78
79 return auth_context->challenge_may_be_modified;
80}
81
82/**
83 * NTLM2 authentication modifies the effective challenge,
84 * @param challenge The new challenge value
85 */
86static NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge)
87{
88 struct auth_ntlmssp_state *auth_ntlmssp_state =
89 (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
90 struct auth_context *auth_context = auth_ntlmssp_state->auth_context;
91
92 SMB_ASSERT(challenge->length == 8);
93
94 auth_context->challenge = data_blob_talloc(auth_context,
95 challenge->data, challenge->length);
96
97 auth_context->challenge_set_by = "NTLMSSP callback (NTLM2)";
98
99 DEBUG(5, ("auth_context challenge set by %s\n", auth_context->challenge_set_by));
100 DEBUG(5, ("challenge is: \n"));
101 dump_data(5, auth_context->challenge.data, auth_context->challenge.length);
102 return NT_STATUS_OK;
103}
104
105/**
106 * Check the password on an NTLMSSP login.
107 *
108 * Return the session keys used on the connection.
109 */
110
111static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state, TALLOC_CTX *mem_ctx,
112 DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key)
113{
114 struct auth_ntlmssp_state *auth_ntlmssp_state =
115 (struct auth_ntlmssp_state *)ntlmssp_state->callback_private;
116 struct auth_usersupplied_info *user_info = NULL;
117 NTSTATUS nt_status;
118 bool username_was_mapped;
119
120 /* the client has given us its machine name (which we otherwise would not get on port 445).
121 we need to possibly reload smb.conf if smb.conf includes depend on the machine name */
122
123 set_remote_machine_name(auth_ntlmssp_state->ntlmssp_state->client.netbios_name, True);
124
125 /* setup the string used by %U */
126 /* sub_set_smb_name checks for weird internally */
127 sub_set_smb_name(auth_ntlmssp_state->ntlmssp_state->user);
128
129 reload_services(smbd_messaging_context(), -1, True);
130
131 nt_status = make_user_info_map(&user_info,
132 auth_ntlmssp_state->ntlmssp_state->user,
133 auth_ntlmssp_state->ntlmssp_state->domain,
134 auth_ntlmssp_state->ntlmssp_state->client.netbios_name,
135 auth_ntlmssp_state->ntlmssp_state->lm_resp.data ? &auth_ntlmssp_state->ntlmssp_state->lm_resp : NULL,
136 auth_ntlmssp_state->ntlmssp_state->nt_resp.data ? &auth_ntlmssp_state->ntlmssp_state->nt_resp : NULL,
137 NULL, NULL, NULL,
138 AUTH_PASSWORD_RESPONSE);
139
140 if (!NT_STATUS_IS_OK(nt_status)) {
141 return nt_status;
142 }
143
144 user_info->logon_parameters = MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT | MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT;
145
146 nt_status = auth_ntlmssp_state->auth_context->check_ntlm_password(auth_ntlmssp_state->auth_context,
147 user_info, &auth_ntlmssp_state->server_info);