check privileges

This commit is contained in:
Alexander M. Turek
2003-02-14 14:47:41 +00:00
parent 98a8b57ee7
commit d19d064a89
95 changed files with 419 additions and 5 deletions

View File

@@ -727,7 +727,7 @@ require('./server_links.inc.php3');
/**
* Displays the page
*/
if (empty($adduser)) {
if (empty($adduser) && empty($checkprivs)) {
if (!isset($username)) {
// No username is given --> display the overview
echo '<h2>' . "\n"
@@ -1082,7 +1082,7 @@ if (empty($adduser)) {
}
echo '</ul>' . "\n";
}
} else {
} else if (!empty($adduser)) {
// Add a new user
echo '<h2>' . "\n"
. ' ' . $strAddUser . "\n"
@@ -1180,7 +1180,141 @@ if (empty($adduser)) {
echo ' <br />' . "\n"
. ' <input type="submit" name="adduser_submit" value="' . $strGo . '" />' . "\n"
. '</form>' . "\n";
} // end if (empty($adduser)) ... else ...
} else {
// check the privileges for a particular database.
echo '<h2>' . "\n"
. ' ' . sprintf($strUsersHavingAccessToDb, htmlspecialchars($checkprivs)) . "\n"
. '</h2>' . "\n"
. '<table border="0">' . "\n"
. ' <tr>' . "\n"
. ' <th>' . "\n"
. ' &nbsp;' . $strUser . '&nbsp;' . "\n"
. ' </th>' . "\n"
. ' <th>' . "\n"
. ' &nbsp;' . $strHost . '&nbsp;' . "\n"
. ' </th>' . "\n"
. ' <th>' . "\n"
. ' &nbsp;' . $strType . '&nbsp;' . "\n"
. ' </th>' . "\n"
. ' <th>' . "\n"
. ' &nbsp;' . $strPrivileges . '&nbsp;' . "\n"
. ' </th>' . "\n";
if (PMA_MYSQL_INT_VERSION >= 32211) {
echo ' <th>' . "\n"
. ' &nbsp;' . $strGrantOption . '&nbsp;' . "\n"
. ' </th>' . "\n";
}
echo ' <th>' . "\n"
. ' &nbsp;' . $strAction . '&nbsp;' . "\n"
. ' </th>' . "\n"
. ' </tr>' . "\n";
$useBgcolorOne = TRUE;
// 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!
$sql_query = '(SELECT `User`, `Host`, `Db`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `db` WHERE `Db` = "' . $checkprivs . '" 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")) UNION (SELECT `User`, `Host`, "*" AS "Db", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `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, `Db` ASC;';
$res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
$row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
$row2 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
} else {
// With MySQL 3, we need 2 seperate queries here.
$sql_query = 'SELECT * FROM `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" ' . (PMA_MYSQL_INT_VERSION >= 32211 ? 'AND `Grant_priv` = "N" ' : '') . 'AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;';
$res1 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
$row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC);
$sql_query = 'SELECT * FROM `db` WHERE `Db` = "' . $checkprivs . '" 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" ' . (PMA_MYSQL_INT_VERSION >= 32211 ? 'AND `Grant_priv` = "N" ' : '') . 'AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;';
$res2 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
$row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
} // end if (PMA_MYSQL_INT_VERSION >= 40000) ... else ...
while (!empty($row1) || !empty($row2)) {
echo ' <tr>' . "\n";
if (!empty($row1) && !empty($row2) && $row1['User'] == $row2['User'] && $row1['Host'] == $row2['Host']) {
$useRow1 = $useRow2 = TRUE;
echo ' <td rowspan="2" bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . (empty($row1['User']) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($row1['User'])) . "\n"
. ' </td>' . "\n"
. ' <td rowspan="2" bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . htmlspecialchars($row1['Host']) . "\n"
. ' </td>' . "\n";
} else if (PMA_MYSQL_INT_VERSION >= 40000 || empty($row2) || $row1['User'] < $row2['User'] || ($row1['User'] == $row2['User'] && $row1['Host'] < $row2['Host'])) {
$useRow1 = TRUE;
$useRow2 = FALSE;
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . (empty($row1['User']) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($row1['User'])) . "\n"
. ' </td>' . "\n"
. ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . htmlspecialchars($row1['Host']) . "\n"
. ' </td>' . "\n";
} else {
$useRow1 = FALSE;
$useRow2 = TRUE;
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . (empty($row2['User']) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($row2['User'])) . "\n"
. ' </td>' . "\n"
. ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . htmlspecialchars($row2['Host']) . "\n"
. ' </td>' . "\n";
}
if ($useRow1) {
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . $strGlobal . "\n"
. ' </td>' . "\n"
. ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' <tt>' . "\n"
. ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row1, TRUE)) . "\n"
. ' <tt>' . "\n"
. ' </td>' . "\n";
if (PMA_MYSQL_INT_VERSION >= 32211) {
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . ($row1['Grant_priv'] == 'Y' ? $strYes : $strNo) . "\n"
. ' </td>' . "\n";
}
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' <a href="./server_privileges.php3?' . $url_query . '&amp;username=' . urlencode($row1['User']) . ($row1['Host'] == '%' ? '' : '&amp;hostname=' . urlencode($row1['Host'])) . '">' . "\n"
. ' ' . $strEdit . "\n"
. ' </a>' . "\n"
. ' </td>' . "\n"
. ' </tr>' . "\n";
if (PMA_MYSQL_INT_VERSION < 40000) {
$row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC);
}
}
if ($useRow2) {
if ($useRow1) {
echo ' <tr>' . "\n";
}
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . $strDbSpecific . "\n"
. ' </td>' . "\n"
. ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' <tt>' . "\n"
. ' ' . join(',' . "\n" . ' ', PMA_extractPrivInfo($row2, TRUE)) . "\n"
. ' </tt>' . "\n"
. ' </td>' . "\n";
if (PMA_MYSQL_INT_VERSION >= 32211) {
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' ' . ($row2['Grant_priv'] == 'Y' ? $strYes : $strNo) . "\n"
. ' </td>' . "\n";
}
echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
. ' <a href="./server_privileges.php3?' . $url_query . '&amp;username=' . urlencode($row2['User']) . ($row2['Host'] == '%' ? '' : '&amp;hostname=' . urlencode($row2['Host'])) . '&amp;dbname=' . urlencode($checkprivs) . '">' . "\n"
. ' ' . $strEdit . "\n"
. ' </a>' . "\n"
. ' </td>' . "\n"
. ' </tr>' . "\n";
if (PMA_MYSQL_INT_VERSION < 40000) {
$row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC);
} else {
$row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
$row2 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
}
} else if (PMA_MYSQL_INT_VERSION >= 40000) {
$row1 = $row2;
$row2 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
}
$useBgcolorOne = !$useBgcolorOne;
}
} // end if (empty($adduser) && empty($checkprivs)) ... else if ... else ...
/**