~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <drizzled/authentication.h>

static bool are_plugins_loaded= false;

static bool authenticate_by(THD *thd, plugin_ref plugin, void* p_data)
{
  const char *password= (const char *)p_data;
  authentication_st *auth= plugin_data(plugin, authentication_st *);

  (void)p_data;

  if (auth && auth->authenticate)
  {
    if (auth->authenticate(thd, password))
      return true;
  }

  return false;
}

bool authenticate_user(THD *thd, const char *password)
{
  /* If we never loaded any auth plugins, just return true */
  if (are_plugins_loaded != true)
    return true;

  printf("PASSWORD :%s:\n", password);

  return plugin_foreach(thd, authenticate_by, MYSQL_AUTH_PLUGIN, (void *)password);
}


int authentication_initializer(st_plugin_int *plugin)
{
  authentication_st *authen;

  if ((authen= (authentication_st *)malloc(sizeof(authentication_st))) == 0)
      return(1);

  memset(authen, 0, sizeof(authentication_st));

  if (plugin->plugin->init)
  {
    if (plugin->plugin->init(authen))
    {
      sql_print_error("Plugin '%s' init function returned error.",
                      plugin->name.str);
      goto err;
    }
  }

  plugin->data= (void *)authen;
  are_plugins_loaded= true;

  return(0);
err:
  free(authen);
  return(1);
}

int authentication_finalizer(st_plugin_int *plugin)
{
  authentication_st *authen= (authentication_st *)plugin->data;

  assert(authen);
  if (authen && plugin->plugin->deinit)
    plugin->plugin->deinit(authen);

  free(authen);

  return(0);
}