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

Commit25f050d

Browse files
committed
Make sure that usesuper is always accessed through superuser(), so that the
single-user escape path always works.
1 parenta62f43a commit25f050d

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

‎src/backend/catalog/aclchk.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.62 2002/04/09 20:35:46 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.63 2002/04/11 05:32:02 petere Exp $
1212
*
1313
* NOTES
1414
* See acl.h.
@@ -734,21 +734,19 @@ pg_class_aclcheck(Oid table_oid, Oid userid, AclMode mode)
734734

735735
/*
736736
* Validate userid, find out if he is superuser
737-
*
738-
* We do not use superuser_arg() here because we also need to check
739-
* usecatupd.
740737
*/
741738
tuple=SearchSysCache(SHADOWSYSID,
742739
ObjectIdGetDatum(userid),
743740
0,0,0);
744741
if (!HeapTupleIsValid(tuple))
745742
elog(ERROR,"pg_class_aclcheck: invalid user id %u",userid);
746743

747-
usesuper= ((Form_pg_shadow)GETSTRUCT(tuple))->usesuper;
748744
usecatupd= ((Form_pg_shadow)GETSTRUCT(tuple))->usecatupd;
749745

750746
ReleaseSysCache(tuple);
751747

748+
usesuper=superuser_arg(userid);
749+
752750
/*
753751
* Now get the relation's tuple from pg_class
754752
*/

‎src/backend/commands/dbcommands.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.85 2002/03/06 06:09:32 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.86 2002/04/11 05:32:03 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -49,7 +49,7 @@ static bool get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
4949
int*encodingP,bool*dbIsTemplateP,Oid*dbLastSysOidP,
5050
TransactionId*dbVacuumXidP,TransactionId*dbFrozenXidP,
5151
char*dbpath);
52-
staticboolget_user_info(Oiduse_sysid,bool*use_super,bool*use_createdb);
52+
staticboolhave_createdb_privilege(void);
5353
staticchar*resolve_alt_dbpath(constchar*dbpath,Oiddboid);
5454
staticboolremove_dbdirs(constchar*real_loc,constchar*altloc);
5555

@@ -67,8 +67,6 @@ createdb(const char *dbname, const char *dbowner,
6767
char*target_dir;
6868
charsrc_loc[MAXPGPATH];
6969
charbuf[2*MAXPGPATH+100];
70-
booluse_super,
71-
use_createdb;
7270
Oidsrc_dboid;
7371
int4src_owner;
7472
intsrc_encoding;
@@ -91,21 +89,17 @@ createdb(const char *dbname, const char *dbowner,
9189
else
9290
datdba=GetUserId();
9391

94-
/* check permission to create database */
95-
if (!get_user_info(GetUserId(),&use_super,&use_createdb))
96-
elog(ERROR,"current user name is invalid");
97-
9892
if (datdba== (int32)GetUserId())
9993
{
10094
/* creating database for self: can be superuser or createdb */
101-
if (!use_createdb&& !use_super)
95+
if (!superuser()&& !have_createdb_privilege())
10296
elog(ERROR,"CREATE DATABASE: permission denied");
10397
}
10498
else
10599
{
106100
/* creating database for someone else: must be superuser */
107101
/* note that the someone else need not have any permissions */
108-
if (!use_super)
102+
if (!superuser())
109103
elog(ERROR,"CREATE DATABASE: permission denied");
110104
}
111105

@@ -143,7 +137,7 @@ createdb(const char *dbname, const char *dbowner,
143137
*/
144138
if (!src_istemplate)
145139
{
146-
if (!use_super&&GetUserId()!=src_owner)
140+
if (!superuser()&&GetUserId()!=src_owner)
147141
elog(ERROR,"CREATE DATABASE: permission to copy \"%s\" denied",
148142
dbtemplate);
149143
}
@@ -332,7 +326,6 @@ dropdb(const char *dbname)
332326
{
333327
int4db_owner;
334328
booldb_istemplate;
335-
booluse_super;
336329
Oiddb_id;
337330
char*alt_loc;
338331
char*nominal_loc;
@@ -350,9 +343,6 @@ dropdb(const char *dbname)
350343
if (IsTransactionBlock())
351344
elog(ERROR,"DROP DATABASE: may not be called in a transaction block");
352345

353-
if (!get_user_info(GetUserId(),&use_super,NULL))
354-
elog(ERROR,"current user name is invalid");
355-
356346
/*
357347
* Obtain exclusive lock on pg_database. We need this to ensure that
358348
* no new backend starts up in the target database while we are
@@ -368,7 +358,7 @@ dropdb(const char *dbname)
368358
&db_istemplate,NULL,NULL,NULL,dbpath))
369359
elog(ERROR,"DROP DATABASE: database \"%s\" does not exist",dbname);
370360

371-
if (!use_super&&GetUserId()!=db_owner)
361+
if (GetUserId()!=db_owner&& !superuser())
372362
elog(ERROR,"DROP DATABASE: permission denied");
373363

374364
/*
@@ -605,25 +595,23 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
605595
}
606596

607597
staticbool
608-
get_user_info(Oiduse_sysid,bool*use_super,bool*use_createdb)
598+
have_createdb_privilege(void)
609599
{
610600
HeapTupleutup;
601+
boolretval;
611602

612603
utup=SearchSysCache(SHADOWSYSID,
613-
ObjectIdGetDatum(use_sysid),
604+
ObjectIdGetDatum(GetUserId()),
614605
0,0,0);
615606

616607
if (!HeapTupleIsValid(utup))
617-
return false;
618-
619-
if (use_super)
620-
*use_super= ((Form_pg_shadow)GETSTRUCT(utup))->usesuper;
621-
if (use_createdb)
622-
*use_createdb= ((Form_pg_shadow)GETSTRUCT(utup))->usecreatedb;
608+
retval= true;
609+
else
610+
retval= ((Form_pg_shadow)GETSTRUCT(utup))->usecreatedb;
623611

624612
ReleaseSysCache(utup);
625613

626-
returntrue;
614+
returnretval;
627615
}
628616

629617

‎src/backend/utils/misc/superuser.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.20 2002/02/18 23:11:26 petere Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.21 2002/04/11 05:32:03 petere Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -27,6 +27,11 @@
2727

2828
/*
2929
* The Postgres user running this command has Postgres superuser privileges
30+
*
31+
* All code should use either of these two functions to find out
32+
* whether a given user is a superuser, rather than evaluating
33+
* pg_shadow.usesuper directly, so that the escape hatch built in for
34+
* the single-user case works.
3035
*/
3136
bool
3237
superuser(void)

‎src/include/catalog/pg_shadow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: pg_shadow.h,v 1.18 2002/03/01 22:45:17 petere Exp $
12+
* $Id: pg_shadow.h,v 1.19 2002/04/11 05:32:03 petere Exp $
1313
*
1414
* NOTES
1515
* the genbki.sh script reads this file and generates .bki
@@ -35,7 +35,7 @@ CATALOG(pg_shadow) BOOTSTRAP BKI_WITHOUT_OIDS
3535
int4usesysid;
3636
boolusecreatedb;
3737
boolusetrace;
38-
boolusesuper;
38+
boolusesuper;/* read this field via superuser() only */
3939
boolusecatupd;
4040
textpasswd;
4141
int4valuntil;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp