Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
25f050d9
Commit
25f050d9
authored
Apr 11, 2002
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure that usesuper is always accessed through superuser(), so that the
single-user escape path always works.
parent
a62f43ae
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
33 deletions
+24
-33
src/backend/catalog/aclchk.c
src/backend/catalog/aclchk.c
+3
-5
src/backend/commands/dbcommands.c
src/backend/commands/dbcommands.c
+13
-25
src/backend/utils/misc/superuser.c
src/backend/utils/misc/superuser.c
+6
-1
src/include/catalog/pg_shadow.h
src/include/catalog/pg_shadow.h
+2
-2
No files found.
src/backend/catalog/aclchk.c
View file @
25f050d9
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.6
2 2002/04/09 20:35:46 tgl
Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.6
3 2002/04/11 05:32:02 petere
Exp $
*
*
* NOTES
* NOTES
* See acl.h.
* See acl.h.
...
@@ -734,9 +734,6 @@ pg_class_aclcheck(Oid table_oid, Oid userid, AclMode mode)
...
@@ -734,9 +734,6 @@ pg_class_aclcheck(Oid table_oid, Oid userid, AclMode mode)
/*
/*
* Validate userid, find out if he is superuser
* Validate userid, find out if he is superuser
*
* We do not use superuser_arg() here because we also need to check
* usecatupd.
*/
*/
tuple
=
SearchSysCache
(
SHADOWSYSID
,
tuple
=
SearchSysCache
(
SHADOWSYSID
,
ObjectIdGetDatum
(
userid
),
ObjectIdGetDatum
(
userid
),
...
@@ -744,11 +741,12 @@ pg_class_aclcheck(Oid table_oid, Oid userid, AclMode mode)
...
@@ -744,11 +741,12 @@ pg_class_aclcheck(Oid table_oid, Oid userid, AclMode mode)
if
(
!
HeapTupleIsValid
(
tuple
))
if
(
!
HeapTupleIsValid
(
tuple
))
elog
(
ERROR
,
"pg_class_aclcheck: invalid user id %u"
,
userid
);
elog
(
ERROR
,
"pg_class_aclcheck: invalid user id %u"
,
userid
);
usesuper
=
((
Form_pg_shadow
)
GETSTRUCT
(
tuple
))
->
usesuper
;
usecatupd
=
((
Form_pg_shadow
)
GETSTRUCT
(
tuple
))
->
usecatupd
;
usecatupd
=
((
Form_pg_shadow
)
GETSTRUCT
(
tuple
))
->
usecatupd
;
ReleaseSysCache
(
tuple
);
ReleaseSysCache
(
tuple
);
usesuper
=
superuser_arg
(
userid
);
/*
/*
* Now get the relation's tuple from pg_class
* Now get the relation's tuple from pg_class
*/
*/
...
...
src/backend/commands/dbcommands.c
View file @
25f050d9
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.8
5 2002/03/06 06:09:32 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.8
6 2002/04/11 05:32:03 petere
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -49,7 +49,7 @@ static bool get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
...
@@ -49,7 +49,7 @@ static bool get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
int
*
encodingP
,
bool
*
dbIsTemplateP
,
Oid
*
dbLastSysOidP
,
int
*
encodingP
,
bool
*
dbIsTemplateP
,
Oid
*
dbLastSysOidP
,
TransactionId
*
dbVacuumXidP
,
TransactionId
*
dbFrozenXidP
,
TransactionId
*
dbVacuumXidP
,
TransactionId
*
dbFrozenXidP
,
char
*
dbpath
);
char
*
dbpath
);
static
bool
get_user_info
(
Oid
use_sysid
,
bool
*
use_super
,
bool
*
use_createdb
);
static
bool
have_createdb_privilege
(
void
);
static
char
*
resolve_alt_dbpath
(
const
char
*
dbpath
,
Oid
dboid
);
static
char
*
resolve_alt_dbpath
(
const
char
*
dbpath
,
Oid
dboid
);
static
bool
remove_dbdirs
(
const
char
*
real_loc
,
const
char
*
altloc
);
static
bool
remove_dbdirs
(
const
char
*
real_loc
,
const
char
*
altloc
);
...
@@ -67,8 +67,6 @@ createdb(const char *dbname, const char *dbowner,
...
@@ -67,8 +67,6 @@ createdb(const char *dbname, const char *dbowner,
char
*
target_dir
;
char
*
target_dir
;
char
src_loc
[
MAXPGPATH
];
char
src_loc
[
MAXPGPATH
];
char
buf
[
2
*
MAXPGPATH
+
100
];
char
buf
[
2
*
MAXPGPATH
+
100
];
bool
use_super
,
use_createdb
;
Oid
src_dboid
;
Oid
src_dboid
;
int4
src_owner
;
int4
src_owner
;
int
src_encoding
;
int
src_encoding
;
...
@@ -91,21 +89,17 @@ createdb(const char *dbname, const char *dbowner,
...
@@ -91,21 +89,17 @@ createdb(const char *dbname, const char *dbowner,
else
else
datdba
=
GetUserId
();
datdba
=
GetUserId
();
/* check permission to create database */
if
(
!
get_user_info
(
GetUserId
(),
&
use_super
,
&
use_createdb
))
elog
(
ERROR
,
"current user name is invalid"
);
if
(
datdba
==
(
int32
)
GetUserId
())
if
(
datdba
==
(
int32
)
GetUserId
())
{
{
/* creating database for self: can be superuser or createdb */
/* creating database for self: can be superuser or createdb */
if
(
!
use_createdb
&&
!
use_super
)
if
(
!
superuser
()
&&
!
have_createdb_privilege
()
)
elog
(
ERROR
,
"CREATE DATABASE: permission denied"
);
elog
(
ERROR
,
"CREATE DATABASE: permission denied"
);
}
}
else
else
{
{
/* creating database for someone else: must be superuser */
/* creating database for someone else: must be superuser */
/* note that the someone else need not have any permissions */
/* note that the someone else need not have any permissions */
if
(
!
use_super
)
if
(
!
superuser
()
)
elog
(
ERROR
,
"CREATE DATABASE: permission denied"
);
elog
(
ERROR
,
"CREATE DATABASE: permission denied"
);
}
}
...
@@ -143,7 +137,7 @@ createdb(const char *dbname, const char *dbowner,
...
@@ -143,7 +137,7 @@ createdb(const char *dbname, const char *dbowner,
*/
*/
if
(
!
src_istemplate
)
if
(
!
src_istemplate
)
{
{
if
(
!
use_super
&&
GetUserId
()
!=
src_owner
)
if
(
!
superuser
()
&&
GetUserId
()
!=
src_owner
)
elog
(
ERROR
,
"CREATE DATABASE: permission to copy
\"
%s
\"
denied"
,
elog
(
ERROR
,
"CREATE DATABASE: permission to copy
\"
%s
\"
denied"
,
dbtemplate
);
dbtemplate
);
}
}
...
@@ -332,7 +326,6 @@ dropdb(const char *dbname)
...
@@ -332,7 +326,6 @@ dropdb(const char *dbname)
{
{
int4
db_owner
;
int4
db_owner
;
bool
db_istemplate
;
bool
db_istemplate
;
bool
use_super
;
Oid
db_id
;
Oid
db_id
;
char
*
alt_loc
;
char
*
alt_loc
;
char
*
nominal_loc
;
char
*
nominal_loc
;
...
@@ -350,9 +343,6 @@ dropdb(const char *dbname)
...
@@ -350,9 +343,6 @@ dropdb(const char *dbname)
if
(
IsTransactionBlock
())
if
(
IsTransactionBlock
())
elog
(
ERROR
,
"DROP DATABASE: may not be called in a transaction block"
);
elog
(
ERROR
,
"DROP DATABASE: may not be called in a transaction block"
);
if
(
!
get_user_info
(
GetUserId
(),
&
use_super
,
NULL
))
elog
(
ERROR
,
"current user name is invalid"
);
/*
/*
* Obtain exclusive lock on pg_database. We need this to ensure that
* Obtain exclusive lock on pg_database. We need this to ensure that
* no new backend starts up in the target database while we are
* no new backend starts up in the target database while we are
...
@@ -368,7 +358,7 @@ dropdb(const char *dbname)
...
@@ -368,7 +358,7 @@ dropdb(const char *dbname)
&
db_istemplate
,
NULL
,
NULL
,
NULL
,
dbpath
))
&
db_istemplate
,
NULL
,
NULL
,
NULL
,
dbpath
))
elog
(
ERROR
,
"DROP DATABASE: database
\"
%s
\"
does not exist"
,
dbname
);
elog
(
ERROR
,
"DROP DATABASE: database
\"
%s
\"
does not exist"
,
dbname
);
if
(
!
use_super
&&
GetUserId
()
!=
db_owner
)
if
(
GetUserId
()
!=
db_owner
&&
!
superuser
()
)
elog
(
ERROR
,
"DROP DATABASE: permission denied"
);
elog
(
ERROR
,
"DROP DATABASE: permission denied"
);
/*
/*
...
@@ -605,25 +595,23 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
...
@@ -605,25 +595,23 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
}
}
static
bool
static
bool
get_user_info
(
Oid
use_sysid
,
bool
*
use_super
,
bool
*
use_createdb
)
have_createdb_privilege
(
void
)
{
{
HeapTuple
utup
;
HeapTuple
utup
;
bool
retval
;
utup
=
SearchSysCache
(
SHADOWSYSID
,
utup
=
SearchSysCache
(
SHADOWSYSID
,
ObjectIdGetDatum
(
use_sysid
),
ObjectIdGetDatum
(
GetUserId
()
),
0
,
0
,
0
);
0
,
0
,
0
);
if
(
!
HeapTupleIsValid
(
utup
))
if
(
!
HeapTupleIsValid
(
utup
))
return
false
;
retval
=
true
;
else
if
(
use_super
)
retval
=
((
Form_pg_shadow
)
GETSTRUCT
(
utup
))
->
usecreatedb
;
*
use_super
=
((
Form_pg_shadow
)
GETSTRUCT
(
utup
))
->
usesuper
;
if
(
use_createdb
)
*
use_createdb
=
((
Form_pg_shadow
)
GETSTRUCT
(
utup
))
->
usecreatedb
;
ReleaseSysCache
(
utup
);
ReleaseSysCache
(
utup
);
return
true
;
return
retval
;
}
}
...
...
src/backend/utils/misc/superuser.c
View file @
25f050d9
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.2
0 2002/02/18 23:11:26
petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.2
1 2002/04/11 05:32:03
petere Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -27,6 +27,11 @@
...
@@ -27,6 +27,11 @@
/*
/*
* The Postgres user running this command has Postgres superuser privileges
* The Postgres user running this command has Postgres superuser privileges
*
* All code should use either of these two functions to find out
* whether a given user is a superuser, rather than evaluating
* pg_shadow.usesuper directly, so that the escape hatch built in for
* the single-user case works.
*/
*/
bool
bool
superuser
(
void
)
superuser
(
void
)
...
...
src/include/catalog/pg_shadow.h
View file @
25f050d9
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pg_shadow.h,v 1.1
8 2002/03/01 22:45:17
petere Exp $
* $Id: pg_shadow.h,v 1.1
9 2002/04/11 05:32:03
petere Exp $
*
*
* NOTES
* NOTES
* the genbki.sh script reads this file and generates .bki
* the genbki.sh script reads this file and generates .bki
...
@@ -35,7 +35,7 @@ CATALOG(pg_shadow) BOOTSTRAP BKI_WITHOUT_OIDS
...
@@ -35,7 +35,7 @@ CATALOG(pg_shadow) BOOTSTRAP BKI_WITHOUT_OIDS
int4
usesysid
;
int4
usesysid
;
bool
usecreatedb
;
bool
usecreatedb
;
bool
usetrace
;
bool
usetrace
;
bool
usesuper
;
bool
usesuper
;
/* read this field via superuser() only */
bool
usecatupd
;
bool
usecatupd
;
text
passwd
;
text
passwd
;
int4
valuntil
;
int4
valuntil
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment