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 |
*
|
|
4 |
* Copyright (C) 2008 Brian Aker
|
|
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 |
||
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
21 |
#include <drizzled/server_includes.h> |
259
by Brian Aker
First pass on PAM auth |
22 |
#include <drizzled/authentication.h> |
538
by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib. |
23 |
#include <drizzled/gettext.h> |
722.4.1
by Mark Atwood
integrate errmsg plugin into sql_print_* functions |
24 |
#include <drizzled/errmsg_print.h> |
259
by Brian Aker
First pass on PAM auth |
25 |
|
26 |
static bool are_plugins_loaded= false; |
|
27 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
28 |
static bool authenticate_by(Session *session, plugin_ref plugin, void* p_data) |
259
by Brian Aker
First pass on PAM auth |
29 |
{
|
30 |
const char *password= (const char *)p_data; |
|
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
31 |
Authentication *auth= plugin_data(plugin, Authentication *); |
259
by Brian Aker
First pass on PAM auth |
32 |
|
33 |
(void)p_data; |
|
34 |
||
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
35 |
if (auth) |
259
by Brian Aker
First pass on PAM auth |
36 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
37 |
if (auth->authenticate(session, password)) |
259
by Brian Aker
First pass on PAM auth |
38 |
return true; |
39 |
}
|
|
40 |
||
41 |
return false; |
|
42 |
}
|
|
43 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
44 |
bool authenticate_user(Session *session, const char *password) |
259
by Brian Aker
First pass on PAM auth |
45 |
{
|
46 |
/* If we never loaded any auth plugins, just return true */
|
|
47 |
if (are_plugins_loaded != true) |
|
48 |
return true; |
|
49 |
||
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
50 |
return plugin_foreach(session, authenticate_by, |
51 |
DRIZZLE_AUTH_PLUGIN, (void *)password); |
|
259
by Brian Aker
First pass on PAM auth |
52 |
}
|
53 |
||
54 |
||
55 |
int authentication_initializer(st_plugin_int *plugin) |
|
56 |
{
|
|
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
57 |
Authentication *authen; |
58 |
||
259
by Brian Aker
First pass on PAM auth |
59 |
|
60 |
if (plugin->plugin->init) |
|
61 |
{
|
|
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
62 |
if (plugin->plugin->init(&authen)) |
259
by Brian Aker
First pass on PAM auth |
63 |
{
|
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
64 |
errmsg_printf(ERRMSG_LVL_ERROR, |
65 |
_("Plugin '%s' init function returned error."), |
|
66 |
plugin->name.str); |
|
259
by Brian Aker
First pass on PAM auth |
67 |
goto err; |
68 |
}
|
|
69 |
}
|
|
70 |
||
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
71 |
if (authen == NULL) |
72 |
return 1; |
|
73 |
||
74 |
plugin->data= static_cast<void *>(authen); |
|
259
by Brian Aker
First pass on PAM auth |
75 |
are_plugins_loaded= true; |
76 |
||
810
by Brian Aker
Fix for making sure I_S has good information about which plugins are |
77 |
plugin->state= PLUGIN_IS_READY; |
78 |
||
259
by Brian Aker
First pass on PAM auth |
79 |
return(0); |
80 |
err: |
|
683.1.1
by Mark Atwood
use new/delete instead of malloc/free for plugin structs |
81 |
delete authen; |
259
by Brian Aker
First pass on PAM auth |
82 |
return(1); |
83 |
}
|
|
84 |
||
85 |
int authentication_finalizer(st_plugin_int *plugin) |
|
86 |
{
|
|
942.1.14
by Monty Taylor
Changed authentication_st to class Authentication. |
87 |
Authentication *authen= static_cast<Authentication *>(plugin->data); |
259
by Brian Aker
First pass on PAM auth |
88 |
|
89 |
assert(authen); |
|
90 |
if (authen && plugin->plugin->deinit) |
|
91 |
plugin->plugin->deinit(authen); |
|
92 |
||
93 |
return(0); |
|
94 |
}
|