From: Antonin Houska <ah@cybertec.at>
To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: refactor ExecGrant_*() functions
Date: Tue, 06 Dec 2022 09:41:58 +0100
Message-ID: <24706.1670316118@antos> (raw)
In-Reply-To: <22c7e802-4e7d-8d87-8b71-cba95e6f4bcf@enterprisedb.com>
References: <22c7e802-4e7d-8d87-8b71-cba95e6f4bcf@enterprisedb.com>
Peter Eisentraut <peter.eisentraut@enterprisedb.com> wrote:
> Continuing the ideas in [0], this patch refactors the ExecGrant_Foo()
> functions and replaces many of them by a common function that is driven by the
> ObjectProperty table.
>
> It would be nice to do more here, for example ExecGrant_Language(), which has
> additional non-generalizable checks, but I think this is already a good start.
> For example, the work being discussed on privileges on publications [1] would
> be able to take good advantage of this.
Right, I mostly copy and pasted the code when writing
ExecGrant_Publication(). I agree that your refactoring is very useful.
Attached are my proposals for improvements. One is to avoid memory leak, the
other tries to improve readability a little bit.
> [0]:
> https://www.postgresql.org/message-id/95c30f96-4060-2f48-98b5-a4392d3b6066@enterprisedb.com
> [1]: https://www.postgresql.org/message-id/flat/20330.1652105397@antos
--
Antonin Houska
Web: https://www.cybertec-postgresql.comAttachments:download all (2 files, .tar.gz)free_local_variables.diff (text/x-diff, 503B) downloaddiff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.cindex d3121a469f..ac4490c0b8 100644--- a/src/backend/catalog/aclchk.c+++ b/src/backend/catalog/aclchk.c@@ -2228,6 +2234,9 @@ ExecGrant_generic(InternalGrant *istmt, Oid classid, AclMode default_privs)
newtuple = heap_modify_tuple(tuple, RelationGetDescr(relation), values,
nulls, replaces);
+ pfree(values);+ pfree(nulls);+ pfree(replaces);
CatalogTupleUpdate(relation, &newtuple->t_self, newtuple);
introduce_nameDatum_variable.diff (text/x-diff, 1.3K) downloaddiff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.cindex d3121a469f..ac4490c0b8 100644--- a/src/backend/catalog/aclchk.c+++ b/src/backend/catalog/aclchk.c@@ -2144,6 +2144,7 @@ ExecGrant_generic(InternalGrant *istmt, Oid classid, AclMode default_privs)
{
Oid objectid = lfirst_oid(cell);
Datum aclDatum;
+ Datum nameDatum;
bool isNull;
AclMode avail_goptions;
AclMode this_privileges;
@@ -2197,6 +2198,11 @@ ExecGrant_generic(InternalGrant *istmt, Oid classid, AclMode default_privs)
old_acl, ownerId,
&grantorId, &avail_goptions);
+ nameDatum = SysCacheGetAttr(cacheid, tuple,+ get_object_attnum_name(classid),+ &isNull);+ Assert(!isNull);+
/*
* Restrict the privileges to what we can actually grant, and emit the
* standards-mandated warning and error messages.
@@ -2205,7 +2211,7 @@ ExecGrant_generic(InternalGrant *istmt, Oid classid, AclMode default_privs)
restrict_and_check_grant(istmt->is_grant, avail_goptions,
istmt->all_privs, istmt->privileges,
objectid, grantorId, get_object_type(classid, objectid),
- NameStr(*DatumGetName(SysCacheGetAttr(cacheid, tuple, get_object_attnum_name(classid), &isNull))),+ NameStr(*DatumGetName(nameDatum)),
0, NULL);
/*
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: ah@cybertec.at, peter.eisentraut@enterprisedb.com
Subject: Re: refactor ExecGrant_*() functions
In-Reply-To: <24706.1670316118@antos>
References: <22c7e802-4e7d-8d87-8b71-cba95e6f4bcf@enterprisedb.com> <24706.1670316118@antos>
* 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