' . "\n" . ' ' . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') . ' ' . $GLOBALS['strPrivileges'] . "\n" . '' . "\n" . $GLOBALS['strNoPrivileges'] . "\n"; require_once('./footer.inc.php'); } /** * Extracts the privilege information of a priv table row * * @param array $row the row * @param boolean $enableHTML add tag with tooltips * * @global ressource $user_link the database connection * * @return array */ function PMA_extractPrivInfo($row = '', $enableHTML = FALSE) { $grants = array( array('Select_priv', 'SELECT', $GLOBALS['strPrivDescSelect']), array('Insert_priv', 'INSERT', $GLOBALS['strPrivDescInsert']), array('Update_priv', 'UPDATE', $GLOBALS['strPrivDescUpdate']), array('Delete_priv', 'DELETE', $GLOBALS['strPrivDescDelete']), array('Create_priv', 'CREATE', $GLOBALS['strPrivDescCreateDb']), array('Drop_priv', 'DROP', $GLOBALS['strPrivDescDropDb']), array('Reload_priv', 'RELOAD', $GLOBALS['strPrivDescReload']), array('Shutdown_priv', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']), array('Process_priv', 'PROCESS', $GLOBALS['strPrivDescProcess' . ((!empty($row) && isset($row['Super_priv'])) || (empty($row) && isset($GLOBALS['Super_priv'])) ? '4' : '3')]), array('File_priv', 'FILE', $GLOBALS['strPrivDescFile']), array('References_priv', 'REFERENCES', $GLOBALS['strPrivDescReferences']), array('Index_priv', 'INDEX', $GLOBALS['strPrivDescIndex']), array('Alter_priv', 'ALTER', $GLOBALS['strPrivDescAlter']), array('Show_db_priv', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']), array('Super_priv', 'SUPER', $GLOBALS['strPrivDescSuper']), array('Create_tmp_table_priv', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']), array('Lock_tables_priv', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']), array('Repl_slave_priv', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']), array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']), array('Create_view_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']), // for table privs: array('Create View_priv', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']), array('Show_view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']), // for table privs: array('Show view_priv', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']), array('Create_routine_priv', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']), array('Alter_routine_priv', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']), array('Create_user_priv', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']) ); if (PMA_MYSQL_INT_VERSION >= 40002 && PMA_MYSQL_INT_VERSION <50003) { $grants[] = array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute']); } else { $grants[] = array('Execute_priv', 'EXECUTE', $GLOBALS['strPrivDescExecute5']); } if (!empty($row) && isset($row['Table_priv'])) { $res = PMA_DBI_query('SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', $GLOBALS['userlink']); $row1 = PMA_DBI_fetch_assoc($res); PMA_DBI_free_result($res); $av_grants = explode ('\',\'' , substr($row1['Type'], 5, strlen($row1['Type']) - 7)); unset($row1); $users_grants = explode(',', $row['Table_priv']); foreach ($av_grants as $current_grant) { $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; } unset($current_grant); unset($av_grants); unset($users_grants); } $privs = array(); $allPrivileges = TRUE; foreach ($grants as $current_grant) { if ((!empty($row) && isset($row[$current_grant[0]])) || (empty($row) && isset($GLOBALS[$current_grant[0]]))) { if ((!empty($row) && $row[$current_grant[0]] == 'Y') || (empty($row) && ($GLOBALS[$current_grant[0]] == 'Y' || (is_array($GLOBALS[$current_grant[0]]) && count($GLOBALS[$current_grant[0]]) == $GLOBALS['column_count'] && empty($GLOBALS[$current_grant[0] . '_none']))))) { if ($enableHTML) { $privs[] = '' . $current_grant[1] . ''; } else { $privs[] = $current_grant[1]; } } else if (!empty($GLOBALS[$current_grant[0]]) && is_array($GLOBALS[$current_grant[0]]) && empty($GLOBALS[$current_grant[0] . '_none'])) { if ($enableHTML) { $priv_string = '' . $current_grant[1] . ''; } else { $priv_string = $current_grant[1]; } $privs[] = $priv_string . ' (`' . join('`, `', $GLOBALS[$current_grant[0]]) . '`)'; } else { $allPrivileges = FALSE; } } } if (empty($privs)) { if ($enableHTML) { $privs[] = 'USAGE'; } else { $privs[] = 'USAGE'; } } else if ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) { if ($enableHTML) { $privs = array('ALL PRIVILEGES'); } else { $privs = array('ALL PRIVILEGES'); } } return $privs; } // end of the 'PMA_extractPrivInfo()' function /** * Displays on which column(s) a table-specific privilege is granted */ function PMA_display_column_privs($spaces, $columns, $row, $name_for_select, $priv_for_header, $name, $name_for_dfn, $name_for_current) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . $GLOBALS['strOr'] . '' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n"; } // end function /** * Displays the privileges form table * * @param string $db the database * @param string $table the table * @param boolean $submit wheather to display the submit button or not * @param int $indent the indenting level of the code * * @global array $cfg the phpMyAdmin configuration * @global ressource $user_link the database connection * * @return void */ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0) { if ($db == '*') { $table = '*'; } $spaces = str_repeat( ' ', $indent ); if (isset($GLOBALS['username'])) { $username = $GLOBALS['username']; $hostname = $GLOBALS['hostname']; if ($db == '*') { $sql_query = 'SELECT * FROM `mysql`.`user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';'; } else if ($table == '*') { $sql_query = 'SELECT * FROM `mysql`.`db` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($db, 'quoted') . ';'; } else { $sql_query = 'SELECT `Table_priv` FROM `mysql`.`tables_priv` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' .PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($db, 'quoted') . ' AND ' . PMA_convert_using('Table_name') . ' = ' . PMA_convert_using($table, 'quoted') . ';'; } $res = PMA_DBI_query($sql_query); $row = PMA_DBI_fetch_assoc($res); PMA_DBI_free_result($res); } if (empty($row)) { if ($table == '*') { if ($db == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;'; } else if ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } $res = PMA_DBI_query($sql_query); while ($row1 = PMA_DBI_fetch_row($res)) { if (substr($row1[0], 0, 4) == 'max_') { $row[$row1[0]] = 0; } else { $row[$row1[0]] = 'N'; } } PMA_DBI_free_result($res); } else { $row = array('Table_priv' => ''); } } if (isset($row['Table_priv'])) { $res = PMA_DBI_query('SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', $GLOBALS['userlink']); // note: in MySQL 5.0.3 we get "Create View', 'Show view'; // the View for Create is spelled with uppercase V // the view for Show is spelled with lowercase v // and there is a space between the words $row1 = PMA_DBI_fetch_assoc($res); PMA_DBI_free_result($res); $av_grants = explode ('\',\'' , substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3)); unset($res, $row1); $users_grants = explode(',', $row['Table_priv']); foreach ($av_grants as $current_grant) { $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; } unset($row['Table_priv'], $current_grant, $av_grants, $users_grants); $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;'); $columns = array(); if ($res) { while ($row1 = PMA_DBI_fetch_row($res)) { $columns[$row1[0]] = array( 'Select' => FALSE, 'Insert' => FALSE, 'Update' => FALSE, 'References' => FALSE ); } PMA_DBI_free_result($res); } unset($res, $row1); } // t a b l e - s p e c i f i c p r i v i l e g e s if (!empty($columns)) { $res = PMA_DBI_QUERY('SELECT `Column_name`, `Column_priv` FROM `mysql`.`columns_priv` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($db, 'quoted') . ' AND ' . PMA_convert_using('Table_name') . ' = ' . PMA_convert_using($table, 'quoted') . ';'); while ($row1 = PMA_DBI_fetch_row($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { $columns[$row1[0]][$current] = TRUE; } } PMA_DBI_free_result($res); unset($res); unset($row1); unset($current); echo $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . $GLOBALS['strTblPrivileges'] . '' . "\n" . $spaces . '

