r23792: convert Samba4 to GPLv3
[bbaumbach/samba-autobuild/.git] / source4 / auth / auth_developer.c
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 "libcli/security/security.h"
25 #include "librpc/gen_ndr/ndr_samr.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_serversupplied_info **_server_info)
51 {
52         NTSTATUS nt_status;
53         struct auth_serversupplied_info *server_info;
54         uint32_t error_num;
55         const char *user;
56
57         user = user_info->client.account_name;
58
59         if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
60                 nt_status = nt_status_string_to_code(user);
61         } else {
62                 error_num = strtoul(user, NULL, 16);
63                 DEBUG(5,("name_to_ntstatus_check_password: Error for user %s was 0x%08X\n", user, error_num));
64                 nt_status = NT_STATUS(error_num);
65         }
66         NT_STATUS_NOT_OK_RETURN(nt_status);
67
68         server_info = talloc(mem_ctx, struct auth_serversupplied_info);
69         NT_STATUS_HAVE_NO_MEMORY(server_info);
70
71         server_info->account_sid = dom_sid_parse_talloc(server_info, SID_NT_ANONYMOUS);
72         NT_STATUS_HAVE_NO_MEMORY(server_info->account_sid);
73
74         /* is this correct? */
75         server_info->primary_group_sid = dom_sid_parse_talloc(server_info, SID_BUILTIN_GUESTS);
76         NT_STATUS_HAVE_NO_MEMORY(server_info->primary_group_sid);
77
78         server_info->n_domain_groups = 0;
79         server_info->domain_groups = NULL;
80
81         /* annoying, but the Anonymous really does have a session key, 
82            and it is all zeros! */
83         server_info->user_session_key = data_blob_talloc(server_info, NULL, 16);
84         NT_STATUS_HAVE_NO_MEMORY(server_info->user_session_key.data);
85
86         server_info->lm_session_key = data_blob_talloc(server_info, NULL, 16);
87         NT_STATUS_HAVE_NO_MEMORY(server_info->lm_session_key.data);
88
89         data_blob_clear(&server_info->user_session_key);
90         data_blob_clear(&server_info->lm_session_key);
91
92         server_info->account_name = talloc_asprintf(server_info, "NAME TO NTSTATUS %s ANONYMOUS LOGON", user);
93         NT_STATUS_HAVE_NO_MEMORY(server_info->account_name);
94
95         server_info->domain_name = talloc_strdup(server_info, "NT AUTHORITY");
96         NT_STATUS_HAVE_NO_MEMORY(server_info->domain_name);
97
98         server_info->full_name = talloc_asprintf(server_info, "NAME TO NTSTATUS %s Anonymous Logon", user);
99         NT_STATUS_HAVE_NO_MEMORY(server_info->full_name);
100
101         server_info->logon_script = talloc_strdup(server_info, "");
102         NT_STATUS_HAVE_NO_MEMORY(server_info->logon_script);
103
104         server_info->profile_path = talloc_strdup(server_info, "");
105         NT_STATUS_HAVE_NO_MEMORY(server_info->profile_path);
106
107         server_info->home_directory = talloc_strdup(server_info, "");
108         NT_STATUS_HAVE_NO_MEMORY(server_info->home_directory);
109
110         server_info->home_drive = talloc_strdup(server_info, "");
111         NT_STATUS_HAVE_NO_MEMORY(server_info->home_drive);
112
113         server_info->last_logon = 0;
114         server_info->last_logoff = 0;
115         server_info->acct_expiry = 0;
116         server_info->last_password_change = 0;
117         server_info->allow_password_change = 0;
118         server_info->force_password_change = 0;
119
120         server_info->logon_count = 0;
121         server_info->bad_password_count = 0;
122
123         server_info->acct_flags = ACB_NORMAL;
124
125         server_info->authenticated = False;
126
127         *_server_info = server_info;
128
129         return nt_status;
130 }
131
132 static 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, DATA_BLOB *_blob)
154 {
155         DATA_BLOB blob;
156         const char *challenge = "I am a teapot";
157
158         blob = data_blob_talloc(mem_ctx, challenge, 8);
159         NT_STATUS_HAVE_NO_MEMORY(blob.data);
160
161         *_blob = blob;
162         return NT_STATUS_OK;
163 }
164
165 static NTSTATUS fixed_challenge_want_check(struct auth_method_context *ctx,
166                                            TALLOC_CTX *mem_ctx,
167                                            const struct auth_usersupplied_info *user_info)
168 {
169         /* don't handle any users */
170         return NT_STATUS_NOT_IMPLEMENTED;
171 }
172
173 static NTSTATUS fixed_challenge_check_password(struct auth_method_context *ctx,
174                                                TALLOC_CTX *mem_ctx,
175                                                const struct auth_usersupplied_info *user_info,
176                                                struct auth_serversupplied_info **_server_info)
177 {
178         /* don't handle any users */
179         return NT_STATUS_NO_SUCH_USER;
180 }
181
182 static struct auth_operations fixed_challenge_auth_ops = {
183         .name           = "fixed_challenge",
184         .get_challenge  = fixed_challenge_get_challenge,
185         .want_check     = fixed_challenge_want_check,
186         .check_password = fixed_challenge_check_password
187 };
188
189 NTSTATUS auth_developer_init(void)
190 {
191         NTSTATUS ret;
192
193         ret = auth_register(&name_to_ntstatus_auth_ops);
194         if (!NT_STATUS_IS_OK(ret)) {
195                 DEBUG(0,("Failed to register 'name_to_ntstatus' auth backend!\n"));
196                 return ret;
197         }
198
199         ret = auth_register(&fixed_challenge_auth_ops);
200         if (!NT_STATUS_IS_OK(ret)) {
201                 DEBUG(0,("Failed to register 'fixed_challenge' auth backend!\n"));
202                 return ret;
203         }
204
205         return ret;
206 }