Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2a1d707

Browse files
committed
Refactor recordExtObjInitPriv()
Instead of half a dozen of mostly-duplicate conditional branches, write one common one that can handle most catalogs. We already have all the information we need, such as which system catalog corresponds to which catalog table and which column is the ACL column. Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/504bc485-6bd6-dd1b-fe10-e7351aeb310d@enterprisedb.com
1 parent 13b345d commit 2a1d707

File tree

1 file changed

+8
-144
lines changed

1 file changed

+8
-144
lines changed

src/backend/catalog/aclchk.c

+8-144
Original file line numberDiff line numberDiff line change
@@ -4241,9 +4241,6 @@ recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId,
42414241
*
42424242
* For the object passed in, this will record its ACL (if any) and the ACLs of
42434243
* any sub-objects (eg: columns) into pg_init_privs.
4244-
*
4245-
* Any new kinds of objects which have ACLs associated with them and can be
4246-
* added to an extension should be added to the if-else tree below.
42474244
*/
42484245
void
42494246
recordExtObjInitPriv(Oid objoid, Oid classoid)
@@ -4336,74 +4333,6 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
43364333

43374334
ReleaseSysCache(tuple);
43384335
}
4339-
/* pg_foreign_data_wrapper */
4340-
else if (classoid == ForeignDataWrapperRelationId)
4341-
{
4342-
Datum aclDatum;
4343-
bool isNull;
4344-
HeapTuple tuple;
4345-
4346-
tuple = SearchSysCache1(FOREIGNDATAWRAPPEROID,
4347-
ObjectIdGetDatum(objoid));
4348-
if (!HeapTupleIsValid(tuple))
4349-
elog(ERROR, "cache lookup failed for foreign data wrapper %u",
4350-
objoid);
4351-
4352-
aclDatum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID, tuple,
4353-
Anum_pg_foreign_data_wrapper_fdwacl,
4354-
&isNull);
4355-
4356-
/* Add the record, if any, for the top-level object */
4357-
if (!isNull)
4358-
recordExtensionInitPrivWorker(objoid, classoid, 0,
4359-
DatumGetAclP(aclDatum));
4360-
4361-
ReleaseSysCache(tuple);
4362-
}
4363-
/* pg_foreign_server */
4364-
else if (classoid == ForeignServerRelationId)
4365-
{
4366-
Datum aclDatum;
4367-
bool isNull;
4368-
HeapTuple tuple;
4369-
4370-
tuple = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(objoid));
4371-
if (!HeapTupleIsValid(tuple))
4372-
elog(ERROR, "cache lookup failed for foreign server %u",
4373-
objoid);
4374-
4375-
aclDatum = SysCacheGetAttr(FOREIGNSERVEROID, tuple,
4376-
Anum_pg_foreign_server_srvacl,
4377-
&isNull);
4378-
4379-
/* Add the record, if any, for the top-level object */
4380-
if (!isNull)
4381-
recordExtensionInitPrivWorker(objoid, classoid, 0,
4382-
DatumGetAclP(aclDatum));
4383-
4384-
ReleaseSysCache(tuple);
4385-
}
4386-
/* pg_language */
4387-
else if (classoid == LanguageRelationId)
4388-
{
4389-
Datum aclDatum;
4390-
bool isNull;
4391-
HeapTuple tuple;
4392-
4393-
tuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(objoid));
4394-
if (!HeapTupleIsValid(tuple))
4395-
elog(ERROR, "cache lookup failed for language %u", objoid);
4396-
4397-
aclDatum = SysCacheGetAttr(LANGOID, tuple, Anum_pg_language_lanacl,
4398-
&isNull);
4399-
4400-
/* Add the record, if any, for the top-level object */
4401-
if (!isNull)
4402-
recordExtensionInitPrivWorker(objoid, classoid, 0,
4403-
DatumGetAclP(aclDatum));
4404-
4405-
ReleaseSysCache(tuple);
4406-
}
44074336
/* pg_largeobject_metadata */
44084337
else if (classoid == LargeObjectMetadataRelationId)
44094338
{
@@ -4446,60 +4375,21 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
44464375

44474376
systable_endscan(scan);
44484377
}
4449-
/* pg_namespace */
4450-
else if (classoid == NamespaceRelationId)
4378+
/* This will error on unsupported classoid. */
4379+
else if (get_object_attnum_acl(classoid) != InvalidAttrNumber)
44514380
{
44524381
Datum aclDatum;
44534382
bool isNull;
44544383
HeapTuple tuple;
44554384

4456-
tuple = SearchSysCache1(NAMESPACEOID, ObjectIdGetDatum(objoid));
4457-
if (!HeapTupleIsValid(tuple))
4458-
elog(ERROR, "cache lookup failed for schema %u", objoid);
4459-
4460-
aclDatum = SysCacheGetAttr(NAMESPACEOID, tuple,
4461-
Anum_pg_namespace_nspacl, &isNull);
4462-
4463-
/* Add the record, if any, for the top-level object */
4464-
if (!isNull)
4465-
recordExtensionInitPrivWorker(objoid, classoid, 0,
4466-
DatumGetAclP(aclDatum));
4467-
4468-
ReleaseSysCache(tuple);
4469-
}
4470-
/* pg_proc */
4471-
else if (classoid == ProcedureRelationId)
4472-
{
4473-
Datum aclDatum;
4474-
bool isNull;
4475-
HeapTuple tuple;
4476-
4477-
tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(objoid));
4478-
if (!HeapTupleIsValid(tuple))
4479-
elog(ERROR, "cache lookup failed for function %u", objoid);
4480-
4481-
aclDatum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proacl,
4482-
&isNull);
4483-
4484-
/* Add the record, if any, for the top-level object */
4485-
if (!isNull)
4486-
recordExtensionInitPrivWorker(objoid, classoid, 0,
4487-
DatumGetAclP(aclDatum));
4488-
4489-
ReleaseSysCache(tuple);
4490-
}
4491-
/* pg_type */
4492-
else if (classoid == TypeRelationId)
4493-
{
4494-
Datum aclDatum;
4495-
bool isNull;
4496-
HeapTuple tuple;
4497-
4498-
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(objoid));
4385+
tuple = SearchSysCache1(get_object_catcache_oid(classoid),
4386+
ObjectIdGetDatum(objoid));
44994387
if (!HeapTupleIsValid(tuple))
4500-
elog(ERROR, "cache lookup failed for type %u", objoid);
4388+
elog(ERROR, "cache lookup failed for %s %u",
4389+
get_object_class_descr(classoid), objoid);
45014390

