Пример #1
0
 /**
  * connects to the database server
  *
  * @param string $user                 user name
  * @param string $password             user password
  * @param bool   $is_controluser       whether this is a control user connection
  * @param array  $server               host/port/socket/persistent
  * @param bool   $auxiliary_connection (when true, don't go back to login if
  *                                     connection fails)
  *
  * @return mixed false on error or a connection object on success
  */
 public function connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false)
 {
     $result = $this->_extension->connect($user, $password, $is_controluser, $server, $auxiliary_connection);
     if ($result) {
         if (!$auxiliary_connection && !$is_controluser) {
             $GLOBALS['dbi']->postConnect($result);
         }
         return $result;
     }
     if ($is_controluser) {
         trigger_error(__('Connection for controluser as defined in your ' . 'configuration failed.'), E_USER_WARNING);
         return false;
     }
     // Do not go back to main login if connection failed
     // (currently used only in unit testing)
     if ($auxiliary_connection) {
         return false;
     }
     PMA_logUser($user, 'mysql-denied');
     $GLOBALS['auth_plugin']->authFails();
     return $result;
 }
Пример #2
0
 /** @var PMA_DatabaseInterface $userlink */
 $userlink = $GLOBALS['dbi']->connect($cfg['Server']['user'], $cfg['Server']['password'], false);
 // Set timestamp for the session, if required.
 if ($cfg['Server']['SessionTimeZone'] != '') {
     $sql_query_tz = 'SET ' . PMA_Util::backquote('time_zone') . ' = ' . '\'' . PMA_Util::sqlAddSlashes($cfg['Server']['SessionTimeZone']) . '\'';
     if (!$userlink->query($sql_query_tz)) {
         $error_message_tz = sprintf(__('Unable to use timezone %1$s for server %2$d. ' . 'Please check your configuration setting for ' . '[em]$cfg[\'Servers\'][%3$d][\'SessionTimeZone\'][/em]. ' . 'phpMyAdmin is currently using the default time zone ' . 'of the database server.'), $cfg['Servers'][$GLOBALS['server']]['SessionTimeZone'], $GLOBALS['server'], $GLOBALS['server']);
         $GLOBALS['error_handler']->addError($error_message_tz, E_USER_WARNING, '', '', false);
     }
 }
 if (!$controllink) {
     $controllink = $userlink;
 }
 $auth_plugin->storeUserCredentials();
 /* Log success */
 PMA_logUser($cfg['Server']['user']);
 if (PMA_MYSQL_INT_VERSION < $cfg['MysqlMinVersion']['internal']) {
     PMA_fatalError(__('You should upgrade to %s %s or later.'), array('MySQL', $cfg['MysqlMinVersion']['human']));
 }
 /**
  * Type handling object.
  */
 if (PMA_DRIZZLE) {
     $GLOBALS['PMA_Types'] = new PMA_Types_Drizzle();
 } else {
     $GLOBALS['PMA_Types'] = new PMA_Types_MySQL();
 }
 if (PMA_DRIZZLE) {
     // DisableIS must be set to false for Drizzle, it maps SHOW commands
     // to INFORMATION_SCHEMA queries anyway so it's fast on large servers
     $cfg['Server']['DisableIS'] = false;
 /**
  * connects to the database server
  *
  * @param string $user                 user name
  * @param string $password             user password
  * @param bool   $is_controluser       whether this is a control user connection
  * @param array  $server               host/port/socket/persistent
  * @param bool   $auxiliary_connection (when true, don't go back to login if
  *                                     connection fails)
  *
  * @return mixed false on error or a connection object on success
  */
 public function connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false)
 {
     $result = $this->_extension->connect($user, $password, $is_controluser, $server, $auxiliary_connection);
     if ($result) {
         if (!$auxiliary_connection && !$is_controluser) {
             $GLOBALS['dbi']->postConnect($result);
         }
         return $result;
     }
     if ($is_controluser) {
         trigger_error(__('Connection for controluser as defined in your ' . 'configuration failed.'), E_USER_WARNING);
         return false;
     }
     // we could be calling $GLOBALS['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) {
         return false;
     }
     PMA_logUser($user, 'mysql-denied');
     $GLOBALS['auth_plugin']->authFails();
     return $result;
 }