' . $GLOBALS['strEnglishPrivileges'] . '

' . "\n"; // privs that are attached to a specific column PMA_display_column_privs($spaces, $columns, $row, 'Select_priv', 'SELECT', 'select', $GLOBALS['strPrivDescSelect'], 'Select'); PMA_display_column_privs($spaces, $columns, $row, 'Insert_priv', 'INSERT', 'insert', $GLOBALS['strPrivDescInsert'], 'Insert'); PMA_display_column_privs($spaces, $columns, $row, 'Update_priv', 'UPDATE', 'update', $GLOBALS['strPrivDescUpdate'], 'Update'); PMA_display_column_privs($spaces, $columns, $row, 'References_priv', 'REFERENCES', 'references', $GLOBALS['strPrivDescReferences'], 'References'); // privs that are not attached to a specific column foreach($row as $current_grant => $current_grant_value) { if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) { continue; } // make a substitution to match the messages variables; // also we must substitute the grant we get, because we can't generate // a form variable containing blanks (those would get changed to // an underscore when receiving the POST) if ($current_grant == 'Create View_priv') { $tmp_current_grant = 'CreateView_priv'; $current_grant = 'Create_view_priv'; } elseif ($current_grant == 'Show view_priv') { $tmp_current_grant = 'ShowView_priv'; $current_grant = 'Show_view_priv'; } else { $tmp_current_grant = $current_grant; } echo $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . "\n"; echo $spaces . ' ' . "\n" . $spaces . '
' . "\n"; } // end foreach() echo $spaces . '
' . "\n"; } else { // g l o b a l o r d b - s p e c i f i c // // d a t a $privTable[0] = array( array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']), array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']), array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']), array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete']) ); if ($db == '*') { $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']); } // s t r u c t u r e $privTable[1] = array( array('Create', 'CREATE', ($table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl'])), array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']), array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']), array('Drop', 'DROP', ($table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl'])) ); if (isset($row['Create_tmp_table_priv'])) { $privTable[1][] = array('Create_tmp_table', 'CREATE TEMPORARY TABLES', $GLOBALS['strPrivDescCreateTmpTable']); } // this one is for a db-specific priv: Create_view_priv if (isset($row['Create_view_priv'])) { $privTable[1][] = array('Create_view', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']); } // this one is for a table-specific priv: Create View_priv if (isset($row['Create View_priv'])) { $privTable[1][] = array('Create View', 'CREATE VIEW', $GLOBALS['strPrivDescCreateView']); } if (isset($row['Show_view_priv'])) { $privTable[1][] = array('Show_view', 'SHOW VIEW', $GLOBALS['strPrivDescShowView']); } if (isset($row['Create_routine_priv'])) { $privTable[1][] = array('Create_routine', 'CREATE ROUTINE', $GLOBALS['strPrivDescCreateRoutine']); } if (isset($row['Alter_routine_priv'])) { $privTable[1][] = array('Alter_routine', 'ALTER ROUTINE', $GLOBALS['strPrivDescAlterRoutine']); } if (isset($row['Execute_priv'])) { if (PMA_MYSQL_INT_VERSION >= 40002 && PMA_MYSQL_INT_VERSION <50003) { $privTable[1][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']); } else { $privTable[1][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute5']); } } // a d m i n i s t r a t i o n $privTable[2] = array(); if (isset($row['Grant_priv'])) { $privTable[2][] = array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']); } if ($db == '*') { if (isset($row['Super_priv'])) { $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']); $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess4']); } else { $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess3']); } $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']); $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']); if (isset($row['Show_db_priv'])) { $privTable[2][] = array('Show_db', 'SHOW DATABASES', $GLOBALS['strPrivDescShowDb']); } } if (isset($row['Lock_tables_priv'])) { $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $GLOBALS['strPrivDescLockTables']); } $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']); if ($db == '*') { //if (isset($row['Execute_priv'])) { // $privTable[2][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']); //} if (isset($row['Repl_client_priv'])) { $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']); } if (isset($row['Repl_slave_priv'])) { $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', $GLOBALS['strPrivDescReplSlave']); } if (isset($row['Create_user_priv'])) { $privTable[2][] = array('Create_user', 'CREATE USER', $GLOBALS['strPrivDescCreateUser']); } } echo $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . ($db == '*' ? $GLOBALS['strGlobalPrivileges'] : ($table == '*' ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges'])) . "\n" . $spaces . ' ( ' . $GLOBALS['strCheckAll'] . ' /' . "\n" . $spaces . ' ' . $GLOBALS['strUncheckAll'] . ' )' . "\n" . $spaces . ' ' . "\n" . $spaces . '

