This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[jra/samba/.git] / source3 / auth / auth_winbind.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Winbind authentication mechnism
5
6    Copyright (C) Tim Potter 2000
7    Copyright (C) Andrew Bartlett 2001
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 2 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, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 /* Prototypes from common.h */
27
28 NSS_STATUS winbindd_request(int req_type, 
29                             struct winbindd_request *request,
30                             struct winbindd_response *response);
31
32
33 /* Authenticate a user with a challenge/response */
34
35 static NTSTATUS check_winbind_security(const struct auth_context *auth_context,
36                                        void *my_private_data, 
37                                        TALLOC_CTX *mem_ctx,
38                                        const auth_usersupplied_info *user_info, 
39                                        auth_serversupplied_info **server_info)
40 {
41         struct winbindd_request request;
42         struct winbindd_response response;
43         NSS_STATUS result;
44         struct passwd *pw;
45         NTSTATUS nt_status;
46
47         if (!user_info) {
48                 return NT_STATUS_UNSUCCESSFUL;
49         }
50
51         if (!auth_context) {
52                 DEBUG(3,("Password for user %s cannot be checked because we have no auth_info to get the challenge from.\n", 
53                          user_info->internal_username.str));            
54                 return NT_STATUS_UNSUCCESSFUL;
55         }               
56
57         /* Send off request */
58
59         ZERO_STRUCT(request);
60         ZERO_STRUCT(response);
61
62         snprintf(request.data.auth_crap.user, sizeof(request.data.auth_crap.user),
63                  "%s\\%s", user_info->domain.str, user_info->smb_name.str);
64
65         fstrcpy(request.data.auth_crap.user, user_info->smb_name.str);
66         fstrcpy(request.data.auth_crap.domain, user_info->domain.str);
67
68         memcpy(request.data.auth_crap.chal, auth_context->challenge.data, sizeof(request.data.auth_crap.chal));
69         
70         request.data.auth_crap.lm_resp_len = MIN(user_info->lm_resp.length, 
71                                                  sizeof(request.data.auth_crap.lm_resp));
72         request.data.auth_crap.nt_resp_len = MIN(user_info->nt_resp.length, 
73                                                  sizeof(request.data.auth_crap.nt_resp));
74         
75         memcpy(request.data.auth_crap.lm_resp, user_info->lm_resp.data, 
76                sizeof(request.data.auth_crap.lm_resp_len));
77         memcpy(request.data.auth_crap.nt_resp, user_info->nt_resp.data, 
78                request.data.auth_crap.lm_resp_len);
79         
80         result = winbindd_request(WINBINDD_PAM_AUTH_CRAP, &request, &response);
81
82         if (result == NSS_STATUS_SUCCESS) {
83                 
84                 pw = Get_Pwnam(user_info->internal_username.str);
85                 
86                 if (pw) {                       
87                         if (make_server_info_pw(server_info, pw)) {
88                                 nt_status = NT_STATUS_OK;
89                         } else {
90                                 nt_status = NT_STATUS_NO_MEMORY;
91                         }
92                 } else {
93                         nt_status = NT_STATUS_NO_SUCH_USER;
94                 }
95         } else {
96                 nt_status = NT_STATUS_LOGON_FAILURE;
97         }
98
99         return nt_status;
100 }
101
102 /* module initialisation */
103 BOOL auth_init_winbind(struct auth_context *auth_context, auth_methods **auth_method) 
104 {
105         if (!make_auth_methods(auth_context, auth_method)) {
106                 return False;
107         }
108
109         (*auth_method)->auth = check_winbind_security;
110         return True;
111 }