Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJvj2-007PRh-LZ for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2024 13:51:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sJvj0-00GvXh-CX for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2024 13:51:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJvj0-00GvXZ-1G for pgsql-hackers@lists.postgresql.org; Wed, 19 Jun 2024 13:51:46 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sJviy-002TZf-SF for pgsql-hackers@postgresql.org; Wed, 19 Jun 2024 13:51:46 +0000 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a6e349c0f2bso855221366b.2 for ; Wed, 19 Jun 2024 06:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718805103; x=1719409903; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OY1aEpd9i/w7kv10XB1Wl28daRhZtA9dPwXN7AJQQ6M=; b=XUN5CWak7q+p4bym1CnseR5BT5mfmoBjj99IBDQKtz0rcUnQ8tQsPKfTmOoNuGAiha 9gMm06WfGTUrJxlNGQ9JOLAiABCqTwzW3FQzX90HLb6Xzc7Aw/pWf35ys3foLIruNxyS yMsRNqgIxVZTbYy4xERrARy8X0f6MkuoVCmiRuszZeh+Bfagy7XnBOVHnCGhAvXyQ3kn S5euS7+93ISdd3I13vNaabTxT80XtfTMeBXvhQt3myvhcGBBuByTBX0eHoTeeFx1F+VE 9IylM/fAM2u3Ki0U6Ja/Da6cdhmEwaHCkFjEdpT1F3kHGeD120bkZ0cYRtQIo9EIni20 gLQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718805103; x=1719409903; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OY1aEpd9i/w7kv10XB1Wl28daRhZtA9dPwXN7AJQQ6M=; b=KIOTJrV7oT8fNfUJ1vZLzgiZnRo0uizQzEiOZ9Y5tWrU7cdwiu5iuUt8Tmg7l0bi8w fSgZJPTTce+RprNVvUPB7Gaa8te1SwA9Is3c8NLTZsABRL5Bxh/5zNBtJe3zsSGQeqI4 f/sKJZHmNnNV2uHPcgawQXho70AmTOaVl9+mmKtVIJF66wkwUBdSLuTzAPzVqBueG43i ME978qbYQfTVwnHL0hgqakD69wx1goiIYXBgC6rMcxjIZGP0rz+LldW7GxcxTO6EkXHi knlhEu2eydeP/wBv1FRNFP2bOp0wdh/58qoPmEnUi97ThlqvfPpeJc0RC4IPqTGkcJnh x2Nw== X-Gm-Message-State: AOJu0Yw26lGSPKjqydndv2mgUNag2hLjoEM/nIo4rnCKz2rz9TBavDjZ PfbMgPqsKgMGskmoBIihP+gFv7SmtTY1lT0d/mg2A4FshRWFjXCFMF3neG8TbpbfFMgjTtNSXVf 0+xFoE4Erc3z/uEI2fZJFN2nrW0YvVqBY X-Google-Smtp-Source: AGHT+IFVxcCysH9uSCNMsP8BtfA+MRq44neJTrzWMEvRWk4ojgiF0wKCUYhg+vrbtaT7jN2M4TyFIefixTVCogEcZfU= X-Received: by 2002:a17:906:2316:b0:a6d:f339:f8 with SMTP id a640c23a62f3a-a6fab62f612mr157551466b.31.1718805103354; Wed, 19 Jun 2024 06:51:43 -0700 (PDT) MIME-Version: 1.0 References: <80b16434-b9b1-4c3d-8f28-569f21c2c102@app.fastmail.com> <2c4c70ef-6567-4f5a-baa0-e16eb9430572@app.fastmail.com> In-Reply-To: From: Ranier Vilela Date: Wed, 19 Jun 2024 10:51:32 -0300 Message-ID: Subject: Re: Add pg_get_acl() function get the ACL for a database object To: Joel Jacobson Cc: pgsql-hackers Content-Type: multipart/alternative; boundary="0000000000009fad60061b3e7f7e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009fad60061b3e7f7e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em qua., 19 de jun. de 2024 =C3=A0s 10:28, Ranier Vilela escreveu: > Em qua., 19 de jun. de 2024 =C3=A0s 10:26, Joel Jacobson > escreveu: > >> Hi Ranier, >> >> Thanks for looking at this. >> >> I've double-checked the patch I sent, and it works fine. >> >> I think I know the cause of your problem: >> >> Since this is a catalog change, you need to run `make clean`, to ensure >> the catalog is rebuilt, >> followed by the usual `make && make install`. >> >> You also need to run `initdb` to create a new database cluster, with the >> new catalog version. >> >> Let me know if you need more specific instructions. >> > Sorry, sorry but I'm on Windows -> meson. > > Double checked with: > ninja clean > ninja > ninja install > Sorry for the noise, now pg_get_acl is shown in the regress test. Regarding the patch, could it be written in the following style? Datum pg_get_acl(PG_FUNCTION_ARGS) { Oid classId =3D PG_GETARG_OID(0); Oid objectId =3D PG_GETARG_OID(1); Oid catalogId; AttrNumber Anum_oid; AttrNumber Anum_acl; /* for "pinned" items in pg_depend, return null */ if (!OidIsValid(classId) && !OidIsValid(objectId)) PG_RETURN_NULL(); catalogId =3D (classId =3D=3D LargeObjectRelationId) ? LargeObjectMetadataRelationId : classId; Anum_oid =3D get_object_attnum_oid(catalogId); Anum_acl =3D get_object_attnum_acl(catalogId); if (Anum_acl !=3D InvalidAttrNumber) { Relation rel; HeapTuple tup; Datum datum; bool isnull; rel =3D table_open(catalogId, AccessShareLock); tup =3D get_catalog_object_by_oid(rel, Anum_oid, objectId); if (!HeapTupleIsValid(tup)) elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"", objectId, RelationGetRelationName(rel)); datum =3D heap_getattr(tup, Anum_acl, RelationGetDescr(rel), &isnull); table_close(rel, AccessShareLock); if (!isnull) PG_RETURN_DATUM(datum); } PG_RETURN_NULL(); } best regards, Ranier Vilela --0000000000009fad60061b3e7f7e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Em qua., 19 de jun. de 2024 =C3=A0s 10:28, Ranier Vilela <ranier.vf@gmail.com> escreveu:
Em qua., 19 de= jun. de 2024 =C3=A0s 10:26, Joel Jacobson <joel@compiler.org> escreveu:
Hi Ranier,

