s3-rpc_client: move protos to cli_lsarpc.h
[Samba/ekacnet.git] / source3 / auth / auth_builtin.c
blobe2ad84834da6887fd78779e135d04cf6d4da6d1b
1 /*
2 Unix SMB/CIFS implementation.
3 Generic authentication types
4 Copyright (C) Andrew Bartlett 2001-2002
5 Copyright (C) Jelmer Vernooij 2002
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.
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.
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/>.
21 #include "includes.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_AUTH
26 /**
27 * Return a guest logon for guest users (username = "")
29 * Typically used as the first module in the auth chain, this allows
30 * guest logons to be dealt with in one place. Non-guest logons 'fail'
31 * and pass onto the next module.
32 **/
34 static NTSTATUS check_guest_security(const struct auth_context *auth_context,
35 void *my_private_data,
36 TALLOC_CTX *mem_ctx,
37 const struct auth_usersupplied_info *user_info,
38 struct auth_serversupplied_info **server_info)
40 /* mark this as 'not for me' */
41 NTSTATUS nt_status = NT_STATUS_NOT_IMPLEMENTED;
43 if (!(user_info->internal_username
44 && *user_info->internal_username)) {
45 nt_status = make_server_info_guest(NULL, server_info);
48 return nt_status;
51 /* Guest modules initialisation */
53 static NTSTATUS auth_init_guest(struct auth_context *auth_context, const char *options, auth_methods **auth_method)
55 struct auth_methods *result;
57 result = TALLOC_ZERO_P(auth_context, struct auth_methods);
58 if (result == NULL) {
59 return NT_STATUS_NO_MEMORY;
61 result->auth = check_guest_security;
62 result->name = "guest";
64 *auth_method = result;
65 return NT_STATUS_OK;
68 #ifdef DEVELOPER
69 /**
70 * Return an error based on username
72 * This function allows the testing of obsure errors, as well as the generation
73 * of NT_STATUS -> DOS error mapping tables.
75 * This module is of no value to end-users.
77 * The password is ignored.
79 * @return An NTSTATUS value based on the username
80 **/
82 static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_context,
83 void *my_private_data,
84 TALLOC_CTX *mem_ctx,
85 const struct auth_usersupplied_info *user_info,
86 struct auth_serversupplied_info **server_info)
88 NTSTATUS nt_status;
89 fstring user;
90 long error_num;
91 fstrcpy(user, user_info->smb_name);
93 if (strnequal("NT_STATUS", user, strlen("NT_STATUS"))) {
94 strupper_m(user);
95 return nt_status_string_to_code(user);
98 strlower_m(user);
99 error_num = strtoul(user, NULL, 16);
101 DEBUG(5,("check_name_to_ntstatus_security: Error for user %s was %lx\n", user, error_num));
103 nt_status = NT_STATUS(error_num);
105 return nt_status;
108 /** Module initialisation function */
110 static NTSTATUS auth_init_name_to_ntstatus(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
112 struct auth_methods *result;
114 result = TALLOC_ZERO_P(auth_context, struct auth_methods);
115 if (result == NULL) {
116 return NT_STATUS_NO_MEMORY;
118 result->auth = check_name_to_ntstatus_security;
119 result->name = "name_to_ntstatus";
121 *auth_method = result;
122 return NT_STATUS_OK;
125 /**
126 * Return a 'fixed' challenge instead of a variable one.
128 * The idea of this function is to make packet snifs consistant
129 * with a fixed challenge, so as to aid debugging.
131 * This module is of no value to end-users.
133 * This module does not actually authenticate the user, but
134 * just pretenteds to need a specified challenge.
135 * This module removes *all* security from the challenge-response system
137 * @return NT_STATUS_UNSUCCESSFUL
140 static NTSTATUS check_fixed_challenge_security(const struct auth_context *auth_context,
141 void *my_private_data,
142 TALLOC_CTX *mem_ctx,
143 const struct auth_usersupplied_info *user_info,
144 struct auth_serversupplied_info **server_info)
146 return NT_STATUS_NOT_IMPLEMENTED;
149 /****************************************************************************
150 Get the challenge out of a password server.
151 ****************************************************************************/
153 static DATA_BLOB auth_get_fixed_challenge(const struct auth_context *auth_context,
154 void **my_private_data,
155 TALLOC_CTX *mem_ctx)
157 const char *challenge = "I am a teapot";
158 return data_blob(challenge, 8);
162 /** Module initialisation function */
164 static NTSTATUS auth_init_fixed_challenge(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
166 struct auth_methods *result;
168 result = TALLOC_ZERO_P(auth_context, struct auth_methods);
169 if (result == NULL) {
170 return NT_STATUS_NO_MEMORY;
172 result->auth = check_fixed_challenge_security;
173 result->get_chal = auth_get_fixed_challenge;
174 result->name = "fixed_challenge";
176 *auth_method = result;
177 return NT_STATUS_OK;
179 #endif /* DEVELOPER */
181 NTSTATUS auth_builtin_init(void)
183 smb_register_auth(AUTH_INTERFACE_VERSION, "guest", auth_init_guest);
184 #ifdef DEVELOPER
185 smb_register_auth(AUTH_INTERFACE_VERSION, "fixed_challenge", auth_init_fixed_challenge);
186 smb_register_auth(AUTH_INTERFACE_VERSION, "name_to_ntstatus", auth_init_name_to_ntstatus);
187 #endif
188 return NT_STATUS_OK;