Re: Remove duplicate static function check_permissions in slotfuncs.c and logicalfuncs.c - Mailing list pgsql-hackers

From Bossart, Nathan
Subject Re: Remove duplicate static function check_permissions in slotfuncs.c and logicalfuncs.c
Date
Msg-id 8B25951C-11C8-466E-9612-5DE0362083E1@amazon.com
Whole thread Raw
In response to Re: Remove duplicate static function check_permissions in slotfuncs.c and logicalfuncs.c  ("Euler Taveira" <euler@eulerto.com>)
Responses Re: Remove duplicate static function check_permissions in slotfuncs.c and logicalfuncs.c
List pgsql-hackers
On 9/11/21, 1:31 AM, "Bharath Rupireddy" <bharath.rupireddyforpostgres@gmail.com> wrote:
> We have two static check_permissions functions (one in slotfuncs.c
> another in logicalfuncs.c) with the same name and same code for
> checking the privileges for using replication slots. Why can't we have
> a single function CheckReplicationSlotPermissions in slot.c? This way,
> we can get rid of redundant code. Attaching a patch for it.

+1

+/*
+ * Check whether the user has privilege to use replication slots.
+ */
+void
+CheckReplicationSlotPermissions(void)
+{
+    if (!superuser() && !has_rolreplication(GetUserId()))
+        ereport(ERROR,
+                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                 (errmsg("must be superuser or replication role to use replication slots"))));
+}

nitpick: It looks like there's an extra set of parentheses around
errmsg().

Nathan


pgsql-hackers by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: Numeric x^y for negative x
Next
From: "Euler Taveira"
Date:
Subject: Re: TAP test for recovery_end_command