~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Monty Taylor
  • Date: 2010-04-27 21:03:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1510.
  • Revision ID: mordred@inaugust.com-20100427210313-6h4uz2553kapi196
Undid the libdrizzled.so.

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
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
22
 
#include <drizzled/plugin/authentication.h>
23
 
#include <drizzled/error.h>
24
 
#include <drizzled/gettext.h>
25
 
#include <drizzled/identifier.h>
 
21
#include "config.h"
 
22
#include "drizzled/plugin/authentication.h"
 
23
#include "drizzled/error.h"
 
24
#include "drizzled/plugin/registry.h"
 
25
#include "drizzled/gettext.h"
 
26
#include "drizzled/security_context.h"
26
27
 
27
28
#include <vector>
28
29
 
 
30
using namespace std;
 
31
 
29
32
namespace drizzled
30
33
{
31
34
 
36
39
{
37
40
  if (auth != NULL)
38
41
    all_authentication.push_back(auth);
39
 
 
40
42
  return false;
41
43
}
42
44
 
43
45
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
44
46
{
45
47
  if (auth != NULL)
46
 
    all_authentication.erase(std::find(all_authentication.begin(),
47
 
                                       all_authentication.end(),
48
 
                                       auth));
 
48
    all_authentication.erase(find(all_authentication.begin(),
 
49
                                  all_authentication.end(),
 
50
                                  auth));
49
51
}
50
52
 
51
 
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
 
53
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
52
54
{
53
 
  const identifier::User &sctx;
54
 
  const std::string &password;
55
 
 
 
55
  const SecurityContext &sctx;
 
56
  const string &password;
56
57
public:
57
 
  AuthenticateBy(const identifier::User &sctx_arg, const std::string &password_arg) :
58
 
    std::unary_function<plugin::Authentication *, bool>(),
 
58
  AuthenticateBy(const SecurityContext &sctx_arg, const string &password_arg) :
 
59
    unary_function<plugin::Authentication *, bool>(),
59
60
    sctx(sctx_arg), password(password_arg) {}
60
61
 
61
62
  inline result_type operator()(argument_type auth)
64
65
  }
65
66
};
66
67
 
67
 
bool plugin::Authentication::isAuthenticated(drizzled::identifier::User::const_reference sctx,
68
 
                                             const std::string &password)
 
68
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
 
69
                                             const string &password)
69
70
{
70
71
  /* If we never loaded any auth plugins, just return true */
71
72
  if (all_authentication.empty())
72
73
    return true;
73
74
 
74
75
  /* 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));
 
76
  vector<plugin::Authentication *>::iterator iter=
 
77
    find_if(all_authentication.begin(), all_authentication.end(),
 
78
            AuthenticateBy(sctx, password));
78
79
 
79
80
  /* We only require one plugin to return success in order to authenticate.
80
81
   * If iter is == end() here, that means that all of the plugins returned
82
83
   */
83
84
  if (iter == all_authentication.end())
84
85
  {
85
 
    error::access(sctx);
86
 
 
 
86
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
 
87
             sctx.getUser().c_str(),
 
88
             sctx.getIp().c_str(),
 
89
             password.empty() ? ER(ER_NO) : ER(ER_YES));
87
90
    return false;
88
91
  }
89
 
 
90
92
  return true;
91
93
}
92
94