sync'ing up for 3.0alpha20 release
[Samba/gbeck.git] / source3 / auth / auth_builtin.c
blobd54a8660b35d5e827f33bc62b0987b767ca95134
1 /*
2 Unix SMB/CIFS implementation.
3 Generic authenticaion 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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_AUTH
27 /**
28 * Return a guest logon for guest users (username = "")
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 **/
35 static NTSTATUS check_guest_security(const struct auth_context *auth_context,
36 void *my_private_data,
37 TALLOC_CTX *mem_ctx,
38 const auth_usersupplied_info *user_info,
39 auth_serversupplied_info **server_info)
41 NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
43 if (!(user_info->internal_username.str
44 && *user_info->internal_username.str))
45 nt_status = make_server_info_guest(server_info);
47 return nt_status;
50 /* Guest modules initialisation */
51 NTSTATUS auth_init_guest(struct auth_context *auth_context, const char *options, auth_methods **auth_method)
53 if (!make_auth_methods(auth_context, auth_method)) {
54 return NT_STATUS_NO_MEMORY;
57 (*auth_method)->auth = check_guest_security;
58 (*auth_method)->name = "guest";
59 return NT_STATUS_OK;
62 /**
63 * Return an error based on username
65 * This function allows the testing of obsure errors, as well as the generation
66 * of NT_STATUS -> DOS error mapping tables.
68 * This module is of no value to end-users.
70 * The password is ignored.
72 * @return An NTSTATUS value based on the username
73 **/
75 static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_context,
76 void *my_private_data,
77 TALLOC_CTX *mem_ctx,
78 const auth_usersupplied_info *user_info,
79 auth_serversupplied_info **server_info)
81 NTSTATUS nt_status;
82 fstring user;
83 long error_num;
84 fstrcpy(user, user_info->smb_name.str);
86 if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
87 strupper(user);
88 return nt_status_string_to_code(user);
91 strlower(user);
92 error_num = strtoul(user, NULL, 16);
94 DEBUG(5,("Error for user %s was %lx\n", user, error_num));
96 nt_status = NT_STATUS(error_num);
98 return nt_status;
101 /** Module initailisation function */
102 NTSTATUS auth_init_name_to_ntstatus(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
104 if (!make_auth_methods(auth_context, auth_method)) {
105 return NT_STATUS_NO_MEMORY;
108 (*auth_method)->auth = check_name_to_ntstatus_security;
109 (*auth_method)->name = "name_to_ntstatus";
110 return NT_STATUS_OK;
113 /**
114 * Return a 'fixed' challenge instead of a varaible one.
116 * The idea of this function is to make packet snifs consistant
117 * with a fixed challenge, so as to aid debugging.
119 * This module is of no value to end-users.
121 * This module does not actually authenticate the user, but
122 * just pretenteds to need a specified challenge.
123 * This module removes *all* security from the challenge-response system
125 * @return NT_STATUS_UNSUCCESSFUL
128 static NTSTATUS check_fixed_challenge_security(const struct auth_context *auth_context,
129 void *my_private_data,
130 TALLOC_CTX *mem_ctx,
131 const auth_usersupplied_info *user_info,
132 auth_serversupplied_info **server_info)
134 return NT_STATUS_UNSUCCESSFUL;
137 /****************************************************************************
138 Get the challenge out of a password server.
139 ****************************************************************************/
141 static DATA_BLOB auth_get_fixed_challenge(const struct auth_context *auth_context,
142 void **my_private_data,
143 TALLOC_CTX *mem_ctx)
145 const char *challenge = "I am a teapot";
146 return data_blob(challenge, 8);
150 /** Module initailisation function */
151 NTSTATUS auth_init_fixed_challenge(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
153 if (!make_auth_methods(auth_context, auth_method)) {
154 return NT_STATUS_NO_MEMORY;
157 (*auth_method)->auth = check_fixed_challenge_security;
158 (*auth_method)->get_chal = auth_get_fixed_challenge;
159 (*auth_method)->name = "fixed_challenge";
160 return NT_STATUS_OK;
164 * Outsorce an auth module to an external loadable .so
166 * Only works on systems with dlopen() etc.
169 /* Plugin modules initialisation */
170 NTSTATUS auth_init_plugin(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
172 void * dl_handle;
173 char *plugin_param, *plugin_name, *p;
174 auth_init_function plugin_init;
176 if (param == NULL) {
177 DEBUG(0, ("The plugin module needs an argument!\n"));
178 return NT_STATUS_UNSUCCESSFUL;
181 plugin_name = smb_xstrdup(param);
182 p = strchr(plugin_name, ':');
183 if (p) {
184 *p = 0;
185 plugin_param = p+1;
186 trim_string(plugin_param, " ", " ");
187 } else plugin_param = NULL;
189 trim_string(plugin_name, " ", " ");
191 DEBUG(5, ("Trying to load auth plugin %s\n", plugin_name));
192 dl_handle = sys_dlopen(plugin_name, RTLD_NOW );
193 if (!dl_handle) {
194 DEBUG(0, ("Failed to load auth plugin %s using sys_dlopen (%s)\n", plugin_name, sys_dlerror()));
195 return NT_STATUS_UNSUCCESSFUL;
198 plugin_init = sys_dlsym(dl_handle, "auth_init");
199 if (!plugin_init){
200 DEBUG(0, ("Failed to find function 'pdb_init' using sys_dlsym in sam plugin %s (%s)\n", plugin_name, sys_dlerror()));
201 return NT_STATUS_UNSUCCESSFUL;
204 DEBUG(5, ("Starting sam plugin %s with paramater %s\n", plugin_name, plugin_param?plugin_param:"(null)"));
205 return plugin_init(auth_context, plugin_param, auth_method);