' . $GLOBALS['strEnglishPrivileges'] . '

' . "\n" . $spaces . '

' . "\n" . $spaces . ' ' . $GLOBALS['strData'] . '' . "\n"; foreach ( $privTable[0] as $priv ) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n"; } echo $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . $GLOBALS['strStructure'] . '' . "\n"; foreach ( $privTable[1] as $priv ) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n"; } echo $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . $GLOBALS['strAdministration'] . '' . "\n"; foreach ( $privTable[2] as $priv ) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n"; } echo $spaces . '
' . "\n"; // The "Resource limits" box is not displayed for db-specific privs if ($db == '*') { echo $spaces . '
' . "\n" . $spaces . ' ' . $GLOBALS['strResourceLimits'] . '' . "\n" . $spaces . '

' . $GLOBALS['strZeroRemovesTheLimit'] . '

' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n"; if (PMA_MYSQL_INT_VERSION >= 50003) { echo $spaces . '
' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '
' . "\n"; } echo $spaces . '
' . "\n"; } } echo $spaces . '
' . "\n"; if ($submit) { echo $spaces . '' . "\n"; } } // end of the 'PMA_displayPrivTable()' function /** * Displays the fields used by the "new user" form as well as the * "change login information / copy user" form. * * @param string $mode are we creating a new user or are we just * changing one? (allowed values: 'new', 'change') * @param int $indent the indenting level of the code * * @global array $cfg the phpMyAdmin configuration * @global ressource $user_link the database connection * * @return void */ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0 ) { $spaces = str_repeat( ' ', $indent); // Get user/host name lengths $fields_info = PMA_DBI_get_fields('mysql', 'user'); $username_length = 16; $hostname_length = 41; foreach($fields_info as $key => $val) { if ($val['Field'] == 'User') { strtok($val['Type'], '()'); $v = strtok('()'); if (is_int($v)) $username_length = $v; } elseif ($val['Field'] == 'Host') { strtok($val['Type'], '()'); $v = strtok('()'); if (is_int($v)) $hostname_length = $v; } } unset($fields_info); echo $spaces . '
' . "\n" . $spaces . '' . $GLOBALS['strLoginInformation'] . '' . "\n" . $spaces . '
' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . ' ' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . ' ' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . ' ' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n"; } // end of the 'PMA_displayUserAndHostFields()' function /** * Changes / copies a user, part I */ if (!empty($change_copy)) { $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($old_hostname, 'quoted') . ';'; $res = PMA_DBI_query('SELECT * FROM `mysql`.`user` ' . $user_host_condition); if (!$res) { $message = $GLOBALS['strNoUsersFound']; unset($change_copy); } else { $row = PMA_DBI_fetch_assoc($res); extract($row, EXTR_OVERWRITE); // Recent MySQL versions have the field "Password" in mysql.user, // so the previous extract creates $Password but this script // uses $password if (!isset($password) && isset($Password)) { $password=$Password; } PMA_DBI_free_result($res); $queries = array(); } } /** * Adds a user * (Changes / copies a user, part II) */ if (!empty($adduser_submit) || !empty($change_copy)) { unset($sql_query); if ($pred_username == 'any') { $username = ''; } switch ($pred_hostname) { case 'any': $hostname = '%'; break; case 'localhost': $hostname = 'localhost'; break; case 'hosttable': $hostname = ''; break; case 'thishost': $res = PMA_DBI_query('SELECT USER();'); $row = PMA_DBI_fetch_row($res); PMA_DBI_free_result($res); unset($res); $hostname = substr($row[0], (strrpos($row[0], '@') + 1)); unset($row); break; } $res = PMA_DBI_query('SELECT \'foo\' FROM `mysql`.`user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';', NULL, PMA_DBI_QUERY_STORE); if (PMA_DBI_num_rows($res) == 1) { PMA_DBI_free_result($res); $message = sprintf($GLOBALS['strUserAlreadyExists'], '[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]'); $adduser = 1; } else { PMA_DBI_free_result($res); $real_sql_query = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''; if ($pred_password != 'none' && $pred_password != 'keep') { $pma_pw_hidden = ''; for ($i = 0; $i < strlen($pma_pw); $i++) { $pma_pw_hidden .= '*'; } $sql_query = $real_sql_query . ' IDENTIFIED BY \'' . $pma_pw_hidden . '\''; $real_sql_query .= ' IDENTIFIED BY \'' . $pma_pw . '\''; } else { if ($pred_password == 'keep' && !empty($password)) { $real_sql_query .= ' IDENTIFIED BY PASSWORD \'' . $password . '\''; } $sql_query = $real_sql_query; } // FIXME: similar code appears twice in this script if ((isset($Grant_priv) && $Grant_priv == 'Y') || (PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates) || isset($max_user_connections)))) { $real_sql_query .= 'WITH'; $sql_query .= 'WITH'; if (isset($Grant_priv) && $Grant_priv == 'Y') { $real_sql_query .= ' GRANT OPTION'; $sql_query .= ' GRANT OPTION'; } if (PMA_MYSQL_INT_VERSION >= 40002) { if (isset($max_questions)) { // avoid negative values $max_questions = max(0, (int)$max_questions); $real_sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions; $sql_query .= ' MAX_QUERIES_PER_HOUR ' . $max_questions; } if (isset($max_connections)) { $max_connections = max(0, (int)$max_connections); $real_sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections; $sql_query .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections; } if (isset($max_updates)) { $max_updates = max(0, (int)$max_updates); $real_sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates; $sql_query .= ' MAX_UPDATES_PER_HOUR ' . $max_updates; } } if (PMA_MYSQL_INT_VERSION >= 50003) { if (isset($max_user_connections)) { $max_user_connections = max(0, (int)$max_user_connections); $real_sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections; $sql_query .= ' MAX_USER_CONNECTIONS ' . $max_user_connections; } } } $real_sql_query .= ';'; $sql_query .= ';'; if (empty($change_copy)) { PMA_DBI_try_query($real_sql_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query); $message = $GLOBALS['strAddUserMessage']; } else { $queries[] = $real_sql_query; // we put the query containing the hidden password in // $queries_for_display, at the same position occupied // by the real query in $queries $tmp_count = count($queries); $queries_for_display[$tmp_count - 1] = $sql_query; } unset($res, $real_sql_query); } } /** * Changes / copies a user, part III */ if (!empty($change_copy)) { $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($old_hostname, 'quoted') . ';'; $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition ); while ($row = PMA_DBI_fetch_assoc($res)) { $queries[] = 'GRANT ' . join(', ', PMA_extractPrivInfo($row)) . ' ON `' . $row['Db'] . '`.* TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION' : '') . ';'; } PMA_DBI_free_result($res); $res = PMA_DBI_query('SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv`' . $user_host_condition, $GLOBALS['userlink'], PMA_DBI_QUERY_STORE); while ($row = PMA_DBI_fetch_assoc($res)) { $res2 = PMA_DBI_QUERY('SELECT `Column_name`, `Column_priv` FROM `mysql`.`columns_priv` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($old_username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($old_hostname, 'quoted') . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($row['Db'], 'quoted') . ' AND ' . PMA_convert_using('Table_name') . ' = ' . PMA_convert_using($row['Table_name'], 'quoted') . ';', NULL, PMA_DBI_QUERY_STORE); $tmp_privs1 = PMA_extractPrivInfo($row); $tmp_privs2 = array( 'Select' => array(), 'Insert' => array(), 'Update' => array(), 'References' => array() ); while ($row2 = PMA_DBI_fetch_assoc($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']; } unset($tmp_array); } 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']) . '`)'; } unset($tmp_privs2); $queries[] = 'GRANT ' . join(', ', $tmp_privs1) . ' ON `' . $row['Db'] . '`.`' . $row['Table_name'] . '` TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\'' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION' : '') . ';'; } } /** * Updates privileges */ if (!empty($update_privs)) { // escaping a wildcard character in a GRANT is only accepted at the global // or database level, not at table level; this is why I remove // the escaping character // Note: in the phpMyAdmin list of Database-specific privileges, // we will have for example // test\_db SELECT (this one is for privileges on a db level) // test_db USAGE (this one is for table-specific privileges) // // It looks curious but reflects the way MySQL works if (empty($dbname)) { $db_and_table = '*.*'; } else { if (!empty($tablename)) { $db_and_table = str_replace('\\','',PMA_backquote($dbname)) . '.' . PMA_backquote($tablename); } else { // do not remove the escaping character when working at db level $db_and_table = PMA_backquote($dbname) . '.*'; } } $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; if (!isset($Grant_priv) || $Grant_priv != 'Y') { $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\';'; } $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON ' . $db_and_table . ' TO \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''; // FIXME: similar code appears twice in this script if ((isset($Grant_priv) && $Grant_priv == 'Y') || (empty($dbname) && PMA_MYSQL_INT_VERSION >= 40002 && (isset($max_questions) || isset($max_connections) || isset($max_updates) || isset($max_user_connections)))) { $sql_query2 .= 'WITH'; if (isset($Grant_priv) && $Grant_priv == 'Y') { $sql_query2 .= ' GRANT OPTION'; } if (PMA_MYSQL_INT_VERSION >= 40002) { if (isset($max_questions)) { $max_questions = max(0, (int)$max_questions); $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . $max_questions; } if (isset($max_connections)) { $max_connections = max(0, (int)$max_connections); $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . $max_connections; } if (isset($max_updates)) { $max_updates = max(0, (int)$max_updates); $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . $max_updates; } } if (PMA_MYSQL_INT_VERSION >= 50003) { if (isset($max_user_connections)) { $max_user_connections = max(0, (int)$max_user_connections); $sql_query2 .= ' MAX_USER_CONNECTIONS ' . $max_user_connections; } } } $sql_query2 .= ';'; if (!PMA_DBI_try_query($sql_query0)) { // this query may fail, but this does not matter :o) unset($sql_query0); } if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) { // this one may fail, too... unset($sql_query1); } PMA_DBI_query($sql_query2); $sql_query = (isset($sql_query0) ? $sql_query0 . ' ' : '') . (isset($sql_query1) ? $sql_query1 . ' ' : '') . $sql_query2; $message = sprintf($GLOBALS['strUpdatePrivMessage'], '\'' . $username . '\'@\'' . $hostname . '\''); } /** * Revokes Privileges */ if (!empty($revokeall)) { $db_and_table = PMA_backquote($dbname) . '.' . (empty($tablename) ? '*' : PMA_backquote($tablename)); $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM \'' . $username . '\'@\'' . $hostname . '\';'; $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM \'' . $username . '\'@\'' . $hostname . '\';'; PMA_DBI_query($sql_query0); if (!PMA_DBI_try_query($sql_query1)) { // this one may fail, too... unset($sql_query1); } $sql_query = $sql_query0 . (isset($sql_query1) ? ' ' . $sql_query1 : ''); $message = sprintf($GLOBALS['strRevokeMessage'], '\'' . $username . '\'@\'' . $hostname . '\''); if (empty($tablename)) { unset($dbname); } else { unset($tablename); } } /** * Updates the password */ if (!empty($change_pw)) { if ($nopass == 1) { $sql_query = 'SET PASSWORD FOR \'' . $username . '\'@\'' . $hostname . '\' = \'\';'; PMA_DBI_query($sql_query); $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\''); } else if (empty($pma_pw) || empty($pma_pw2)) { $message = $GLOBALS['strPasswordEmpty']; } else if ($pma_pw != $pma_pw2) { $message = $GLOBALS['strPasswordNotSame']; } else { $hidden_pw = ''; for ($i = 0; $i < strlen($pma_pw); $i++) { $hidden_pw .= '*'; } $local_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')'; $sql_query = 'SET PASSWORD FOR \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\' = PASSWORD(\'' . $hidden_pw . '\')'; PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query); $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\''); } } /** * Deletes users * (Changes / copies a user, part IV) */ $user_host_separator = chr(27); if (!empty($delete) || (!empty($change_copy) && $mode < 4)) { if (!empty($change_copy)) { $selected_usr = array($old_username . $user_host_separator . $old_hostname); } else { $queries = array(); } for ($i = 0; isset($selected_usr[$i]); $i++) { list($this_user, $this_host) = explode($user_host_separator, $selected_usr[$i]); $queries[] = '# ' . sprintf($GLOBALS['strDeleting'], '\'' . $this_user . '\'@\'' . $this_host . '\'') . ' ...'; if ($mode == 2) { // The SHOW GRANTS query may fail if the user has not been loaded // into memory $res = PMA_DBI_try_query('SHOW GRANTS FOR \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'); if ($res) { $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; while ($row = PMA_DBI_fetch_row($res)) { $this_table = substr($row[0], (strpos($row[0], 'ON') + 3), (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3)); if ($this_table != '*.*') { $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; if (strpos($row[0], 'WITH GRANT OPTION')) { $queries[] = 'REVOKE GRANT OPTION ON ' . $this_table . ' FROM \'' . PMA_sqlAddslashes($this_user) . '\'@\'' . $this_host . '\';'; } } unset($this_table); } PMA_DBI_free_result($res); } unset($res); } $queries[] = 'DELETE FROM `mysql`.`user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($this_user), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($this_host, 'quoted') . ';'; if ($mode != 2) { // If we REVOKE the table grants, we should not need to modify the // `mysql`.`db`, `mysql`.`tables_priv` and `mysql`.`columns_priv` tables manually... $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($this_user), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($this_host, 'quoted') . ';'; $queries[] = 'DELETE FROM `mysql`.`db`' . $user_host_condition; $queries[] = 'DELETE FROM `mysql`.`tables_priv`' . $user_host_condition; $queries[] = 'DELETE FROM `mysql`.`columns_priv`' . $user_host_condition; } if (!empty($drop_users_db)) { $queries[] = 'DROP DATABASE IF EXISTS ' . PMA_backquote($this_user) . ';'; $GLOBALS['reload'] = TRUE; PMA_reloadNavigation(); } } if (empty($change_copy)) { if (empty($queries)) { $show_error_header = TRUE; $message = $GLOBALS['strDeleteNoUsersSelected']; } else { if ($mode == 3) { $queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...'; $queries[] = 'FLUSH PRIVILEGES;'; } foreach ($queries as $sql_query) { if ($sql_query{0} != '#') { PMA_DBI_query($sql_query, $GLOBALS['userlink']); } } $sql_query = join("\n", $queries); $message = $GLOBALS['strUsersDeleted']; } unset($queries); } } /** * Changes / copies a user, part V */ if (!empty($change_copy)) { $tmp_count = -1; foreach ($queries as $sql_query) { $tmp_count++; if ($sql_query{0} != '#') { PMA_DBI_query($sql_query); } // when there is a query containing a hidden password, take it // instead of the real query sent if (isset($queries_for_display[$tmp_count])) { $queries[$tmp_count] = $queries_for_display[$tmp_count]; } } $message = $GLOBALS['strSuccess']; $sql_query = join("\n", $queries); } /** * Reloads the privilege tables into memory */ if (!empty($flush_privileges)) { $sql_query = 'FLUSH PRIVILEGES;'; PMA_DBI_query($sql_query); $message = $GLOBALS['strPrivilegesReloaded']; } /** * Displays the links */ if (isset($viewing_mode) && $viewing_mode == 'db') { $db = $checkprivs; $url_query .= '&goto=db_operations.php'; // Gets the database structure $sub_part = '_structure'; require('./db_details_db_info.php'); echo "\n"; } else { require('./server_links.inc.php'); } /** * Displays the page */ if (empty($adduser) && empty($checkprivs)) { if (!isset($username)) { // No username is given --> display the overview echo '

