diff --git a/ChangeLog b/ChangeLog index e2fd9da2b..f248d0604 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,9 +5,15 @@ phpMyAdmin - Changelog $Id$ $Source$ +2001-10-24 Loïc Chapeaux + * main.php3: + - taken into account wildcards in the databases names get from the + "mysql.db" table; + - get all privilege at the begenning of the script. + 2001-10-24 Marc Delisle - * main.php3 (for Loïc): a non-empty only_db was removing the - MySQL links on the main page + * main.php3 (for Loïc): a non-empty only_db was removing the MySQL links on + the main page. 2001-10-23 Robin Johnson * Documentation.html: Redid documentation of advanced authentication mode. diff --git a/main.php3 b/main.php3 index 611ec3df4..8c979f756 100755 --- a/main.php3 +++ b/main.php3 @@ -154,41 +154,51 @@ if ($server > 0) $common_url_query = 'lang=' . $lang . '&server=' . $server; - // Get user's rights ($dbh and $userlink are links to MySQL defined in the - // "common.lib.php3" library - $create = FALSE; + // Get user's global privileges ($dbh and $userlink are links to MySQL + // defined in the "common.lib.php3" library) + $is_create_priv = FALSE; + $is_process_priv = FALSE; + $is_reload_priv = FALSE; + $is_superuser = @mysql_query('USE mysql', $userlink); if ($dbh) { - // Does user have global Create priv? - $local_query = 'SELECT * FROM mysql.user WHERE User = \'' . sql_addslashes($cfgServer['user']) . '\''; - $rs_usr = mysql_query($local_query, $dbh); + $local_query = 'SELECT * FROM mysql.user WHERE User = \'' . sql_addslashes($cfgServer['user']) . '\''; + $rs_usr = mysql_query($local_query, $dbh); // Debug: or mysql_die('', $local_query, FALSE); if ($rs_usr) { - $result_usr = mysql_fetch_array($rs_usr); - $create = ($result_usr['Create_priv'] == 'Y'); - $db_to_create = ''; - } - - // Does user have Create priv on a inexistant db? - // if yes, show him in the dialog the first inexistant db name that we - // find, in most cases it's probably the one he just dropped :) - // (Note: we only get here after a browser reload, I don't know why) - if (!$create) { - $local_query = 'SELECT Db FROM mysql.db WHERE User = \'' . sql_addslashes($cfgServer['user']) . '\''; - $rs_usr = mysql_query($local_query, $dbh); - if ($rs_usr) { - while ($row = mysql_fetch_array($rs_usr)) { - if (!mysql_select_db($row['Db'], $userlink)) { - $db_to_create = $row['Db']; - $create = TRUE; - break; - } // end if - } // end while - mysql_free_result($rs_usr); - } // end if + $result_usr = mysql_fetch_array($rs_usr); + $is_create_priv = ($result_usr['Create_priv'] == 'Y'); + $is_process_priv = ($result_usr['Process_priv'] == 'Y'); + $is_reload_priv = ($result_usr['Reload_priv'] == 'Y'); + mysql_free_result($rs_usr); } // end if - } // end get user privileges + } // end if + + // If the user has Create priv on a inexistant db, show him in the dialog + // the first inexistant db name that we find, in most cases it's probably + // the one he just dropped :) + // (Note: we only get here after a browser reload, I don't know why) + if (!$is_create_priv) { + $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = \'Y\' AND (User = \'' . sql_addslashes($cfgServer['user']) . '\' OR User = \'\')'; + $rs_usr = mysql_query($local_query, $dbh); // Debug: or mysql_die('', $local_query, FALSE); + if (@mysql_numrows($rs_usr) > 0) { + while ($row = mysql_fetch_array($rs_usr)) { + if (!mysql_select_db($row['Db'], $dbh)) { + $re = '(^|(\\\\\\\\)+|[^\])'; + $row['Db'] = ereg_replace($re . '%', '\\1...', ereg_replace($re . '_', '\\1?', $row['Db'])); + $db_to_create = $row['Db']; + $is_create_priv = TRUE; + break; + } // end if + } // end while + mysql_free_result($rs_usr); + } // end if + } // end if + else { + $db_to_create = ''; + } // end else + // The user is allowed to create a db - if ($create) { + if ($is_create_priv) { echo "\n"; ?> @@ -206,8 +216,8 @@ if ($server > 0) @@ -231,7 +241,7 @@ if ($server > 0) item @@ -242,10 +252,10 @@ if ($server > 0) item @@ -256,11 +266,10 @@ if ($server > 0) item @@ -286,7 +295,7 @@ if ($server > 0) } echo "\n"; - // With advanced authentication -> logout + // Logout for advanced authentication if ($cfgServer['adv_auth']) { ?> @@ -299,16 +308,16 @@ if ($server > 0)      0) +echo "\n"; /**