pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Nathan Bossart <nathan@postgresql.org>
Subject: [PATCH v6 4/4] avoid locking before privilege checks in dblink
Date: Fri, 10 Oct 2025 09:37:51 -0500
---
contrib/dblink/dblink.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 0cf4c27f2e9..1e7696beb50 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -2460,6 +2460,21 @@ get_tuple_of_interest(Relation rel, int *pkattnums, int pknumatts, char **src_pk
return NULL;
}
+static void
+RangeVarCallbackForDblink(const RangeVar *relation,
+ Oid relId, Oid oldRelId, void *arg)
+{
+ AclResult aclresult;
+
+ if (!OidIsValid(relId))
+ return;
+
+ aclresult = pg_class_aclcheck(relId, GetUserId(), *((AclMode *) arg));
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, get_relkind_objtype(get_rel_relkind(relId)),
+ relation->relname);
+}
+
/*
* Open the relation named by relname_text, acquire specified type of lock,
* verify we have specified permissions.
@@ -2469,19 +2484,13 @@ static Relation
get_rel_from_relname(text *relname_text, LOCKMODE lockmode, AclMode aclmode)
{
RangeVar *relvar;
- Relation rel;
- AclResult aclresult;
+ Oid relid;
relvar = makeRangeVarFromNameList(textToQualifiedNameList(relname_text));
- rel = table_openrv(relvar, lockmode);
-
- aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
- aclmode);
- if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
- RelationGetRelationName(rel));
+ relid = RangeVarGetRelidExtended(relvar, lockmode, 0,
+ RangeVarCallbackForDblink, &aclmode);
- return rel;
+ return table_open(relid, NoLock);
}
/*
--
2.39.5 (Apple Git-154)
--iujXWOSrXz0NaSpd--
Message-ID: <no-message-id-49386@localhost>
Permalink: ../no-message-id-49386@localhost/
Also on: postgresql.org/message-id/no-message-id-49386@localhost
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-general@postgresql.org
Cc: nathan@postgresql.org
Subject: Re: [PATCH v6 4/4] avoid locking before privilege checks in dblink
In-Reply-To: <no-message-id-49386@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox