1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-22 21:53:06 +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:
Tom Lane
2005-03-12 21:12:05 +00:00
parent 8806b09b82
commit b3dbaab1e9

View File

@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.148 2004/12/31 21:59:41 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.148.4.1 2005/03/12 21:12:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -717,8 +717,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")));
@@ -882,8 +882,7 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
bool isNull; bool isNull;
HeapTuple newtuple; HeapTuple newtuple;
/* changing owner's database for someone else: must be superuser */ /* must be superuser to change ownership */
/* note that the someone else need not have any permissions */
if (!superuser()) if (!superuser())
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
@@ -1004,24 +1003,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;
} }
/* /*