~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Lee Bieber
  • Date: 2010-11-07 19:34:48 UTC
  • mfrom: (1910.1.2 build)
  • Revision ID: kalebral@gmail.com-20101107193448-64kdu912qej354sh
Merge Stewart - including adapting and expanding the "differences from mysql" page from the wiki.
Merge Stewart - fix bug 668143: drizzleslap with --commit runs second iteration data load in a transaction

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
22
22
#include "drizzled/plugin/authentication.h"
23
23
#include "drizzled/error.h"
24
24
#include "drizzled/gettext.h"
25
 
#include "drizzled/identifier.h"
 
25
#include "drizzled/security_context.h"
26
26
 
27
27
#include <vector>
28
28
 
 
29
using namespace std;
 
30
 
29
31
namespace drizzled
30
32
{
31
33
 
36
38
{
37
39
  if (auth != NULL)
38
40
    all_authentication.push_back(auth);
39
 
 
40
41
  return false;
41
42
}
42
43
 
43
44
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
44
45
{
45
46
  if (auth != NULL)
46
 
    all_authentication.erase(std::find(all_authentication.begin(),
47
 
                                       all_authentication.end(),
48
 
                                       auth));
 
47
    all_authentication.erase(find(all_authentication.begin(),
 
48
                                  all_authentication.end(),
 
49
                                  auth));
49
50
}
50
51
 
51
 
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
 
52
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
52
53
{
53
 
  const identifier::User &sctx;
54
 
  const std::string &password;
55
 
 
 
54
  const SecurityContext &sctx;
 
55
  const string &password;
56
56
public:
57
 
  AuthenticateBy(const identifier::User &sctx_arg, const std::string &password_arg) :
58
 
    std::unary_function<plugin::Authentication *, bool>(),
 
57
  AuthenticateBy(const SecurityContext &sctx_arg, const string &password_arg) :
 
58
    unary_function<plugin::Authentication *, bool>(),
59
59
    sctx(sctx_arg), password(password_arg) {}
60
60
 
61
61
  inline result_type operator()(argument_type auth)
64
64
  }
65
65
};
66
66
 
67
 
bool plugin::Authentication::isAuthenticated(drizzled::identifier::User::const_shared_ptr sctx,
68
 
                                             const std::string &password)
 
67
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
 
68
                                             const string &password)
69
69
{
70
70
  /* If we never loaded any auth plugins, just return true */
71
71
  if (all_authentication.empty())
72
72
    return true;
73
73
 
74
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));
 
75
  vector<plugin::Authentication *>::iterator iter=
 
76
    find_if(all_authentication.begin(), all_authentication.end(),
 
77
            AuthenticateBy(sctx, password));
78
78
 
79
79
  /* We only require one plugin to return success in order to authenticate.
80
80
   * If iter is == end() here, that means that all of the plugins returned
83
83
  if (iter == all_authentication.end())
84
84
  {
85
85
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
86
 
             sctx->username().c_str(),
87
 
             sctx->address().c_str(),
 
86
             sctx.getUser().c_str(),
 
87
             sctx.getIp().c_str(),
88
88
             password.empty() ? ER(ER_NO) : ER(ER_YES));
89
 
 
90
89
    return false;
91
90
  }
92
 
 
93
91
  return true;
94
92
}
95
93