~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1010 by Brian Aker
Replacing Sun employee copyright headers (aka... anything done by a Sun
4
 *  Copyright (C) 2008 Sun Microsystems
390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
21
#include "drizzled/server_includes.h"
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
22
#include "drizzled/plugin/authentication.h"
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
23
#include "drizzled/errmsg_print.h"
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
24
#include "drizzled/plugin/registry.h"
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
25
#include "drizzled/gettext.h"
259 by Brian Aker
First pass on PAM auth
26
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
27
#include <vector>
28
29
using namespace std;
30
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
31
namespace drizzled
32
{
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
33
34
std::vector<plugin::Authentication *> all_authentication;
35
36
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
37
bool plugin::Authentication::addPlugin(plugin::Authentication *auth)
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
38
{
39
  if (auth != NULL)
40
    all_authentication.push_back(auth);
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
41
  return false;
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
42
}
43
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
44
void plugin::Authentication::removePlugin(plugin::Authentication *auth)
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
45
{
46
  if (auth != NULL)
47
    all_authentication.erase(find(all_authentication.begin(),
48
                                  all_authentication.end(),
49
                                  auth));
50
}
51
52
class AuthenticateBy : public unary_function<plugin::Authentication *, bool>
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
53
{
54
  Session *session;
55
  const char *password;
56
public:
57
  AuthenticateBy(Session *session_arg, const char *password_arg) :
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
58
    unary_function<plugin::Authentication *, bool>(),
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
59
    session(session_arg), password(password_arg) {}
60
61
  inline result_type operator()(argument_type auth)
259 by Brian Aker
First pass on PAM auth
62
  {
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
63
    return auth->authenticate(session, password);
259 by Brian Aker
First pass on PAM auth
64
  }
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
65
};
259 by Brian Aker
First pass on PAM auth
66
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
67
bool plugin::Authentication::isAuthenticated(Session *session,
68
                                             const char *password)
259 by Brian Aker
First pass on PAM auth
69
{
70
  /* If we never loaded any auth plugins, just return true */
971.7.1 by Eric Day
Client/Listen cleanup, moved globals, console plugin cleanup.
71
  if (all_authentication.size() == 0)
259 by Brian Aker
First pass on PAM auth
72
    return true;
73
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
74
  /* Use find_if instead of foreach so that we can collect return codes */
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
75
  vector<plugin::Authentication *>::iterator iter=
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
76
    find_if(all_authentication.begin(), all_authentication.end(),
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
77
            AuthenticateBy(session, password));
968.2.35 by Monty Taylor
Removed plugin_foreach from authentication.
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 != 
81
   */
82
  return iter != all_authentication.end();
259 by Brian Aker
First pass on PAM auth
83
}
84
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
85
} /* namespace drizzled */