' . "\n" . ' ' . ($GLOBALS['cfg']['MainPageIconic'] ? '' : '') . $GLOBALS['strUserOverview'] . "\n" . '

' . "\n"; $sql_query = 'SELECT `User`, `Host`, IF(`Password` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . '\'\', \'N\', \'Y\') AS \'Password\', `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Index_priv`, `Alter_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`'; if (PMA_MYSQL_INT_VERSION >= 40002) { $sql_query .= ', `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`'; } if (PMA_MYSQL_INT_VERSION >= 50001) { $sql_query .= ', `Create_view_priv`, `Show_view_priv`'; } if (PMA_MYSQL_INT_VERSION >= 50003) { $sql_query .= ', `Create_user_priv`, `Create_routine_priv`, `Alter_routine_priv`'; } $sql_query .= ' FROM `mysql`.`user`'; // the strtolower() is because sometimes the User field // might be BINARY, so LIKE would be case sensitive if (isset($initial)) { $sql_query .= " WHERE " . PMA_convert_using('User') . " LIKE " . PMA_convert_using($initial . '%', 'quoted') . " OR ". PMA_convert_using('User') . " LIKE " . PMA_convert_using(strtolower($initial) . '%', 'quoted'); } $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; $res = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_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 $sql_query = 'SELECT * FROM `mysql`.`user`'; $res = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_STORE); if (!$res) { echo '' . $GLOBALS['strNoPrivileges'] . '' . "\n"; PMA_DBI_free_result($res); unset($res); } else { // rabus: This message is hardcoded because I will replace it by // a automatic repair feature soon. echo '
' . "\n" . ' Warning: Your privilege table structure seems to be older than this MySQL version!
' . "\n" . ' Please run the script mysql_fix_privilege_tables that should be included in your MySQL server distribution to solve this problem!' . "\n" . '

' . "\n"; } } else { /** * Displays the initials */ // for all initials, even non A-Z $array_initials = array(); // initialize to FALSE the letters A-Z for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) { $array_initials[chr($letter_counter + 64)] = FALSE; } $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(' . PMA_convert_using('User') . ',1)) FROM `mysql`.`user` ORDER BY `User` ASC', NULL, PMA_DBI_QUERY_STORE); while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) { $array_initials[$tmp_initial] = TRUE; } // Display the initials, which can be any characters, not // just letters. For letters A-Z, we add the non-used letters // as greyed out. uksort($array_initials, "strnatcasecmp"); reset($array_initials); echo ''; foreach ($array_initials as $tmp_initial => $initial_was_found) { if ($initial_was_found) { echo '' . "\n"; } else { echo ''; } } echo '' . "\n"; echo '
' . $tmp_initial . '' . $tmp_initial . '[' . $GLOBALS['strShowAll'] . ']
'; /** * Display the user overview * (if less than 50 users, display them immediately) */ if (isset($initial) || isset($showall) || PMA_DBI_num_rows($res) < 50) { echo '
' . "\n" . PMA_generate_common_hidden_inputs('', '', 1) . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . ($GLOBALS['cfg']['PropertiesIconic'] ? '' : '') . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; $odd_row = true; for ($i = 0; $row = PMA_DBI_fetch_assoc($res); $i++) { echo ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n"; $privs = PMA_extractPrivInfo($row, TRUE); echo ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n"; $odd_row = ! $odd_row; } @PMA_DBI_free_result($res); unset($res); unset ($row); echo ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . $GLOBALS['strUser'] . '' . $GLOBALS['strHost'] . '' . $GLOBALS['strPassword'] . '' . $GLOBALS['strGlobalPrivileges'] . '' . $GLOBALS['strGrantOption'] . '' . $GLOBALS['strAction'] . '
' . htmlspecialchars($row['Host']) . '' . ($row['Password'] == 'Y' ? $GLOBALS['strYes'] : '' . $GLOBALS['strNo'] . '') . '' . "\n" . ' ' . join(',' . "\n" . ' ', $privs) . "\n" . ' ' . ($row['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . ''; if ($GLOBALS['cfg']['PropertiesIconic']) { echo '' . $GLOBALS['strEditPrivileges'] . ''; } else { echo $GLOBALS['strEditPrivileges']; } echo '
' . "\n" . ' ' . $GLOBALS['strEnglishPrivileges'] . '' . "\n" . '
' . "\n" . ' ' . $GLOBALS['strWithChecked'] . '' . "\n" . ' ' . $GLOBALS['strCheckAll'] . '' . "\n" . ' /' . "\n" . ' ' . $GLOBALS['strUncheckAll'] . '' . "\n" . '

