MySQL  8.0.18
Source Code Documentation
dialog.cc File Reference

dialog client authentication plugin with examples More...

#include "my_config.h"
#include <mysql.h>
#include <mysql/client_plugin.h>
#include <mysql/plugin_auth.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "my_compiler.h"

Macros

#define _GNU_SOURCE   /* for RTLD_DEFAULT */
 
#define ORDINARY_QUESTION   "\2"
 first byte of the question string is the question "type". More...
 
#define LAST_QUESTION   "\3"
 
#define PASSWORD_QUESTION   "\4"
 
#define LAST_PASSWORD   "\5"
 

Typedefs

typedef char *(* mysql_authentication_dialog_ask_t) (MYSQL *mysql, int type, const char *prompt, char *buf, int buf_len)
 type of the mysql_authentication_dialog_ask function More...
 

Functions

static int two_questions (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
 dialog demo with two questions, one password and one, the last, ordinary. 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 three_attempts (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
 
 mysql_declare_plugin (dialog)
 
static char * builtin_ask (MYSQL *mysql, int type, const char *prompt, char *buf, int buf_len)
 
static int perform_dialog (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
 The main function of the dialog plugin. More...
 
static int init_dialog (char *unused1, size_t unused2, int unused3, va_list unused4)
 initialization function of the dialog plugin More...
 
 mysql_declare_client_plugin (AUTHENTICATION) "dialog"
 

Variables

static struct st_mysql_auth two_handler
 
static struct st_mysql_auth three_handler
 
static mysql_authentication_dialog_ask_t ask
 
Sergei Golubchik
 
Sergei Dialog Client Authentication Plugin
 
Sergei Dialog Client Authentication GPL
 
Sergei Dialog Client Authentication NULL
 
Sergei Dialog Client Authentication init_dialog
 
Sergei Dialog Client Authentication perform_dialog
 
Sergei Dialog Client Authentication NULL mysql_end_client_plugin
 

Detailed Description

dialog client authentication plugin with examples

dialog is a general purpose client authentication plugin, it simply asks the user the question, as provided by the server and reports the answer back to the server. No encryption is involved, the answers are sent in clear text.

Two examples are provided: two_questions server plugin, that asks the password and an "Are you sure?" question with a reply "yes, of course". It demonstrates the usage of "password" (input is hidden) and "ordinary" (input can be echoed) questions, and how to mark the last question, to avoid an extra roundtrip.

And three_attempts plugin that gives the user three attempts to enter a correct password. It shows the situation when a number of questions is not known in advance.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* for RTLD_DEFAULT */

◆ LAST_PASSWORD

#define LAST_PASSWORD   "\5"

◆ LAST_QUESTION

#define LAST_QUESTION   "\3"

◆ ORDINARY_QUESTION

#define ORDINARY_QUESTION   "\2"

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

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

◆ PASSWORD_QUESTION

#define PASSWORD_QUESTION   "\4"

Typedef Documentation

◆ mysql_authentication_dialog_ask_t

typedef char*(* mysql_authentication_dialog_ask_t) (MYSQL *mysql, int type, const char *prompt, char *buf, int buf_len)
Initial value:
{
"three_attempts",
"Sergei Golubchik",
"Dialog plugin demo 2",
NULL,
NULL,
NULL,
0x0101,
0,
static struct st_mysql_auth three_handler
Definition: dialog.cc:175
#define MYSQL_AUTHENTICATION_PLUGIN
Definition: plugin.h:111
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
#define mysql_declare_plugin_end
Definition: plugin.h:152
#define PLUGIN_LICENSE_GPL
Definition: plugin.h:120

type of the mysql_authentication_dialog_ask function

Parameters
mysqlmysql
typetype of the input 1 - ordinary string input 2 - password string
promptprompt
bufa buffer to store the use input
buf_lenthe length of the buffer
Return values
apointer to the user input string. It may be equal to 'buf' or to 'mysql->password'. In all other cases it is assumed to be an allocated string, and the "dialog" plugin will free() it.

Function Documentation

◆ builtin_ask()

static char* builtin_ask ( MYSQL mysql,
int  type,
const char *  prompt,
char *  buf,
int  buf_len 
)
static

◆ generate_auth_string_hash()

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

◆ init_dialog()

static int init_dialog ( char *  unused1,
size_t  unused2,
int  unused3,
va_list  unused4 
)
static

initialization function of the dialog plugin

Pick up the client's authentication_dialog_ask() function, if exists, or fall back to the default implementation.

◆ mysql_declare_client_plugin()

mysql_declare_client_plugin ( AUTHENTICATION  )

◆ mysql_declare_plugin()

mysql_declare_plugin ( dialog  )

◆ perform_dialog()

static int perform_dialog ( MYSQL_PLUGIN_VIO vio,
MYSQL mysql 
)
static

The main function of the dialog plugin.

Read the prompt, ask the question, send the reply, repeat until the server is satisfied.

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

◆ set_salt()

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

◆ three_attempts()

static int three_attempts ( MYSQL_PLUGIN_VIO vio,
MYSQL_SERVER_AUTH_INFO info 
)
static

◆ two_questions()

static int two_questions ( MYSQL_PLUGIN_VIO vio,
MYSQL_SERVER_AUTH_INFO info 
)
static

dialog demo with two questions, one password and one, the last, ordinary.

◆ validate_auth_string_hash()

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

Variable Documentation

◆ ask

◆ Golubchik

Sergei Golubchik

◆ GPL

Sergei Dialog Client Authentication GPL

◆ init_dialog

Sergei Dialog Client Authentication init_dialog

◆ mysql_end_client_plugin

Sergei Dialog Client Authentication NULL mysql_end_client_plugin

◆ NULL

Sergei Dialog Client Authentication NULL

◆ perform_dialog

Sergei Dialog Client Authentication perform_dialog

◆ Plugin

Sergei Dialog Client Authentication Plugin

◆ three_handler

struct st_mysql_auth three_handler
static
Initial value:
= {
"dialog",
static int set_salt(const char *password, unsigned int password_len, unsigned char *salt, unsigned char *salt_len)
Definition: dialog.cc:130
#define MYSQL_AUTHENTICATION_INTERFACE_VERSION
Definition: plugin_auth.h:36
static int validate_auth_string_hash(char *const inbuf, unsigned int buflen)
Definition: dialog.cc:124
static int three_attempts(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
Definition: dialog.cc:149
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
#define AUTH_FLAG_PRIVILEGED_USER_FOR_PASSWORD_CHANGE
Definition: plugin_auth.h:48
static int generate_auth_string_hash(char *outbuf, unsigned int *buflen, const char *inbuf, unsigned int inbuflen)
Definition: dialog.cc:112

◆ two_handler

struct st_mysql_auth two_handler
static
Initial value:
= {
"dialog",
static int set_salt(const char *password, unsigned int password_len, unsigned char *salt, unsigned char *salt_len)
Definition: dialog.cc:130
static int two_questions(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
dialog demo with two questions, one password and one, the last, ordinary.
Definition: dialog.cc:82
#define MYSQL_AUTHENTICATION_INTERFACE_VERSION
Definition: plugin_auth.h:36
static int validate_auth_string_hash(char *const inbuf, unsigned int buflen)
Definition: dialog.cc:124
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
#define AUTH_FLAG_PRIVILEGED_USER_FOR_PASSWORD_CHANGE
Definition: plugin_auth.h:48
static int generate_auth_string_hash(char *outbuf, unsigned int *buflen, const char *inbuf, unsigned int inbuflen)
Definition: dialog.cc:112