|
15 | 15 | * |
16 | 16 | * |
17 | 17 | * IDENTIFICATION |
18 | | - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.152 2005/03/04 20:21:05 tgl Exp $ |
| 18 | + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.153 2005/03/12 21:11:50 tgl Exp $ |
19 | 19 | * |
20 | 20 | *------------------------------------------------------------------------- |
21 | 21 | */ |
@@ -722,8 +722,8 @@ RenameDatabase(const char *oldname, const char *newname) |
722 | 722 | aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE, |
723 | 723 | oldname); |
724 | 724 |
|
725 | | - /* must have createdb */ |
726 | | - if (!have_createdb_privilege()) |
| 725 | + /* must have createdb rights */ |
| 726 | + if (!superuser() && !have_createdb_privilege()) |
727 | 727 | ereport(ERROR, |
728 | 728 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
729 | 729 | errmsg("permission denied to rename database"))); |
@@ -883,8 +883,7 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId) |
883 | 883 | bool isNull; |
884 | 884 | HeapTuple newtuple; |
885 | 885 |
|
886 | | - /* changing owner's database for someone else: must be superuser */ |
887 | | - /* note that the someone else need not have any permissions */ |
| 886 | + /* must be superuser to change ownership */ |
888 | 887 | if (!superuser()) |
889 | 888 | ereport(ERROR, |
890 | 889 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
@@ -999,24 +998,22 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP, |
999 | 998 | return gottuple; |
1000 | 999 | } |
1001 | 1000 |
|
| 1001 | +/* Check if current user has createdb privileges */ |
1002 | 1002 | static bool |
1003 | 1003 | have_createdb_privilege(void) |
1004 | 1004 | { |
| 1005 | + bool result = false; |
1005 | 1006 | HeapTuple utup; |
1006 | | - bool retval; |
1007 | 1007 |
|
1008 | 1008 | utup = SearchSysCache(SHADOWSYSID, |
1009 | 1009 | Int32GetDatum(GetUserId()), |
1010 | 1010 | 0, 0, 0); |
1011 | | - |
1012 | | - if (!HeapTupleIsValid(utup)) |
1013 | | - retval = false; |
1014 | | - else |
1015 | | - retval = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb; |
1016 | | - |
1017 | | - ReleaseSysCache(utup); |
1018 | | - |
1019 | | - return retval; |
| 1011 | + if (HeapTupleIsValid(utup)) |
| 1012 | + { |
| 1013 | + result = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb; |
| 1014 | + ReleaseSysCache(utup); |
| 1015 | + } |
| 1016 | + return result; |
1020 | 1017 | } |
1021 | 1018 |
|
1022 | 1019 | /* |
|
0 commit comments