public function isUserType($type)
{
if (Util::cacheExists('is_' . $type . 'user')) {
return Util::cacheGet('is_' . $type . 'user');
}
// when connection failed we don't have a $userlink
if (!isset($GLOBALS['userlink'])) {
Util::cacheSet('is_' . $type . 'user', false);
return Util::cacheGet('is_' . $type . 'user');
}
if (!$GLOBALS['cfg']['Server']['DisableIS'] || $type === 'super') {
// Prepare query for each user type check
$query = '';
if ($type === 'super') {
$query = 'SELECT 1 FROM mysql.user LIMIT 1';
} elseif ($type === 'create') {
list($user, $host) = $this->getCurrentUserAndHost();
$query = "SELECT 1 FROM `INFORMATION_SCHEMA`.`USER_PRIVILEGES` " . "WHERE `PRIVILEGE_TYPE` = 'CREATE USER' AND " . "'''" . $user . "''@''" . $host . "''' LIKE `GRANTEE` LIMIT 1";
} elseif ($type === 'grant') {
list($user, $host) = $this->getCurrentUserAndHost();
$query = "SELECT 1 FROM (" . "SELECT `GRANTEE`, `IS_GRANTABLE` FROM " . "`INFORMATION_SCHEMA`.`COLUMN_PRIVILEGES` UNION " . "SELECT `GRANTEE`, `IS_GRANTABLE` FROM " . "`INFORMATION_SCHEMA`.`TABLE_PRIVILEGES` UNION " . "SELECT `GRANTEE`, `IS_GRANTABLE` FROM " . "`INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES` UNION " . "SELECT `GRANTEE`, `IS_GRANTABLE` FROM " . "`INFORMATION_SCHEMA`.`USER_PRIVILEGES`) t " . "WHERE `IS_GRANTABLE` = 'YES' AND " . "'''" . $user . "''@''" . $host . "''' LIKE `GRANTEE` LIMIT 1";
}
$is = false;
$result = $this->tryQuery($query, $GLOBALS['userlink'], self::QUERY_STORE);
if ($result) {
$is = (bool) $this->numRows($result);
}
$this->freeResult($result);
Util::cacheSet('is_' . $type . 'user', $is);
} else {
$is = false;
$grants = $this->fetchResult("SHOW GRANTS FOR CURRENT_USER();", null, null, $GLOBALS['userlink'], self::QUERY_STORE);
if ($grants) {
foreach ($grants as $grant) {
if ($type === 'create') {
if (strpos($grant, "ALL PRIVILEGES ON *.*") !== false || strpos($grant, "CREATE USER") !== false) {
$is = true;
break;
}
} elseif ($type === 'grant') {
if (strpos($grant, "WITH GRANT OPTION") !== false) {
$is = true;
break;
}
}
}
}
Util::cacheSet('is_' . $type . 'user', $is);
}
return Util::cacheGet('is_' . $type . 'user');
}