~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>
259 by Brian Aker
First pass on PAM auth
24
25
static bool are_plugins_loaded= false;
26
520.1.22 by Brian Aker
Second pass of thd cleanup
27
static bool authenticate_by(Session *session, plugin_ref plugin, void* p_data)
259 by Brian Aker
First pass on PAM auth
28
{
29
  const char *password= (const char *)p_data;
30
  authentication_st *auth= plugin_data(plugin, authentication_st *);
31
32
  (void)p_data;
33
34
  if (auth && auth->authenticate)
35
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
36
    if (auth->authenticate(session, password))
259 by Brian Aker
First pass on PAM auth
37
      return true;
38
  }
39
40
  return false;
41
}
42
520.1.22 by Brian Aker
Second pass of thd cleanup
43
bool authenticate_user(Session *session, const char *password)
259 by Brian Aker
First pass on PAM auth
44
{
45
  /* If we never loaded any auth plugins, just return true */
46
  if (are_plugins_loaded != true)
47
    return true;
48
520.1.22 by Brian Aker
Second pass of thd cleanup
49
  return plugin_foreach(session, authenticate_by, DRIZZLE_AUTH_PLUGIN, (void *)password);
259 by Brian Aker
First pass on PAM auth
50
}
51
52
53
int authentication_initializer(st_plugin_int *plugin)
54
{
55
  authentication_st *authen;
56
57
  if ((authen= (authentication_st *)malloc(sizeof(authentication_st))) == 0)
58
      return(1);
59
60
  memset(authen, 0, sizeof(authentication_st));
61
62
  if (plugin->plugin->init)
63
  {
64
    if (plugin->plugin->init(authen))
65
    {
338 by Monty Taylor
Tagged more strings.
66
      sql_print_error(_("Plugin '%s' init function returned error."),
259 by Brian Aker
First pass on PAM auth
67
                      plugin->name.str);
68
      goto err;
69
    }
70
  }
71
72
  plugin->data= (void *)authen;
73
  are_plugins_loaded= true;
74
75
  return(0);
76
err:
77
  free(authen);
78
  return(1);
79
}
80
81
int authentication_finalizer(st_plugin_int *plugin)
82
{
83
  authentication_st *authen= (authentication_st *)plugin->data;
84
85
  assert(authen);
86
  if (authen && plugin->plugin->deinit)
87
    plugin->plugin->deinit(authen);
88
89
  free(authen);
90
91
  return(0);
92
}