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" |
22 |
#include "drizzled/authentication.h" |
|
23 |
#include "drizzled/gettext.h" |
|
24 |
#include "drizzled/errmsg_print.h" |
|
25 |
#include "drizzled/plugin_registry.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 |
||
31 |
static vector<Authentication *> all_authentication; |
|
32 |
||
259
by Brian Aker
First pass on PAM auth |
33 |
static bool are_plugins_loaded= false; |
34 |
||
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
35 |
void add_authentication(Authentication *auth) |
968.2.35
by Monty Taylor
Removed plugin_foreach from authentication. |
36 |
{
|
37 |
all_authentication.push_back(auth); |
|
38 |
}
|
|
39 |
||
971.1.46
by Monty Taylor
Made plugin registration go through Plugin_registry. |
40 |
void remove_authentication(Authentication *auth) |
968.2.35
by Monty Taylor
Removed plugin_foreach from authentication. |
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> |
|
48 |
{
|
|
49 |
Session *session; |
|
50 |
const char *password; |
|
51 |
public: |
|
52 |
AuthenticateBy(Session *session_arg, const char *password_arg) : |
|
53 |
unary_function<Authentication *, bool>(), |
|
54 |
session(session_arg), password(password_arg) {} |
|
55 |
||
56 |
inline result_type operator()(argument_type auth) |
|
259
by Brian Aker
First pass on PAM auth |
57 |
{
|
968.2.35
by Monty Taylor
Removed plugin_foreach from authentication. |
58 |
return auth->authenticate(session, password); |
259
by Brian Aker
First pass on PAM auth |
59 |
}
|
968.2.35
by Monty Taylor
Removed plugin_foreach from authentication. |
60 |
};
|
259
by Brian Aker
First pass on PAM auth |
61 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
62 |
bool authenticate_user(Session *session, const char *password) |
259
by Brian Aker
First pass on PAM auth |
63 |
{
|
64 |
/* If we never loaded any auth plugins, just return true */
|
|
65 |
if (are_plugins_loaded != true) |
|
66 |
return true; |
|
67 |
||
968.2.35
by Monty Taylor
Removed plugin_foreach from authentication. |
68 |
/* Use find_if instead of foreach so that we can collect return codes */
|
69 |
vector<Authentication *>::iterator iter= |
|
70 |
find_if(all_authentication.begin(), all_authentication.end(), |
|
71 |
AuthenticateBy(session, password)); |
|
72 |
/* If iter is == end() here, that means that all of the plugins returned
|
|
73 |
* false, which in this case means they all succeeded. Since we want to
|
|
74 |
* return false on success, we return the value of the two being !=
|
|
75 |
*/
|
|
76 |
return iter != all_authentication.end(); |
|
259
by Brian Aker
First pass on PAM auth |
77 |
}
|
78 |