Skip to content

Commit 298d1f8

Browse files
committed
Fix privilege dumping from servers too old to have that type of privilege.
pg_dump produced fairly silly GRANT/REVOKE commands when dumping types from pre-9.2 servers, and when dumping functions or procedural languages from pre-7.3 servers. Those server versions lack the typacl, proacl, and/or lanacl columns respectively, and pg_dump substituted default values that were in fact incorrect. We ended up revoking all the owner's own privileges for the object while granting all privileges to PUBLIC. Of course the owner would then have those privileges again via PUBLIC, so long as she did not try to revoke PUBLIC's privileges; which may explain the lack of field reports. Nonetheless this is pretty silly behavior. The stakes were raised by my recent patch to make pg_dump dump shell types, because 9.2 and up pg_dump would proceed to emit bogus GRANT/REVOKE commands for a shell type if dumping from a pre-9.2 server; and the server will not accept GRANT/REVOKE commands for a shell type. (Perhaps it should, but that's a topic for another day.) So the resulting dump script wouldn't load without errors. The right thing to do is to act as though these objects have default privileges (null ACL entries), which causes pg_dump to print no GRANT/REVOKE commands at all for them. That fixes the silly results and also dodges the problem with shell types. In passing, modify getProcLangs() to be less creatively different about how to handle missing columns when dumping from older server versions. Every other data-acquisition function in pg_dump does that by substituting appropriate default values in the version-specific SQL commands, and I see no reason why this one should march to its own drummer. Its use of "SELECT *" was likewise not conformant with anyplace else, not to mention it's not considered good SQL style for production queries. Back-patch to all supported versions. Although 9.0 and 9.1 pg_dump don't have the issue with typacl, they are more likely than newer versions to be used to dump from ancient servers, so we ought to fix the proacl/lanacl issues all the way back.
1 parent a6b279c commit 298d1f8

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,7 +3197,7 @@ getAggregates(int *numAggs)
31973197
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
31983198
"aggbasetype AS proargtypes, "
31993199
"(%s aggowner) AS rolname, "
3200-
"'{=X}' AS aggacl "
3200+
"NULL AS aggacl "
32013201
"FROM pg_aggregate "
32023202
"where oid > '%u'::oid",
32033203
username_subquery,
@@ -3212,7 +3212,7 @@ getAggregates(int *numAggs)
32123212
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
32133213
"aggbasetype AS proargtypes, "
32143214
"(%s aggowner) AS rolname, "
3215-
"'{=X}' AS aggacl "
3215+
"NULL AS aggacl "
32163216
"FROM pg_aggregate "
32173217
"where oid > '%u'::oid",
32183218
username_subquery,
@@ -3328,7 +3328,7 @@ getFuncs(int *numFuncs)
33283328
appendPQExpBuffer(query,
33293329
"SELECT tableoid, oid, proname, prolang, "
33303330
"pronargs, proargtypes, prorettype, "
3331-
"'{=X}' AS proacl, "
3331+
"NULL AS proacl, "
33323332
"0::oid AS pronamespace, "
33333333
"(%s proowner) AS rolname "
33343334
"FROM pg_proc "
@@ -3344,7 +3344,7 @@ getFuncs(int *numFuncs)
33443344
" WHERE relname = 'pg_proc') AS tableoid, "
33453345
"oid, proname, prolang, "
33463346
"pronargs, proargtypes, prorettype, "
3347-
"'{=X}' AS proacl, "
3347+
"NULL AS proacl, "
33483348
"0::oid AS pronamespace, "
33493349
"(%s proowner) AS rolname "
33503350
"FROM pg_proc "
@@ -4864,7 +4864,7 @@ getProcLangs(int *numProcLangs)
48644864
/* pg_language has a laninline column */
48654865
appendPQExpBuffer(query, "SELECT tableoid, oid, "
48664866
"lanname, lanpltrusted, lanplcallfoid, "
4867-
"laninline, lanvalidator, lanacl, "
4867+
"laninline, lanvalidator, lanacl, "
48684868
"(%s lanowner) AS lanowner "
48694869
"FROM pg_language "
48704870
"WHERE lanispl "
@@ -4876,7 +4876,7 @@ getProcLangs(int *numProcLangs)
48764876
/* pg_language has a lanowner column */
48774877
appendPQExpBuffer(query, "SELECT tableoid, oid, "
48784878
"lanname, lanpltrusted, lanplcallfoid, "
4879-
"lanvalidator, lanacl, "
4879+
"0 AS laninline, lanvalidator, lanacl, "
48804880
"(%s lanowner) AS lanowner "
48814881
"FROM pg_language "
48824882
"WHERE lanispl "
@@ -4886,7 +4886,9 @@ getProcLangs(int *numProcLangs)
48864886
else if (g_fout->remoteVersion >= 80100)
48874887
{
48884888
/* Languages are owned by the bootstrap superuser, OID 10 */
4889-
appendPQExpBuffer(query, "SELECT tableoid, oid, *, "
4889+
appendPQExpBuffer(query, "SELECT tableoid, oid, "
4890+
"lanname, lanpltrusted, lanplcallfoid, "
4891+
"0 AS laninline, lanvalidator, lanacl, "
48904892
"(%s '10') AS lanowner "
48914893
"FROM pg_language "
48924894
"WHERE lanispl "
@@ -4896,25 +4898,45 @@ getProcLangs(int *numProcLangs)
48964898
else if (g_fout->remoteVersion >= 70400)
48974899
{
48984900
/* Languages are owned by the bootstrap superuser, sysid 1 */
4899-
appendPQExpBuffer(query, "SELECT tableoid, oid, *, "
4901+
appendPQExpBuffer(query, "SELECT tableoid, oid, "
4902+
"lanname, lanpltrusted, lanplcallfoid, "
4903+
"0 AS laninline, lanvalidator, lanacl, "
49004904
"(%s '1') AS lanowner "
49014905
"FROM pg_language "
49024906
"WHERE lanispl "
49034907
"ORDER BY oid",
49044908
username_subquery);
49054909
}
4906-
else if (g_fout->remoteVersion >= 70100)
4910+
else if (g_fout->remoteVersion >= 70300)
49074911
{
49084912
/* No clear notion of an owner at all before 7.4 ... */
4909-
appendPQExpBuffer(query, "SELECT tableoid, oid, * FROM pg_language "
4913+
appendPQExpBuffer(query, "SELECT tableoid, oid, "
4914+
"lanname, lanpltrusted, lanplcallfoid, "
4915+
"0 AS laninline, lanvalidator, lanacl, "
4916+
"NULL AS lanowner "
4917+
"FROM pg_language "
4918+
"WHERE lanispl "
4919+
"ORDER BY oid");
4920+
}
4921+
else if (g_fout->remoteVersion >= 70100)
4922+
{
4923+
appendPQExpBuffer(query, "SELECT tableoid, oid, "
4924+
"lanname, lanpltrusted, lanplcallfoid, "
4925+
"0 AS laninline, 0 AS lanvalidator, NULL AS lanacl, "
4926+
"NULL AS lanowner "
4927+
"FROM pg_language "
49104928
"WHERE lanispl "
49114929
"ORDER BY oid");
49124930
}
49134931
else
49144932
{
49154933
appendPQExpBuffer(query, "SELECT "
49164934
"(SELECT oid FROM pg_class WHERE relname = 'pg_language') AS tableoid, "
4917-
"oid, * FROM pg_language "
4935+
"oid, "
4936+
"lanname, lanpltrusted, lanplcallfoid, "
4937+
"0 AS laninline, 0 AS lanvalidator, NULL AS lanacl, "
4938+
"NULL AS lanowner "
4939+
"FROM pg_language "
49184940
"WHERE lanispl "
49194941
"ORDER BY oid");
49204942
}
@@ -4933,7 +4955,6 @@ getProcLangs(int *numProcLangs)
49334955
i_lanname = PQfnumber(res, "lanname");
49344956
i_lanpltrusted = PQfnumber(res, "lanpltrusted");
49354957
i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
4936-
/* these may fail and return -1: */
49374958
i_laninline = PQfnumber(res, "laninline");
49384959
i_lanvalidator = PQfnumber(res, "lanvalidator");
49394960
i_lanacl = PQfnumber(res, "lanacl");
@@ -4949,22 +4970,10 @@ getProcLangs(int *numProcLangs)
49494970
planginfo[i].dobj.name = strdup(PQgetvalue(res, i, i_lanname));
49504971
planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
49514972
planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
4952-
if (i_laninline >= 0)
4953-
planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
4954-
else
4955-
planginfo[i].laninline = InvalidOid;
4956-
if (i_lanvalidator >= 0)
4957-
planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
4958-
else
4959-
planginfo[i].lanvalidator = InvalidOid;
4960-
if (i_lanacl >= 0)
4961-
planginfo[i].lanacl = strdup(PQgetvalue(res, i, i_lanacl));
4962-
else
4963-
planginfo[i].lanacl = strdup("{=U}");
4964-
if (i_lanowner >= 0)
4965-
planginfo[i].lanowner = strdup(PQgetvalue(res, i, i_lanowner));
4966-
else
4967-
planginfo[i].lanowner = strdup("");
4973+
planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
4974+
planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
4975+
planginfo[i].lanacl = strdup(PQgetvalue(res, i, i_lanacl));
4976+
planginfo[i].lanowner = strdup(PQgetvalue(res, i, i_lanowner));
49684977

49694978
if (g_fout->remoteVersion < 70300)
49704979
{

0 commit comments

Comments
 (0)