~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/authentication.cc

  • Committer: Brian Aker
  • Date: 2009-01-21 05:53:36 UTC
  • mto: This revision was merged to the branch mainline in revision 801.
  • Revision ID: brian@tangent.org-20090121055336-fxoz6wfzreo8gi9x
Removed purge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
1
21
#include <drizzled/server_includes.h>
2
22
#include <drizzled/authentication.h>
 
23
#include <drizzled/gettext.h>
 
24
#include <drizzled/errmsg_print.h>
3
25
 
4
26
static bool are_plugins_loaded= false;
5
27
 
6
 
static bool authenticate_by(THD *thd, plugin_ref plugin, void* p_data)
 
28
static bool authenticate_by(Session *session, plugin_ref plugin, void* p_data)
7
29
{
8
30
  const char *password= (const char *)p_data;
9
31
  authentication_st *auth= plugin_data(plugin, authentication_st *);
12
34
 
13
35
  if (auth && auth->authenticate)
14
36
  {
15
 
    if (auth->authenticate(thd, password))
 
37
    if (auth->authenticate(session, password))
16
38
      return true;
17
39
  }
18
40
 
19
41
  return false;
20
42
}
21
43
 
22
 
bool authenticate_user(THD *thd, const char *password)
 
44
bool authenticate_user(Session *session, const char *password)
23
45
{
24
46
  /* If we never loaded any auth plugins, just return true */
25
47
  if (are_plugins_loaded != true)
26
48
    return true;
27
49
 
28
 
  printf("PASSWORD :%s:\n", password);
29
 
 
30
 
  return plugin_foreach(thd, authenticate_by, DRIZZLE_AUTH_PLUGIN, (void *)password);
 
50
  return plugin_foreach(session, authenticate_by, DRIZZLE_AUTH_PLUGIN, (void *)password);
31
51
}
32
52
 
33
53
 
35
55
{
36
56
  authentication_st *authen;
37
57
 
38
 
  if ((authen= (authentication_st *)malloc(sizeof(authentication_st))) == 0)
39
 
      return(1);
 
58
  authen= new authentication_st;
 
59
 
 
60
  if (authen == NULL)
 
61
    return 1;
40
62
 
41
63
  memset(authen, 0, sizeof(authentication_st));
42
64
 
44
66
  {
45
67
    if (plugin->plugin->init(authen))
46
68
    {
47
 
      sql_print_error("Plugin '%s' init function returned error.",
 
69
      errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' init function returned error."),
48
70
                      plugin->name.str);
49
71
      goto err;
50
72
    }
55
77
 
56
78
  return(0);
57
79
err:
58
 
  free(authen);
 
80
  delete authen;
59
81
  return(1);
60
82
}
61
83
 
67
89
  if (authen && plugin->plugin->deinit)
68
90
    plugin->plugin->deinit(authen);
69
91
 
70
 
  free(authen);
 
92
  delete authen;
71
93
 
72
94
  return(0);
73
95
}