23
23
#include <drizzled/gettext.h>
24
24
#include <drizzled/errmsg_print.h>
30
static vector<Authentication *> all_authentication;
26
32
static bool are_plugins_loaded= false;
28
static bool authenticate_by(Session *session, plugin_ref plugin, void* p_data)
30
const char *password= (const char *)p_data;
31
Authentication *auth= plugin_data(plugin, Authentication *);
34
static void add_authentication(Authentication *auth)
36
all_authentication.push_back(auth);
39
static void remove_authentication(Authentication *auth)
41
all_authentication.erase(find(all_authentication.begin(),
42
all_authentication.end(),
46
class AuthenticateBy : public unary_function<Authentication *, bool>
51
AuthenticateBy(Session *session_arg, const char *password_arg) :
52
unary_function<Authentication *, bool>(),
53
session(session_arg), password(password_arg) {}
55
inline result_type operator()(argument_type auth)
37
if (auth->authenticate(session, password))
57
return auth->authenticate(session, password);
44
61
bool authenticate_user(Session *session, const char *password)
47
64
if (are_plugins_loaded != true)
50
return plugin_foreach(session, authenticate_by, DRIZZLE_AUTH_PLUGIN, (void *)password);
67
/* Use find_if instead of foreach so that we can collect return codes */
68
vector<Authentication *>::iterator iter=
69
find_if(all_authentication.begin(), all_authentication.end(),
70
AuthenticateBy(session, password));
71
/* If iter is == end() here, that means that all of the plugins returned
72
* false, which in this case means they all succeeded. Since we want to
73
* return false on success, we return the value of the two being !=
75
return iter != all_authentication.end();
54
79
int authentication_initializer(st_plugin_int *plugin)
56
Authentication *authen;
81
Authentication *authen= NULL;
59
83
if (plugin->plugin->init)
63
87
errmsg_printf(ERRMSG_LVL_ERROR,
64
88
_("Plugin '%s' init function returned error."),
70
94
if (authen == NULL)
73
plugin->data= static_cast<void *>(authen);
97
add_authentication(authen);
74
99
are_plugins_loaded= true;
82
104
int authentication_finalizer(st_plugin_int *plugin)
84
106
Authentication *authen= static_cast<Authentication *>(plugin->data);
109
remove_authentication(authen);
87
111
if (authen && plugin->plugin->deinit)
88
112
plugin->plugin->deinit(authen);