diff options
author | Stephen Frost <sfrost@snowman.net> | 2017-01-31 16:24:14 -0500 |
---|---|---|
committer | Stephen Frost <sfrost@snowman.net> | 2017-01-31 16:24:14 -0500 |
commit | eb5e9d90df7536d0cf5c0d669d874f91b7be36d6 (patch) | |
tree | 69630404f3569542ccb0d4e693839bbc004314fb /src/bin/pg_dump/dumputils.c | |
parent | 3e9c36165377b07ffb182c366e295ac48ea5d5ba (diff) |
pg_dump: Fix handling of ALTER DEFAULT PRIVILEGES
In commit 23f34fa, we changed how ACLs were handled to use the new
pg_init_privs catalog and to dump out the ACL commands as REVOKE+GRANT
combinations instead of trying to REVOKE all rights always and then
GRANT back just the ones which were in place.
Unfortunately, the DEFAULT PRIVILEGES system didn't quite get the
correct treatment with this change and ended up (incorrectly) only
including positive GRANTs instead of both the REVOKEs and GRANTs
necessary to preserve the correct privileges.
There are only a couple cases where such REVOKEs are possible because,
generally speaking, there's few rights which exist on objects by
default to be revoked.
Examples of REVOKEs which weren't being correctly preserved are when
privileges are REVOKE'd from the creator/owner, like so:
ALTER DEFAULT PRIVILEGES
FOR ROLE myrole
REVOKE SELECT ON TABLES FROM myrole;
or when other default privileges are being revoked, such as EXECUTE
rights granted to public for functions:
ALTER DEFAULT PRIVILEGES
FOR ROLE myrole
REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
Fix this by correctly working out what the correct REVOKE statements are
(if any) and dump them out, just as we do for everything else.
Noticed while developing additional regression tests for pg_dump, which
will be landing shortly.
Back-patch to 9.6 where the bug was introduced.
Diffstat (limited to 'src/bin/pg_dump/dumputils.c')
-rw-r--r-- | src/bin/pg_dump/dumputils.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index cd1e8c4a680..a062a6b3301 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -368,11 +368,12 @@ buildACLCommands(const char *name, const char *subname, */ bool buildDefaultACLCommands(const char *type, const char *nspname, - const char *acls, const char *owner, + const char *acls, const char *racls, + const char *initacls, const char *initracls, + const char *owner, int remoteVersion, PQExpBuffer sql) { - bool result; PQExpBuffer prefix; prefix = createPQExpBuffer(); @@ -388,14 +389,22 @@ buildDefaultACLCommands(const char *type, const char *nspname, if (nspname) appendPQExpBuffer(prefix, "IN SCHEMA %s ", fmtId(nspname)); - result = buildACLCommands("", NULL, - type, acls, "", owner, - prefix->data, remoteVersion, - sql); + if (strlen(initacls) != 0 || strlen(initracls) != 0) + { + appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n"); + if (!buildACLCommands("", NULL, type, initacls, initracls, owner, + prefix->data, remoteVersion, sql)) + return false; + appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n"); + } + + if (!buildACLCommands("", NULL, type, acls, racls, owner, + prefix->data, remoteVersion, sql)) + return false; destroyPQExpBuffer(prefix); - return result; + return true; } /* |