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 <drizzled/gettext.h>
24
#include <drizzled/errmsg_print.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;
26
33
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)
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)
37
if (auth->authenticate(session, password))
58
return auth->authenticate(session, password);
44
62
bool authenticate_user(Session *session, const char *password)
47
65
if (are_plugins_loaded != true)
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)
67
if (plugin->plugin->init(authen))
69
errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' init function returned error."),
75
plugin->data= (void *)authen;
76
are_plugins_loaded= true;
78
plugin->state= PLUGIN_IS_READY;
86
int authentication_finalizer(st_plugin_int *plugin)
88
authentication_st *authen= (authentication_st *)plugin->data;
91
if (authen && plugin->plugin->deinit)
92
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();