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/>.
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"
30 #define DBGC_CLASS DBGC_AUTH
34 _PUBLIC_ NTSTATUS
auth4_developer_init(TALLOC_CTX
*);
36 static NTSTATUS
name_to_ntstatus_want_check(struct auth_method_context
*ctx
,
38 const struct auth_usersupplied_info
*user_info
)
44 * Return an error based on username
46 * This function allows the testing of obsure 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
56 static NTSTATUS
name_to_ntstatus_check_password(struct auth_method_context
*ctx
,
58 const struct auth_usersupplied_info
*user_info
,
59 struct auth_user_info_dc
**_user_info_dc
,
63 struct auth_user_info_dc
*user_info_dc
;
64 struct auth_user_info
*info
;
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
);
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
= dom_sid_parse_talloc(user_info_dc
, SID_NT_ANONYMOUS
);
86 NT_STATUS_HAVE_NO_MEMORY(user_info_dc
->sids
);
88 /* annoying, but the Anonymous really does have a session key,
89 and it is all zeros! */
90 user_info_dc
->user_session_key
= data_blob_talloc(user_info_dc
, NULL
, 16);
91 NT_STATUS_HAVE_NO_MEMORY(user_info_dc
->user_session_key
.data
);
93 user_info_dc
->lm_session_key
= data_blob_talloc(user_info_dc
, NULL
, 16);
94 NT_STATUS_HAVE_NO_MEMORY(user_info_dc
->lm_session_key
.data
);
96 data_blob_clear(&user_info_dc
->user_session_key
);
97 data_blob_clear(&user_info_dc
->lm_session_key
);
99 user_info_dc
->info
= info
= talloc_zero(user_info_dc
, struct auth_user_info
);
100 NT_STATUS_HAVE_NO_MEMORY(user_info_dc
->info
);
102 info
->account_name
= talloc_asprintf(user_info_dc
, "NAME TO NTSTATUS %s ANONYMOUS LOGON", user
);
103 NT_STATUS_HAVE_NO_MEMORY(info
->account_name
);
105 info
->domain_name
= talloc_strdup(user_info_dc
, "NT AUTHORITY");
106 NT_STATUS_HAVE_NO_MEMORY(info
->domain_name
);
108 info
->full_name
= talloc_asprintf(user_info_dc
, "NAME TO NTSTATUS %s Anonymous Logon", user
);
109 NT_STATUS_HAVE_NO_MEMORY(info
->full_name
);
111 info
->logon_script
= talloc_strdup(user_info_dc
, "");
112 NT_STATUS_HAVE_NO_MEMORY(info
->logon_script
);
114 info
->profile_path
= talloc_strdup(user_info_dc
, "");
115 NT_STATUS_HAVE_NO_MEMORY(info
->profile_path
);
117 info
->home_directory
= talloc_strdup(user_info_dc
, "");
118 NT_STATUS_HAVE_NO_MEMORY(info
->home_directory
);
120 info
->home_drive
= talloc_strdup(user_info_dc
, "");
121 NT_STATUS_HAVE_NO_MEMORY(info
->home_drive
);
123 info
->last_logon
= 0;
124 info
->last_logoff
= 0;
125 info
->acct_expiry
= 0;
126 info
->last_password_change
= 0;
127 info
->allow_password_change
= 0;
128 info
->force_password_change
= 0;
130 info
->logon_count
= 0;
131 info
->bad_password_count
= 0;
133 info
->acct_flags
= ACB_NORMAL
;
135 info
->authenticated
= true;
137 *_user_info_dc
= user_info_dc
;
142 struct name_to_ntstatus_check_password_state
{
143 struct auth_user_info_dc
*user_info_dc
;
147 static struct tevent_req
*name_to_ntstatus_check_password_send(
149 struct tevent_context
*ev
,
150 struct auth_method_context
*ctx
,
151 const struct auth_usersupplied_info
*user_info
)
153 struct tevent_req
*req
= NULL
;
154 struct name_to_ntstatus_check_password_state
*state
= NULL
;
157 req
= tevent_req_create(
160 struct name_to_ntstatus_check_password_state
);
165 status
= name_to_ntstatus_check_password(
169 &state
->user_info_dc
,
170 &state
->authoritative
);
171 if (tevent_req_nterror(req
, status
)) {
172 return tevent_req_post(req
, ev
);
174 tevent_req_done(req
);
175 return tevent_req_post(req
, ev
);
178 static NTSTATUS
name_to_ntstatus_check_password_recv(
179 struct tevent_req
*req
,
181 struct auth_user_info_dc
**interim_info
,
184 struct name_to_ntstatus_check_password_state
*state
= tevent_req_data(
185 req
, struct name_to_ntstatus_check_password_state
);
188 if (tevent_req_is_nterror(req
, &status
)) {
189 tevent_req_received(req
);
192 *interim_info
= talloc_move(mem_ctx
, &state
->user_info_dc
);
193 *authoritative
= state
->authoritative
;
194 tevent_req_received(req
);
198 static const struct auth_operations name_to_ntstatus_auth_ops
= {
199 .name
= "name_to_ntstatus",
200 .want_check
= name_to_ntstatus_want_check
,
201 .check_password_send
= name_to_ntstatus_check_password_send
,
202 .check_password_recv
= name_to_ntstatus_check_password_recv
,
205 _PUBLIC_ NTSTATUS
auth4_developer_init(TALLOC_CTX
*ctx
)
209 ret
= auth_register(ctx
, &name_to_ntstatus_auth_ops
);
210 if (!NT_STATUS_IS_OK(ret
)) {
211 DEBUG(0,("Failed to register 'name_to_ntstatus' auth backend!\n"));