feba4b93ac178eca8ad10621fa9fa47257254537
[abartlet/samba.git/.git] / source4 / s3compat / s3compat_authenticate.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Implement a hook into the Samba4 auth subsystem
5
6    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2010
7    Copyright (C) Stefan Metzmacher <metze@samba.org>  2005
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/auth.h"
25 #include "auth/auth_sam_reply.h"
26 #include "s3_smbd_proto.h"
27 #include "s3compat_authenticate.h"
28 #include "smbd/service.h"
29
30 NTSTATUS s3compat_authenticate(TALLOC_CTX *mem_ctx, uint8_t chall[8], const struct auth_usersupplied_info *user_info, struct netr_SamInfo3 **info3) 
31 {
32         struct stream_connection *samba3_conn;
33         struct auth_context *auth_context;
34         struct auth_serversupplied_info *server_info;
35         NTSTATUS nt_status;
36         samba3_conn = s3compat_get_conn();
37
38         nt_status = auth_context_create(mem_ctx,
39                                         samba3_conn->event.ctx, samba3_conn->msg_ctx, samba3_conn->lp_ctx,
40                                         &auth_context);
41         NT_STATUS_NOT_OK_RETURN(nt_status);
42                 
43         nt_status = auth_context_set_challenge(auth_context, chall, "s3compat");
44         NT_STATUS_NOT_OK_RETURN_AND_FREE(nt_status, auth_context);
45
46         nt_status = auth_check_password(auth_context, auth_context, user_info, &server_info);
47         NT_STATUS_NOT_OK_RETURN_AND_FREE(nt_status, auth_context);
48         
49         nt_status = auth_convert_server_info_saminfo3(mem_ctx,
50                                                       server_info,
51                                                       info3);
52         talloc_free(auth_context);
53         return nt_status;
54 }
55