Skip to content

Commit 1b68bcf

Browse files
committed
Tweak pg_dump to say GRANT ALL when appropriate, rather than enumerating
the individual privilege bits. I regard this as an important change for cross-version compatibility: without this, a 7.1 dump loaded into 7.2 is likely to be short a few privileges.
1 parent 06f0820 commit 1b68bcf

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.238 2002/01/18 19:17:05 momjian Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.239 2002/01/25 18:49:31 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -3885,47 +3885,53 @@ AddAcl(char *aclbuf, const char *keyword)
38853885
}
38863886

38873887
/*
3888-
* This will take a string of 'arwR' and return a malloced,
3889-
* comma delimited string of SELECT,INSERT,UPDATE,DELETE,RULE
3888+
* This will take a string of privilege code letters and return a malloced,
3889+
* comma delimited string of keywords for GRANT.
3890+
*
3891+
* Note: for cross-version compatibility, it's important to use ALL when
3892+
* appropriate.
38903893
*/
38913894
static char *
38923895
GetPrivileges(Archive *AH, const char *s)
38933896
{
38943897
char aclbuf[100];
3898+
bool all = true;
38953899

38963900
aclbuf[0] = '\0';
38973901

3898-
if (strchr(s, 'a'))
3899-
AddAcl(aclbuf, "INSERT");
3900-
3901-
if (strchr(s, 'r'))
3902-
AddAcl(aclbuf, "SELECT");
3902+
#define CONVERT_PRIV(code,keywd) \
3903+
if (strchr(s, code)) \
3904+
AddAcl(aclbuf, keywd); \
3905+
else \
3906+
all = false
39033907

3904-
if (strchr(s, 'R'))
3905-
AddAcl(aclbuf, "RULE");
3908+
CONVERT_PRIV('a', "INSERT");
3909+
CONVERT_PRIV('r', "SELECT");
3910+
CONVERT_PRIV('R', "RULE");
39063911

39073912
if (AH->remoteVersion >= 70200)
39083913
{
3909-
if (strchr(s, 'w'))
3910-
AddAcl(aclbuf, "UPDATE");
3911-
if (strchr(s, 'd'))
3912-
AddAcl(aclbuf, "DELETE");
3913-
if (strchr(s, 'x'))
3914-
AddAcl(aclbuf, "REFERENCES");
3915-
if (strchr(s, 't'))
3916-
AddAcl(aclbuf, "TRIGGER");
3914+
CONVERT_PRIV('w', "UPDATE");
3915+
CONVERT_PRIV('d', "DELETE");
3916+
CONVERT_PRIV('x', "REFERENCES");
3917+
CONVERT_PRIV('t', "TRIGGER");
39173918
}
39183919
else
39193920
{
3920-
if (strchr(s, 'w'))
3921-
AddAcl(aclbuf, "UPDATE,DELETE");
3921+
/* 7.0 and 7.1 have a simpler worldview */
3922+
CONVERT_PRIV('w', "UPDATE,DELETE");
39223923
}
39233924

3924-
return strdup(aclbuf);
3925+
#undef CONVERT_PRIV
3926+
3927+
if (all)
3928+
return strdup("ALL");
3929+
else
3930+
return strdup(aclbuf);
39253931
}
39263932

39273933
/*
3928-
* The name says it all; a function to append a string is the dest
3934+
* The name says it all; a function to append a string if the dest
39293935
* is big enough. If not, it does a realloc.
39303936
*/
39313937
static void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy