Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUhPX-0008Qo-Op for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jan 2017 22:11:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cUhPV-0005Kh-Qs for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jan 2017 22:11:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cUhPU-0005K5-BA for pgsql-bugs@postgresql.org; Fri, 20 Jan 2017 22:11:52 +0000 Received: from tamriel.snowman.net ([72.66.115.51]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUhPJ-0002lp-Tj for pgsql-bugs@postgresql.org; Fri, 20 Jan 2017 22:11:51 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 2C87B5F796; Fri, 20 Jan 2017 17:10:40 -0500 (EST) Date: Fri, 20 Jan 2017 17:10:40 -0500 From: Stephen Frost To: Tom Lane Cc: Moshe Jacobson , daniele.varrazzo@gmail.com, pgsql-bugs@postgresql.org Subject: Re: BUG #14456: pg_dump doesn't restore permissions on tables belonging to an extension Message-ID: <20170120221039.GZ18360@tamriel.snowman.net> References: <20161208191642.1407.30751@wrigleys.postgresql.org> <20161208192933.GG23417@tamriel.snowman.net> <20170112183457.GJ18360@tamriel.snowman.net> <12559.1484247701@sss.pgh.pa.us> <20170112190830.GP18360@tamriel.snowman.net> <13549.1484248592@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="azbj2yYfSrDqVwxe" Content-Disposition: inline In-Reply-To: <13549.1484248592@sss.pgh.pa.us> X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/3.13.0-91-generic (x86_64) X-Uptime: 17:05:34 up 195 days, 23:29, 3 users, load average: 0.03, 0.11, 0.13 User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -5.1 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --azbj2yYfSrDqVwxe Content-Type: multipart/mixed; boundary="kiLOsm1CQXt3zDau" Content-Disposition: inline --kiLOsm1CQXt3zDau Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Tom, Moshe, * Tom Lane (tgl@sss.pgh.pa.us) wrote: > Stephen Frost writes: > > * Tom Lane (tgl@sss.pgh.pa.us) wrote: > >> Hmm. There's an argument to be made that ALTER EXTENSION ADD should > >> absorb whatever the object's current ACLs are into the pg_init_privs > >> entries for the extension. (I don't think it does that now, though > >> I might be wrong.) However ... >=20 > > I've not gone and looked yet, but I doubt that it does. I think I can > > agree with the argument that it really should add those ACLs to > > pg_init_privs. Of course, any furhter manipulation of the ACLs from > > that point will cause those ACLs to be included in the pg_dump. >=20 > > I'll take a look at ALTER EXTENSION ADD and pg_init_privs. >=20 > By the same token, does ALTER EXTENSION DROP remove those entries? Please find attached a WIP patch to have ALTER EXTENSION ADD/DROP update pg_init_privs accordingly. It's a bit big as it needs to have independent code for every different kind of object that ALTER EXTENSION ADD/DROP supports. Most of that code is pretty boiler-plate, of course. I'm planning to review it further, add more regression tests, and then back-patch it to 9.6. Moshe, if you're feeling adventurous and want to give it a spin and make sure it behaves as you're expecting, that'd be great. Tom, your thoughts and comments are always welcome, if you'd like to peruse the patch, of course. Otherwise, I expect to have time to wrap this all up over the weekend. Thanks! Stephen --kiLOsm1CQXt3zDau Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="alter_ext_adddrop_init_privs_v1_master.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c new file mode 100644 index 7803d0d..73471c6 *** a/src/backend/catalog/aclchk.c --- b/src/backend/catalog/aclchk.c *************** *** 27,33 **** --- 27,36 ---- #include "catalog/dependency.h" #include "catalog/indexing.h" #include "catalog/objectaccess.h" + #include "catalog/pg_aggregate.h" + #include "catalog/pg_am.h" #include "catalog/pg_authid.h" + #include "catalog/pg_cast.h" #include "catalog/pg_collation.h" #include "catalog/pg_conversion.h" #include "catalog/pg_database.h" *************** *** 49,54 **** --- 52,60 ---- #include "catalog/pg_type.h" #include "catalog/pg_ts_config.h" #include "catalog/pg_ts_dict.h" + #include "catalog/pg_ts_parser.h" + #include "catalog/pg_ts_template.h" + #include "catalog/pg_transform.h" #include "commands/dbcommands.h" #include "commands/event_trigger.h" #include "commands/extension.h" *************** static AclMode pg_aclmask(AclObjectKind *** 130,135 **** --- 136,143 ---- Oid roleid, AclMode mask, AclMaskHow how); static void recordExtensionInitPriv(Oid objoid, Oid classoid, int objsubi= d, Acl *new_acl); + static void recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int o= bjsubid, + Acl *new_acl); =20 =20 #ifdef ACLDEBUG *************** get_user_default_acl(GrantObjectType obj *** 5226,5235 **** } =20 /* ! * Record initial ACL for an extension object * ! * This will perform a wholesale replacement of the entire ACL for the ob= ject ! * passed in, therefore be sure to pass in the complete new ACL to use. * * Can be called at any time, we check if 'creating_extension' is set and= , if * not, exit immediately. --- 5234,5604 ---- } =20 /* ! * Record initial privileges for the top-level object passed in. * ! * For the object passed in, this will record its ACL (if any) and the AC= Ls of ! * any sub-objects (eg: columns) into pg_init_privs. ! * ! * Any new kinds of objects which have ACLs associated with them and can = be ! * added to an extension should be added to the if-else tree below. ! */ ! void ! recordExtObjInitPriv(Oid objoid, Oid classoid) ! { ! /* ! * pg_class / pg_attribute ! * ! * If this is a relation then we need to see if there are any sub-objects ! * (eg: columns) for it and, if so, be sure to call ! * recordExtensionInitPrivWorker() for each one. ! */ ! if (classoid =3D=3D RelationRelationId) ! { ! Form_pg_class pg_class_tuple; ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(RELOID, ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for relation %u", objoid); ! pg_class_tuple =3D (Form_pg_class) GETSTRUCT(tuple); !=20 ! /* Indexes don't have permissions */ ! if (pg_class_tuple->relkind =3D=3D RELKIND_INDEX) ! return; !=20 ! /* Composite types don't have permissions either */ ! if (pg_class_tuple->relkind =3D=3D RELKIND_COMPOSITE_TYPE) ! return; !=20 ! /* ! * If this isn't a sequence, index, or composite type then it's ! * possibly going to have columns associated with it that might have ! * ACLs. ! */ ! if (pg_class_tuple->relkind !=3D RELKIND_SEQUENCE) ! { ! AttrNumber curr_att; ! AttrNumber nattrs =3D pg_class_tuple->relnatts; !=20 ! for (curr_att =3D 1; curr_att <=3D nattrs; curr_att++) ! { ! HeapTuple attTuple; ! Datum attaclDatum; !=20 ! attTuple =3D SearchSysCache2(ATTNUM, ! ObjectIdGetDatum(objoid), ! Int16GetDatum(curr_att)); !=20 ! if (!HeapTupleIsValid(attTuple)) ! continue; !=20 ! /* ignore dropped columns */ ! if (((Form_pg_attribute) GETSTRUCT(attTuple))->attisdropped) ! { ! ReleaseSysCache(attTuple); ! continue; ! } !=20 ! attaclDatum =3D SysCacheGetAttr(ATTNUM, attTuple, ! Anum_pg_attribute_attacl, ! &isNull); !=20 ! /* no need to do anything for a NULL ACL */ ! if (isNull) ! { ! ReleaseSysCache(attTuple); ! continue; ! } !=20 ! recordExtensionInitPrivWorker(objoid, classoid, curr_att, ! DatumGetAclP(attaclDatum)); !=20 ! ReleaseSysCache(attTuple); ! } ! } !=20 ! aclDatum =3D SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relacl, ! &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! ReleaseSysCache(tuple); ! } ! /* pg_foreign_data_wrapper */ ! else if (classoid =3D=3D ForeignDataWrapperRelationId) ! { ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(FOREIGNDATAWRAPPEROID, ! ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for foreign data wrapper %u", ! objoid); !=20 ! aclDatum =3D SysCacheGetAttr(FOREIGNDATAWRAPPEROID, tuple, ! Anum_pg_foreign_data_wrapper_fdwacl, ! &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! ReleaseSysCache(tuple); ! } ! /* pg_foreign_server */ ! else if (classoid =3D=3D ForeignServerRelationId) ! { ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for foreign data wrapper %u", ! objoid); !=20 ! aclDatum =3D SysCacheGetAttr(FOREIGNSERVEROID, tuple, ! Anum_pg_foreign_server_srvacl, ! &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! ReleaseSysCache(tuple); ! } ! /* pg_language */ ! else if (classoid =3D=3D LanguageRelationId) ! { ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(LANGOID, ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for language %u", objoid); !=20 ! aclDatum =3D SysCacheGetAttr(LANGOID, tuple, Anum_pg_language_lanacl, ! &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! ReleaseSysCache(tuple); ! } ! /* pg_largeobject_metadata */ ! else if (classoid =3D=3D LargeObjectMetadataRelationId) ! { ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; ! ScanKeyData entry[1]; ! SysScanDesc scan; ! Relation relation; !=20 ! relation =3D heap_open(LargeObjectMetadataRelationId, RowExclusiveLock); !=20 ! /* There's no syscache for pg_largeobject_metadata */ ! ScanKeyInit(&entry[0], ! ObjectIdAttributeNumber, ! BTEqualStrategyNumber, F_OIDEQ, ! ObjectIdGetDatum(objoid)); !=20 ! scan =3D systable_beginscan(relation, ! LargeObjectMetadataOidIndexId, true, ! NULL, 1, entry); !=20 ! tuple =3D systable_getnext(scan); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for large object %u", objoid); !=20 ! aclDatum =3D heap_getattr(tuple, ! Anum_pg_largeobject_metadata_lomacl, ! RelationGetDescr(relation), &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! systable_endscan(scan); ! } ! /* pg_namespace */ ! else if (classoid =3D=3D NamespaceRelationId) ! { ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(NAMESPACEOID, ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for function %u", objoid); !=20 ! aclDatum =3D SysCacheGetAttr(NAMESPACEOID, tuple, ! Anum_pg_namespace_nspacl, &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! ReleaseSysCache(tuple); ! } ! /* pg_proc */ ! else if (classoid =3D=3D ProcedureRelationId) ! { ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(PROCOID, ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for function %u", objoid); !=20 ! aclDatum =3D SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proacl, ! &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! ReleaseSysCache(tuple); ! } ! /* pg_type */ ! else if (classoid =3D=3D TypeRelationId) ! { ! Datum aclDatum; ! bool isNull; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(TYPEOID, ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for function %u", objoid); !=20 ! aclDatum =3D SysCacheGetAttr(TYPEOID, tuple, Anum_pg_type_typacl, ! &isNull); !=20 ! /* Add the record, if any, for the top-level object */ ! if (!isNull) ! recordExtensionInitPrivWorker(objoid, classoid, 0, ! DatumGetAclP(aclDatum)); !=20 ! ReleaseSysCache(tuple); ! } ! else if (classoid =3D=3D AccessMethodRelationId || ! classoid =3D=3D AggregateRelationId || ! classoid =3D=3D CastRelationId || ! classoid =3D=3D CollationRelationId || ! classoid =3D=3D ConversionRelationId || ! classoid =3D=3D EventTriggerRelationId || ! classoid =3D=3D OperatorRelationId || ! classoid =3D=3D OperatorClassRelationId || ! classoid =3D=3D OperatorFamilyRelationId || ! classoid =3D=3D NamespaceRelationId || ! classoid =3D=3D TSConfigRelationId || ! classoid =3D=3D TSDictionaryRelationId || ! classoid =3D=3D TSParserRelationId || ! classoid =3D=3D TSTemplateRelationId || ! classoid =3D=3D TransformRelationId ! ) ! { ! /* no ACL for these object types, so do nothing. */ ! } ! /* ! * complain if we are given a class OID for a class that extensions don't ! * support or that we don't recognize. ! */ ! else ! { ! elog(ERROR, "unrecognized or unsupported class OID: %u", classoid); ! } ! } !=20 ! /* ! * For the object passed in, remove its ACL and the ACLs of any object su= bIds ! * from pg_init_privs (via recordExtensionInitPrivWorker()). ! */ ! void ! removeExtObjInitPriv(Oid objoid, Oid classoid) ! { ! /* ! * If this is a relation then we need to see if there are any sub-objects ! * (eg: columns) for it and, if so, be sure to call ! * recordExtensionInitPrivWorker() for each one. ! */ ! if (classoid =3D=3D RelationRelationId) ! { ! Form_pg_class pg_class_tuple; ! HeapTuple tuple; !=20 ! tuple =3D SearchSysCache1(RELOID, ObjectIdGetDatum(objoid)); ! if (!HeapTupleIsValid(tuple)) ! elog(ERROR, "cache lookup failed for relation %u", objoid); ! pg_class_tuple =3D (Form_pg_class) GETSTRUCT(tuple); !=20 ! /* Indexes don't have permissions */ ! if (pg_class_tuple->relkind =3D=3D RELKIND_INDEX) ! return; !=20 ! /* Composite types don't have permissions either */ ! if (pg_class_tuple->relkind =3D=3D RELKIND_COMPOSITE_TYPE) ! return; !=20 ! /* ! * If this isn't a sequence, index, or composite type then it's ! * possibly going to have columns associated with it that might have ! * ACLs. ! */ ! if (pg_class_tuple->relkind !=3D RELKIND_SEQUENCE) ! { ! AttrNumber curr_att; ! AttrNumber nattrs =3D pg_class_tuple->relnatts; !=20 ! for (curr_att =3D 1; curr_att <=3D nattrs; curr_att++) ! { ! HeapTuple attTuple; !=20 ! attTuple =3D SearchSysCache2(ATTNUM, ! ObjectIdGetDatum(objoid), ! Int16GetDatum(curr_att)); !=20 ! if (!HeapTupleIsValid(attTuple)) ! continue; !=20 ! /* ignore dropped columns */ ! if (((Form_pg_attribute) GETSTRUCT(attTuple))->attisdropped) ! { ! ReleaseSysCache(attTuple); ! continue; ! } !=20 ! recordExtensionInitPrivWorker(objoid, classoid, curr_att, NULL); !=20 ! ReleaseSysCache(attTuple); ! } ! } !=20 ! ReleaseSysCache(tuple); ! } !=20 ! /* Remove the record, if any, for the top-level object */ ! recordExtensionInitPrivWorker(objoid, classoid, 0, NULL); ! } !=20 ! /* ! * Record initial ACL for an extension object * * Can be called at any time, we check if 'creating_extension' is set and= , if * not, exit immediately. *************** get_user_default_acl(GrantObjectType obj *** 5248,5259 **** static void recordExtensionInitPriv(Oid objoid, Oid classoid, int objsubid, Acl *new_= acl) { - Relation relation; - ScanKeyData key[3]; - SysScanDesc scan; - HeapTuple tuple; - HeapTuple oldtuple; -=20 /* * Generally, we only record the initial privileges when an extension is * being created, but because we don't actually use CREATE EXTENSION --- 5617,5622 ---- *************** recordExtensionInitPriv(Oid objoid, Oid *** 5265,5270 **** --- 5628,5657 ---- if (!creating_extension && !binary_upgrade_record_init_privs) return; =20 + recordExtensionInitPrivWorker(objoid, classoid, objsubid, new_acl); + } +=20 + /* + * Record initial ACL for an extension object, worker. + * + * This will perform a wholesale replacement of the entire ACL for the ob= ject + * passed in, therefore be sure to pass in the complete new ACL to use. + * + * Generally speaking, do *not* use this function directly but instead use + * recordExtensionInitPriv(), which checks if 'creating_extension' is set. + * This function does *not* check if 'creating_extension' is set as it is= also + * used when an object is added to or removed from an extension via ALTER + * EXTENSION ... ADD/DROP. + */ + static void + recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl= *new_acl) + { + Relation relation; + ScanKeyData key[3]; + SysScanDesc scan; + HeapTuple tuple; + HeapTuple oldtuple; +=20 relation =3D heap_open(InitPrivsRelationId, RowExclusiveLock); =20 ScanKeyInit(&key[0], *************** recordExtensionInitPriv(Oid objoid, Oid *** 5317,5344 **** } else { - /* No entry found, so add it. */ Datum values[Natts_pg_init_privs]; bool nulls[Natts_pg_init_privs]; =20 ! MemSet(nulls, false, sizeof(nulls)); =20 ! values[Anum_pg_init_privs_objoid - 1] =3D ObjectIdGetDatum(objoid); ! values[Anum_pg_init_privs_classoid - 1] =3D ObjectIdGetDatum(classoid); ! values[Anum_pg_init_privs_objsubid - 1] =3D Int32GetDatum(objsubid); =20 ! /* This function only handles initial privileges of extensions */ ! values[Anum_pg_init_privs_privtype - 1] =3D ! CharGetDatum(INITPRIVS_EXTENSION); =20 ! values[Anum_pg_init_privs_privs - 1] =3D PointerGetDatum(new_acl); =20 ! tuple =3D heap_form_tuple(RelationGetDescr(relation), values, nulls); =20 ! simple_heap_insert(relation, tuple); =20 ! /* keep the catalog indexes up to date */ ! CatalogUpdateIndexes(relation, tuple); } =20 systable_endscan(scan); --- 5704,5740 ---- } else { Datum values[Natts_pg_init_privs]; bool nulls[Natts_pg_init_privs]; =20 ! /*=20 ! * Only add a new entry if the new ACL is non-NULL. ! * ! * If we are passed in a NULL ACL and no entry exists, we can just fall ! * through and do nothing. ! */ ! if (new_acl) ! { ! /* No entry found, so add it. */ ! MemSet(nulls, false, sizeof(nulls)); =20 ! values[Anum_pg_init_privs_objoid - 1] =3D ObjectIdGetDatum(objoid); ! values[Anum_pg_init_privs_classoid - 1] =3D ObjectIdGetDatum(classoid); ! values[Anum_pg_init_privs_objsubid - 1] =3D Int32GetDatum(objsubid); =20 ! /* This function only handles initial privileges of extensions */ ! values[Anum_pg_init_privs_privtype - 1] =3D ! CharGetDatum(INITPRIVS_EXTENSION); =20 ! values[Anum_pg_init_privs_privs - 1] =3D PointerGetDatum(new_acl); =20 ! tuple =3D heap_form_tuple(RelationGetDescr(relation), values, nulls); =20 ! simple_heap_insert(relation, tuple); =20 ! /* keep the catalog indexes up to date */ ! CatalogUpdateIndexes(relation, tuple); ! } } =20 systable_endscan(scan); diff --git a/src/backend/commands/extension.c b/src/backend/commands/extens= ion.c new file mode 100644 index be52148..e6108ff *** a/src/backend/commands/extension.c --- b/src/backend/commands/extension.c *************** *** 52,57 **** --- 52,58 ---- #include "nodes/makefuncs.h" #include "storage/fd.h" #include "tcop/utility.h" + #include "utils/acl.h" #include "utils/builtins.h" #include "utils/fmgroids.h" #include "utils/lsyscache.h" *************** ExecAlterExtensionContentsStmt(AlterExte *** 3239,3244 **** --- 3240,3255 ---- * OK, add the dependency. */ recordDependencyOn(&object, &extension, DEPENDENCY_EXTENSION); +=20 + /* + * Also record the initial ACL on the object, if any. + * + * Note that this will handle the object's ACLs, as well as any ACLs + * on object subIds. (In other words, when the object is a table, + * this will record the table's ACL and the ACLs for the columns on + * the table, if any). + */ + recordExtObjInitPriv(object.objectId, object.classId); } else { *************** ExecAlterExtensionContentsStmt(AlterExte *** 3266,3271 **** --- 3277,3292 ---- */ if (object.classId =3D=3D RelationRelationId) extension_config_remove(extension.objectId, object.objectId); +=20 + /* + * Remove all the initial ACLs, if any. + * + * Note that this will remove the object's ACLs, as well as any ACLs + * on object subIds. (In other words, when the object is a table, + * this will remove the table's ACL and the ACLs for the columns on + * the table, if any). + */ + removeExtObjInitPriv(object.objectId, object.classId); } =20 InvokeObjectPostAlterHook(ExtensionRelationId, extension.objectId, 0); diff --git a/src/include/utils/acl.h b/src/include/utils/acl.h new file mode 100644 index 433ba2d..6508cc1 *** a/src/include/utils/acl.h --- b/src/include/utils/acl.h *************** extern void aclcheck_error_col(AclResult *** 312,317 **** --- 312,321 ---- =20 extern void aclcheck_error_type(AclResult aclerr, Oid typeOid); =20 + extern void recordExtObjInitPriv(Oid objoid, Oid classoid); + extern void removeExtObjInitPriv(Oid objoid, Oid classoid); +=20 +=20 /* ownercheck routines just return true (owner) or false (not) */ extern bool pg_class_ownercheck(Oid class_oid, Oid roleid); extern bool pg_type_ownercheck(Oid type_oid, Oid roleid); diff --git a/src/test/modules/test_pg_dump/expected/test_pg_dump.out b/src/= test/modules/test_pg_dump/expected/test_pg_dump.out new file mode 100644 index 360caa2..d37aea0 *** a/src/test/modules/test_pg_dump/expected/test_pg_dump.out --- b/src/test/modules/test_pg_dump/expected/test_pg_dump.out *************** *** 1,6 **** ! SELECT 1; ! ?column?=20 ! ---------- ! 1 ! (1 row) !=20 --- 1,2 ---- ! CREATE ROLE regress_dump_test_role; ! CREATE EXTENSION test_pg_dump;=20 diff --git a/src/test/modules/test_pg_dump/sql/test_pg_dump.sql b/src/test/= modules/test_pg_dump/sql/test_pg_dump.sql new file mode 100644 index e0ac49d..d37aea0 *** a/src/test/modules/test_pg_dump/sql/test_pg_dump.sql --- b/src/test/modules/test_pg_dump/sql/test_pg_dump.sql *************** *** 1 **** ! SELECT 1; --- 1,2 ---- ! CREATE ROLE regress_dump_test_role; ! CREATE EXTENSION test_pg_dump;=20 diff --git a/src/test/modules/test_pg_dump/t/001_base.pl b/src/test/modules= /test_pg_dump/t/001_base.pl new file mode 100644 index dc90a4a..643fc8d *** a/src/test/modules/test_pg_dump/t/001_base.pl --- b/src/test/modules/test_pg_dump/t/001_base.pl *************** my %pgdump_runs =3D ( *** 188,193 **** --- 188,213 ---- # as the regexps are used for each run the test applies to. =20 my %tests =3D ( + 'ALTER EXTENSION test_pg_dump' =3D> { + create_order =3D> 9, + create_sql =3D> 'ALTER EXTENSION test_pg_dump ADD TABLE regress_pg_du= mp_table_added;', + regexp =3D> qr/^ + \QCREATE TABLE regress_pg_dump_table_added (\E + \n\s+\Qcol1 integer NOT NULL,\E + \n\s+\Qcol2 integer\E + \n\);\n/xm, + like =3D> { binary_upgrade =3D> 1, }, + unlike =3D> { + clean =3D> 1, + clean_if_exists =3D> 1, + createdb =3D> 1, + defaults =3D> 1, + no_privs =3D> 1, + no_owner =3D> 1, + pg_dumpall_globals =3D> 1, + schema_only =3D> 1, + section_pre_data =3D> 1, + section_post_data =3D> 1, }, }, 'CREATE EXTENSION test_pg_dump' =3D> { create_order =3D> 2, create_sql =3D> 'CREATE EXTENSION test_pg_dump;', *************** my %tests =3D ( *** 283,288 **** --- 303,328 ---- schema_only =3D> 1, section_pre_data =3D> 1, section_post_data =3D> 1, }, }, + 'CREATE TABLE regress_pg_dump_table_added' =3D> { + create_order =3D> 7, + create_sql =3D> 'CREATE TABLE regress_pg_dump_table_added (col1 int not= null, col2 int);', + regexp =3D> qr/^ + \QCREATE TABLE regress_pg_dump_table_added (\E + \n\s+\Qcol1 integer NOT NULL,\E + \n\s+\Qcol2 integer\E + \n\);\n/xm, + like =3D> { binary_upgrade =3D> 1, }, + unlike =3D> { + clean =3D> 1, + clean_if_exists =3D> 1, + createdb =3D> 1, + defaults =3D> 1, + no_privs =3D> 1, + no_owner =3D> 1, + pg_dumpall_globals =3D> 1, + schema_only =3D> 1, + section_pre_data =3D> 1, + section_post_data =3D> 1, }, }, 'CREATE ACCESS METHOD regress_test_am' =3D> { regexp =3D> qr/^ \QCREATE ACCESS METHOD regress_test_am TYPE INDEX HANDLER bthandler;\E *************** my %tests =3D ( *** 373,378 **** --- 413,457 ---- no_privs =3D> 1, pg_dumpall_globals =3D> 1, section_post_data =3D> 1, }, }, + 'GRANT SELECT regress_pg_dump_table_added pre-ALTER EXTENSION' =3D> { + create_order =3D> 8, + create_sql =3D> 'GRANT SELECT ON regress_pg_dump_table_added TO regre= ss_dump_test_role;', + regexp =3D> qr/^ + \QGRANT SELECT ON TABLE regress_pg_dump_table_added TO regress_dump_te= st_role;\E + \n/xm, + like =3D> { binary_upgrade =3D> 1, }, + unlike =3D> { + clean =3D> 1, + clean_if_exists =3D> 1, + createdb =3D> 1, + defaults =3D> 1, + no_privs =3D> 1, + no_owner =3D> 1, + pg_dumpall_globals =3D> 1, + schema_only =3D> 1, + section_pre_data =3D> 1, + section_post_data =3D> 1, }, }, + 'REVOKE SELECT regress_pg_dump_table_added post-ALTER EXTENSION' =3D> { + create_order =3D> 10, + create_sql =3D> 'REVOKE SELECT ON regress_pg_dump_table_added FROM re= gress_dump_test_role;', + regexp =3D> qr/^ + \QREVOKE SELECT ON TABLE regress_pg_dump_table_added FROM regress_dump= _test_role;\E + \n/xm, + like =3D> { + binary_upgrade =3D> 1, + clean =3D> 1, + clean_if_exists =3D> 1, + createdb =3D> 1, + defaults =3D> 1, + no_owner =3D> 1, + schema_only =3D> 1, + section_pre_data =3D> 1, + }, + unlike =3D> { + no_privs =3D> 1, + pg_dumpall_globals =3D> 1, + section_post_data =3D> 1, + }, }, 'GRANT USAGE ON regress_pg_dump_table_col1_seq TO regress_dump_test_role' =3D> { create_order =3D> 5, --kiLOsm1CQXt3zDau-- --azbj2yYfSrDqVwxe Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJYgorfAAoJEO1sijiDR2RVbB8QAIs1vDg4rNDqkPzIPFXnCnxb mqYBD8XLUvMv80Ka/3WonLfdOrnD3uFAWSdvwe+uv76wMvLZzWuu+fS7dPGGEitx lFFXlBat0VUAGZ9r+3BvnLM6tfkJiYmBHZrQReU+W4JN2TKkqcX+3tJsFYCIEtkE C1sktZ3dCUgGJ+ut7G4Vn5Vfoenz9Qm+6NxUdKyptY3EgH7nsLb5QIjBChcwoVOd EV2opyZr0u9wh+yRu8bxyabDJFM5VggUFnKjXjV/RpxSrS0boyz+OV9uNpQr7wwl jKP8vhxd4tWZJqzJtLuo0W66d4l6JYKUzu+rwrICJScb4YyBsHqlRMcYBRs/Fd7O Xjs8n656Vghr06h5uwFsH8pvpneAEfH3klAcary21iFCFHyyyRnANV88RehLxvFf 9LND4hQGZYFijyVhQ+znPEU8b2oZY8cPV/aOMFobvoJ393ncj3b0KP+ysWFl1JEQ 4C8qKxBJj9WIND6bnvURukDU9vKTP+iU2SaOG7AxxUgWG79DDHhY+j8skt+LUbmP Tt5a44iWMEbS6Kz0OoptEVmn2F+IkhELjf8wMkE6cpSaAoZmSgOFNAvVmgxKp1zu ulttV3W1BDSwGFoLxElI2SczaIao6GaqVFsG2FV8wZ2d9poppYNqmQ0w0o7PoGkl OfnGQPoghaDsdbmLd0Em =r+dC -----END PGP SIGNATURE----- --azbj2yYfSrDqVwxe--