MySQL 9.1.0
Source Code Documentation
test_plugin.cc File Reference

Test driver for the mysql-test/t/plugin_auth.test. More...

#include <mysql/client_plugin.h>
#include <mysql/components/my_service.h>
#include <mysql/components/services/log_builtins.h>
#include <mysql/plugin_auth.h>
#include <mysqld_error.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql.h>
#include "my_compiler.h"

Macros

#define LOG_COMPONENT_TAG   "test_plugin_server"
 
#define ORDINARY_QUESTION   "\2"
 first byte of the question string is the question "type". More...
 
#define LAST_QUESTION   "\3"
 
#define LAST_PASSWORD   "\4"
 
#define PASSWORD_QUESTION   "\5"
 

Functions

static int test_plugin_init (MYSQL_PLUGIN plugin_info)
 
static int auth_test_plugin (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
 dialog test plugin mimicking the ordinary auth mechanism. More...
 
static int generate_auth_string_hash (char *outbuf, unsigned int *buflen, const char *inbuf, unsigned int inbuflen)
 
static int validate_auth_string_hash (char *const inbuf, unsigned int buflen)
 
static int set_salt (const char *password, unsigned int password_len, unsigned char *salt, unsigned char *salt_len)
 
static int auth_cleartext_plugin (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
 dialog test plugin mimicking the ordinary auth mechanism. More...
 
 mysql_declare_plugin (test_plugin)
 
static int test_plugin_client (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
 The main function of the test plugin. More...
 
 mysql_declare_client_plugin (AUTHENTICATION) "auth_test_plugin"
 

Variables

static const mysql_service_registry_treg_srv = nullptr
 Initialize parameters required for error logging. More...
 
const mysql_service_log_builtins_tlog_bi = nullptr
 accessor built-ins More...
 
const mysql_service_log_builtins_string_tlog_bs = nullptr
 string built-ins More...
 
static MYSQL_PLUGIN plugin_info_ptr
 Handle assigned when loading the plugin. More...
 
static struct st_mysql_auth auth_test_handler
 
static struct st_mysql_auth auth_cleartext_handler
 
 MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE
 
Dialog Client Authentication Plugin
 
Dialog Client Authentication GPL
 
Dialog Client Authentication nullptr
 
Dialog Client Authentication test_plugin_client
 
Dialog Client Authentication mysql_end_client_plugin
 

Detailed Description

Test driver for the mysql-test/t/plugin_auth.test.

This is a set of test plugins used to test the external authentication implementation. See the above test file for more details. This test plugin is based on the dialog plugin example.

Macro Definition Documentation

◆ LAST_PASSWORD

#define LAST_PASSWORD   "\4"

◆ LAST_QUESTION

#define LAST_QUESTION   "\3"

◆ LOG_COMPONENT_TAG

#define LOG_COMPONENT_TAG   "test_plugin_server"

◆ ORDINARY_QUESTION

#define ORDINARY_QUESTION   "\2"

first byte of the question string is the question "type".

It can be a "ordinary" or a "password" question. The last bit set marks a last question in the authentication exchange.

◆ PASSWORD_QUESTION

#define PASSWORD_QUESTION   "\5"

Function Documentation

◆ auth_cleartext_plugin()

static int auth_cleartext_plugin ( MYSQL_PLUGIN_VIO vio,
MYSQL_SERVER_AUTH_INFO info 
)
static

dialog test plugin mimicking the ordinary auth mechanism.

Used to test the clear text plugin API

◆ auth_test_plugin()

static int auth_test_plugin ( MYSQL_PLUGIN_VIO vio,
MYSQL_SERVER_AUTH_INFO info 
)
static

dialog test plugin mimicking the ordinary auth mechanism.

Used to test the auth plugin API

◆ generate_auth_string_hash()

static int generate_auth_string_hash ( char *  outbuf,
unsigned int *  buflen,
const char *  inbuf,
unsigned int  inbuflen 
)
static

◆ mysql_declare_client_plugin()

mysql_declare_client_plugin ( AUTHENTICATION  )

◆ mysql_declare_plugin()

mysql_declare_plugin ( test_plugin  )

◆ set_salt()

static int set_salt ( const char *  password,
unsigned int  password_len,
unsigned char *  salt,
unsigned char *  salt_len 
)
static

◆ test_plugin_client()

static int test_plugin_client ( MYSQL_PLUGIN_VIO vio,
MYSQL mysql 
)
static

The main function of the test plugin.

Reads the prompt, check if the handshake is done and if the prompt is a password request and returns the password. Otherwise return error.

Note
  1. this plugin shows how a client authentication plugin may read a MySQL protocol OK packet internally - which is important where a number of packets is not known in advance.
  2. the first byte of the prompt is special. it is not shown to the user, but signals whether it is the last question (prompt[0] & 1 == 1) or not last (prompt[0] & 1 == 0), and whether the input is a password (not echoed).
  3. the prompt is expected to be sent zero-terminated

◆ test_plugin_init()

static int test_plugin_init ( MYSQL_PLUGIN  plugin_info)
static

◆ validate_auth_string_hash()

static int validate_auth_string_hash ( char *const  inbuf,
unsigned int  buflen 
)
static

Variable Documentation

◆ auth_cleartext_handler

struct st_mysql_auth auth_cleartext_handler
static
Initial value:
= {
"mysql_clear_password",
nullptr}
#define AUTH_FLAG_PRIVILEGED_USER_FOR_PASSWORD_CHANGE
Definition: plugin_auth.h:49
#define MYSQL_AUTHENTICATION_INTERFACE_VERSION
Definition: plugin_auth.h:37
static int validate_auth_string_hash(char *const inbuf, unsigned int buflen)
Definition: test_plugin.cc:134
static int set_salt(const char *password, unsigned int password_len, unsigned char *salt, unsigned char *salt_len)
Definition: test_plugin.cc:139
static int auth_cleartext_plugin(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
dialog test plugin mimicking the ordinary auth mechanism.
Definition: test_plugin.cc:161
static int generate_auth_string_hash(char *outbuf, unsigned int *buflen, const char *inbuf, unsigned int inbuflen)
Definition: test_plugin.cc:122

◆ auth_test_handler

struct st_mysql_auth auth_test_handler
static
Initial value:
= {
"auth_test_plugin",
nullptr}
static int auth_test_plugin(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
dialog test plugin mimicking the ordinary auth mechanism.
Definition: test_plugin.cc:81

◆ GPL

Dialog Client Authentication GPL

◆ log_bi

accessor built-ins

accessor built-ins

◆ log_bs

string built-ins

◆ MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE

MYSQL_CLIENT_PLUGIN_AUTHOR_ORACLE

◆ mysql_end_client_plugin

Dialog Client Authentication mysql_end_client_plugin

◆ nullptr

Dialog Client Authentication nullptr

◆ Plugin

Dialog Client Authentication Plugin

◆ plugin_info_ptr

MYSQL_PLUGIN plugin_info_ptr
static

Handle assigned when loading the plugin.

Used with the error reporting functions.

◆ reg_srv

const mysql_service_registry_t* reg_srv = nullptr
static

Initialize parameters required for error logging.

◆ test_plugin_client

Dialog Client Authentication test_plugin_client