2 Unix SMB/CIFS implementation.
3 Authenticate against Samba4's auth subsystem
4 Copyright (C) Volker Lendecke 2008
5 Copyright (C) Andrew Bartlett 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "source3/include/auth.h"
23 #include "source4/auth/auth.h"
24 #include "auth/auth_sam_reply.h"
25 #include "param/param.h"
26 #include "source4/lib/events/events.h"
29 #define DBGC_CLASS DBGC_AUTH
31 static NTSTATUS
check_samba4_security(const struct auth_context
*auth_context
,
32 void *my_private_data
,
34 const struct auth_usersupplied_info
*user_info
,
35 struct auth_serversupplied_info
**server_info
)
37 TALLOC_CTX
*frame
= talloc_stackframe();
38 struct netr_SamInfo3
*info3
= NULL
;
40 struct auth_user_info_dc
*user_info_dc
;
41 struct auth4_context
*auth4_context
;
42 struct loadparm_context
*lp_ctx
;
44 lp_ctx
= loadparm_init_s3(frame
, loadparm_s3_context());
46 DEBUG(10, ("loadparm_init_s3 failed\n"));
48 return NT_STATUS_INVALID_SERVER_STATE
;
51 /* We create a private tevent context here to avoid nested loops in
52 * the s3 one, as that may not be expected */
53 nt_status
= auth_context_create(mem_ctx
,
54 s4_event_context_init(frame
), NULL
,
57 NT_STATUS_NOT_OK_RETURN(nt_status
);
59 nt_status
= auth_context_set_challenge(auth4_context
, auth_context
->challenge
.data
, "auth_samba4");
60 NT_STATUS_NOT_OK_RETURN_AND_FREE(nt_status
, auth4_context
);
62 nt_status
= auth_check_password(auth4_context
, auth4_context
, user_info
, &user_info_dc
);
63 NT_STATUS_NOT_OK_RETURN_AND_FREE(nt_status
, auth4_context
);
65 nt_status
= auth_convert_user_info_dc_saminfo3(mem_ctx
,
68 if (NT_STATUS_IS_OK(nt_status
)) {
69 /* We need the strings from the server_info to be valid as long as the info3 is around */
70 talloc_steal(info3
, user_info_dc
);
72 talloc_free(auth4_context
);
74 if (!NT_STATUS_IS_OK(nt_status
)) {
78 nt_status
= make_server_info_info3(mem_ctx
, user_info
->client
.account_name
,
79 user_info
->mapped
.domain_name
, server_info
,
81 if (!NT_STATUS_IS_OK(nt_status
)) {
82 DEBUG(10, ("make_server_info_info3 failed: %s\n",
83 nt_errstr(nt_status
)));
88 nt_status
= NT_STATUS_OK
;
95 /* module initialisation */
96 static NTSTATUS
auth_init_samba4(struct auth_context
*auth_context
,
98 auth_methods
**auth_method
)
100 struct auth_methods
*result
;
102 result
= talloc_zero(auth_context
, struct auth_methods
);
103 if (result
== NULL
) {
104 return NT_STATUS_NO_MEMORY
;
106 result
->name
= "samba4";
107 result
->auth
= check_samba4_security
;
109 *auth_method
= result
;
113 NTSTATUS
auth_samba4_init(void)
115 smb_register_auth(AUTH_INTERFACE_VERSION
, "samba4",