22
22
*
23
23
*
24
24
* IDENTIFICATION
25
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.300 2002/09/22 20:57:20 petere Exp $
25
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.301 2002/09/24 23:14:25 tgl Exp $
26
26
*
27
27
*-------------------------------------------------------------------------
28
28
*/
@@ -4839,16 +4839,18 @@ GetPrivileges(Archive *AH, const char *s, const char *type)
4839
4839
}
4840
4840
4841
4841
4842
- /*
4842
+ /*----------
4843
4843
* Write out grant/revoke information
4844
4844
*
4845
- * 'type' must be TABLE, FUNCTION, LANGUAGE, or SCHEMA. 'name' is the
4846
- * formatted name of the object. Must be quoted etc. already.
4845
+ * 'type' must be TABLE, FUNCTION, LANGUAGE, or SCHEMA.
4846
+ * 'name' is the formatted name of the object. Must be quoted etc. already.
4847
+ * 'tag' is the tag for the archive entry (typ. unquoted name of object).
4847
4848
* 'nspname' is the namespace the object is in (NULL if none).
4848
4849
* 'usename' is the owner, NULL if there is no owner (for languages).
4849
4850
* 'acls' is the string read out of the fooacl system catalog field;
4850
4851
* it will be parsed here.
4851
4852
* 'objoid' is the OID of the object for purposes of ordering.
4853
+ *----------
4852
4854
*/
4853
4855
static void
4854
4856
dumpACL (Archive * fout ,const char * type ,const char * name ,
@@ -4867,6 +4869,14 @@ dumpACL(Archive *fout, const char *type, const char *name,
4867
4869
4868
4870
sql = createPQExpBuffer ();
4869
4871
4872
+ /*
4873
+ * Always start with REVOKE ALL FROM PUBLIC, so that we don't have to
4874
+ * wire-in knowledge about the default public privileges for different
4875
+ * kinds of objects.
4876
+ */
4877
+ appendPQExpBuffer (sql ,"REVOKE ALL ON %s %s FROM PUBLIC;\n" ,
4878
+ type ,name );
4879
+
4870
4880
/* Make a working copy of acls so we can use strtok */
4871
4881
aclbuf = strdup (acls );
4872
4882
@@ -4938,18 +4948,21 @@ dumpACL(Archive *fout, const char *type, const char *name,
4938
4948
else
4939
4949
{
4940
4950
/* No privileges. Issue explicit REVOKE for safety. */
4941
- appendPQExpBuffer (sql ,"REVOKE ALL ON %s %s FROM " ,
4942
- type ,name );
4943
4951
if (eqpos == tok )
4944
4952
{
4945
- /* Empty left-hand side means "PUBLIC" */
4946
- appendPQExpBuffer (sql ,"PUBLIC;\n" );
4953
+ /* Empty left-hand side means "PUBLIC"; already did it */
4947
4954
}
4948
4955
else if (strncmp (tok ,"group " ,strlen ("group " ))== 0 )
4949
- appendPQExpBuffer (sql ,"GROUP %s;\n" ,
4956
+ {
4957
+ appendPQExpBuffer (sql ,"REVOKE ALL ON %s %s FROM GROUP %s;\n" ,
4958
+ type ,name ,
4950
4959
fmtId (tok + strlen ("group " )));
4960
+ }
4951
4961
else
4952
- appendPQExpBuffer (sql ,"%s;\n" ,fmtId (tok ));
4962
+ {
4963
+ appendPQExpBuffer (sql ,"REVOKE ALL ON %s %s FROM %s;\n" ,
4964
+ type ,name ,fmtId (tok ));
4965
+ }
4953
4966
}
4954
4967
free (priv );
4955
4968
}
@@ -4960,9 +4973,8 @@ dumpACL(Archive *fout, const char *type, const char *name,
4960
4973
*/
4961
4974
if (!found_owner_privs && usename )
4962
4975
{
4963
- appendPQExpBuffer (sql ,"REVOKE ALL ON %s %s FROM " ,
4964
- type ,name );
4965
- appendPQExpBuffer (sql ,"%s;\n" ,fmtId (usename ));
4976
+ appendPQExpBuffer (sql ,"REVOKE ALL ON %s %s FROM %s;\n" ,
4977
+ type ,name ,fmtId (usename ));
4966
4978
}
4967
4979
4968
4980
ArchiveEntry (fout ,objoid ,tag ,nspname ,usename ?usename :"" ,