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