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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "auth/auth.h"
27 * Return an error based on username
29 * This function allows the testing of obsure errors, as well as the generation
30 * of NT_STATUS -> DOS error mapping tables.
32 * This module is of no value to end-users.
34 * The password is ignored.
36 * @return An NTSTATUS value based on the username
39 static NTSTATUS name_to_ntstatus_check_password(struct auth_method_context *ctx,
41 const struct auth_usersupplied_info *user_info,
42 struct auth_serversupplied_info **_server_info)
45 struct auth_serversupplied_info *server_info;
49 user = user_info->client.account_name;
51 if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
52 nt_status = nt_status_string_to_code(user);
54 error_num = strtoul(user, NULL, 16);
55 DEBUG(5,("name_to_ntstatus_check_password: Error for user %s was 0x%08X\n", user, error_num));
56 nt_status = NT_STATUS(error_num);
59 if (!NT_STATUS_IS_OK(nt_status)) {
63 server_info = talloc(mem_ctx, struct auth_serversupplied_info);
64 NT_STATUS_HAVE_NO_MEMORY(server_info);
66 server_info->account_sid = dom_sid_parse_talloc(server_info, SID_NT_ANONYMOUS);
67 NT_STATUS_HAVE_NO_MEMORY(server_info->account_sid);
69 /* is this correct? */
70 server_info->primary_group_sid = dom_sid_parse_talloc(server_info, SID_BUILTIN_GUESTS);
71 NT_STATUS_HAVE_NO_MEMORY(server_info->primary_group_sid);
73 server_info->n_domain_groups = 0;
74 server_info->domain_groups = NULL;
76 /* annoying, but the Anonymous really does have a session key,
77 and it is all zeros! */
78 server_info->user_session_key = data_blob_talloc(server_info, NULL, 16);
79 NT_STATUS_HAVE_NO_MEMORY(server_info->user_session_key.data);
81 server_info->lm_session_key = data_blob_talloc(server_info, NULL, 16);
82 NT_STATUS_HAVE_NO_MEMORY(server_info->lm_session_key.data);
84 data_blob_clear(&server_info->user_session_key);
85 data_blob_clear(&server_info->lm_session_key);
87 server_info->account_name = talloc_asprintf(server_info, "NAME TO NTSTATUS %s ANONYMOUS LOGON", user);
88 NT_STATUS_HAVE_NO_MEMORY(server_info->account_name);
90 server_info->domain_name = talloc_strdup(server_info, "NT AUTHORITY");
91 NT_STATUS_HAVE_NO_MEMORY(server_info->domain_name);
93 server_info->full_name = talloc_asprintf(server_info, "NAME TO NTSTATUS %s Anonymous Logon", user);
94 NT_STATUS_HAVE_NO_MEMORY(server_info->full_name);
96 server_info->logon_script = talloc_strdup(server_info, "");
97 NT_STATUS_HAVE_NO_MEMORY(server_info->logon_script);
99 server_info->profile_path = talloc_strdup(server_info, "");
100 NT_STATUS_HAVE_NO_MEMORY(server_info->profile_path);
102 server_info->home_directory = talloc_strdup(server_info, "");
103 NT_STATUS_HAVE_NO_MEMORY(server_info->home_directory);
105 server_info->home_drive = talloc_strdup(server_info, "");
106 NT_STATUS_HAVE_NO_MEMORY(server_info->home_drive);
108 server_info->last_logon = 0;
109 server_info->last_logoff = 0;
110 server_info->acct_expiry = 0;
111 server_info->last_password_change = 0;
112 server_info->allow_password_change = 0;
113 server_info->force_password_change = 0;
115 server_info->logon_count = 0;
116 server_info->bad_password_count = 0;
118 server_info->acct_flags = ACB_NORMAL;
120 server_info->authenticated = False;
122 *_server_info = server_info;
127 static struct auth_operations name_to_ntstatus_auth_ops = {
128 .name = "name_to_ntstatus",
129 .get_challenge = auth_get_challenge_not_implemented,
130 .check_password = name_to_ntstatus_check_password
134 * Return a 'fixed' challenge instead of a variable one.
136 * The idea of this function is to make packet snifs consistant
137 * with a fixed challenge, so as to aid debugging.
139 * This module is of no value to end-users.
141 * This module does not actually authenticate the user, but
142 * just pretenteds to need a specified challenge.
143 * This module removes *all* security from the challenge-response system
145 * @return NT_STATUS_UNSUCCESSFUL
147 static NTSTATUS fixed_challenge_get_challenge(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, DATA_BLOB *_blob)
150 const char *challenge = "I am a teapot";
152 blob = data_blob_talloc(mem_ctx, challenge, 8);
153 NT_STATUS_HAVE_NO_MEMORY(blob.data);
159 static NTSTATUS fixed_challenge_check_password(struct auth_method_context *ctx,
161 const struct auth_usersupplied_info *user_info,
162 struct auth_serversupplied_info **_server_info)
164 /* don't handle any users */
165 return NT_STATUS_NOT_IMPLEMENTED;
168 static struct auth_operations fixed_challenge_auth_ops = {
169 .name = "fixed_challenge",
170 .get_challenge = fixed_challenge_get_challenge,
171 .check_password = fixed_challenge_check_password
174 NTSTATUS auth_developer_init(void)
178 ret = auth_register(&name_to_ntstatus_auth_ops);
179 if (!NT_STATUS_IS_OK(ret)) {
180 DEBUG(0,("Failed to register 'name_to_ntstatus' auth backend!\n"));
184 ret = auth_register(&fixed_challenge_auth_ops);
185 if (!NT_STATUS_IS_OK(ret)) {
186 DEBUG(0,("Failed to register 'fixed_challenge' auth backend!\n"));