]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
The no-updates-to-system-catalogs-unless-usecatupd restriction should
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Jan 2004 03:45:02 +0000 (03:45 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Jan 2004 03:45:02 +0000 (03:45 +0000)
not apply to system views.  It never mattered before 7.4, but it does now.

src/backend/catalog/aclchk.c

index 6b97bd6325ffce011be266b0b10963b68d27d6a3..d3c8b865dfea93da1d946eeb66b17a6cd2d477f3 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.91.2.1 2003/12/19 14:21:43 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.91.2.2 2004/01/14 03:45:02 tgl Exp $
  *
  * NOTES
  *       See acl.h.
@@ -1013,6 +1013,7 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode)
        bool            usesuper,
                                usecatupd;
        HeapTuple       tuple;
+       Form_pg_class classForm;
        Datum           aclDatum;
        bool            isNull;
        Acl                *acl;
@@ -1044,16 +1045,22 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode)
                ereport(ERROR,
                                (errcode(ERRCODE_UNDEFINED_TABLE),
                          errmsg("relation with OID %u does not exist", table_oid)));
+       classForm = (Form_pg_class) GETSTRUCT(tuple);
 
        /*
         * Deny anyone permission to update a system catalog unless
         * pg_shadow.usecatupd is set.  (This is to let superusers protect
-        * themselves from themselves.)
+        * themselves from themselves.)  Also allow it if allowSystemTableMods.
+        *
+        * As of 7.4 we have some updatable system views; those shouldn't
+        * be protected in this way.  Assume the view rules can take care
+        * of themselves.
         */
        if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
-               !allowSystemTableMods &&
-               IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
-               !usecatupd)
+               IsSystemClass(classForm) &&
+               classForm->relkind != RELKIND_VIEW &&
+               !usecatupd &&
+               !allowSystemTableMods)
        {
 #ifdef ACLDEBUG
                elog(DEBUG2, "permission denied for system catalog update");
@@ -1082,9 +1089,8 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode)
        if (isNull)
        {
                /* No ACL, so build default ACL */
-               AclId           ownerId;
+               AclId           ownerId = classForm->relowner;
 
-               ownerId = ((Form_pg_class) GETSTRUCT(tuple))->relowner;
                acl = acldefault(ACL_OBJECT_RELATION, ownerId);
                aclDatum = (Datum) 0;
        }