|
22 | 22 | *
|
23 | 23 | *
|
24 | 24 | * 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 $ |
26 | 26 | *
|
27 | 27 | *-------------------------------------------------------------------------
|
28 | 28 | */
|
@@ -3885,47 +3885,53 @@ AddAcl(char *aclbuf, const char *keyword)
|
3885 | 3885 | }
|
3886 | 3886 |
|
3887 | 3887 | /*
|
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. |
3890 | 3893 | */
|
3891 | 3894 | static char *
|
3892 | 3895 | GetPrivileges(Archive *AH, const char *s)
|
3893 | 3896 | {
|
3894 | 3897 | char aclbuf[100];
|
| 3898 | + bool all = true; |
3895 | 3899 |
|
3896 | 3900 | aclbuf[0] = '\0';
|
3897 | 3901 |
|
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 |
3903 | 3907 |
|
3904 |
| - if (strchr(s, 'R')) |
3905 |
| - AddAcl(aclbuf, "RULE"); |
| 3908 | + CONVERT_PRIV('a', "INSERT"); |
| 3909 | + CONVERT_PRIV('r', "SELECT"); |
| 3910 | + CONVERT_PRIV('R', "RULE"); |
3906 | 3911 |
|
3907 | 3912 | if (AH->remoteVersion >= 70200)
|
3908 | 3913 | {
|
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"); |
3917 | 3918 | }
|
3918 | 3919 | else
|
3919 | 3920 | {
|
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"); |
3922 | 3923 | }
|
3923 | 3924 |
|
3924 |
| - return strdup(aclbuf); |
| 3925 | +#undef CONVERT_PRIV |
| 3926 | + |
| 3927 | + if (all) |
| 3928 | + return strdup("ALL"); |
| 3929 | + else |
| 3930 | + return strdup(aclbuf); |
3925 | 3931 | }
|
3926 | 3932 |
|
3927 | 3933 | /*
|
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 |
3929 | 3935 | * is big enough. If not, it does a realloc.
|
3930 | 3936 | */
|
3931 | 3937 | static void
|
|
0 commit comments