aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/dbcommands.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-03-12 21:12:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-03-12 21:12:18 +0000
commit80fba0f8eeff2e9aaa37ad4a86103a0b600df75c (patch)
treee6df3862aaae9ca2a8137a267664fc67515aa64b /src/backend/commands/dbcommands.c
parent2450224e6bd10563188985a26d54c2c3d091a223 (diff)
downloadpostgresql-80fba0f8eeff2e9aaa37ad4a86103a0b600df75c.tar.gz
postgresql-80fba0f8eeff2e9aaa37ad4a86103a0b600df75c.zip
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().
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r--src/backend/commands/dbcommands.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 63fc6a1a3ec..1e870b975e5 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -9,7 +9,7 @@
*
*
* 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,
oldname);
- /* must have createdb */
- if (!have_createdb_privilege())
+ /* must have createdb rights */
+ if (!superuser() && !have_createdb_privilege())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to rename database")));
@@ -853,24 +853,22 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
return gottuple;
}
+/* Check if current user has createdb privileges */
static bool
have_createdb_privilege(void)
{
+ bool result = false;
HeapTuple utup;
- bool retval;
utup = SearchSysCache(SHADOWSYSID,
Int32GetDatum(GetUserId()),
0, 0, 0);
-
- if (!HeapTupleIsValid(utup))
- retval = false;
- else
- retval = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;
-
- ReleaseSysCache(utup);
-
- return retval;
+ if (HeapTupleIsValid(utup))
+ {
+ result = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;
+ ReleaseSysCache(utup);
+ }
+ return result;
}