Thanks for looking at this.

I've double-checked the patch I sent, and it works fine.

I think I know the cause of your problem:

Since this is a catalog change, you need to run `make clean`, to ensure the= catalog is rebuilt,
followed by the usual `make && make install`.

You also need to run `initdb` to create a new database cluster, with the ne= w catalog version.

Let me know if you need more specific instructions.
So= rry,=C2=A0sorry but I'm on Windows -> meson.

Double checked with:
ninja clean
ninja
ninj= a install
Sorry for the noise, now pg_ge= t_acl is shown in the regress test.

Regarding the = patch, could it be written in the following style?

Datum
pg_get_acl(PG_FUNCTION_ARGS)
{
Oid classId =3D PG_GETARG= _OID(0);
Oid objectId =3D PG_GETARG_OID(1);
Oid catalogId;
= AttrNumber Anum_oid;
AttrNumber Anum_acl;

/* for "pinned&q= uot; items in pg_depend, return null */
if (!OidIsValid(classId) &&= amp; !OidIsValid(objectId))
PG_RETURN_NULL();

catalogId =3D (c= lassId =3D=3D LargeObjectRelationId) ? LargeObjectMetadataRelationId : clas= sId;
Anum_oid =3D get_object_attnum_oid(catalogId);
Anum_acl =3D ge= t_object_attnum_acl(catalogId);

if (Anum_acl !=3D InvalidAttrNumber= )
{
Relation rel;
HeapTuple tup;
Datum datum;
bool= isnull;

rel =3D table_open(catalogId, AccessShareLock);

= tup =3D get_catalog_object_by_oid(rel, Anum_oid, objectId);
if (!Heap= TupleIsValid(tup))
elog(ERROR, "cache lookup failed for object %= u of catalog \"%s\"",
objectId, RelationGetRelationNa= me(rel));

datum =3D heap_getattr(tup, Anum_acl, RelationGetDescr(r= el), &isnull);

table_close(rel, AccessShareLock);

if = (!isnull)
PG_RETURN_DATUM(datum);
}

PG_RETURN_NULL();
= }

best regards,
Ranier Vilela
<= /div> --0000000000009fad60061b3e7f7e--