ctdb-common: Map ENOENT for a missing event script to ENOEXEC
[samba4-gss.git] / source4 / auth / ntlm / auth_developer.c
blob89db15d0ee7c353566ab2f48dc764591ea8fda59
1 /*
2 Unix SMB/CIFS implementation.
3 Generic authentication types
4 Copyright (C) Andrew Bartlett 2001-2002
5 Copyright (C) Jelmer Vernooij 2002
6 Copyright (C) Stefan Metzmacher 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include <tevent.h>
24 #include "auth/auth.h"
25 #include "auth/ntlm/auth_proto.h"
26 #include "libcli/security/security.h"
27 #include "lib/util/tevent_ntstatus.h"
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_AUTH
32 #undef strncasecmp
34 _PUBLIC_ NTSTATUS auth4_developer_init(TALLOC_CTX *);
36 static NTSTATUS name_to_ntstatus_want_check(struct auth_method_context *ctx,
37 TALLOC_CTX *mem_ctx,
38 const struct auth_usersupplied_info *user_info)
40 return NT_STATUS_OK;
43 /**
44 * Return an error based on username
46 * This function allows the testing of obscure errors, as well as the generation
47 * of NT_STATUS -> DOS error mapping tables.
49 * This module is of no value to end-users.
51 * The password is ignored.
53 * @return An NTSTATUS value based on the username
54 **/
56 static NTSTATUS name_to_ntstatus_check_password(struct auth_method_context *ctx,
57 TALLOC_CTX *mem_ctx,
58 const struct auth_usersupplied_info *user_info,
59 struct auth_user_info_dc **_user_info_dc,
60 bool *authoritative)
62 NTSTATUS nt_status;
63 struct auth_user_info_dc *user_info_dc;
64 struct auth_user_info *info;
65 uint32_t error_num;
66 const char *user;
68 user = user_info->client.account_name;
70 if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
71 nt_status = nt_status_string_to_code(user);
72 } else {
73 error_num = strtoul(user, NULL, 16);
74 DEBUG(5,("name_to_ntstatus_check_password: Error for user %s was 0x%08X\n", user, error_num));
75 nt_status = NT_STATUS(error_num);
77 NT_STATUS_NOT_OK_RETURN(nt_status);
79 user_info_dc = talloc_zero(mem_ctx, struct auth_user_info_dc);
80 NT_STATUS_HAVE_NO_MEMORY(user_info_dc);
82 /* This returns a pointer to a struct dom_sid, which is the
83 * same as a 1 element list of struct dom_sid */
84 user_info_dc->num_sids = 1;
85 user_info_dc->sids = talloc(user_info_dc, struct auth_SidAttr);
86 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->sids);
88 user_info_dc->sids->sid = global_sid_Anonymous;
89 user_info_dc->sids->attrs = SE_GROUP_DEFAULT_FLAGS;
91 /* annoying, but the Anonymous really does have a session key,
92 and it is all zeros! */
93 user_info_dc->user_session_key = data_blob_talloc(user_info_dc, NULL, 16);
94 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->user_session_key.data);
96 user_info_dc->lm_session_key = data_blob_talloc(user_info_dc, NULL, 16);
97 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->lm_session_key.data);
99 data_blob_clear(&user_info_dc->user_session_key);
100 data_blob_clear(&user_info_dc->lm_session_key);
102 user_info_dc->info = info = talloc_zero(user_info_dc, struct auth_user_info);
103 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->info);
105 info->account_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s ANONYMOUS LOGON", user);
106 NT_STATUS_HAVE_NO_MEMORY(info->account_name);
108 info->domain_name = talloc_strdup(user_info_dc, "NT AUTHORITY");
109 NT_STATUS_HAVE_NO_MEMORY(info->domain_name);
111 info->full_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s Anonymous Logon", user);
112 NT_STATUS_HAVE_NO_MEMORY(info->full_name);
114 info->logon_script = talloc_strdup(user_info_dc, "");
115 NT_STATUS_HAVE_NO_MEMORY(info->logon_script);
117 info->profile_path = talloc_strdup(user_info_dc, "");
118 NT_STATUS_HAVE_NO_MEMORY(info->profile_path);
120 info->home_directory = talloc_strdup(user_info_dc, "");
121 NT_STATUS_HAVE_NO_MEMORY(info->home_directory);
123 info->home_drive = talloc_strdup(user_info_dc, "");
124 NT_STATUS_HAVE_NO_MEMORY(info->home_drive);
126 info->last_logon = 0;
127 info->last_logoff = 0;
128 info->acct_expiry = 0;
129 info->last_password_change = 0;
130 info->allow_password_change = 0;
131 info->force_password_change = 0;
133 info->logon_count = 0;
134 info->bad_password_count = 0;
136 info->acct_flags = ACB_NORMAL;
138 info->user_flags = 0;
140 *_user_info_dc = user_info_dc;
142 return nt_status;
145 struct name_to_ntstatus_check_password_state {
146 struct auth_user_info_dc *user_info_dc;
147 bool authoritative;
150 static struct tevent_req *name_to_ntstatus_check_password_send(
151 TALLOC_CTX *mem_ctx,
152 struct tevent_context *ev,
153 struct auth_method_context *ctx,
154 const struct auth_usersupplied_info *user_info)
156 struct tevent_req *req = NULL;
157 struct name_to_ntstatus_check_password_state *state = NULL;
158 NTSTATUS status;
160 req = tevent_req_create(
161 mem_ctx,
162 &state,
163 struct name_to_ntstatus_check_password_state);
164 if (req == NULL) {
165 return NULL;
168 status = name_to_ntstatus_check_password(
169 ctx,
170 state,
171 user_info,
172 &state->user_info_dc,
173 &state->authoritative);
174 if (tevent_req_nterror(req, status)) {
175 return tevent_req_post(req, ev);
177 tevent_req_done(req);
178 return tevent_req_post(req, ev);
181 static NTSTATUS name_to_ntstatus_check_password_recv(
182 struct tevent_req *req,
183 TALLOC_CTX *mem_ctx,
184 struct auth_user_info_dc **interim_info,
185 const struct authn_audit_info **client_audit_info,
186 const struct authn_audit_info **server_audit_info,
187 bool *authoritative)
189 struct name_to_ntstatus_check_password_state *state = tevent_req_data(
190 req, struct name_to_ntstatus_check_password_state);
191 NTSTATUS status;
193 *authoritative = state->authoritative;
194 *client_audit_info = NULL;
195 *server_audit_info = NULL;
197 if (tevent_req_is_nterror(req, &status)) {
198 tevent_req_received(req);
199 return status;
201 *interim_info = talloc_move(mem_ctx, &state->user_info_dc);
202 tevent_req_received(req);
203 return NT_STATUS_OK;
206 static const struct auth_operations name_to_ntstatus_auth_ops = {
207 .name = "name_to_ntstatus",
208 .want_check = name_to_ntstatus_want_check,
209 .check_password_send = name_to_ntstatus_check_password_send,
210 .check_password_recv = name_to_ntstatus_check_password_recv,
213 _PUBLIC_ NTSTATUS auth4_developer_init(TALLOC_CTX *ctx)
215 NTSTATUS ret;
217 ret = auth_register(ctx, &name_to_ntstatus_auth_ops);
218 if (!NT_STATUS_IS_OK(ret)) {
219 DEBUG(0,("Failed to register 'name_to_ntstatus' auth backend!\n"));
220 return ret;
223 return ret;