2 Unix SMB/CIFS implementation.
4 Winbind authentication mechnism
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Andrew Bartlett 2001 - 2002
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.
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, see <http://www.gnu.org/licenses/>.
26 #include "nsswitch/libwbclient/wbclient.h"
29 #define DBGC_CLASS DBGC_AUTH
31 /* Authenticate a user with a challenge/response */
33 static NTSTATUS
check_winbind_security(const struct auth_context
*auth_context
,
34 void *my_private_data
,
36 const struct auth_usersupplied_info
*user_info
,
37 struct auth_serversupplied_info
**server_info
)
41 struct wbcAuthUserParams params
;
42 struct wbcAuthUserInfo
*info
= NULL
;
43 struct wbcAuthErrorInfo
*err
= NULL
;
48 return NT_STATUS_INVALID_PARAMETER
;
51 DEBUG(10, ("Check auth for: [%s]\n", user_info
->mapped
.account_name
));
54 DEBUG(3,("Password for user %s cannot be checked because we have no auth_info to get the challenge from.\n",
55 user_info
->mapped
.account_name
));
56 return NT_STATUS_INVALID_PARAMETER
;
59 if (strequal(user_info
->mapped
.domain_name
, get_global_sam_name())) {
60 DEBUG(3,("check_winbind_security: Not using winbind, requested domain [%s] was for this SAM.\n",
61 user_info
->mapped
.domain_name
));
62 return NT_STATUS_NOT_IMPLEMENTED
;
65 /* Send off request */
66 params
.account_name
= user_info
->client
.account_name
;
68 * We need to send the domain name from the client to the DC. With
69 * NTLMv2 the domain name is part of the hashed second challenge,
70 * if we change the domain name, the DC will fail to verify the
71 * challenge cause we changed the domain name, this is like a
72 * man in the middle attack.
74 params
.domain_name
= user_info
->client
.domain_name
;
75 params
.workstation_name
= user_info
->workstation_name
;
78 params
.parameter_control
= user_info
->logon_parameters
;
80 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
82 memcpy(params
.password
.response
.challenge
,
83 auth_context
->challenge
.data
,
84 sizeof(params
.password
.response
.challenge
));
86 if (user_info
->password
.response
.nt
.length
!= 0) {
87 params
.password
.response
.nt_length
=
88 user_info
->password
.response
.nt
.length
;
89 params
.password
.response
.nt_data
=
90 user_info
->password
.response
.nt
.data
;
92 if (user_info
->password
.response
.lanman
.length
!= 0) {
93 params
.password
.response
.lm_length
=
94 user_info
->password
.response
.lanman
.length
;
95 params
.password
.response
.lm_data
=
96 user_info
->password
.response
.lanman
.data
;
99 /* we are contacting the privileged pipe */
101 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
104 if (!WBC_ERROR_IS_OK(wbc_status
)) {
105 DEBUG(10,("check_winbind_security: wbcAuthenticateUserEx failed: %s\n",
106 wbcErrorString(wbc_status
)));
109 if (wbc_status
== WBC_ERR_NO_MEMORY
) {
110 return NT_STATUS_NO_MEMORY
;
113 if (wbc_status
== WBC_ERR_WINBIND_NOT_AVAILABLE
) {
114 struct pdb_trusted_domain
**domains
= NULL
;
115 uint32_t num_domains
= 0;
118 if (lp_server_role() == ROLE_DOMAIN_MEMBER
) {
119 status
= NT_STATUS_NO_LOGON_SERVERS
;
120 DBG_ERR("winbindd not running - "
121 "but required as domain member: %s\n",
126 status
= pdb_enum_trusted_domains(talloc_tos(), &num_domains
, &domains
);
127 if (!NT_STATUS_IS_OK(status
)) {
128 DBG_ERR("pdb_enum_trusted_domains() failed - %s\n",
132 TALLOC_FREE(domains
);
134 if (num_domains
== 0) {
135 DBG_DEBUG("winbindd not running - ignoring without "
136 "trusted domains\n");
137 return NT_STATUS_NOT_IMPLEMENTED
;
140 status
= NT_STATUS_NO_LOGON_SERVERS
;
141 DBG_ERR("winbindd not running - "
142 "but required as DC with trusts: %s\n",
147 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
148 nt_status
= NT_STATUS(err
->nt_status
);
150 if (NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_SUCH_USER
) &&
151 (err
->authoritative
== 0)) {
153 * Trigger a fallback to local SAM
155 nt_status
= NT_STATUS_NOT_IMPLEMENTED
;
162 if (!WBC_ERROR_IS_OK(wbc_status
)) {
163 return NT_STATUS_LOGON_FAILURE
;
166 nt_status
= make_server_info_wbcAuthUserInfo(mem_ctx
,
167 user_info
->client
.account_name
,
168 user_info
->mapped
.domain_name
,
171 if (!NT_STATUS_IS_OK(nt_status
)) {
175 (*server_info
)->nss_token
|= user_info
->was_mapped
;
180 /* module initialisation */
181 static NTSTATUS
auth_init_winbind(struct auth_context
*auth_context
, const char *param
, auth_methods
**auth_method
)
183 struct auth_methods
*result
;
185 result
= talloc_zero(auth_context
, struct auth_methods
);
186 if (result
== NULL
) {
187 return NT_STATUS_NO_MEMORY
;
189 result
->name
= "winbind";
190 result
->auth
= check_winbind_security
;
192 *auth_method
= result
;
196 NTSTATUS
auth_winbind_init(TALLOC_CTX
*mem_ctx
)
198 return smb_register_auth(AUTH_INTERFACE_VERSION
, "winbind", auth_init_winbind
);