Documentation Home
Extending MySQL 8.0
Download this Manual
PDF (US Ltr) - 420.3Kb
PDF (A4) - 419.7Kb


Extending MySQL 8.0  / ...  / The MySQL Plugin API  / Writing Plugins  / Writing Authentication Plugins  /  Writing the Client-Side Authentication Plugin

4.4.9.2 Writing the Client-Side Authentication Plugin

Declare the client-side plugin descriptor with themysql_declare_client_plugin() andmysql_end_client_plugin macros (seeSection 4.4.2.3, “Client Plugin Descriptors”). For theauth_simple plugin, the descriptor looks like this:

mysql_declare_client_plugin(AUTHENTICATION)  "auth_simple",                        /* plugin name */  "Author Name",                        /* author */  "Any-password authentication plugin", /* description */  {1,0,0},                              /* version = 1.0.0 */  "GPL",                                /* license type */  NULL,                                 /* for internal use */  NULL,                                 /* no init function */  NULL,                                 /* no deinit function */  NULL,                                 /* no option-handling function */  auth_simple_client                    /* main function */mysql_end_client_plugin;

The descriptor members from the plugin name through the option-handling function are common to all client plugin types. (For descriptions, seeSection 4.4.2.3, “Client Plugin Descriptors”.) Following the common members, the descriptor has an additional member specific to authentication plugins. This is themain function, which handles communication with the server. The function takes two arguments representing an I/O structure and a connection handler. For our simple any-password plugin, the main function does nothing but write to the server the password provided by the user:

static int auth_simple_client (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql){  int res;  /* send password as null-terminated string as cleartext */  res= vio->write_packet(vio, (const unsigned char *) mysql->passwd,                         strlen(mysql->passwd) + 1);  return res ? CR_ERROR : CR_OK;}

The main function should return one of the error codes shown in the following table.

Error CodeMeaning
CR_OKSuccess
CR_OK_HANDSHAKE_COMPLETESuccess, client done
CR_ERRORError

CR_OK_HANDSHAKE_COMPLETE indicates that the client has done its part successfully and has read the last packet. A client plugin may returnCR_OK_HANDSHAKE_COMPLETE if the number of round trips in the authentication protocol is not known in advance and the plugin must read another packet to determine whether authentication is finished.