-
Notifications
You must be signed in to change notification settings - Fork 17
/
my_auth_plugin.c
59 lines (47 loc) · 1.32 KB
/
my_auth_plugin.c
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
/* Copyright (C) 2018 Werner */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <mysql/plugin_auth.h>
#include <mysql/auth_dialog_client.h>
static int school_number_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
{
int pkt_len;
unsigned char *pkt;
if (vio->write_packet(vio, (const unsigned char *) ORDINARY_QUESTION "Please enter your name: ", 26))
return CR_ERROR;
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
return CR_ERROR;
if (strcmp((const char *) pkt, info->user_name))
return CR_ERROR;
if (vio->write_packet(vio, (const unsigned char *) LAST_QUESTION "Please enter your school number: ", 35))
return CR_ERROR;
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
return CR_ERROR;
if (strcmp((const char *) pkt, info->auth_string))
return CR_ERROR;
return CR_OK;
}
static struct st_mysql_auth my_auth_plugin=
{
MYSQL_AUTHENTICATION_INTERFACE_VERSION,
"dialog",
school_number_auth
};
mysql_declare_plugin(dialog)
{
MYSQL_AUTHENTICATION_PLUGIN,
&my_auth_plugin,
"school_number",
"Werner",
"A simple MariaDB auth plugin",
PLUGIN_LICENSE_GPL,
NULL,
NULL,
0x0100,
NULL,
NULL,
NULL,
0,
}
mysql_declare_plugin_end;