examples/VFS: fix skel_transparent.c in reference to shadow_copy changes
[Samba/gebeck_regimport.git] / source3 / auth / auth_samba4.c
blob03b7884068da70c98fda2d3e8988b535af6e0d58
1 /*
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/>.
21 #include "includes.h"
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"
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_AUTH
31 static NTSTATUS check_samba4_security(const struct auth_context *auth_context,
32 void *my_private_data,
33 TALLOC_CTX *mem_ctx,
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;
39 NTSTATUS nt_status;
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());
45 if (lp_ctx == NULL) {
46 DEBUG(10, ("loadparm_init_s3 failed\n"));
47 talloc_free(frame);
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,
55 lp_ctx,
56 &auth4_context);
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,
66 user_info_dc,
67 &info3);
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)) {
75 goto done;
78 nt_status = make_server_info_info3(mem_ctx, user_info->client.account_name,
79 user_info->mapped.domain_name, server_info,
80 info3);
81 if (!NT_STATUS_IS_OK(nt_status)) {
82 DEBUG(10, ("make_server_info_info3 failed: %s\n",
83 nt_errstr(nt_status)));
84 TALLOC_FREE(frame);
85 return nt_status;
88 nt_status = NT_STATUS_OK;
90 done:
91 TALLOC_FREE(frame);
92 return nt_status;
95 /* module initialisation */
96 static NTSTATUS auth_init_samba4(struct auth_context *auth_context,
97 const char *param,
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;
110 return NT_STATUS_OK;
113 NTSTATUS auth_samba4_init(void)
115 smb_register_auth(AUTH_INTERFACE_VERSION, "samba4",
116 auth_init_samba4);
117 return NT_STATUS_OK;