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
pull/137/head
Peter Eisentraut 3 years ago
parent 3b7cd8c690
commit 442f870065
  1. 2
      src/backend/replication/slot.c
  2. 4
      src/backend/utils/init/miscinit.c
  3. 2
      src/backend/utils/init/postinit.c

@ -1140,7 +1140,7 @@ CheckSlotRequirements(void)
void void
CheckSlotPermissions(void) CheckSlotPermissions(void)
{ {
if (!superuser() && !has_rolreplication(GetUserId())) if (!has_rolreplication(GetUserId()))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser or replication role to use replication slots"))); errmsg("must be superuser or replication role to use replication slots")));

@ -709,6 +709,10 @@ has_rolreplication(Oid roleid)
bool result = false; bool result = false;
HeapTuple utup; HeapTuple utup;
/* Superusers bypass all permission checking. */
if (superuser_arg(roleid))
return true;
utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid)); utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
if (HeapTupleIsValid(utup)) if (HeapTupleIsValid(utup))
{ {

@ -962,7 +962,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
{ {
Assert(!bootstrap); Assert(!bootstrap);
if (!superuser() && !has_rolreplication(GetUserId())) if (!has_rolreplication(GetUserId()))
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser or replication role to start walsender"))); errmsg("must be superuser or replication role to start walsender")));

Loading…
Cancel
Save