summaryrefslogtreecommitdiffstats
path: root/plugin/auth_examples/auth_0x0100.c
blob: e23f495f43b5cb5671e8397eb9fe6abbe4665175 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Copyright (C) 2013 Sergei Golubchik and Monty Program Ab

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; version 2 of the
    License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */

/**
  @file

  auth plugin that uses old structures as of
  MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0100

  To test the old version support.
  It intentionally uses no constants like CR_OK ok PASSWORD_USED_YES.
*/

#include <mysql/plugin.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#if 0
#include <mysql/plugin_auth.h>
#else
#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0100
typedef void MYSQL_PLUGIN_VIO; /* we don't use it here */

typedef struct st_mysql_server_auth_info
{
  char *user_name;
  unsigned int user_name_length;
  const char *auth_string;
  unsigned long auth_string_length;
  char authenticated_as[49]; 
  char external_user[512];
  int  password_used;
  const char *host_or_ip;
  unsigned int host_or_ip_length;
} MYSQL_SERVER_AUTH_INFO;

struct st_mysql_auth
{
  int interface_version;
  const char *client_auth_plugin;
  int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
};
#endif

static int do_auth_0x0100(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
{
  info->password_used= 1;
  strcpy(info->authenticated_as, "zzzzzzzzzzzzzzzz");
  memset(info->external_user, 'o', 510);
  info->external_user[510]='.';
  info->external_user[511]=0;
  return vio ? -1 : 0; /* use vio to avoid the 'unused' warning */
}

static struct st_mysql_auth auth_0x0100_struct=
{
  MYSQL_AUTHENTICATION_INTERFACE_VERSION, 0, do_auth_0x0100
};

maria_declare_plugin(auth_0x0100)
{
  MYSQL_AUTHENTICATION_PLUGIN,
  &auth_0x0100_struct,
  "auth_0x0100",
  "Sergei Golubchik",
  "Test for API 0x0100 support",
  PLUGIN_LICENSE_GPL,
  NULL,
  NULL,
  0x0100,
  NULL,
  NULL,
  "1.0",
  MariaDB_PLUGIN_MATURITY_EXPERIMENTAL,
}
maria_declare_plugin_end;