| From: | "Bossart, Nathan" <bossartn(at)amazon(dot)com> | 
|---|---|
| To: | Euler Taveira <euler(at)eulerto(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> | 
| Subject: | Re: Remove duplicate static function check_permissions in slotfuncs.c and logicalfuncs.c | 
| Date: | 2021-09-12 23:02:49 | 
| Message-ID: | 8B25951C-11C8-466E-9612-5DE0362083E1@amazon.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On 9/11/21, 1:31 AM, "Bharath Rupireddy" <bharath(dot)rupireddyforpostgres(at)gmail(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Euler Taveira | 2021-09-13 00:25:32 | Re: TAP test for recovery_end_command | 
| Previous Message | Justin Pryzby | 2021-09-12 20:10:29 | Re: CLUSTER on partitioned index |