' . "\n"; // add/delete user fieldset echo '
' . "\n" . ' ' . "\n" . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '' ) . ' ' . $GLOBALS['strAddUser'] . '' . "\n" . '
' . "\n" . '
' . ' ' . "\n" . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '' ) . ' ' . $GLOBALS['strRemoveSelectedUsers'] . '' . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . "\n" . ' ' . "\n" . '
' . "\n" . ' ' . "\n" . '
' . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . "\n" . ' ' . "\n"; } else { unset ($row); echo '
' . "\n" . ' ' . "\n" . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '' ) . ' ' . $GLOBALS['strAddUser'] . '' . "\n" . '
' . "\n"; } // end if (display overview) echo '
' . "\n" . '
' . "\n" . ' ' . sprintf($GLOBALS['strFlushPrivilegesNote'], '', '') . "\n" . '
' . "\n"; } } else { // A user was selected -> display the user's properties echo '

' . "\n" . ($GLOBALS['cfg']['PropertiesIconic'] ? '' : '' ) . ' ' . $GLOBALS['strUser'] . ' \'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'' . "\n"; if (!empty($dbname)) { echo ' - ' . $GLOBALS['strDatabase'] . ' ' . htmlspecialchars($dbname) . '' . "\n"; if (!empty($tablename)) { echo ' - ' . $GLOBALS['strTable'] . ' ' . htmlspecialchars($tablename) . '' . "\n"; } } echo ' : ' . $GLOBALS['strEditPrivileges'] . '

