Skip to content

Commit 10f9faf

Browse files
committed
pg_dump: fix mis-dumping of non-global default privileges.
Non-global default privilege entries should be dumped as-is, not made relative to the default ACL for their object type. This would typically only matter if one had revoked some on-by-default privileges in a global entry, and then wanted to grant them again in a non-global entry. Per report from Boris Korzun. This is an old bug, so back-patch to all supported branches. Neil Chen, test case by Masahiko Sawada Discussion: https://postgr.es/m/111621616618184@mail.yandex.ru Discussion: https://postgr.es/m/CAA3qoJnr2+1dVJObNtfec=qW4Z0nz=A9+r5bZKoTSy5RDjskMw@mail.gmail.com
1 parent 13e52d7 commit 10f9faf

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8967,9 +8967,26 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
89678967
PQExpBuffer initacl_subquery = createPQExpBuffer();
89688968
PQExpBuffer initracl_subquery = createPQExpBuffer();
89698969

8970+
/*
8971+
* Global entries (with defaclnamespace=0) replace the hard-wired
8972+
* default ACL for their object type. We should dump them as deltas
8973+
* from the default ACL, since that will be used as a starting point
8974+
* for interpreting the ALTER DEFAULT PRIVILEGES commands. On the
8975+
* other hand, non-global entries can only add privileges not revoke
8976+
* them. We must dump those as-is (i.e., as deltas from an empty
8977+
* ACL). We implement that by passing NULL as the object type for
8978+
* acldefault(), which works because acldefault() is STRICT.
8979+
*
8980+
* We can use defaclobjtype as the object type for acldefault(),
8981+
* except for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be
8982+
* converted to 's'.
8983+
*/
89708984
buildACLQueries(acl_subquery, racl_subquery, initacl_subquery,
89718985
initracl_subquery, "defaclacl", "defaclrole",
8972-
"CASE WHEN defaclobjtype = 'S' THEN 's' ELSE defaclobjtype END::\"char\"",
8986+
"CASE WHEN defaclnamespace = 0 THEN"
8987+
" CASE WHEN defaclobjtype = 'S' THEN 's'::\"char\""
8988+
" ELSE defaclobjtype END "
8989+
"ELSE NULL END",
89738990
dopt->binary_upgrade);
89748991

89758992
appendPQExpBuffer(query, "SELECT d.oid, d.tableoid, "

src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,46 @@
339339
section_pre_data => 1,
340340
section_data => 1, }, },
341341

342+
'ALTER DEFAULT PRIVILEGES FOR ROLE regress_dump_test_role GRANT EXECUTE ON FUNCTIONS'
343+
=> {
344+
all_runs => 1,
345+
create_order => 15,
346+
create_sql => 'ALTER DEFAULT PRIVILEGES
347+
FOR ROLE regress_dump_test_role IN SCHEMA dump_test
348+
GRANT EXECUTE ON FUNCTIONS TO regress_dump_test_role;',
349+
regexp => qr/^
350+
\QALTER DEFAULT PRIVILEGES \E
351+
\QFOR ROLE regress_dump_test_role IN SCHEMA dump_test \E
352+
\QGRANT ALL ON FUNCTIONS TO regress_dump_test_role;\E
353+
/xm,
354+
like => {
355+
binary_upgrade => 1,
356+
clean => 1,
357+
clean_if_exists => 1,
358+
createdb => 1,
359+
defaults => 1,
360+
exclude_test_table => 1,
361+
exclude_test_table_data => 1,
362+
no_blobs => 1,
363+
no_owner => 1,
364+
only_dump_test_schema => 1,
365+
pg_dumpall_dbprivs => 1,
366+
schema_only => 1,
367+
section_post_data => 1,
368+
test_schema_plus_blobs => 1,
369+
with_oids => 1, },
370+
unlike => {
371+
column_inserts => 1,
372+
data_only => 1,
373+
exclude_dump_test_schema => 1,
374+
no_privs => 1,
375+
only_dump_test_table => 1,
376+
pg_dumpall_globals => 1,
377+
pg_dumpall_globals_clean => 1,
378+
role => 1,
379+
section_pre_data => 1,
380+
section_data => 1, }, },
381+
342382
'ALTER DEFAULT PRIVILEGES FOR ROLE regress_dump_test_role REVOKE' => {
343383
all_runs => 1,
344384
create_order => 55,

0 commit comments

Comments
 (0)