source: vendor/3.6.0/source3/auth/auth_builtin.c

Last change on this file was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

File size: 5.8 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 Generic authentication types
4 Copyright (C) Andrew Bartlett 2001-2002
5 Copyright (C) Jelmer Vernooij 2002
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include "includes.h"
22#include "auth.h"
23
24#undef DBGC_CLASS
25#define DBGC_CLASS DBGC_AUTH
26
27/**
28 * Return a guest logon for guest users (username = "")
29 *
30 * Typically used as the first module in the auth chain, this allows
31 * guest logons to be dealt with in one place. Non-guest logons 'fail'
32 * and pass onto the next module.
33 **/
34
35static NTSTATUS check_guest_security(const struct auth_context *auth_context,
36 void *my_private_data,
37 TALLOC_CTX *mem_ctx,
38 const struct auth_usersupplied_info *user_info,
39 struct auth_serversupplied_info **server_info)
40{
41 /* mark this as 'not for me' */
42 NTSTATUS nt_status = NT_STATUS_NOT_IMPLEMENTED;
43
44 DEBUG(10, ("Check auth for: [%s]\n", user_info->mapped.account_name));
45
46 if (!(user_info->mapped.account_name
47 && *user_info->mapped.account_name)) {
48 nt_status = make_server_info_guest(NULL, server_info);
49 }
50
51 return nt_status;
52}
53
54/* Guest modules initialisation */
55
56static NTSTATUS auth_init_guest(struct auth_context *auth_context, const char *options, auth_methods **auth_method)
57{
58 struct auth_methods *result;
59
60 result = TALLOC_ZERO_P(auth_context, struct auth_methods);
61 if (result == NULL) {
62 return NT_STATUS_NO_MEMORY;
63 }
64 result->auth = check_guest_security;
65 result->name = "guest";
66
67 *auth_method = result;
68 return NT_STATUS_OK;
69}
70
71#ifdef DEVELOPER
72/**
73 * Return an error based on username
74 *
75 * This function allows the testing of obsure errors, as well as the generation
76 * of NT_STATUS -> DOS error mapping tables.
77 *
78 * This module is of no value to end-users.
79 *
80 * The password is ignored.
81 *
82 * @return An NTSTATUS value based on the username
83 **/
84
85static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_context,
86 void *my_private_data,
87 TALLOC_CTX *mem_ctx,
88 const struct auth_usersupplied_info *user_info,
89 struct auth_serversupplied_info **server_info)
90{
91 NTSTATUS nt_status;
92 fstring user;
93 long error_num;
94
95 DEBUG(10, ("Check auth for: [%s]\n", user_info->mapped.account_name));
96
97 fstrcpy(user, user_info->client.account_name);
98
99 if (strnequal("NT_STATUS", user, strlen("NT_STATUS"))) {
100 strupper_m(user);
101 return nt_status_string_to_code(user);
102 }
103
104 strlower_m(user);
105 error_num = strtoul(user, NULL, 16);
106
107 DEBUG(5,("check_name_to_ntstatus_security: Error for user %s was %lx\n", user, error_num));
108
109 nt_status = NT_STATUS(error_num);
110
111 return nt_status;
112}
113
114/** Module initialisation function */
115
116static NTSTATUS auth_init_name_to_ntstatus(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
117{
118 struct auth_methods *result;
119
120 result = TALLOC_ZERO_P(auth_context, struct auth_methods);
121 if (result == NULL) {
122 return NT_STATUS_NO_MEMORY;
123 }
124 result->auth = check_name_to_ntstatus_security;
125 result->name = "name_to_ntstatus";
126
127 *auth_method = result;
128 return NT_STATUS_OK;
129}
130
131/**
132 * Return a 'fixed' challenge instead of a variable one.
133 *
134 * The idea of this function is to make packet snifs consistant
135 * with a fixed challenge, so as to aid debugging.
136 *
137 * This module is of no value to end-users.
138 *
139 * This module does not actually authenticate the user, but
140 * just pretenteds to need a specified challenge.
141 * This module removes *all* security from the challenge-response system
142 *
143 * @return NT_STATUS_UNSUCCESSFUL
144 **/
145
146static NTSTATUS check_fixed_challenge_security(const struct auth_context *auth_context,
147 void *my_private_data,
148 TALLOC_CTX *mem_ctx,
149 const struct auth_usersupplied_info *user_info,
150 struct auth_serversupplied_info **server_info)
151{
152 return NT_STATUS_NOT_IMPLEMENTED;
153}
154
155/****************************************************************************
156 Get the challenge out of a password server.
157****************************************************************************/
158
159static DATA_BLOB auth_get_fixed_challenge(const struct auth_context *auth_context,
160 void **my_private_data,
161 TALLOC_CTX *mem_ctx)
162{
163 const char *challenge = "I am a teapot";
164 return data_blob(challenge, 8);
165}
166
167
168/** Module initialisation function */
169
170static NTSTATUS auth_init_fixed_challenge(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
171{
172 struct auth_methods *result;
173
174 result = TALLOC_ZERO_P(auth_context, struct auth_methods);
175 if (result == NULL) {
176 return NT_STATUS_NO_MEMORY;
177 }
178 result->auth = check_fixed_challenge_security;
179 result->get_chal = auth_get_fixed_challenge;
180 result->name = "fixed_challenge";
181
182 *auth_method = result;
183 return NT_STATUS_OK;
184}
185#endif /* DEVELOPER */
186
187NTSTATUS auth_builtin_init(void)
188{
189 smb_register_auth(AUTH_INTERFACE_VERSION, "guest", auth_init_guest);
190#ifdef DEVELOPER
191 smb_register_auth(AUTH_INTERFACE_VERSION, "fixed_challenge", auth_init_fixed_challenge);
192 smb_register_auth(AUTH_INTERFACE_VERSION, "name_to_ntstatus", auth_init_name_to_ntstatus);
193#endif
194 return NT_STATUS_OK;
195}
Note: See TracBrowser for help on using the repository browser.