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;
43 const char *config_file;
45 lp_ctx = loadparm_init(frame);
47 DEBUG(10, ("loadparm_init failed\n"));
49 return NT_STATUS_INVALID_SERVER_STATE;
53 config_file = lp_configfile();
55 if (!config_file || !config_file[0]) {
56 config_file = get_dyn_CONFIGFILE();
59 if (!lpcfg_load(lp_ctx, config_file)) {
60 DEBUG(1, ("s4 lpcfg_load() of s3 config file %s failed", config_file));
62 return NT_STATUS_INVALID_SERVER_STATE;
65 /* We create a private tevent context here to avoid nested loops in
66 * the s3 one, as that may not be expected */
67 nt_status = auth_context_create(mem_ctx,
68 s4_event_context_init(frame), NULL,
71 NT_STATUS_NOT_OK_RETURN(nt_status);
73 nt_status = auth_context_set_challenge(auth4_context, auth_context->challenge.data, "auth_samba4");
74 NT_STATUS_NOT_OK_RETURN_AND_FREE(nt_status, auth4_context);
76 nt_status = auth_check_password(auth4_context, auth4_context, user_info, &user_info_dc);
77 NT_STATUS_NOT_OK_RETURN_AND_FREE(nt_status, auth4_context);
79 nt_status = auth_convert_user_info_dc_saminfo3(mem_ctx,
82 if (NT_STATUS_IS_OK(nt_status)) {
83 /* We need the strings from the server_info to be valid as long as the info3 is around */
84 talloc_steal(info3, user_info_dc);
86 talloc_free(auth4_context);
88 if (!NT_STATUS_IS_OK(nt_status)) {
92 nt_status = make_server_info_info3(mem_ctx, user_info->client.account_name,
93 user_info->mapped.domain_name, server_info,
95 if (!NT_STATUS_IS_OK(nt_status)) {
96 DEBUG(10, ("make_server_info_info3 failed: %s\n",
97 nt_errstr(nt_status)));
102 nt_status = NT_STATUS_OK;
109 /* module initialisation */
110 static NTSTATUS auth_init_samba4(struct auth_context *auth_context,
112 auth_methods **auth_method)
114 struct auth_methods *result;
116 result = TALLOC_ZERO_P(auth_context, struct auth_methods);
117 if (result == NULL) {
118 return NT_STATUS_NO_MEMORY;
120 result->name = "samba4";
121 result->auth = check_samba4_security;
123 *auth_method = result;
127 NTSTATUS auth_samba4_init(void)
129 smb_register_auth(AUTH_INTERFACE_VERSION, "samba4",