Janitorial duties to make autogen.sh portable.
[Samba/gebeck_regimport.git] / source3 / auth / auth_builtin.c
blob3b0b84b5256711852bf97ce7f74f77d43c598ae4
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);
48 return nt_status;
51 /* Guest modules initialisation */
53 NTSTATUS auth_init_guest(struct auth_context *auth_context, const char *options, auth_methods **auth_method)
55 if (!make_auth_methods(auth_context, auth_method))
56 return NT_STATUS_NO_MEMORY;
58 (*auth_method)->auth = check_guest_security;
59 (*auth_method)->name = "guest";
60 return NT_STATUS_OK;
63 /**
64 * Return an error based on username
66 * This function allows the testing of obsure errors, as well as the generation
67 * of NT_STATUS -> DOS error mapping tables.
69 * This module is of no value to end-users.
71 * The password is ignored.
73 * @return An NTSTATUS value based on the username
74 **/
76 static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_context,
77 void *my_private_data,
78 TALLOC_CTX *mem_ctx,
79 const auth_usersupplied_info *user_info,
80 auth_serversupplied_info **server_info)
82 NTSTATUS nt_status;
83 fstring user;
84 long error_num;
85 fstrcpy(user, user_info->smb_name.str);
87 if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
88 strupper(user);
89 return nt_status_string_to_code(user);
92 strlower(user);
93 error_num = strtoul(user, NULL, 16);
95 DEBUG(5,("check_name_to_ntstatus_security: Error for user %s was %lx\n", user, error_num));
97 nt_status = NT_STATUS(error_num);
99 return nt_status;
102 /** Module initialisation function */
104 NTSTATUS auth_init_name_to_ntstatus(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
106 if (!make_auth_methods(auth_context, auth_method))
107 return NT_STATUS_NO_MEMORY;
109 (*auth_method)->auth = check_name_to_ntstatus_security;
110 (*auth_method)->name = "name_to_ntstatus";
111 return NT_STATUS_OK;
114 /**
115 * Return a 'fixed' challenge instead of a variable one.
117 * The idea of this function is to make packet snifs consistant
118 * with a fixed challenge, so as to aid debugging.
120 * This module is of no value to end-users.
122 * This module does not actually authenticate the user, but
123 * just pretenteds to need a specified challenge.
124 * This module removes *all* security from the challenge-response system
126 * @return NT_STATUS_UNSUCCESSFUL
129 static NTSTATUS check_fixed_challenge_security(const struct auth_context *auth_context,
130 void *my_private_data,
131 TALLOC_CTX *mem_ctx,
132 const auth_usersupplied_info *user_info,
133 auth_serversupplied_info **server_info)
135 return NT_STATUS_UNSUCCESSFUL;
138 /****************************************************************************
139 Get the challenge out of a password server.
140 ****************************************************************************/
142 static DATA_BLOB auth_get_fixed_challenge(const struct auth_context *auth_context,
143 void **my_private_data,
144 TALLOC_CTX *mem_ctx)
146 const char *challenge = "I am a teapot";
147 return data_blob(challenge, 8);
151 /** Module initailisation function */
153 NTSTATUS auth_init_fixed_challenge(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
155 if (!make_auth_methods(auth_context, auth_method))
156 return NT_STATUS_NO_MEMORY;
158 (*auth_method)->auth = check_fixed_challenge_security;
159 (*auth_method)->get_chal = auth_get_fixed_challenge;
160 (*auth_method)->name = "fixed_challenge";
161 return NT_STATUS_OK;
165 * Outsorce an auth module to an external loadable .so
167 * Only works on systems with dlopen() etc.
170 /* Plugin modules initialisation */
172 NTSTATUS auth_init_plugin(struct auth_context *auth_context, const char *param, auth_methods **auth_method)
174 void * dl_handle;
175 char *plugin_param, *plugin_name, *p;
176 auth_init_function plugin_init;
178 if (param == NULL) {
179 DEBUG(0, ("auth_init_plugin: The plugin module needs an argument!\n"));
180 return NT_STATUS_UNSUCCESSFUL;
183 plugin_name = smb_xstrdup(param);
184 p = strchr(plugin_name, ':');
185 if (p) {
186 *p = 0;
187 plugin_param = p+1;
188 trim_string(plugin_param, " ", " ");
189 } else plugin_param = NULL;
191 trim_string(plugin_name, " ", " ");
193 DEBUG(5, ("auth_init_plugin: Trying to load auth plugin %s\n", plugin_name));
194 dl_handle = sys_dlopen(plugin_name, RTLD_NOW );
195 if (!dl_handle) {
196 DEBUG(0, ("auth_init_plugin: Failed to load auth plugin %s using sys_dlopen (%s)\n",
197 plugin_name, sys_dlerror()));
198 return NT_STATUS_UNSUCCESSFUL;
201 plugin_init = sys_dlsym(dl_handle, "auth_init");
202 if (!plugin_init){
203 DEBUG(0, ("Failed to find function 'auth_init' using sys_dlsym in sam plugin %s (%s)\n",
204 plugin_name, sys_dlerror()));
205 return NT_STATUS_UNSUCCESSFUL;
208 DEBUG(5, ("Starting sam plugin %s with paramater %s\n", plugin_name, plugin_param?plugin_param:"(null)"));
209 return plugin_init(auth_context, plugin_param, auth_method);