From 9ae329e4ad604dfc77a2916fabc1e69a16b51e06 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Fri, 16 Oct 2009 00:32:42 +0000 Subject: [PATCH] in Synchronize, the connection problems detection no longer worked --- libraries/dbi/mysql.dbi.lib.php | 37 ++++++++++++++++++++------------ libraries/dbi/mysqli.dbi.lib.php | 29 +++++++++++++++---------- server_synchronize.php | 8 +++---- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index 55dd8a3bb..cac41fca1 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -46,9 +46,10 @@ function PMA_DBI_real_connect($server, $user, $password, $client_flags, $persist * @param string $password mysql user password * @param boolean $is_controluser * @param array $server host/port/socket/persistant + * @param boolean $auxiliary_connection (if fails, don't go back to login) * @return mixed false on error or a mysqli object on success */ -function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null) +function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false) { global $cfg, $php_errormsg; @@ -93,29 +94,37 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu } if (!$server) { - $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); + $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); // Retry with empty password if we're allowed to - if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { - $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); - } + if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { + $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); + } } else { - if (!isset($server['host'])) - $link = PMA_DBI_real_connect($server_socket, $user, $password, NULL, $server_persistant); - else - $link = PMA_DBI_real_connect($server['host'] . $server_port . $server_socket, $user, $password, NULL, $server_persistant); + if (!isset($server['host'])) { + $link = PMA_DBI_real_connect($server_socket, $user, $password, NULL, $server_persistant); + } else { + $link = PMA_DBI_real_connect($server['host'] . $server_port . $server_socket, $user, $password, NULL, $server_persistant); + } } if (empty($link)) { if ($is_controluser) { trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); return false; } - PMA_log_user($user, 'mysql-denied'); - PMA_auth_fails(); + // we could be calling PMA_DBI_connect() to connect to another + // server, for example in the Synchronize feature, so do not + // go back to main login if it fails + if (! $auxiliary_connection) { + PMA_log_user($user, 'mysql-denied'); + PMA_auth_fails(); + } else { + return false; + } } // end if - if (!$server) - PMA_DBI_postConnect($link, $is_controluser); - + if (! $server) { + PMA_DBI_postConnect($link, $is_controluser); + } return $link; } diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index bc8306814..7e5d2cdfb 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -55,9 +55,10 @@ if (! defined('MYSQLI_TYPE_BIT')) { * @param string $password mysql user password * @param boolean $is_controluser * @param array $server host/port/socket + * @param boolean $auxiliary_connection (if fails, don't go back to login) * @return mixed false on error or a mysqli object on success */ -function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null) +function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false) { if ($server) { $server_port = (empty($server['port'])) @@ -85,7 +86,6 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu // NULL enables connection to the default socket - $link = mysqli_init(); mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true); @@ -114,15 +114,22 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu } if ($return_value == false) { - if ($is_controluser) { - trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); - return false; - } - PMA_log_user($user, 'mysql-denied'); - PMA_auth_fails(); - } // end if - - PMA_DBI_postConnect($link, $is_controluser); + if ($is_controluser) { + trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); + return false; + } + // we could be calling PMA_DBI_connect() to connect to another + // server, for example in the Synchronize feature, so do not + // go back to main login if it fails + if (! $auxiliary_connection) { + PMA_log_user($user, 'mysql-denied'); + PMA_auth_fails(); + } else { + return false; + } + } else { + PMA_DBI_postConnect($link, $is_controluser); + } return $link; } diff --git a/server_synchronize.php b/server_synchronize.php index bf46b3e57..b3b0d2e6c 100644 --- a/server_synchronize.php +++ b/server_synchronize.php @@ -80,20 +80,20 @@ if ((isset($_REQUEST['submit_connect']))) { } } - ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}); + ${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true); } // end foreach ($cons as $con) - if ((! $src_connection && $src_type=='rmt') || (! $trg_connection && $trg_type=='rmt')) { + if ((! $src_connection && $src_type == 'rmt') || (! $trg_connection && $trg_type == 'rmt')) { /** * Displays the connection error string if * connections are not established */ echo '
' . "\n" ; - if(! $src_connection) { + if(! $src_connection && $src_type == 'rmt') { echo $GLOBALS['strCouldNotConnectSource'].'
'; } - if(! $trg_connection){ + if(! $trg_connection && $trg_type == 'rmt'){ echo $GLOBALS['strCouldNotConnectTarget']; } echo '
';