4502-
aclDatum = SysCacheGetAttr(TYPEOID, tuple, Anum_pg_type_typacl,
4391+
aclDatum = SysCacheGetAttr(get_object_catcache_oid(classoid), tuple,
4392+
get_object_attnum_acl(classoid),
45034393
&isNull);
45044394

45054395
/* Add the record, if any, for the top-level object */
@@ -4509,32 +4399,6 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
45094399

45104400
ReleaseSysCache(tuple);
45114401
}
4512-
else if (classoid == AccessMethodRelationId ||
4513-
classoid == CastRelationId ||
4514-
classoid == CollationRelationId ||
4515-
classoid == ConversionRelationId ||
4516-
classoid == EventTriggerRelationId ||
4517-
classoid == OperatorRelationId ||
4518-
classoid == OperatorClassRelationId ||
4519-
classoid == OperatorFamilyRelationId ||
4520-
classoid == TSConfigRelationId ||
4521-
classoid == TSDictionaryRelationId ||
4522-
classoid == TSParserRelationId ||
4523-
classoid == TSTemplateRelationId ||
4524-
classoid == TransformRelationId
4525-
)
4526-
{
4527-
/* no ACL for these object types, so do nothing. */
4528-
}
4529-
4530-
/*
4531-
* complain if we are given a class OID for a class that extensions don't
4532-
* support or that we don't recognize.
4533-
*/
4534-
else
4535-
{
4536-
elog(ERROR, "unrecognized or unsupported class OID: %u", classoid);
4537-
}
45384402
}
45394403

45404404
/*

0 commit comments

Comments
 (0)