~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/authentication.cc

  • Committer: Brian Aker
  • Date: 2008-08-03 22:14:59 UTC
  • Revision ID: brian@tangent.org-20080803221459-gz8on1zlp22dbr9d
First pass on PAM auth

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <drizzled/authentication.h>
 
2
 
 
3
static bool are_plugins_loaded= false;
 
4
 
 
5
static bool authenticate_by(THD *thd, plugin_ref plugin, void* p_data)
 
6
{
 
7
  const char *password= (const char *)p_data;
 
8
  authentication_st *auth= plugin_data(plugin, authentication_st *);
 
9
 
 
10
  (void)p_data;
 
11
 
 
12
  if (auth && auth->authenticate)
 
13
  {
 
14
    if (auth->authenticate(thd, password))
 
15
      return true;
 
16
  }
 
17
 
 
18
  return false;
 
19
}
 
20
 
 
21
bool authenticate_user(THD *thd, const char *password)
 
22
{
 
23
  /* If we never loaded any auth plugins, just return true */
 
24
  if (are_plugins_loaded != true)
 
25
    return true;
 
26
 
 
27
  printf("PASSWORD :%s:\n", password);
 
28
 
 
29
  return plugin_foreach(thd, authenticate_by, MYSQL_AUTH_PLUGIN, (void *)password);
 
30
}
 
31
 
 
32
 
 
33
int authentication_initializer(st_plugin_int *plugin)
 
34
{
 
35
  authentication_st *authen;
 
36
 
 
37
  if ((authen= (authentication_st *)malloc(sizeof(authentication_st))) == 0)
 
38
      return(1);
 
39
 
 
40
  memset(authen, 0, sizeof(authentication_st));
 
41
 
 
42
  if (plugin->plugin->init)
 
43
  {
 
44
    if (plugin->plugin->init(authen))
 
45
    {
 
46
      sql_print_error("Plugin '%s' init function returned error.",
 
47
                      plugin->name.str);
 
48
      goto err;
 
49
    }
 
50
  }
 
51
 
 
52
  plugin->data= (void *)authen;
 
53
  are_plugins_loaded= true;
 
54
 
 
55
  return(0);
 
56
err:
 
57
  free(authen);
 
58
  return(1);
 
59
}
 
60
 
 
61
int authentication_finalizer(st_plugin_int *plugin)
 
62
{
 
63
  authentication_st *authen= (authentication_st *)plugin->data;
 
64
 
 
65
  assert(authen);
 
66
  if (authen && plugin->plugin->deinit)
 
67
    plugin->plugin->deinit(authen);
 
68
 
 
69
  free(authen);
 
70
 
 
71
  return(0);
 
72
}