postgresql/src/include/catalog
Tom Lane 277602dfee Fix missing role dependencies for some schema and type ACLs.
This patch fixes several related cases in which pg_shdepend entries were
never made, or were lost, for references to roles appearing in the ACLs of
schemas and/or types.  While that did no immediate harm, if a referenced
role were later dropped, the drop would be allowed and would leave a
dangling reference in the object's ACL.  That still wasn't a big problem
for normal database usage, but it would cause obscure failures in
subsequent dump/reload or pg_upgrade attempts, taking the form of
attempts to grant privileges to all-numeric role names.  (I think I've
seen field reports matching that symptom, but can't find any right now.)

Several cases are fixed here:

1. ALTER DOMAIN SET/DROP DEFAULT would lose the dependencies for any
existing ACL entries for the domain.  This case is ancient, dating
back as far as we've had pg_shdepend tracking at all.

2. If a default type privilege applies, CREATE TYPE recorded the
ACL properly but forgot to install dependency entries for it.
This dates to the addition of default privileges for types in 9.2.

3. If a default schema privilege applies, CREATE SCHEMA recorded the
ACL properly but forgot to install dependency entries for it.
This dates to the addition of default privileges for schemas in v10
(commit ab89e465c).

Another somewhat-related problem is that when creating a relation
rowtype or implicit array type, TypeCreate would apply any available
default type privileges to that type, which we don't really want
since such an object isn't supposed to have privileges of its own.
(You can't, for example, drop such privileges once they've been added
to an array type.)

ab89e465c is also to blame for a race condition in the regression tests:
privileges.sql transiently installed globally-applicable default
privileges on schemas, which sometimes got absorbed into the ACLs of
schemas created by concurrent test scripts.  This should have resulted
in failures when privileges.sql tried to drop the role holding such
privileges; but thanks to the bug fixed here, it instead led to dangling
ACLs in the final state of the regression database.  We'd managed not to
notice that, but it became obvious in the wake of commit da906766c, which
allowed the race condition to occur in pg_upgrade tests.

To fix, add a function recordDependencyOnNewAcl to encapsulate what
callers of get_user_default_acl need to do; while the original call
sites got that right via ad-hoc code, none of the later-added ones
have.  Also change GenerateTypeDependencies to generate these
dependencies, which requires adding the typacl to its parameter list.
(That might be annoying if there are any extensions calling that
function directly; but if there are, they're most likely buggy in the
same way as the core callers were, so they need work anyway.)  While
I was at it, I changed GenerateTypeDependencies to accept most of its
parameters in the form of a Form_pg_type pointer, making its parameter
list a bit less unwieldy and mistake-prone.

The test race condition is fixed just by wrapping the addition and
removal of default privileges into a single transaction, so that that
state is never visible externally.  We might eventually prefer to
separate out tests of default privileges into a script that runs by
itself, but that would be a bigger change and would make the tests
run slower overall.

Back-patch relevant parts to all supported branches.

Discussion: https://postgr.es/m/15719.1541725287@sss.pgh.pa.us
2018-11-09 20:42:03 -05:00
..
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
binary_upgrade.h Fix pg_upgrade to not fail when new-cluster TOAST rules differ from old. 2016-05-06 22:05:51 -04:00
catalog.h Rationalize common/relpath.[hc]. 2014-04-30 17:30:50 -04:00
catversion.h Change JSONB's on-disk format for improved performance. 2014-09-29 12:29:24 -04:00
dependency.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
duplicate_oids pgindent run for 9.4 2014-05-06 12:12:18 -04:00
genbki.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
heap.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
index.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
indexing.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
namespace.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
objectaccess.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
objectaddress.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_aggregate.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_am.h Allow opclasses to provide tri-valued GIN consistent functions. 2014-03-12 17:51:30 +02:00
pg_amop.h Add btree and hash opclasses for pg_lsn. 2014-06-04 20:45:56 -04:00
pg_amproc.h Add btree and hash opclasses for pg_lsn. 2014-06-04 20:45:56 -04:00
pg_attrdef.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_attribute.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_auth_members.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_authid.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_cast.h Fix copy-pasto in comment. 2016-10-12 12:08:59 +03:00
pg_class.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_collation.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_collation_fn.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_constraint.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_control.h Add defenses against running with a wrong selection of LOBLKSIZE. 2014-06-05 11:31:06 -04:00
pg_conversion.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_conversion_fn.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_database.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_db_role_setting.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_default_acl.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_depend.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_description.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_enum.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_event_trigger.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_extension.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_foreign_data_wrapper.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_foreign_server.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_foreign_table.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_index.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_inherits.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_inherits_fn.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_language.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_largeobject.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_largeobject_metadata.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_namespace.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_opclass.h Add btree and hash opclasses for pg_lsn. 2014-06-04 20:45:56 -04:00
pg_operator.h Fix assorted oversights in range selectivity estimation. 2015-01-30 12:31:08 -05:00
pg_opfamily.h Add btree and hash opclasses for pg_lsn. 2014-06-04 20:45:56 -04:00
pg_pltemplate.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_proc.h Fix bogus provolatile/proparallel markings on a few built-in functions. 2018-03-30 18:14:51 -04:00
pg_proc_fn.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_range.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_rewrite.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_seclabel.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_shdepend.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_shdescription.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_shseclabel.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_statistic.h Further patch rangetypes_selfuncs.c's statistics slot management. 2017-05-08 15:02:58 -04:00
pg_tablespace.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_trigger.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_ts_config.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_ts_config_map.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_ts_dict.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_ts_parser.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_ts_template.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_type.h pg_lsn should not be marked typispreferred. 2014-05-28 00:26:46 -04:00
pg_type_fn.h Fix missing role dependencies for some schema and type ACLs. 2018-11-09 20:42:03 -05:00
pg_user_mapping.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
storage.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
storage_xlog.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
toasting.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
unused_oids Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00