18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "drizzled/plugin/authentication.h"
23
#include "drizzled/error.h"
24
#include "drizzled/gettext.h"
25
#include "drizzled/security_context.h"
32
std::vector<plugin::Authentication *> all_authentication;
35
bool plugin::Authentication::addPlugin(plugin::Authentication *auth)
38
all_authentication.push_back(auth);
21
#include <drizzled/server_includes.h>
22
#include <drizzled/authentication.h>
23
#include <libdrizzle/gettext.h>
25
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)
36
if (auth->authenticate(thd, password))
42
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
45
all_authentication.erase(std::find(all_authentication.begin(),
46
all_authentication.end(),
50
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
52
const SecurityContext &sctx;
53
const std::string &password;
55
AuthenticateBy(const SecurityContext &sctx_arg, const std::string &password_arg) :
56
std::unary_function<plugin::Authentication *, bool>(),
57
sctx(sctx_arg), password(password_arg) {}
59
inline result_type operator()(argument_type auth)
61
return auth->authenticate(sctx, password);
65
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
66
const std::string &password)
43
bool authenticate_user(THD *thd, const char *password)
68
45
/* If we never loaded any auth plugins, just return true */
69
if (all_authentication.empty())
46
if (are_plugins_loaded != true)
72
/* Use find_if instead of foreach so that we can collect return codes */
73
std::vector<plugin::Authentication *>::iterator iter=
74
std::find_if(all_authentication.begin(), all_authentication.end(),
75
AuthenticateBy(sctx, password));
77
/* We only require one plugin to return success in order to authenticate.
78
* If iter is == end() here, that means that all of the plugins returned
79
* false, which means they all failed.
81
if (iter == all_authentication.end())
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)
83
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
84
sctx.getUser().c_str(),
86
password.empty() ? ER(ER_NO) : ER(ER_YES));
64
if (plugin->plugin->init(authen))
66
sql_print_error(_("Plugin '%s' init function returned error."),
92
} /* namespace drizzled */
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);