Пример #4
0
 /**
  * connects to the database server
  *
  * @param string $user                 mysql user name
  * @param string $password             mysql user password
  * @param bool   $is_controluser       whether this is a control user connection
  * @param array  $server               host/port/socket/persistent
  * @param bool   $auxiliary_connection (when true, don't go back to login if
  *                                     connection fails)
  *
  * @return mixed false on error or a mysqli object on success
  */
 public function connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false)
 {
     global $cfg;
     if ($server) {
         $server_port = empty($server['port']) ? false : (int) $server['port'];
         $server_socket = empty($server['socket']) ? '' : $server['socket'];
         $server['host'] = empty($server['host']) ? 'localhost' : $server['host'];
     } else {
         $server_port = empty($cfg['Server']['port']) ? false : (int) $cfg['Server']['port'];
         $server_socket = empty($cfg['Server']['socket']) ? null : $cfg['Server']['socket'];
     }
     // NULL enables connection to the default socket
     $link = mysqli_init();
     mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true);
     $client_flags = 0;
     /* Optionally compress connection */
     if ($cfg['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) {
         $client_flags |= MYSQLI_CLIENT_COMPRESS;
     }
     /* Optionally enable SSL */
     if ($cfg['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) {
         mysqli_ssl_set($link, $cfg['Server']['ssl_key'], $cfg['Server']['ssl_cert'], $cfg['Server']['ssl_ca'], $cfg['Server']['ssl_ca_path'], $cfg['Server']['ssl_ciphers']);
         $client_flags |= MYSQLI_CLIENT_SSL;
     }
     if (!$server) {
         $return_value = @$this->_realConnect($link, $cfg['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags);
         // Retry with empty password if we're allowed to
         if ($return_value == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) {
             $return_value = @$this->_realConnect($link, $cfg['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags);
         }
     } else {
         $return_value = @$this->_realConnect($link, $server['host'], $user, $password, false, $server_port, $server_socket);
     }
     if ($return_value == false) {
         if ($is_controluser) {
             trigger_error(__('Connection for controluser as defined in your configuration failed.'), E_USER_WARNING);
             return false;
         }
         // we could be calling $GLOBALS['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_logUser($user, 'mysql-denied');
             global $auth_plugin;
             $auth_plugin->authFails();
         } else {
             return false;
         }
     } else {
         $GLOBALS['dbi']->postConnect($link, $is_controluser);
     }
     return $link;
 }
Пример #5
0
 /**
  * connects to the database server
  *
  * @param string $user                 drizzle user name
  * @param string $password             drizzle user password
  * @param bool   $is_controluser       whether this is a control user connection
  * @param array  $server               host/port/socket/persistent
  * @param bool   $auxiliary_connection (when true, don't go back to login if
  *                                     connection fails)
  *
  * @return mixed false on error or a mysqli object on success
  */
 public function connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false)
 {
     global $cfg;
     if ($server) {
         $server_port = empty($server['port']) ? false : (int) $server['port'];
         $server_socket = empty($server['socket']) ? '' : $server['socket'];
         $server['host'] = empty($server['host']) ? 'localhost' : $server['host'];
     } else {
         $server_port = empty($cfg['Server']['port']) ? false : (int) $cfg['Server']['port'];
         $server_socket = empty($cfg['Server']['socket']) ? null : $cfg['Server']['socket'];
     }
     if (strtolower($GLOBALS['cfg']['Server']['connect_type']) == 'tcp') {
         $GLOBALS['cfg']['Server']['socket'] = '';
     }
     $drizzle = new PMA_Drizzle();
     $client_flags = 0;
     /* Optionally compress connection */
     if ($GLOBALS['cfg']['Server']['compress']) {
         $client_flags |= DRIZZLE_CAPABILITIES_COMPRESS;
     }
     /* Optionally enable SSL */
     if ($GLOBALS['cfg']['Server']['ssl']) {
         $client_flags |= DRIZZLE_CAPABILITIES_SSL;
     }
     if (!$server) {
         $link = @$this->_realConnect($drizzle, $cfg['Server']['host'], $server_port, $server_socket, $user, $password, false, $client_flags);
         // Retry with empty password if we're allowed to
         if ($link == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) {
             $link = @$this->_realConnect($drizzle, $cfg['Server']['host'], $server_port, $server_socket, $user, null, false, $client_flags);
         }
     } else {
         $link = @$this->_realConnect($drizzle, $server['host'], $server_port, $server_socket, $user, $password);
     }
     if ($link != false) {
         $GLOBALS['dbi']->postConnect($link, $is_controluser);
         return $link;
     }
     if ($is_controluser) {
         trigger_error(__('Connection for controluser as defined' . ' in your configuration failed.'), E_USER_WARNING);
         return false;
     }
     // we could be calling $GLOBALS['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) {
         return false;
     }
     PMA_logUser($user, 'drizzle-denied');
     global $auth_plugin;
     $auth_plugin->authFails();
     return $link;
 }
 /**
  * connects to the database server
  *
  * @param string $user                 user name
  * @param string $password             user password
  * @param bool   $is_controluser       whether this is a control user connection
  * @param array  $server               host/port/socket/persistent
  * @param bool   $auxiliary_connection (when true, don't go back to login if
  *                                     connection fails)
  *
  * @return mixed false on error or a connection object on success
  */
 public function connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false)
 {
     $error_count = $GLOBALS['error_handler']->countErrors();
     $result = $this->_extension->connect($user, $password, $is_controluser, $server, $auxiliary_connection);
     /* Any errors from connection? */
     if ($GLOBALS['error_handler']->countErrors() > $error_count) {
         $errors = $GLOBALS['error_handler']->sliceErrors($error_count);
         foreach ($errors as $error) {
             trigger_error($error->getMessage(), E_USER_ERROR);
         }
     }
     if ($result) {
         if (!$auxiliary_connection && !$is_controluser) {
             $GLOBALS['dbi']->postConnect($result);
         }
         return $result;
     }
     if ($is_controluser) {
         trigger_error(__('Connection for controluser as defined in your ' . 'configuration failed.'), E_USER_WARNING);
         return false;
     }
     // Do not go back to main login if connection failed
     // (currently used only in unit testing)
     if ($auxiliary_connection) {
         return false;
     }
     PMA_logUser($user, 'mysql-denied');
     $GLOBALS['auth_plugin']->authFails();
     return $result;
 }
Пример #7
0
 /**
  * connects to the database server
  *
  * @param string $user                 mysql user name
  * @param string $password             mysql user password
  * @param bool   $is_controluser       whether this is a control user connection
  * @param array  $server               host/port/socket/persistent
  * @param bool   $auxiliary_connection (when true, don't go back to login if
  *                                     connection fails)
  *
  * @return mixed false on error or a mysqli object on success
  */
 public function connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false)
 {
     global $cfg;
     if ($server) {
         $server_port = empty($server['port']) ? '' : ':' . (int) $server['port'];
         $server_socket = empty($server['socket']) ? '' : ':' . $server['socket'];
     } else {
         $server_port = empty($cfg['Server']['port']) ? '' : ':' . (int) $cfg['Server']['port'];
         $server_socket = empty($cfg['Server']['socket']) ? '' : ':' . $cfg['Server']['socket'];
     }
     $client_flags = 0;
     // always use CLIENT_LOCAL_FILES as defined in mysql_com.h
     // for the case where the client library was not compiled
     // with --enable-local-infile
     $client_flags |= 128;
     /* Optionally compress connection */
     if (defined('MYSQL_CLIENT_COMPRESS') && $cfg['Server']['compress']) {
         $client_flags |= MYSQL_CLIENT_COMPRESS;
     }
     /* Optionally enable SSL */
     if (defined('MYSQL_CLIENT_SSL') && $cfg['Server']['ssl']) {
         $client_flags |= MYSQL_CLIENT_SSL;
     }
     if (!$server) {
         $link = $this->_realConnect($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 = $this->_realConnect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? null : $client_flags);
         }
     } else {
         if (!isset($server['host'])) {
             $link = $this->_realConnect($server_socket, $user, $password, null);
         } else {
             $link = $this->_realConnect($server['host'] . $server_port . $server_socket, $user, $password, null);
         }
     }
     if (empty($link)) {
         if ($is_controluser) {
             trigger_error(__('Connection for controluser as defined' . ' in your configuration failed.'), E_USER_WARNING);
             return false;
         }
         // we could be calling $GLOBALS['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_logUser($user, 'mysql-denied');
             global $auth_plugin;
             $auth_plugin->authFails();
         } else {
             return false;
         }
     }
     // end if
     if (!$server) {
         $GLOBALS['dbi']->postConnect($link, $is_controluser);
     }
     return $link;
 }