~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authentication.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-02-11 20:01:37 UTC
  • mto: (1300.3.1 query-as-string)
  • mto: This revision was merged to the branch mainline in revision 1307.
  • Revision ID: osullivan.padraig@gmail.com-20100211200137-kx0nmgy8hke3snid
Updated the calls to dtrace probes to use the c_str() pointer from query in Session

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "config.h"
22
22
#include "drizzled/plugin/authentication.h"
23
 
#include "drizzled/error.h"
 
23
#include "drizzled/errmsg_print.h"
 
24
#include "drizzled/plugin/registry.h"
24
25
#include "drizzled/gettext.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
 
42
44
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
43
45
{
44
46
  if (auth != NULL)
45
 
    all_authentication.erase(std::find(all_authentication.begin(),
46
 
                                       all_authentication.end(),
47
 
                                       auth));
 
47
    all_authentication.erase(find(all_authentication.begin(),
 
48
                                  all_authentication.end(),
 
49
                                  auth));
48
50
}
49
51
 
50
 
class AuthenticateBy : public std::unary_function<plugin::Authentication *, bool>
 
52
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
51
53
{
52
 
  const SecurityContext &sctx;
53
 
  const std::string &password;
 
54
  Session *session;
 
55
  const char *password;
54
56
public:
55
 
  AuthenticateBy(const SecurityContext &sctx_arg, const std::string &password_arg) :
56
 
    std::unary_function<plugin::Authentication *, bool>(),
57
 
    sctx(sctx_arg), password(password_arg) {}
 
57
  AuthenticateBy(Session *session_arg, const char *password_arg) :
 
58
    unary_function<plugin::Authentication *, bool>(),
 
59
    session(session_arg), password(password_arg) {}
58
60
 
59
61
  inline result_type operator()(argument_type auth)
60
62
  {
61
 
    return auth->authenticate(sctx, password);
 
63
    return auth->authenticate(session, password);
62
64
  }
63
65
};
64
66
 
65
 
bool plugin::Authentication::isAuthenticated(const SecurityContext &sctx,
66
 
                                             const std::string &password)
 
67
bool plugin::Authentication::isAuthenticated(Session *session,
 
68
                                             const char *password)
67
69
{
68
70
  /* If we never loaded any auth plugins, just return true */
69
 
  if (all_authentication.empty())
 
71
  if (all_authentication.size() == 0)
70
72
    return true;
71
73
 
72
74
  /* Use find_if instead of foreach so that we can collect return codes */
73
 
  std::vector<plugin::Authentication *>::iterator iter=
74
 
    std::find_if(all_authentication.begin(), all_authentication.end(),
75
 
                 AuthenticateBy(sctx, password));
76
 
 
77
 
  /* We only require one plugin to return success in order to authenticate.
78
 
   * If iter is == end() here, that means that all of the plugins returned
79
 
   * false, which means they all failed.
 
75
  vector<plugin::Authentication *>::iterator iter=
 
76
    find_if(all_authentication.begin(), all_authentication.end(),
 
77
            AuthenticateBy(session, password));
 
78
  /* If iter is == end() here, that means that all of the plugins returned
 
79
   * false, which in this case means they all succeeded. Since we want to 
 
80
   * return false on success, we return the value of the two being != 
80
81
   */
81
 
  if (iter == all_authentication.end())
82
 
  {
83
 
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
84
 
             sctx.getUser().c_str(),
85
 
             sctx.getIp().c_str(),
86
 
             password.empty() ? ER(ER_NO) : ER(ER_YES));
87
 
    return false;
88
 
  }
89
 
  return true;
 
82
  return iter != all_authentication.end();
90
83
}
91
84
 
92
85
} /* namespace drizzled */