~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
 *
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;
31
  authentication_st *auth= plugin_data(plugin, authentication_st *);
32
33
  (void)p_data;
34
35
  if (auth && auth->authenticate)
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
520.1.22 by Brian Aker
Second pass of thd cleanup
50
  return plugin_foreach(session, authenticate_by, DRIZZLE_AUTH_PLUGIN, (void *)password);
259 by Brian Aker
First pass on PAM auth
51
}
52
53
54
int authentication_initializer(st_plugin_int *plugin)
55
{
56
  authentication_st *authen;
57
683.1.1 by Mark Atwood
use new/delete instead of malloc/free for plugin structs
58
  authen= new authentication_st;
59
60
  if (authen == NULL)
61
    return 1;
259 by Brian Aker
First pass on PAM auth
62
63
  memset(authen, 0, sizeof(authentication_st));
64
65
  if (plugin->plugin->init)
66
  {
67
    if (plugin->plugin->init(authen))
68
    {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
69
      errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' init function returned error."),
259 by Brian Aker
First pass on PAM auth
70
                      plugin->name.str);
71
      goto err;
72
    }
73
  }
74
75
  plugin->data= (void *)authen;
76
  are_plugins_loaded= true;
77
810 by Brian Aker
Fix for making sure I_S has good information about which plugins are
78
  plugin->state= PLUGIN_IS_READY;
79
259 by Brian Aker
First pass on PAM auth
80
  return(0);
81
err:
683.1.1 by Mark Atwood
use new/delete instead of malloc/free for plugin structs
82
  delete authen;
259 by Brian Aker
First pass on PAM auth
83
  return(1);
84
}
85
86
int authentication_finalizer(st_plugin_int *plugin)
87
{
88
  authentication_st *authen= (authentication_st *)plugin->data;
89
90
  assert(authen);
91
  if (authen && plugin->plugin->deinit)
92
    plugin->plugin->deinit(authen);
93
683.1.1 by Mark Atwood
use new/delete instead of malloc/free for plugin structs
94
  delete authen;
259 by Brian Aker
First pass on PAM auth
95
96
  return(0);
97
}