~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Diego Medina
  • Date: 2009-10-05 04:05:29 UTC
  • mfrom: (1161 staging)
  • mto: This revision was merged to the branch mainline in revision 1178.
  • Revision ID: diego.medina@sun.com-20091005040529-5g1qe9gxzslpgefd
resolved small merge issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "drizzled/server_includes.h"
22
 
#include "drizzled/authentication.h"
23
 
#include "drizzled/gettext.h"
 
22
#include "drizzled/plugin/authentication.h"
24
23
#include "drizzled/errmsg_print.h"
25
24
#include "drizzled/plugin/registry.h"
 
25
#include "drizzled/gettext.h"
26
26
 
27
27
#include <vector>
28
28
 
29
29
using namespace std;
30
30
 
31
 
static vector<Authentication *> all_authentication;
32
 
 
33
 
static bool are_plugins_loaded= false;
34
 
 
35
 
void add_authentication(Authentication *auth)
36
 
{
37
 
  all_authentication.push_back(auth);
38
 
}
39
 
 
40
 
void remove_authentication(Authentication *auth)
41
 
{
42
 
  all_authentication.erase(find(all_authentication.begin(),
43
 
                                all_authentication.end(),
44
 
                                auth));
45
 
}
46
 
 
47
 
class AuthenticateBy : public unary_function<Authentication *, bool>
 
31
namespace drizzled
 
32
{
 
33
 
 
34
std::vector<plugin::Authentication *> all_authentication;
 
35
bool are_plugins_loaded= false;
 
36
 
 
37
 
 
38
bool plugin::Authentication::addPlugin(plugin::Authentication *auth)
 
39
{
 
40
  if (auth != NULL)
 
41
    all_authentication.push_back(auth);
 
42
  return false;
 
43
}
 
44
 
 
45
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
 
46
{
 
47
  if (auth != NULL)
 
48
    all_authentication.erase(find(all_authentication.begin(),
 
49
                                  all_authentication.end(),
 
50
                                  auth));
 
51
}
 
52
 
 
53
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
48
54
{
49
55
  Session *session;
50
56
  const char *password;
51
57
public:
52
58
  AuthenticateBy(Session *session_arg, const char *password_arg) :
53
 
    unary_function<Authentication *, bool>(),
 
59
    unary_function<plugin::Authentication *, bool>(),
54
60
    session(session_arg), password(password_arg) {}
55
61
 
56
62
  inline result_type operator()(argument_type auth)
59
65
  }
60
66
};
61
67
 
62
 
bool authenticate_user(Session *session, const char *password)
 
68
bool plugin::Authentication::isAuthenticated(Session *session,
 
69
                                             const char *password)
63
70
{
64
71
  /* If we never loaded any auth plugins, just return true */
65
72
  if (are_plugins_loaded != true)
66
73
    return true;
67
74
 
68
75
  /* Use find_if instead of foreach so that we can collect return codes */
69
 
  vector<Authentication *>::iterator iter=
 
76
  vector<plugin::Authentication *>::iterator iter=
70
77
    find_if(all_authentication.begin(), all_authentication.end(),
71
78
            AuthenticateBy(session, password));
72
79
  /* If iter is == end() here, that means that all of the plugins returned
76
83
  return iter != all_authentication.end();
77
84
}
78
85
 
 
86
} /* namespace drizzled */