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