Edit report at https://bugs.php.net/bug.php?id=68281&edit=1
ID: 68281
Comment by: roberto at spadim dot com dot br
Reported by: roberto at spadim dot com dot br
Summary: mariadb server with dialog auth method
Status: Open
Type: Feature/Change Request
Package: MySQL related
Operating System: any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
From heidisql:
https://code.google.com/p/heidisql/source/browse/trunk/source/dbconnection.pas#671
one point... when using dialog, we can't use persistent connection, since each new connection
create a new dialog...
Previous Comments:
------------------------------------------------------------------------
[2014-10-22 06:23:05] roberto at spadim dot com dot br
Reading examples from mariadb client/server auth dialog plugin
at php side, we must include a function as callback to builtin_ask function:
MYSQL_PLUGIN_EXPORT char *mysql_authentication_dialog_ask(MYSQL *mysql, int type,const char
*prompt,char *buf, int buf_len)
and the return of this function is the 'mysql_auth_dialog_send'
in other words at php side we have:
mysql_set_callback('any_function');
mysql_connect();
if we got dialog, any_function will be called, the problem is... at what connect we are? maybe
"struct st_mysql *mysql" solve this problem, if not at least we can call a function and
php user must know what he is doing
at mysqli and pdo we could pass this callback function name as a mysqli_option or a array parameter
(pdo)
well i think that's all for now (04:22AM i didn't sleep yet, good night)
------------------------------------------------------------------------
[2014-10-22 06:13:43] roberto at spadim dot com dot br
what kinds of questions exists:
https://github.com/MariaDB/server/blob/e974b564389af8251c2ba51060e6129e45431586/include/mysql/auth_dialog_client.h
------------------------------------------------------------------------
[2014-10-22 06:12:14] roberto at spadim dot com dot br
more example from mariadb server:
https://github.com/MariaDB/server/blob/1e79138459038c39c85239a825bf1727ef43c156/client/mysql.cc#L4500
------------------------------------------------------------------------
[2014-10-22 06:08:56] roberto at spadim dot com dot br
here more info about how to use dialog and client:
https://github.com/MariaDB/server/blob/10.1/plugin/auth_dialog/dialog.c
/*
This plugin performs a dialog with the user, asking questions and
reading answers. Depending on the client it may be desirable to do it
using GUI, or console, with or without curses, or read answers
from a smartcard, for example.
To support all this variety, the dialog plugin has a callback function
>>>>>"authentication_dialog_ask"<<<<<. If the client has a
>>>>>function of this name
dialog plugin will use it for communication with the user. Otherwise
a default implementation will be used.
*/
------------------------------------------------------------------------
[2014-10-22 05:58:53] roberto at spadim dot com dot br
Description:
------------
Hi guys, i'm testing mysql connect with a mariadb server using a dialog auth plugin (server
side)
i didn't found functions to execute dialog with server
a full example of what i want but using heidisql can be found here:
http://www.heidisql.com/forum.php?t=9752
---
here the php files (download only .php files):
https://github.com/rspadim/server/blob/otp_plugin/plugin/auth_otp/
here the today output using mysql_connect: (using otp_auth_example.php php file)
==============================
MYSQL_CONNECT:
PHP Warning: mysql_connect(): The server requested authentication
method unknown to the client [dialog] in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_e
xample.php on line 50
Warning: mysql_connect(): The server requested authentication method
unknown to the client [dialog] in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_exampl
e.php on line 50
PHP Warning: mysql_connect(): The server requested authentication
method umknown to the client in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_example.ph
p on line 50
Warning: mysql_connect(): The server requested authentication method
umknown to the client in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_example.php on
line 50
Error: The server requested authentication method >>>umknown<<< to the
client (CHECK A TYPO ERROR)
==============================
MYSQI_CONNECT:
C:\GIT\mariadb-tmp\server\plugin\auth_otp>php otp_auth_example.php
PHP Warning: mysqli_connect(): The server requested authentication
method unknown to the client [dialog] in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_
example.php on line 60
Warning: mysqli_connect(): The server requested authentication method
unknown to the client [dialog] in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_examp
le.php on line 60
PHP Warning: mysqli_connect(): (HY000/2054): The server requested
authentication method umknown to the client in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_
auth_example.php on line 60
Warning: mysqli_connect(): (HY000/2054): The server requested
authentication method umknown to the client in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_
example.php on line 60
PHP Warning: mysqli_error() expects parameter 1 to be mysqli, boolean
given in C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_example.php
on line 62
Warning: mysqli_error() expects parameter 1 to be mysqli, boolean
given in C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_example.php
on line 62
Error:
===============================
PDO:
C:\GIT\mariadb-tmp\server\plugin\auth_otp>php otp_auth_example.php
PHP Warning: PDO::__construct(): The server requested authentication
method unknown to the client [dialog] in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_aut
h_example.php on line 68
Warning: PDO::__construct(): The server requested authentication
method unknown to the client [dialog] in
C:\GIT\mariadb-tmp\server\plugin\auth_otp\otp_auth_exa
mple.php on line 68
Error: SQLSTATE[HY000] [2054] The server requested authentication
method umknown to the client
Test script:
---------------
https://github.com/rspadim/server/blob/otp_plugin/plugin/auth_otp/
download all .php files
otp_auth_example.php
at mariadb server:
INSTALL PLUGIN three_attempts SONAME 'dialog_examples.so';
CREATE USER test_dialog IDENTIFIED VIA three_attempts USING 'SECRET';
try to connect using username = test_dialog, and password='SECRET'
Expected result:
----------------
implement a new feature of dialog connection
three functions must be implemented for <mysql> and <mysqli> extension:
mysql_auth_dialog_received()
mysql_auth_dialog_receive()
mysql_auth_dialog_send()
and maybe at mysql_connect we will need a parameter to call a mysql function, for example
$link = mysql_connect($HOST, $USER, $PASSWORD);
if(mysql_auth_dialog_received($link)){
$tmp=mysql_auth_dialog_receive($link); /*
array(type=>'pass/text',message=>'any message') */
mysql_auth_dialog_send($link,"any message");
}
if($link){
// ok good connection
}else{
// die("can't connect");
}
-------------
with mysqli we could use mysqli_init, mysqli_options, mysqli_realconnect
$db = mysqli_init();
$test = $db->options(MYSQLI_DIALOG_FUNCTION,function(){});
or
$test = $db->options(MYSQLI_DIALOG_FUNCTION,"an_callback_function");
function an_callback_function($db,$type,$message){
return true; /* wait other message */
return false; /* disconnect */
mysqli_auth_dialog_send($db,"message");
}
------------
PDO:
$dbh = new PDO("mysql:host=$HOST;port=$HOST_PORT;dbname=$DB", $USER, $PASSWORD, array(
"MYSQL_DIALOG_AUTH_CALLBACK_FUNCTION" => function(){} ));
or
$dbh = new PDO("mysql:host=$HOST;port=$HOST_PORT;dbname=$DB", $USER, $PASSWORD, array(
"MYSQL_DIALOG_AUTH_CALLBACK_FUNCTION" => "an_callback_function" ));
function an_callback_function($db,$type,$message){
return true; /* wait other message */
return false; /* disconnect */
$db->mysqli_auth_dialog_send($db,"message");
}
Actual result:
--------------
no client side auth dialog interface
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68281&edit=1