libndr: Avoid assigning duplicate versions to symbols
[amitay/samba.git] / source4 / auth / ntlm / 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 "auth/ntlm/auth_proto.h"
25 #include "libcli/security/security.h"
26
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_AUTH
29
30 #undef strncasecmp
31
32 _PUBLIC_ NTSTATUS auth4_developer_init(TALLOC_CTX *);
33
34 static NTSTATUS name_to_ntstatus_want_check(struct auth_method_context *ctx,
35                                             TALLOC_CTX *mem_ctx,
36                                             const struct auth_usersupplied_info *user_info)
37 {
38         return NT_STATUS_OK;
39 }
40
41 /** 
42  * Return an error based on username
43  *
44  * This function allows the testing of obsure errors, as well as the generation
45  * of NT_STATUS -> DOS error mapping tables.
46  *
47  * This module is of no value to end-users.
48  *
49  * The password is ignored.
50  *
51  * @return An NTSTATUS value based on the username
52  **/
53
54 static NTSTATUS name_to_ntstatus_check_password(struct auth_method_context *ctx,
55                                                 TALLOC_CTX *mem_ctx,
56                                                 const struct auth_usersupplied_info *user_info, 
57                                                 struct auth_user_info_dc **_user_info_dc,
58                                                 bool *authoritative)
59 {
60         NTSTATUS nt_status;
61         struct auth_user_info_dc *user_info_dc;
62         struct auth_user_info *info;
63         uint32_t error_num;
64         const char *user;
65
66         user = user_info->client.account_name;
67
68         if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
69                 nt_status = nt_status_string_to_code(user);
70         } else {
71                 error_num = strtoul(user, NULL, 16);
72                 DEBUG(5,("name_to_ntstatus_check_password: Error for user %s was 0x%08X\n", user, error_num));
73                 nt_status = NT_STATUS(error_num);
74         }
75         NT_STATUS_NOT_OK_RETURN(nt_status);
76
77         user_info_dc = talloc(mem_ctx, struct auth_user_info_dc);
78         NT_STATUS_HAVE_NO_MEMORY(user_info_dc);
79
80         /* This returns a pointer to a struct dom_sid, which is the
81          * same as a 1 element list of struct dom_sid */
82         user_info_dc->num_sids = 1;
83         user_info_dc->sids = dom_sid_parse_talloc(user_info_dc, SID_NT_ANONYMOUS);
84         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->sids);
85
86         /* annoying, but the Anonymous really does have a session key, 
87            and it is all zeros! */
88         user_info_dc->user_session_key = data_blob_talloc(user_info_dc, NULL, 16);
89         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->user_session_key.data);
90
91         user_info_dc->lm_session_key = data_blob_talloc(user_info_dc, NULL, 16);
92         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->lm_session_key.data);
93
94         data_blob_clear(&user_info_dc->user_session_key);
95         data_blob_clear(&user_info_dc->lm_session_key);
96
97         user_info_dc->info = info = talloc_zero(user_info_dc, struct auth_user_info);
98         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->info);
99
100         info->account_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s ANONYMOUS LOGON", user);
101         NT_STATUS_HAVE_NO_MEMORY(info->account_name);
102
103         info->domain_name = talloc_strdup(user_info_dc, "NT AUTHORITY");
104         NT_STATUS_HAVE_NO_MEMORY(info->domain_name);
105
106         info->full_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s Anonymous Logon", user);
107         NT_STATUS_HAVE_NO_MEMORY(info->full_name);
108
109         info->logon_script = talloc_strdup(user_info_dc, "");
110         NT_STATUS_HAVE_NO_MEMORY(info->logon_script);
111
112         info->profile_path = talloc_strdup(user_info_dc, "");
113         NT_STATUS_HAVE_NO_MEMORY(info->profile_path);
114
115         info->home_directory = talloc_strdup(user_info_dc, "");
116         NT_STATUS_HAVE_NO_MEMORY(info->home_directory);
117
118         info->home_drive = talloc_strdup(user_info_dc, "");
119         NT_STATUS_HAVE_NO_MEMORY(info->home_drive);
120
121         info->last_logon = 0;
122         info->last_logoff = 0;
123         info->acct_expiry = 0;
124         info->last_password_change = 0;
125         info->allow_password_change = 0;
126         info->force_password_change = 0;
127
128         info->logon_count = 0;
129         info->bad_password_count = 0;
130
131         info->acct_flags = ACB_NORMAL;
132
133         info->authenticated = true;
134
135         *_user_info_dc = user_info_dc;
136
137         return nt_status;
138 }
139
140 static const struct auth_operations name_to_ntstatus_auth_ops = {
141         .name           = "name_to_ntstatus",
142         .want_check     = name_to_ntstatus_want_check,
143         .check_password = name_to_ntstatus_check_password
144 };
145
146 _PUBLIC_ NTSTATUS auth4_developer_init(TALLOC_CTX *ctx)
147 {
148         NTSTATUS ret;
149
150         ret = auth_register(ctx, &name_to_ntstatus_auth_ops);
151         if (!NT_STATUS_IS_OK(ret)) {
152                 DEBUG(0,("Failed to register 'name_to_ntstatus' auth backend!\n"));
153                 return ret;
154         }
155
156         return ret;
157 }