' . "\n"; $res = PMA_DBI_query('SELECT \'foo\' FROM `mysql`.`user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';', NULL, PMA_DBI_QUERY_STORE); if (PMA_DBI_num_rows($res) < 1) { echo $GLOBALS['strUserNotFound']; require_once('./footer.inc.php'); } PMA_DBI_free_result($res); unset($res); echo '
' . "\n" . PMA_generate_common_hidden_inputs('', '', 3) . '' . "\n" . '' . "\n"; if (!empty($dbname)) { echo '' . "\n"; if (!empty($tablename)) { echo ' ' . "\n"; } } PMA_displayPrivTable((empty($dbname) ? '*' : $dbname), ((empty($dbname) || empty($tablename)) ? '*' : $tablename), TRUE, 3); echo '
' . "\n"; if (empty($tablename)) { echo '
' . "\n" . PMA_generate_common_hidden_inputs('', '', 6) . '' . "\n" . '' . "\n" . '
' . "\n" . '' . (empty($dbname) ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges']) . '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '' . "\n" . '' . "\n" . '' . "\n"; $user_host_condition = ' WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted'); if (empty($dbname)) { $sql_query = 'SELECT * FROM `mysql`.`db`' . $user_host_condition . ' ORDER BY `Db` ASC;'; } else { $sql_query = 'SELECT `Table_name`, `Table_priv`, IF(`Column_priv` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . ' \'\', 0, 1) AS \'Column_priv\' FROM `mysql`.`tables_priv`' . $user_host_condition . ' AND ' . PMA_convert_using('Db') . ' = ' . PMA_convert_using($dbname, 'quoted') . ' ORDER BY `Table_name` ASC;'; } $res = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_STORE); if (PMA_DBI_affected_rows() == 0) { echo '' . "\n" . ' ' . "\n" . '' . "\n"; } else { $odd_row = true; if (empty($dbname)) { $res2 = PMA_DBI_query('SELECT `Db` FROM `mysql`.`tables_priv`' . $user_host_condition . ' GROUP BY `Db` ORDER BY `Db` ASC;'); $row2 = PMA_DBI_fetch_assoc($res2); } $found_rows = array(); while ($row = PMA_DBI_fetch_assoc($res)) { while (empty($dbname) && $row2 && $row['Db'] > $row2['Db']) { $found_rows[] = $row2['Db']; echo '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '' . "\n"; $row2 = PMA_DBI_fetch_assoc($res2); $odd_row = ! $odd_row; } // end while $found_rows[] = empty($dbname) ? $row['Db'] : $row['Table_name']; echo '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '' . "\n"; $odd_row = ! $odd_row; } // end while while (empty($dbname) && $row2) { $found_rows[] = $row2['Db']; echo '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '' . "\n"; $row2 = PMA_DBI_fetch_assoc($res2); $odd_row = ! $odd_row; } // end while if (empty($dbname)) { PMA_DBI_free_result($res2); unset($res2); unset($row2); } } PMA_DBI_free_result($res); unset($res); unset($row); echo '' . "\n" . '
' . (empty($dbname) ? $GLOBALS['strDatabase'] : $GLOBALS['strTable']) . '' . $GLOBALS['strPrivileges'] . '' . $GLOBALS['strGrantOption'] . '' . (empty($dbname) ? $GLOBALS['strTblPrivileges'] : $GLOBALS['strColumnPrivileges']) . '' . $GLOBALS['strAction'] . '
' . $GLOBALS['strNone'] . '
' . htmlspecialchars($row2['Db']) . '' . "\n" . ' USAGE' . "\n" . ' ' . $GLOBALS['strNo'] . '' . $GLOBALS['strYes'] . '' . $GLOBALS['strEdit'] . '' . $GLOBALS['strRevoke'] . '
' . htmlspecialchars(empty($dbname) ? $row['Db'] : $row['Table_name']) . '' . "\n" . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row, TRUE)) . "\n" . ' ' . (((empty($dbname) && $row['Grant_priv'] == 'Y') || (!empty($dbname) && in_array('Grant', explode(',', $row['Table_priv'])))) ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . ''; if ((empty($dbname) && $row2 && $row['Db'] == $row2['Db']) || (!empty($dbname) && $row['Column_priv'])) { echo $GLOBALS['strYes']; if (empty($dbname)) { $row2 = PMA_DBI_fetch_assoc($res2); } } else { echo $GLOBALS['strNo']; } echo '' . $GLOBALS['strEdit'] . '' . $GLOBALS['strRevoke'] . '
' . htmlspecialchars($row2['Db']) . '' . "\n" . ' USAGE' . "\n" . ' ' . $GLOBALS['strNo'] . '' . $GLOBALS['strYes'] . '' . $GLOBALS['strEdit'] . '' . $GLOBALS['strRevoke'] . '
' . "\n"; if (empty($dbname)) { echo ' ' . "\n"; $res = PMA_DBI_query('SHOW DATABASES;'); $pred_db_array = array(); while ($row = PMA_DBI_fetch_row($res)) { if (!isset($found_rows) || !in_array(str_replace('_', '\\_', $row[0]), $found_rows)) { $pred_db_array[] = $row[0]; } } PMA_DBI_free_result($res); unset($res); unset($row); if (!empty($pred_db_array)) { echo ' ' . "\n"; } echo ' ' . "\n"; } else { echo ' ' . "\n" . ' ' . "\n"; if ($res = @PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', NULL, PMA_DBI_QUERY_STORE)) { $pred_tbl_array = array(); while ($row = PMA_DBI_fetch_row($res)) { if (!isset($found_rows) || !in_array($row[0], $found_rows)) { $pred_tbl_array[] = $row[0]; } } PMA_DBI_free_result($res); unset($res); unset($row); if (!empty($pred_tbl_array)) { echo ' ' . "\n"; } } else { unset($res); } echo ' ' . "\n"; } echo ' ' . PMA_showHint($GLOBALS['strEscapeWildcards']) . "\n" . '
' . "\n" . '
' . "\n"; } if (empty($dbname)) { echo '
' . "\n" . PMA_generate_common_hidden_inputs('', '', 3) . '' . "\n" . '' . "\n" . '
' . "\n" . ' ' . $GLOBALS['strChangePassword'] . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . "\n" . '
' . "\n" . '' . "\n" . '
' . "\n" . '
' . "\n" . PMA_generate_common_hidden_inputs('', '', 3) . '' . "\n" . '' . "\n" . '
' . "\n" . ' ' . $GLOBALS['strChangeCopyUser'] . '' . "\n"; PMA_displayLoginInformationFields('change', 3 ); echo '
' . "\n" . ' ' . $GLOBALS['strChangeCopyMode'] . '' . "\n" . '
' . "\n" . '
' . "\n" . '
' . "\n" . ' ' . "\n" . '
' . "\n" . '
' . "\n" . '' . "\n" . '
' . "\n"; } } } else if (!empty($adduser)) { // Add a new user $GLOBALS['url_query'] .= '&adduser=1'; echo '

