One Hat Cyber Team
  • Dir : ~/usr/share/phpmyadmin/libraries/classes/Server/
  • Edit File: Privileges.php
    '; return array($title, $export); } /** * Get HTML for display Add userfieldset * * @param string $db the database * @param string $table the table name * * @return string html output */ public static function getAddUserHtmlFieldset($db = '', $table = '') { if (!$GLOBALS['is_createuser']) { return ''; } $rel_params = array(); $url_params = array( 'adduser' => 1 ); if (!empty($db)) { $url_params['dbname'] = $rel_params['checkprivsdb'] = $db; } if (!empty($table)) { $url_params['tablename'] = $rel_params['checkprivstable'] = $table; } return Template::get('privileges/add_user_fieldset') ->render( array( 'url_params' => $url_params, 'rel_params' => $rel_params ) ); } /** * Get HTML header for display User's properties * * @param boolean $dbname_is_wildcard whether database name is wildcard or not * @param string $url_dbname url database name that urlencode() string * @param string $dbname database name * @param string $username username * @param string $hostname host name * @param string $entity_name entity (table or routine) name * @param string $entity_type optional, type of entity ('table' or 'routine') * * @return string $html_output */ public static function getHtmlHeaderForUserProperties( $dbname_is_wildcard, $url_dbname, $dbname, $username, $hostname, $entity_name, $entity_type='table' ) { $html_output = '

    ' . "\n" . Util::getIcon('b_usredit') . __('Edit privileges:') . ' ' . __('User account'); if (! empty($dbname)) { $html_output .= ' \'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'' . "\n"; $html_output .= ' - '; $html_output .= ($dbname_is_wildcard || is_array($dbname) && count($dbname) > 1) ? __('Databases') : __('Database'); if (! empty($entity_name) && $entity_type === 'table') { $html_output .= ' ' . htmlspecialchars($dbname) . ''; $html_output .= ' - ' . __('Table') . ' ' . htmlspecialchars($entity_name) . ''; } elseif (! empty($entity_name)) { $html_output .= ' ' . htmlspecialchars($dbname) . ''; $html_output .= ' - ' . __('Routine') . ' ' . htmlspecialchars($entity_name) . ''; } else { if (! is_array($dbname)) { $dbname = array($dbname); } $html_output .= ' ' . htmlspecialchars(implode(', ', $dbname)) . ''; } } else { $html_output .= ' \'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'' . "\n"; } $html_output .= '

    ' . "\n"; $cur_user = $GLOBALS['dbi']->getCurrentUser(); $user = $username . '@' . $hostname; // Add a short notice for the user // to remind him that he is editing his own privileges if ($user === $cur_user) { $html_output .= Message::notice( __( 'Note: You are attempting to edit privileges of the ' . 'user with which you are currently logged in.' ) )->getDisplay(); } return $html_output; } /** * Get HTML snippet for display user overview page * * @param string $pmaThemeImage a image source link * @param string $text_dir text directory * * @return string $html_output */ public static function getHtmlForUserOverview($pmaThemeImage, $text_dir) { $html_output = '

    ' . "\n" . Util::getIcon('b_usrlist') . __('User accounts overview') . "\n" . '

    ' . "\n"; $password_column = 'Password'; $server_type = Util::getServerType(); $serverVersion = $GLOBALS['dbi']->getVersion(); if (($server_type == 'MySQL' || $server_type == 'Percona Server') && $serverVersion >= 50706 ) { $password_column = 'authentication_string'; } // $sql_query is for the initial-filtered, // $sql_query_all is for counting the total no. of users $sql_query = $sql_query_all = 'SELECT *,' . " IF(`" . $password_column . "` = _latin1 '', 'N', 'Y') AS 'Password'" . ' FROM `mysql`.`user`'; $sql_query .= (isset($_GET['initial']) ? self::rangeOfUsers($_GET['initial']) : ''); $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; $sql_query_all .= ' ;'; $res = $GLOBALS['dbi']->tryQuery( $sql_query, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); $res_all = $GLOBALS['dbi']->tryQuery( $sql_query_all, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); if (! $res) { // the query failed! This may have two reasons: // - the user does not have enough privileges // - the privilege tables use a structure of an earlier version. // so let's try a more simple query $GLOBALS['dbi']->freeResult($res); $GLOBALS['dbi']->freeResult($res_all); $sql_query = 'SELECT * FROM `mysql`.`user`'; $res = $GLOBALS['dbi']->tryQuery( $sql_query, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); if (! $res) { $html_output .= self::getHtmlForViewUsersError(); $html_output .= self::getAddUserHtmlFieldset(); } else { // This message is hardcoded because I will replace it by // a automatic repair feature soon. $raw = 'Your privilege table structure seems to be older than' . ' this MySQL version!
    ' . 'Please run the mysql_upgrade command' . ' that should be included in your MySQL server distribution' . ' to solve this problem!'; $html_output .= Message::rawError($raw)->getDisplay(); } $GLOBALS['dbi']->freeResult($res); } else { $db_rights = self::getDbRightsForUserOverview(); // for all initials, even non A-Z $array_initials = array(); foreach ($db_rights as $right) { foreach ($right as $account) { if (empty($account['User']) && $account['Host'] == 'localhost') { $html_output .= Message::notice( __( 'A user account allowing any user from localhost to ' . 'connect is present. This will prevent other users ' . 'from connecting if the host part of their account ' . 'allows a connection from any (%) host.' ) . Util::showMySQLDocu('problems-connecting') )->getDisplay(); break 2; } } } /** * Displays the initials * Also not necessary if there is less than 20 privileges */ if ($GLOBALS['dbi']->numRows($res_all) > 20) { $html_output .= self::getHtmlForInitials($array_initials); } /** * Display the user overview * (if less than 50 users, display them immediately) */ if (isset($_GET['initial']) || isset($_GET['showall']) || $GLOBALS['dbi']->numRows($res) < 50 ) { $html_output .= self::getUsersOverview( $res, $db_rights, $pmaThemeImage, $text_dir ); } else { $html_output .= self::getAddUserHtmlFieldset(); } // end if (display overview) $response = Response::getInstance(); if (! $response->isAjax() || ! empty($_REQUEST['ajax_page_request']) ) { if ($GLOBALS['is_reload_priv']) { $flushnote = new Message( __( 'Note: phpMyAdmin gets the users’ privileges directly ' . 'from MySQL’s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'you should %sreload the privileges%s before you continue.' ), Message::NOTICE ); $flushnote->addParamHtml( '' ); $flushnote->addParamHtml(''); } else { $flushnote = new Message( __( 'Note: phpMyAdmin gets the users’ privileges directly ' . 'from MySQL’s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'the privileges have to be reloaded but currently, you ' . 'don\'t have the RELOAD privilege.' ) . Util::showMySQLDocu( 'privileges-provided', false, 'priv_reload' ), Message::NOTICE ); } $html_output .= $flushnote->getDisplay(); } } return $html_output; } /** * Get HTML snippet for display user properties * * @param boolean $dbname_is_wildcard whether database name is wildcard or not * @param string $url_dbname url database name that urlencode() string * @param string $username username * @param string $hostname host name * @param string $dbname database name * @param string $tablename table name * * @return string $html_output */ public static function getHtmlForUserProperties($dbname_is_wildcard, $url_dbname, $username, $hostname, $dbname, $tablename ) { $html_output = '
    '; $html_output .= self::getHtmlHeaderForUserProperties( $dbname_is_wildcard, $url_dbname, $dbname, $username, $hostname, $tablename, 'table' ); $sql = "SELECT '1' FROM `mysql`.`user`" . " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'" . " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "';"; $user_does_not_exists = (bool) ! $GLOBALS['dbi']->fetchValue($sql); if ($user_does_not_exists) { $html_output .= Message::error( __('The selected user was not found in the privilege table.') )->getDisplay(); $html_output .= self::getHtmlForLoginInformationFields(); } $_params = array( 'username' => $username, 'hostname' => $hostname, ); if (! is_array($dbname) && strlen($dbname) > 0) { $_params['dbname'] = $dbname; if (strlen($tablename) > 0) { $_params['tablename'] = $tablename; } } else { $_params['dbname'] = $dbname; } $html_output .= '' . "\n"; $html_output .= Url::getHiddenInputs($_params); $html_output .= self::getHtmlToDisplayPrivilegesTable( // If $dbname is an array, pass any one db as all have same privs. Core::ifSetOr($dbname, (is_array($dbname)) ? $dbname[0] : '*', 'length'), Core::ifSetOr($tablename, '*', 'length') ); $html_output .= '' . "\n"; if (! is_array($dbname) && strlen($tablename) === 0 && empty($dbname_is_wildcard) ) { // no table name was given, display all table specific rights // but only if $dbname contains no wildcards if (strlen($dbname) === 0) { $html_output .= self::getHtmlForAllTableSpecificRights( $username, $hostname, 'database' ); } else { // unescape wildcards in dbname at table level $unescaped_db = Util::unescapeMysqlWildcards($dbname); $html_output .= self::getHtmlForAllTableSpecificRights( $username, $hostname, 'table', $unescaped_db ); $html_output .= self::getHtmlForAllTableSpecificRights( $username, $hostname, 'routine', $unescaped_db ); } } // Provide a line with links to the relevant database and table if (! is_array($dbname) && strlen($dbname) > 0 && empty($dbname_is_wildcard)) { $html_output .= self::getLinkToDbAndTable($url_dbname, $dbname, $tablename); } if (! is_array($dbname) && strlen($dbname) === 0 && ! $user_does_not_exists) { //change login information $html_output .= ChangePassword::getHtml( 'edit_other', $username, $hostname ); $html_output .= self::getChangeLoginInformationHtmlForm($username, $hostname); } $html_output .= '
    '; return $html_output; } /** * Get queries for Table privileges to change or copy user * * @param string $user_host_condition user host condition to * select relevant table privileges * @param array $queries queries array * @param string $username username * @param string $hostname host name * * @return array $queries */ public static function getTablePrivsQueriesForChangeOrCopyUser($user_host_condition, array $queries, $username, $hostname ) { $res = $GLOBALS['dbi']->query( 'SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv`' . $user_host_condition, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { $res2 = $GLOBALS['dbi']->query( 'SELECT `Column_name`, `Column_priv`' . ' FROM `mysql`.`columns_priv`' . ' WHERE `User`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_username']) . "'" . ' AND `Host`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_username']) . '\'' . ' AND `Db`' . ' = \'' . $GLOBALS['dbi']->escapeString($row['Db']) . "'" . ' AND `Table_name`' . ' = \'' . $GLOBALS['dbi']->escapeString($row['Table_name']) . "'" . ';', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); $tmp_privs1 = self::extractPrivInfo($row); $tmp_privs2 = array( 'Select' => array(), 'Insert' => array(), 'Update' => array(), 'References' => array() ); while ($row2 = $GLOBALS['dbi']->fetchAssoc($res2)) { $tmp_array = explode(',', $row2['Column_priv']); if (in_array('Select', $tmp_array)) { $tmp_privs2['Select'][] = $row2['Column_name']; } if (in_array('Insert', $tmp_array)) { $tmp_privs2['Insert'][] = $row2['Column_name']; } if (in_array('Update', $tmp_array)) { $tmp_privs2['Update'][] = $row2['Column_name']; } if (in_array('References', $tmp_array)) { $tmp_privs2['References'][] = $row2['Column_name']; } } if (count($tmp_privs2['Select']) > 0 && ! in_array('SELECT', $tmp_privs1)) { $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)'; } if (count($tmp_privs2['Insert']) > 0 && ! in_array('INSERT', $tmp_privs1)) { $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)'; } if (count($tmp_privs2['Update']) > 0 && ! in_array('UPDATE', $tmp_privs1)) { $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)'; } if (count($tmp_privs2['References']) > 0 && ! in_array('REFERENCES', $tmp_privs1) ) { $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)'; } $queries[] = 'GRANT ' . join(', ', $tmp_privs1) . ' ON ' . Util::backquote($row['Db']) . '.' . Util::backquote($row['Table_name']) . ' TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\'' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION;' : ';'); } return $queries; } /** * Get queries for database specific privileges for change or copy user * * @param array $queries queries array with string * @param string $username username * @param string $hostname host name * * @return array $queries */ public static function getDbSpecificPrivsQueriesForChangeOrCopyUser( array $queries, $username, $hostname ) { $user_host_condition = ' WHERE `User`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_username']) . "'" . ' AND `Host`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_hostname']) . '\';'; $res = $GLOBALS['dbi']->query( 'SELECT * FROM `mysql`.`db`' . $user_host_condition ); while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { $queries[] = 'GRANT ' . join(', ', self::extractPrivInfo($row)) . ' ON ' . Util::backquote($row['Db']) . '.*' . ' TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\'' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';'); } $GLOBALS['dbi']->freeResult($res); $queries = self::getTablePrivsQueriesForChangeOrCopyUser( $user_host_condition, $queries, $username, $hostname ); return $queries; } /** * Prepares queries for adding users and * also create database and return query and message * * @param boolean $_error whether user create or not * @param string $real_sql_query SQL query for add a user * @param string $sql_query SQL query to be displayed * @param string $username username * @param string $hostname host name * @param string $dbname database name * @param string $alter_real_sql_query SQL query for ALTER USER * @param string $alter_sql_query SQL query for ALTER USER to be displayed * * @return array $sql_query, $message */ public static function addUserAndCreateDatabase( $_error, $real_sql_query, $sql_query, $username, $hostname, $dbname, $alter_real_sql_query, $alter_sql_query ) { if ($_error || (!empty($real_sql_query) && !$GLOBALS['dbi']->tryQuery($real_sql_query)) ) { $_POST['createdb-1'] = $_POST['createdb-2'] = $_POST['createdb-3'] = null; $message = Message::rawError($GLOBALS['dbi']->getError()); } elseif ($alter_real_sql_query !== '' && !$GLOBALS['dbi']->tryQuery($alter_real_sql_query)) { $_POST['createdb-1'] = $_POST['createdb-2'] = $_POST['createdb-3'] = null; $message = Message::rawError($GLOBALS['dbi']->getError()); } else { $sql_query .= $alter_sql_query; $message = Message::success(__('You have added a new user.')); } if (isset($_POST['createdb-1'])) { // Create database with same name and grant all privileges $q = 'CREATE DATABASE IF NOT EXISTS ' . Util::backquote( $GLOBALS['dbi']->escapeString($username) ) . ';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } /** * Reload the navigation */ $GLOBALS['reload'] = true; $GLOBALS['db'] = $username; $q = 'GRANT ALL PRIVILEGES ON ' . Util::backquote( Util::escapeMysqlWildcards( $GLOBALS['dbi']->escapeString($username) ) ) . '.* TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } } if (isset($_POST['createdb-2'])) { // Grant all privileges on wildcard name (username\_%) $q = 'GRANT ALL PRIVILEGES ON ' . Util::backquote( Util::escapeMysqlWildcards( $GLOBALS['dbi']->escapeString($username) ) . '\_%' ) . '.* TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } } if (isset($_POST['createdb-3'])) { // Grant all privileges on the specified database to the new user $q = 'GRANT ALL PRIVILEGES ON ' . Util::backquote( $GLOBALS['dbi']->escapeString($dbname) ) . '.* TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } } return array($sql_query, $message); } /** * Get the hashed string for password * * @param string $password password * * @return string $hashedPassword */ public static function getHashedPassword($password) { $password = $GLOBALS['dbi']->escapeString($password); $result = $GLOBALS['dbi']->fetchSingleRow( "SELECT PASSWORD('" . $password . "') AS `password`;" ); $hashedPassword = $result['password']; return $hashedPassword; } /** * Check if MariaDB's 'simple_password_check' * OR 'cracklib_password_check' is ACTIVE * * @return boolean if atleast one of the plugins is ACTIVE */ public static function checkIfMariaDBPwdCheckPluginActive() { $serverVersion = $GLOBALS['dbi']->getVersion(); if (!(Util::getServerType() == 'MariaDB' && $serverVersion >= 100002)) { return false; } $result = $GLOBALS['dbi']->tryQuery( 'SHOW PLUGINS SONAME LIKE \'%_password_check%\'' ); /* Plugins are not working, for example directory does not exists */ if ($result === false) { return false; } while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if ($row['Status'] === 'ACTIVE') { return true; } } return false; } /** * Get SQL queries for Display and Add user * * @param string $username username * @param string $hostname host name * @param string $password password * * @return array ($create_user_real, $create_user_show, $real_sql_query, $sql_query * $password_set_real, $password_set_show, $alter_real_sql_query, $alter_sql_query) */ public static function getSqlQueriesForDisplayAndAddUser($username, $hostname, $password) { $slashedUsername = $GLOBALS['dbi']->escapeString($username); $slashedHostname = $GLOBALS['dbi']->escapeString($hostname); $slashedPassword = $GLOBALS['dbi']->escapeString($password); $serverType = Util::getServerType(); $serverVersion = $GLOBALS['dbi']->getVersion(); $create_user_stmt = sprintf( 'CREATE USER \'%s\'@\'%s\'', $slashedUsername, $slashedHostname ); $isMariaDBPwdPluginActive = self::checkIfMariaDBPwdCheckPluginActive(); // See https://github.com/phpmyadmin/phpmyadmin/pull/11560#issuecomment-147158219 // for details regarding details of syntax usage for various versions // 'IDENTIFIED WITH auth_plugin' // is supported by MySQL 5.5.7+ if (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 50507 && isset($_POST['authentication_plugin']) ) { $create_user_stmt .= ' IDENTIFIED WITH ' . $_POST['authentication_plugin']; } // 'IDENTIFIED VIA auth_plugin' // is supported by MariaDB 5.2+ if ($serverType == 'MariaDB' && $serverVersion >= 50200 && isset($_POST['authentication_plugin']) && ! $isMariaDBPwdPluginActive ) { $create_user_stmt .= ' IDENTIFIED VIA ' . $_POST['authentication_plugin']; } $create_user_real = $create_user_show = $create_user_stmt; $password_set_stmt = 'SET PASSWORD FOR \'%s\'@\'%s\' = \'%s\''; $password_set_show = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, '***' ); $sql_query_stmt = sprintf( 'GRANT %s ON *.* TO \'%s\'@\'%s\'', join(', ', self::extractPrivInfo()), $slashedUsername, $slashedHostname ); $real_sql_query = $sql_query = $sql_query_stmt; // Set the proper hashing method if (isset($_POST['authentication_plugin'])) { self::setProperPasswordHashing( $_POST['authentication_plugin'] ); } // Use 'CREATE USER ... WITH ... AS ..' syntax for // newer MySQL versions // and 'CREATE USER ... VIA .. USING ..' syntax for // newer MariaDB versions if ((($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 50706) || ($serverType == 'MariaDB' && $serverVersion >= 50200) ) { $password_set_real = null; // Required for binding '%' with '%s' $create_user_stmt = str_replace( '%', '%%', $create_user_stmt ); // MariaDB uses 'USING' whereas MySQL uses 'AS' // but MariaDB with validation plugin needs cleartext password if ($serverType == 'MariaDB' && ! $isMariaDBPwdPluginActive ) { $create_user_stmt .= ' USING \'%s\''; } elseif ($serverType == 'MariaDB') { $create_user_stmt .= ' IDENTIFIED BY \'%s\''; } elseif (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011) { $create_user_stmt .= ' BY \'%s\''; } else { $create_user_stmt .= ' AS \'%s\''; } if ($_POST['pred_password'] == 'keep') { $create_user_real = sprintf( $create_user_stmt, $slashedPassword ); $create_user_show = sprintf( $create_user_stmt, '***' ); } elseif ($_POST['pred_password'] == 'none') { $create_user_real = sprintf( $create_user_stmt, null ); $create_user_show = sprintf( $create_user_stmt, '***' ); } else { if (! (($serverType == 'MariaDB' && $isMariaDBPwdPluginActive) || ($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011)) { $hashedPassword = self::getHashedPassword($_POST['pma_pw']); } else { // MariaDB with validation plugin needs cleartext password $hashedPassword = $_POST['pma_pw']; } $create_user_real = sprintf( $create_user_stmt, $hashedPassword ); $create_user_show = sprintf( $create_user_stmt, '***' ); } } else { // Use 'SET PASSWORD' syntax for pre-5.7.6 MySQL versions // and pre-5.2.0 MariaDB versions if ($_POST['pred_password'] == 'keep') { $password_set_real = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, $slashedPassword ); } elseif ($_POST['pred_password'] == 'none') { $password_set_real = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, null ); } else { $hashedPassword = self::getHashedPassword($_POST['pma_pw']); $password_set_real = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, $hashedPassword ); } } $alter_real_sql_query = ''; $alter_sql_query = ''; if (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011) { $sql_query_stmt = ''; if ((isset($_POST['Grant_priv']) && $_POST['Grant_priv'] == 'Y') || (isset($GLOBALS['Grant_priv']) && $GLOBALS['Grant_priv'] == 'Y') ) { $sql_query_stmt = ' WITH GRANT OPTION'; } $real_sql_query .= $sql_query_stmt; $sql_query .= $sql_query_stmt; $alter_sql_query_stmt = sprintf( 'ALTER USER \'%s\'@\'%s\'', $slashedUsername, $slashedHostname ); $alter_real_sql_query = $alter_sql_query_stmt; $alter_sql_query = $alter_sql_query_stmt; } // add REQUIRE clause $require_clause = self::getRequireClause(); $with_clause = self::getWithClauseForAddUserAndUpdatePrivs(); if (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011) { $alter_real_sql_query .= $require_clause; $alter_sql_query .= $require_clause; $alter_real_sql_query .= $with_clause; $alter_sql_query .= $with_clause; } else { $real_sql_query .= $require_clause; $sql_query .= $require_clause; $real_sql_query .= $with_clause; $sql_query .= $with_clause; } if (isset($create_user_real)) { $create_user_real .= ';'; $create_user_show .= ';'; } if ($alter_real_sql_query !== '') { $alter_real_sql_query .= ';'; $alter_sql_query .= ';'; } $real_sql_query .= ';'; $sql_query .= ';'; // No Global GRANT_OPTION privilege if (!$GLOBALS['is_grantuser']) { $real_sql_query = ''; $sql_query = ''; } // Use 'SET PASSWORD' for pre-5.7.6 MySQL versions // and pre-5.2.0 MariaDB if (($serverType == 'MySQL' && $serverVersion >= 50706) || ($serverType == 'MariaDB' && $serverVersion >= 50200) ) { $password_set_real = null; $password_set_show = null; } else { if ($password_set_real !== null) { $password_set_real .= ";"; } $password_set_show .= ";"; } return array( $create_user_real, $create_user_show, $real_sql_query, $sql_query, $password_set_real, $password_set_show, $alter_real_sql_query, $alter_sql_query ); } /** * Returns the type ('PROCEDURE' or 'FUNCTION') of the routine * * @param string $dbname database * @param string $routineName routine * * @return string type */ public static function getRoutineType($dbname, $routineName) { $routineData = $GLOBALS['dbi']->getRoutines($dbname); foreach ($routineData as $routine) { if ($routine['name'] === $routineName) { return $routine['type']; } } return ''; } }