wafsamba: try to fix the build on AIX with xlc_r
[Samba/gebeck_regimport.git] / source4 / auth / ntlm / auth_developer.c
blobbc27f27fa284bd4e7439785110d5d1be31876c6a
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 "auth/auth.h"
24 #include "auth/ntlm/auth_proto.h"
25 #include "libcli/security/security.h"
27 _PUBLIC_ NTSTATUS auth4_developer_init(void);
29 static NTSTATUS name_to_ntstatus_want_check(struct auth_method_context *ctx,
30 TALLOC_CTX *mem_ctx,
31 const struct auth_usersupplied_info *user_info)
33 return NT_STATUS_OK;
36 /**
37 * Return an error based on username
39 * This function allows the testing of obsure errors, as well as the generation
40 * of NT_STATUS -> DOS error mapping tables.
42 * This module is of no value to end-users.
44 * The password is ignored.
46 * @return An NTSTATUS value based on the username
47 **/
49 static NTSTATUS name_to_ntstatus_check_password(struct auth_method_context *ctx,
50 TALLOC_CTX *mem_ctx,
51 const struct auth_usersupplied_info *user_info,
52 struct auth_user_info_dc **_user_info_dc)
54 NTSTATUS nt_status;
55 struct auth_user_info_dc *user_info_dc;
56 struct auth_user_info *info;
57 uint32_t error_num;
58 const char *user;
60 user = user_info->client.account_name;
62 if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
63 nt_status = nt_status_string_to_code(user);
64 } else {
65 error_num = strtoul(user, NULL, 16);
66 DEBUG(5,("name_to_ntstatus_check_password: Error for user %s was 0x%08X\n", user, error_num));
67 nt_status = NT_STATUS(error_num);
69 NT_STATUS_NOT_OK_RETURN(nt_status);
71 user_info_dc = talloc(mem_ctx, struct auth_user_info_dc);
72 NT_STATUS_HAVE_NO_MEMORY(user_info_dc);
74 /* This returns a pointer to a struct dom_sid, which is the
75 * same as a 1 element list of struct dom_sid */
76 user_info_dc->num_sids = 1;
77 user_info_dc->sids = dom_sid_parse_talloc(user_info_dc, SID_NT_ANONYMOUS);
78 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->sids);
80 /* annoying, but the Anonymous really does have a session key,
81 and it is all zeros! */
82 user_info_dc->user_session_key = data_blob_talloc(user_info_dc, NULL, 16);
83 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->user_session_key.data);
85 user_info_dc->lm_session_key = data_blob_talloc(user_info_dc, NULL, 16);
86 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->lm_session_key.data);
88 data_blob_clear(&user_info_dc->user_session_key);
89 data_blob_clear(&user_info_dc->lm_session_key);
91 user_info_dc->info = info = talloc_zero(user_info_dc, struct auth_user_info);
92 NT_STATUS_HAVE_NO_MEMORY(user_info_dc->info);
94 info->account_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s ANONYMOUS LOGON", user);
95 NT_STATUS_HAVE_NO_MEMORY(info->account_name);
97 info->domain_name = talloc_strdup(user_info_dc, "NT AUTHORITY");
98 NT_STATUS_HAVE_NO_MEMORY(info->domain_name);
100 info->full_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s Anonymous Logon", user);
101 NT_STATUS_HAVE_NO_MEMORY(info->full_name);
103 info->logon_script = talloc_strdup(user_info_dc, "");
104 NT_STATUS_HAVE_NO_MEMORY(info->logon_script);
106 info->profile_path = talloc_strdup(user_info_dc, "");
107 NT_STATUS_HAVE_NO_MEMORY(info->profile_path);
109 info->home_directory = talloc_strdup(user_info_dc, "");
110 NT_STATUS_HAVE_NO_MEMORY(info->home_directory);
112 info->home_drive = talloc_strdup(user_info_dc, "");
113 NT_STATUS_HAVE_NO_MEMORY(info->home_drive);
115 info->last_logon = 0;
116 info->last_logoff = 0;
117 info->acct_expiry = 0;
118 info->last_password_change = 0;
119 info->allow_password_change = 0;
120 info->force_password_change = 0;
122 info->logon_count = 0;
123 info->bad_password_count = 0;
125 info->acct_flags = ACB_NORMAL;
127 info->authenticated = true;
129 *_user_info_dc = user_info_dc;
131 return nt_status;
134 static const struct auth_operations name_to_ntstatus_auth_ops = {
135 .name = "name_to_ntstatus",
136 .get_challenge = auth_get_challenge_not_implemented,
137 .want_check = name_to_ntstatus_want_check,
138 .check_password = name_to_ntstatus_check_password
141 /**
142 * Return a 'fixed' challenge instead of a variable one.
144 * The idea of this function is to make packet snifs consistant
145 * with a fixed challenge, so as to aid debugging.
147 * This module is of no value to end-users.
149 * This module does not actually authenticate the user, but
150 * just pretenteds to need a specified challenge.
151 * This module removes *all* security from the challenge-response system
153 * @return NT_STATUS_UNSUCCESSFUL
155 static NTSTATUS fixed_challenge_get_challenge(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, uint8_t chal[8])
157 const char *challenge = "I am a teapot";
159 memcpy(chal, challenge, 8);
161 return NT_STATUS_OK;
164 static NTSTATUS fixed_challenge_want_check(struct auth_method_context *ctx,
165 TALLOC_CTX *mem_ctx,
166 const struct auth_usersupplied_info *user_info)
168 /* don't handle any users */
169 return NT_STATUS_NOT_IMPLEMENTED;
172 static NTSTATUS fixed_challenge_check_password(struct auth_method_context *ctx,
173 TALLOC_CTX *mem_ctx,
174 const struct auth_usersupplied_info *user_info,
175 struct auth_user_info_dc **_user_info_dc)
177 /* don't handle any users */
178 return NT_STATUS_NO_SUCH_USER;
181 static const struct auth_operations fixed_challenge_auth_ops = {
182 .name = "fixed_challenge",
183 .get_challenge = fixed_challenge_get_challenge,
184 .want_check = fixed_challenge_want_check,
185 .check_password = fixed_challenge_check_password
188 _PUBLIC_ NTSTATUS auth4_developer_init(void)
190 NTSTATUS ret;
192 ret = auth_register(&name_to_ntstatus_auth_ops);
193 if (!NT_STATUS_IS_OK(ret)) {
194 DEBUG(0,("Failed to register 'name_to_ntstatus' auth backend!\n"));
195 return ret;
198 ret = auth_register(&fixed_challenge_auth_ops);
199 if (!NT_STATUS_IS_OK(ret)) {
200 DEBUG(0,("Failed to register 'fixed_challenge' auth backend!\n"));
201 return ret;
204 return ret;