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 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.
27 #define DBGC_CLASS DBGC_AUTH
29 static NTSTATUS
get_info3_from_ndr(TALLOC_CTX
*mem_ctx
, struct winbindd_response
*response
, NET_USER_INFO_3
*info3
)
32 size_t len
= response
->length
- sizeof(response
);
35 info3_ndr
= response
->extra_data
;
36 if (!prs_init(&ps
, len
, mem_ctx
, UNMARSHALL
)) {
37 return NT_STATUS_NO_MEMORY
;
39 prs_copy_data_in(&ps
, info3_ndr
, len
);
40 prs_set_offset(&ps
,0);
41 if (!net_io_user_info3("", info3
, &ps
, 1, 3)) {
42 DEBUG(2, ("get_info3_from_ndr: could not parse info3 struct!\n"));
43 return NT_STATUS_UNSUCCESSFUL
;
49 DEBUG(2, ("get_info3_from_ndr: No info3 struct found!\n"));
50 return NT_STATUS_UNSUCCESSFUL
;
54 /* Authenticate a user with a challenge/response */
56 static NTSTATUS
check_winbind_security(const struct auth_context
*auth_context
,
57 void *my_private_data
,
59 const auth_usersupplied_info
*user_info
,
60 auth_serversupplied_info
**server_info
)
62 struct winbindd_request request
;
63 struct winbindd_response response
;
66 NET_USER_INFO_3 info3
;
69 return NT_STATUS_INVALID_PARAMETER
;
73 DEBUG(3,("Password for user %s cannot be checked because we have no auth_info to get the challenge from.\n",
74 user_info
->internal_username
.str
));
75 return NT_STATUS_UNSUCCESSFUL
;
78 /* Send off request */
81 ZERO_STRUCT(response
);
83 request
.data
.auth_crap
.flags
= WINBIND_PAM_INFO3_NDR
;
85 push_utf8_fstring(request
.data
.auth_crap
.user
,
86 user_info
->smb_name
.str
);
87 push_utf8_fstring(request
.data
.auth_crap
.domain
,
88 user_info
->domain
.str
);
89 push_utf8_fstring(request
.data
.auth_crap
.workstation
,
90 user_info
->wksta_name
.str
);
92 memcpy(request
.data
.auth_crap
.chal
, auth_context
->challenge
.data
, sizeof(request
.data
.auth_crap
.chal
));
94 request
.data
.auth_crap
.lm_resp_len
= MIN(user_info
->lm_resp
.length
,
95 sizeof(request
.data
.auth_crap
.lm_resp
));
96 request
.data
.auth_crap
.nt_resp_len
= MIN(user_info
->nt_resp
.length
,
97 sizeof(request
.data
.auth_crap
.nt_resp
));
99 memcpy(request
.data
.auth_crap
.lm_resp
, user_info
->lm_resp
.data
,
100 request
.data
.auth_crap
.lm_resp_len
);
101 memcpy(request
.data
.auth_crap
.nt_resp
, user_info
->nt_resp
.data
,
102 request
.data
.auth_crap
.nt_resp_len
);
104 result
= winbindd_request(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
106 if ( result
== NSS_STATUS_UNAVAIL
) {
107 struct auth_methods
*auth_method
= my_private_data
;
110 return auth_method
->auth(auth_context
, auth_method
->private_data
,
111 mem_ctx
, user_info
, server_info
);
113 /* log an error since this should not happen */
114 DEBUG(0,("check_winbind_security: ERROR! my_private_data == NULL!\n"));
117 nt_status
= NT_STATUS(response
.data
.auth
.nt_status
);
119 if (result
== NSS_STATUS_SUCCESS
&& response
.extra_data
) {
120 if (NT_STATUS_IS_OK(nt_status
)) {
121 if (NT_STATUS_IS_OK(nt_status
= get_info3_from_ndr(mem_ctx
, &response
, &info3
))) {
123 make_server_info_info3(mem_ctx
,
124 user_info
->internal_username
.str
,
125 user_info
->smb_name
.str
,
126 user_info
->domain
.str
,
131 } else if (NT_STATUS_IS_OK(nt_status
)) {
132 nt_status
= NT_STATUS_UNSUCCESSFUL
;
138 /* module initialisation */
139 NTSTATUS
auth_init_winbind(struct auth_context
*auth_context
, const char *param
, auth_methods
**auth_method
)
141 if (!make_auth_methods(auth_context
, auth_method
)) {
142 return NT_STATUS_NO_MEMORY
;
145 (*auth_method
)->name
= "winbind";
146 (*auth_method
)->auth
= check_winbind_security
;
148 if (param
&& *param
) {
149 /* we load the 'fallback' module - if winbind isn't here, call this
151 if (!load_auth_module(auth_context
, param
, (auth_methods
**)&(*auth_method
)->private_data
)) {
152 return NT_STATUS_UNSUCCESSFUL
;
159 NTSTATUS
auth_winbind_init(void)
161 return smb_register_auth(AUTH_INTERFACE_VERSION
, "winbind", auth_init_winbind
);