2 Unix SMB/Netbios implementation.
4 handle NLTMSSP, server side
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett 2001-2003
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 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 static const uint8
*auth_ntlmssp_get_challenge(struct ntlmssp_state
*ntlmssp_state
)
28 AUTH_NTLMSSP_STATE
*auth_ntlmssp_state
= ntlmssp_state
->auth_context
;
29 return auth_ntlmssp_state
->auth_context
->get_ntlm_challenge(auth_ntlmssp_state
->auth_context
);
32 static NTSTATUS
auth_ntlmssp_check_password(struct ntlmssp_state
*ntlmssp_state
)
34 AUTH_NTLMSSP_STATE
*auth_ntlmssp_state
= ntlmssp_state
->auth_context
;
35 uint32 auth_flags
= AUTH_FLAG_NONE
;
36 auth_usersupplied_info
*user_info
= NULL
;
37 DATA_BLOB plaintext_password
= data_blob(NULL
, 0);
40 if (auth_ntlmssp_state
->ntlmssp_state
->lm_resp
.length
) {
41 auth_flags
|= AUTH_FLAG_LM_RESP
;
44 if (auth_ntlmssp_state
->ntlmssp_state
->nt_resp
.length
== 24) {
45 auth_flags
|= AUTH_FLAG_NTLM_RESP
;
46 } else if (auth_ntlmssp_state
->ntlmssp_state
->nt_resp
.length
> 24) {
47 auth_flags
|= AUTH_FLAG_NTLMv2_RESP
;
50 /* the client has given us its machine name (which we otherwise would not get on port 445).
51 we need to possibly reload smb.conf if smb.conf includes depend on the machine name */
53 set_remote_machine_name(auth_ntlmssp_state
->ntlmssp_state
->workstation
, True
);
55 /* setup the string used by %U */
56 /* sub_set_smb_name checks for weird internally */
57 sub_set_smb_name(auth_ntlmssp_state
->ntlmssp_state
->user
);
59 reload_services(True
);
61 nt_status
= make_user_info_map(&user_info
,
62 auth_ntlmssp_state
->ntlmssp_state
->user
,
63 auth_ntlmssp_state
->ntlmssp_state
->domain
,
64 auth_ntlmssp_state
->ntlmssp_state
->workstation
,
65 auth_ntlmssp_state
->ntlmssp_state
->lm_resp
,
66 auth_ntlmssp_state
->ntlmssp_state
->nt_resp
,
70 if (!NT_STATUS_IS_OK(nt_status
)) {
74 nt_status
= auth_ntlmssp_state
->auth_context
->check_ntlm_password(auth_ntlmssp_state
->auth_context
, user_info
, &auth_ntlmssp_state
->server_info
);
76 free_user_info(&user_info
);
81 NTSTATUS
auth_ntlmssp_start(AUTH_NTLMSSP_STATE
**auth_ntlmssp_state
)
86 mem_ctx
= talloc_init("AUTH NTLMSSP context");
88 *auth_ntlmssp_state
= talloc_zero(mem_ctx
, sizeof(**auth_ntlmssp_state
));
89 if (!*auth_ntlmssp_state
) {
90 DEBUG(0,("auth_ntlmssp_start: talloc failed!\n"));
91 talloc_destroy(mem_ctx
);
92 return NT_STATUS_NO_MEMORY
;
95 ZERO_STRUCTP(*auth_ntlmssp_state
);
97 (*auth_ntlmssp_state
)->mem_ctx
= mem_ctx
;
99 if (!NT_STATUS_IS_OK(nt_status
= ntlmssp_server_start(&(*auth_ntlmssp_state
)->ntlmssp_state
))) {
103 if (!NT_STATUS_IS_OK(nt_status
= make_auth_context_subsystem(&(*auth_ntlmssp_state
)->auth_context
))) {
107 (*auth_ntlmssp_state
)->ntlmssp_state
->auth_context
= (*auth_ntlmssp_state
);
108 (*auth_ntlmssp_state
)->ntlmssp_state
->get_challenge
= auth_ntlmssp_get_challenge
;
109 (*auth_ntlmssp_state
)->ntlmssp_state
->check_password
= auth_ntlmssp_check_password
;
110 (*auth_ntlmssp_state
)->ntlmssp_state
->server_role
= lp_server_role();
115 NTSTATUS
auth_ntlmssp_end(AUTH_NTLMSSP_STATE
**auth_ntlmssp_state
)
117 TALLOC_CTX
*mem_ctx
= (*auth_ntlmssp_state
)->mem_ctx
;
119 if ((*auth_ntlmssp_state
)->ntlmssp_state
) {
120 ntlmssp_server_end(&(*auth_ntlmssp_state
)->ntlmssp_state
);
122 if ((*auth_ntlmssp_state
)->auth_context
) {
123 ((*auth_ntlmssp_state
)->auth_context
->free
)(&(*auth_ntlmssp_state
)->auth_context
);
125 if ((*auth_ntlmssp_state
)->server_info
) {
126 free_server_info(&(*auth_ntlmssp_state
)->server_info
);
128 talloc_destroy(mem_ctx
);
129 *auth_ntlmssp_state
= NULL
;
133 NTSTATUS
auth_ntlmssp_update(AUTH_NTLMSSP_STATE
*auth_ntlmssp_state
,
134 const DATA_BLOB request
, DATA_BLOB
*reply
)
136 return ntlmssp_server_update(auth_ntlmssp_state
->ntlmssp_state
, request
, reply
);