Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7bbe99

Browse files
committed
Fix ALTER DATABASE RENAME to allow the operation if user is a superuser
who for some reason isn't marked usecreatedb. Per report from AlexanderPravking. Also fix sloppy coding in have_createdb_privilege().
1 parentfa5e440 commitc7bbe99

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

‎src/backend/commands/dbcommands.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* 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/1221:11:50 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -722,8 +722,8 @@ RenameDatabase(const char *oldname, const char *newname)
722722
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_DATABASE,
723723
oldname);
724724

725-
/* must have createdb */
726-
if (!have_createdb_privilege())
725+
/* must have createdbrights*/
726+
if (!superuser()&& !have_createdb_privilege())
727727
ereport(ERROR,
728728
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
729729
errmsg("permission denied to rename database")));
@@ -883,8 +883,7 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
883883
boolisNull;
884884
HeapTuplenewtuple;
885885

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 */
888887
if (!superuser())
889888
ereport(ERROR,
890889
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
@@ -999,24 +998,22 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
999998
returngottuple;
1000999
}
10011000

1001+
/* Check if current user has createdb privileges */
10021002
staticbool
10031003
have_createdb_privilege(void)
10041004
{
1005+
boolresult= false;
10051006
HeapTupleutup;
1006-
boolretval;
10071007

10081008
utup=SearchSysCache(SHADOWSYSID,
10091009
Int32GetDatum(GetUserId()),
10101010
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-
returnretval;
1011+
if (HeapTupleIsValid(utup))
1012+
{
1013+
result= ((Form_pg_shadow)GETSTRUCT(utup))->usecreatedb;
1014+
ReleaseSysCache(utup);
1015+
}
1016+
returnresult;
10201017
}
10211018

10221019
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp