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