aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2023-03-16 15:43:33 +0100
committerPeter Eisentraut <peter@eisentraut.org>2023-03-16 15:43:33 +0100
commit442f8700656bb5ce525d352241a17bbab14193c7 (patch)
tree6a4edb0d57f6d11ba23576788b8d6bf7c73b98d9
parent3b7cd8c690f294185c1ba074fb7efdf687829361 (diff)
downloadpostgresql-442f8700656bb5ce525d352241a17bbab14193c7.tar.gz
postgresql-442f8700656bb5ce525d352241a17bbab14193c7.zip
Integrate superuser check into has_rolreplication()
This makes it consistent with similar functions like has_createrole_privilege() and allows removing some explicit superuser checks. Author: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://www.postgresql.org/message-id/20230310000313.GA3992372%40nathanxps13
-rw-r--r--src/backend/replication/slot.c2
-rw-r--r--src/backend/utils/init/miscinit.c4
-rw-r--r--src/backend/utils/init/postinit.c2
3 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index f286918f69e..3506b77cc7c 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -1140,7 +1140,7 @@ CheckSlotRequirements(void)
void
CheckSlotPermissions(void)
{
- if (!superuser() && !has_rolreplication(GetUserId()))
+ if (!has_rolreplication(GetUserId()))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser or replication role to use replication slots")));
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 7eb7fe87f68..a604432126c 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -709,6 +709,10 @@ has_rolreplication(Oid roleid)
bool result = false;
HeapTuple utup;
+ /* Superusers bypass all permission checking. */
+ if (superuser_arg(roleid))
+ return true;
+
utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
if (HeapTupleIsValid(utup))
{
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index b0e20cc6357..3026317bfc9 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -962,7 +962,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
{
Assert(!bootstrap);
- if (!superuser() && !has_rolreplication(GetUserId()))
+ if (!has_rolreplication(GetUserId()))
ereport(FATAL,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser or replication role to start walsender")));