18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/server_includes.h>
22
#include <drizzled/authentication.h>
23
#include <libdrizzle/gettext.h>
21
#include "drizzled/server_includes.h"
22
#include "drizzled/authentication.h"
23
#include "drizzled/gettext.h"
24
#include "drizzled/errmsg_print.h"
25
#include "drizzled/plugin_registry.h"
31
static vector<Authentication *> all_authentication;
25
33
static bool are_plugins_loaded= false;
27
static bool authenticate_by(THD *thd, plugin_ref plugin, void* p_data)
29
const char *password= (const char *)p_data;
30
authentication_st *auth= plugin_data(plugin, authentication_st *);
34
if (auth && auth->authenticate)
35
void add_authentication(Authentication *auth)
37
all_authentication.push_back(auth);
40
void remove_authentication(Authentication *auth)
42
all_authentication.erase(find(all_authentication.begin(),
43
all_authentication.end(),
47
class AuthenticateBy : public unary_function<Authentication *, bool>
52
AuthenticateBy(Session *session_arg, const char *password_arg) :
53
unary_function<Authentication *, bool>(),
54
session(session_arg), password(password_arg) {}
56
inline result_type operator()(argument_type auth)
36
if (auth->authenticate(thd, password))
58
return auth->authenticate(session, password);
43
bool authenticate_user(THD *thd, const char *password)
62
bool authenticate_user(Session *session, const char *password)
45
64
/* If we never loaded any auth plugins, just return true */
46
65
if (are_plugins_loaded != true)
49
return plugin_foreach(thd, authenticate_by, DRIZZLE_AUTH_PLUGIN, (void *)password);
53
int authentication_initializer(st_plugin_int *plugin)
55
authentication_st *authen;
57
if ((authen= (authentication_st *)malloc(sizeof(authentication_st))) == 0)
60
memset(authen, 0, sizeof(authentication_st));
62
if (plugin->plugin->init)
64
if (plugin->plugin->init(authen))
66
sql_print_error(_("Plugin '%s' init function returned error."),
72
plugin->data= (void *)authen;
73
are_plugins_loaded= true;
81
int authentication_finalizer(st_plugin_int *plugin)
83
authentication_st *authen= (authentication_st *)plugin->data;
86
if (authen && plugin->plugin->deinit)
87
plugin->plugin->deinit(authen);
68
/* Use find_if instead of foreach so that we can collect return codes */
69
vector<Authentication *>::iterator iter=
70
find_if(all_authentication.begin(), all_authentication.end(),
71
AuthenticateBy(session, password));
72
/* If iter is == end() here, that means that all of the plugins returned
73
* false, which in this case means they all succeeded. Since we want to
74
* return false on success, we return the value of the two being !=
76
return iter != all_authentication.end();