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/identifier.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 <drizzled/gettext.h>
24
#include <drizzled/errmsg_print.h>
26
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_st *auth= plugin_data(plugin, authentication_st *);
35
if (auth && auth->authenticate)
37
if (auth->authenticate(session, password))
43
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
46
all_authentication.erase(std::find(all_authentication.begin(),
47
all_authentication.end(),
51
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
53
const identifier::User &sctx;
54
const std::string &password;
57
AuthenticateBy(const identifier::User &sctx_arg, const std::string &password_arg) :
58
std::unary_function<plugin::Authentication *, bool>(),
59
sctx(sctx_arg), password(password_arg) {}
61
inline result_type operator()(argument_type auth)
63
return auth->authenticate(sctx, password);
67
bool plugin::Authentication::isAuthenticated(drizzled::identifier::User::const_shared_ptr sctx,
68
const std::string &password)
44
bool authenticate_user(Session *session, const char *password)
70
46
/* If we never loaded any auth plugins, just return true */
71
if (all_authentication.empty())
47
if (are_plugins_loaded != true)
74
/* Use find_if instead of foreach so that we can collect return codes */
75
std::vector<plugin::Authentication *>::iterator iter=
76
std::find_if(all_authentication.begin(), all_authentication.end(),
77
AuthenticateBy(*sctx, password));
79
/* We only require one plugin to return success in order to authenticate.
80
* If iter is == end() here, that means that all of the plugins returned
81
* false, which means they all failed.
83
if (iter == all_authentication.end())
50
return plugin_foreach(session, authenticate_by, DRIZZLE_AUTH_PLUGIN, (void *)password);
54
int authentication_initializer(st_plugin_int *plugin)
56
authentication_st *authen;
58
authen= new authentication_st;
63
memset(authen, 0, sizeof(authentication_st));
65
if (plugin->plugin->init)
85
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
86
sctx->username().c_str(),
87
sctx->address().c_str(),
88
password.empty() ? ER(ER_NO) : ER(ER_YES));
67
if (plugin->plugin->init(authen))
69
errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' init function returned error."),
96
} /* namespace drizzled */
75
plugin->data= (void *)authen;
76
are_plugins_loaded= true;
84
int authentication_finalizer(st_plugin_int *plugin)
86
authentication_st *authen= (authentication_st *)plugin->data;
89
if (authen && plugin->plugin->deinit)
90
plugin->plugin->deinit(authen);