2 Unix SMB/CIFS implementation.
3 Generic authentication types
4 Copyright (C) Andrew Bartlett 2001-2002
5 Copyright (C) Jelmer Vernooij 2002
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "auth/auth.h"
24 #include "librpc/gen_ndr/ndr_samr.h"
25 #include "librpc/gen_ndr/ndr_security.h"
28 #define DBGC_CLASS DBGC_AUTH
30 /***************************************************************************
31 Make (and fill) a user_info struct for a anonymous login.
32 ***************************************************************************/
33 static NTSTATUS make_server_info_anonymous(TALLOC_CTX *mem_ctx, struct auth_serversupplied_info **server_info)
35 *server_info = talloc_p(mem_ctx, struct auth_serversupplied_info);
37 return NT_STATUS_NO_MEMORY;
40 (*server_info)->guest = True;
42 (*server_info)->user_sid = dom_sid_parse_talloc((*server_info), SID_NT_ANONYMOUS);
44 /* is this correct? */
45 (*server_info)->primary_group_sid = dom_sid_parse_talloc((*server_info), SID_BUILTIN_GUESTS);
47 (*server_info)->n_domain_groups = 0;
48 (*server_info)->domain_groups = NULL;
50 /* annoying, but the Guest really does have a session key,
51 and it is all zeros! */
52 (*server_info)->user_session_key = data_blob_talloc(*server_info, NULL, 16);
53 (*server_info)->lm_session_key = data_blob_talloc(*server_info, NULL, 16);
55 data_blob_clear(&(*server_info)->user_session_key);
56 data_blob_clear(&(*server_info)->lm_session_key);
58 (*server_info)->account_name = talloc_strdup((*server_info), "ANONYMOUS LOGON");
59 (*server_info)->domain = talloc_strdup((*server_info), "NT AUTHORITY");
60 (*server_info)->full_name = talloc_strdup((*server_info), "Anonymous Logon");
61 (*server_info)->logon_script = talloc_strdup((*server_info), "");
62 (*server_info)->profile_path = talloc_strdup((*server_info), "");
63 (*server_info)->home_directory = talloc_strdup((*server_info), "");
64 (*server_info)->home_drive = talloc_strdup((*server_info), "");
66 (*server_info)->last_logon = 0;
67 (*server_info)->last_logoff = 0;
68 (*server_info)->acct_expiry = 0;
69 (*server_info)->last_password_change = 0;
70 (*server_info)->allow_password_change = 0;
71 (*server_info)->force_password_change = 0;
73 (*server_info)->logon_count = 0;
74 (*server_info)->bad_password_count = 0;
76 (*server_info)->acct_flags = ACB_NORMAL;
82 * Return a anonymous logon for anonymous users (username = "")
84 * Typically used as the first module in the auth chain, this allows
85 * guest logons to be dealt with in one place. Non-guest logons 'fail'
86 * and pass onto the next module.
89 static NTSTATUS check_anonymous_security(const struct auth_context *auth_context,
90 void *my_private_data,
92 const struct auth_usersupplied_info *user_info,
93 struct auth_serversupplied_info **server_info)
95 /* mark this as 'not for me' */
96 NTSTATUS nt_status = NT_STATUS_NOT_IMPLEMENTED;
98 if (!(user_info->internal_username.str
99 && *user_info->internal_username.str)) {
100 nt_status = make_server_info_anonymous(discard_const(auth_context),
107 /* Guest modules initialisation */
109 static NTSTATUS auth_init_anonymous(struct auth_context *auth_context,
111 struct auth_methods **auth_method)
113 if (!make_auth_methods(auth_context, auth_method))
114 return NT_STATUS_NO_MEMORY;
116 (*auth_method)->auth = check_anonymous_security;
117 (*auth_method)->name = "anonymous";
123 * Return an error based on username
125 * This function allows the testing of obsure errors, as well as the generation
126 * of NT_STATUS -> DOS error mapping tables.
128 * This module is of no value to end-users.
130 * The password is ignored.
132 * @return An NTSTATUS value based on the username
135 static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_context,
136 void *my_private_data,
138 const struct auth_usersupplied_info *user_info,
139 struct auth_serversupplied_info **server_info)
144 fstrcpy(user, user_info->smb_name.str);
146 if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
147 return nt_status_string_to_code(user);
150 error_num = strtoul(user, NULL, 16);
152 DEBUG(5,("check_name_to_ntstatus_security: Error for user %s was 0x%lx\n", user, error_num));
154 nt_status = NT_STATUS(error_num);
159 /** Module initialisation function */
161 static NTSTATUS auth_init_name_to_ntstatus(struct auth_context *auth_context,
163 struct auth_methods **auth_method)
165 if (!make_auth_methods(auth_context, auth_method))
166 return NT_STATUS_NO_MEMORY;
168 (*auth_method)->auth = check_name_to_ntstatus_security;
169 (*auth_method)->name = "name_to_ntstatus";
174 * Return a 'fixed' challenge instead of a variable one.
176 * The idea of this function is to make packet snifs consistant
177 * with a fixed challenge, so as to aid debugging.
179 * This module is of no value to end-users.
181 * This module does not actually authenticate the user, but
182 * just pretenteds to need a specified challenge.
183 * This module removes *all* security from the challenge-response system
185 * @return NT_STATUS_UNSUCCESSFUL
188 static NTSTATUS check_fixed_challenge_security(const struct auth_context *auth_context,
189 void *my_private_data,
191 const struct auth_usersupplied_info *user_info,
192 struct auth_serversupplied_info **server_info)
194 return NT_STATUS_NOT_IMPLEMENTED;
197 /****************************************************************************
198 Get the challenge out of a password server.
199 ****************************************************************************/
201 static DATA_BLOB auth_get_fixed_challenge(const struct auth_context *auth_context,
202 void **my_private_data,
205 const char *challenge = "I am a teapot";
206 return data_blob(challenge, 8);
210 /** Module initailisation function */
212 static NTSTATUS auth_init_fixed_challenge(struct auth_context *auth_context,
214 struct auth_methods **auth_method)
216 if (!make_auth_methods(auth_context, auth_method))
217 return NT_STATUS_NO_MEMORY;
219 (*auth_method)->auth = check_fixed_challenge_security;
220 (*auth_method)->get_chal = auth_get_fixed_challenge;
221 (*auth_method)->name = "fixed_challenge";
224 #endif /* DEVELOPER */
226 NTSTATUS auth_builtin_init(void)
229 struct auth_operations ops;
231 ops.name = "anonymous";
232 ops.init = auth_init_anonymous;
233 ret = auth_register(&ops);
234 if (!NT_STATUS_IS_OK(ret)) {
235 DEBUG(0,("Failed to register '%s' auth backend!\n",
241 ops.name = "name_to_ntstatus";
242 ops.init = auth_init_name_to_ntstatus;
243 ret = auth_register(&ops);
244 if (!NT_STATUS_IS_OK(ret)) {
245 DEBUG(0,("Failed to register '%s' auth backend!\n",
250 ops.name = "fixed_challenge";
251 ops.init = auth_init_fixed_challenge;
252 ret = auth_register(&ops);
253 if (!NT_STATUS_IS_OK(ret)) {
254 DEBUG(0,("Failed to register '%s' auth backend!\n",
258 #endif /* DEVELOPER */