' . "\n" . ($GLOBALS['cfg']['PropertiesIconic'] ? '' : '' ) . ' ' . $GLOBALS['strAddUser'] . "\n" . '

' . "\n" . '
' . "\n" . PMA_generate_common_hidden_inputs('', '', 1); PMA_displayLoginInformationFields('new', 2); PMA_displayPrivTable('*', '*', FALSE, 1); echo ' ' . "\n" . '
' . "\n"; } else { // check the privileges for a particular database. echo '' . "\n" . '' . "\n" . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '' . "\n" . '' . "\n"; $odd_row = TRUE; unset($row); unset($row1); unset($row2); // now, we build the table... if (PMA_MYSQL_INT_VERSION >= 40000) { // Starting with MySQL 4.0.0, we may use UNION SELECTs and this makes // the job much easier here! $no = PMA_convert_using('N', 'quoted'); $list_of_privileges = PMA_convert_using('Select_priv') . ' AS Select_priv, ' . PMA_convert_using('Insert_priv') . ' AS Insert_priv, ' . PMA_convert_using('Update_priv') . ' AS Update_priv, ' . PMA_convert_using('Delete_priv') . ' AS Delete_priv, ' . PMA_convert_using('Create_priv') . ' AS Create_priv, ' . PMA_convert_using('Drop_priv') . ' AS Drop_priv, ' . PMA_convert_using('Grant_priv') . ' AS Grant_priv, '. PMA_convert_using('References_priv') . ' AS References_priv'; $list_of_compared_privileges = PMA_convert_using('Select_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Insert_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Update_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Delete_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Create_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Drop_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Grant_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('References_priv') . ' = ' . $no; $sql_query = '(SELECT ' . PMA_convert_using('User') . ' AS User,' . PMA_convert_using('Host') . ' AS Host,' . PMA_convert_using('Db') . ' AS Db,' . $list_of_privileges . ' FROM `mysql`.`db` WHERE ' . PMA_convert_using($checkprivs, 'quoted') . ' LIKE ' . PMA_convert_using('Db') . ' AND NOT (' . $list_of_compared_privileges. ')) UNION (SELECT ' . PMA_convert_using('User') . ' AS User, ' . PMA_convert_using('Host') . ' AS Host, ' . PMA_convert_using('*', 'quoted') . ' AS Db, ' . $list_of_privileges . ' FROM `mysql`.`user` WHERE NOT (' . $list_of_compared_privileges . ')) ORDER BY User ASC, Host ASC, Db ASC;'; $res = PMA_DBI_query($sql_query); $row = PMA_DBI_fetch_assoc($res); if ($row) { $found = TRUE; } } else { // With MySQL 3, we need 2 seperate queries here. $sql_query = 'SELECT * FROM `mysql`.`user` WHERE NOT (`Select_priv` = \'N\' AND `Insert_priv` = \'N\' AND `Update_priv` = \'N\' AND `Delete_priv` = \'N\' AND `Create_priv` = \'N\' AND `Drop_priv` = \'N\' AND `Grant_priv` = \'N\' AND `References_priv` = \'N\') ORDER BY `User` ASC, `Host` ASC;'; $res1 = PMA_DBI_query($sql_query); $row1 = PMA_DBI_fetch_assoc($res1); $sql_query = 'SELECT * FROM `mysql`.`db` WHERE \'' . $checkprivs . '\' LIKE `Db` AND NOT (`Select_priv` = \'N\' AND `Insert_priv` = \'N\' AND `Update_priv` = \'N\' AND `Delete_priv` = \'N\' AND `Create_priv` = \'N\' AND `Drop_priv` = \'N\' AND `Grant_priv` = \'N\' AND `References_priv` = \'N\') ORDER BY `User` ASC, `Host` ASC;'; $res2 = PMA_DBI_query($sql_query); $row2 = PMA_DBI_fetch_assoc($res2); if ($row1 || $row2) { $found = TRUE; } } // end if (PMA_MYSQL_INT_VERSION >= 40000) ... else ... if ($found) { while (TRUE) { // prepare the current user if (PMA_MYSQL_INT_VERSION >= 40000) { $current_privileges = array(); $current_user = $row['User']; $current_host = $row['Host']; while ($row && $current_user == $row['User'] && $current_host == $row['Host']) { $current_privileges[] = $row; $row = PMA_DBI_fetch_assoc($res); } } else { $current_privileges = array(); if ($row1 && (!$row2 || ($row1['User'] < $row2['User'] || ($row1['User'] == $row2['User'] && $row1['Host'] <= $row2['Host'])))) { $current_user = $row1['User']; $current_host = $row1['Host']; $current_privileges = array($row1); $row1 = PMA_DBI_fetch_assoc($res1); } else { $current_user = $row2['User']; $current_host = $row2['Host']; $current_privileges = array(); } while ($row2 && $current_user == $row2['User'] && $current_host == $row2['Host']) { $current_privileges[] = $row2; $row2 = PMA_DBI_fetch_assoc($res2); } } echo ' ' . "\n" . ' 1) { echo ' rowspan="' . count($current_privileges) . '"'; } echo '>' . (empty($current_user) ? '' . $GLOBALS['strAny'] . '' : htmlspecialchars($current_user)) . "\n" . ' ' . "\n" . ' 1) { echo ' rowspan="' . count($current_privileges) . '"'; } echo '>' . htmlspecialchars($current_host) . '' . "\n"; foreach ($current_privileges as $current) { echo ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n"; } if (empty($row) && empty($row1) && empty($row2)) { break; } $odd_row = ! $odd_row; } } else { echo ' ' . "\n" . ' ' . "\n" . ' ' . "\n"; } echo '' . "\n" . '
' . "\n" . ($GLOBALS['cfg']['PropertiesIconic'] ? ' ' . "\n" : '' ) . ' ' . sprintf($GLOBALS['strUsersHavingAccessToDb'], '' . htmlspecialchars($checkprivs) . '') . "\n" . '
' . $GLOBALS['strUser'] . '' . $GLOBALS['strHost'] . '' . $GLOBALS['strType'] . '' . $GLOBALS['strPrivileges'] . '' . $GLOBALS['strGrantOption'] . '' . $GLOBALS['strAction'] . '
' . "\n" . ' '; if (!isset($current['Db']) || $current['Db'] == '*') { echo $GLOBALS['strGlobal']; } else if ($current['Db'] == $checkprivs) { echo $GLOBALS['strDbSpecific']; } else { echo $GLOBALS['strWildcard'], ': ' . htmlspecialchars($current['Db']) . ''; } echo "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($current, TRUE)) . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . ($current['Grant_priv'] == 'Y' ? $GLOBALS['strYes'] : $GLOBALS['strNo']) . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . $GLOBALS['strEdit'] . "\n" . ' ' . "\n" . '
' . "\n" . ' ' . $GLOBALS['strNoUsersFound'] . "\n" . '
' . "\n"; } // end if (empty($adduser) && empty($checkprivs)) ... else if ... else ... /** * Displays the footer */ echo "\n\n"; require_once('./footer.inc.php'); ?>