mirror of
https://github.com/postgres/postgres.git
synced 2025-05-18 17:41:14 +03:00
Fix ALTER DATABASE RENAME to allow the operation if user is a superuser
who for some reason isn't marked usecreatedb. Per report from Alexander Pravking. Also fix sloppy coding in have_createdb_privilege().
This commit is contained in:
parent
2450224e6b
commit
80fba0f8ee
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.124.2.1 2004/11/18 01:19:40 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.124.2.2 2005/03/12 21:12:18 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -658,8 +658,8 @@ RenameDatabase(const char *oldname, const char *newname)
|
|||||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
||||||
oldname);
|
oldname);
|
||||||
|
|
||||||
/* must have createdb */
|
/* must have createdb rights */
|
||||||
if (!have_createdb_privilege())
|
if (!superuser() && !have_createdb_privilege())
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||||
errmsg("permission denied to rename database")));
|
errmsg("permission denied to rename database")));
|
||||||
@ -853,24 +853,22 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
|
|||||||
return gottuple;
|
return gottuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if current user has createdb privileges */
|
||||||
static bool
|
static bool
|
||||||
have_createdb_privilege(void)
|
have_createdb_privilege(void)
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
HeapTuple utup;
|
HeapTuple utup;
|
||||||
bool retval;
|
|
||||||
|
|
||||||
utup = SearchSysCache(SHADOWSYSID,
|
utup = SearchSysCache(SHADOWSYSID,
|
||||||
Int32GetDatum(GetUserId()),
|
Int32GetDatum(GetUserId()),
|
||||||
0, 0, 0);
|
0, 0, 0);
|
||||||
|
if (HeapTupleIsValid(utup))
|
||||||
if (!HeapTupleIsValid(utup))
|
{
|
||||||
retval = false;
|
result = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;
|
||||||
else
|
ReleaseSysCache(utup);
|
||||||
retval = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;
|
}
|
||||||
|
return result;
|
||||||
ReleaseSysCache(utup);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user