Commit 7562103f authored by Tom Lane's avatar Tom Lane

The no-updates-to-system-catalogs-unless-usecatupd restriction should

not apply to system views.  It never mattered before 7.4, but it does now.
parent 303a257b
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.96 2003/12/19 14:21:56 petere Exp $ * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.97 2004/01/14 03:44:53 tgl Exp $
* *
* NOTES * NOTES
* See acl.h. * See acl.h.
...@@ -1015,6 +1015,7 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode) ...@@ -1015,6 +1015,7 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode)
bool usesuper, bool usesuper,
usecatupd; usecatupd;
HeapTuple tuple; HeapTuple tuple;
Form_pg_class classForm;
Datum aclDatum; Datum aclDatum;
bool isNull; bool isNull;
Acl *acl; Acl *acl;
...@@ -1046,16 +1047,22 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode) ...@@ -1046,16 +1047,22 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE), (errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation with OID %u does not exist", table_oid))); 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 * Deny anyone permission to update a system catalog unless
* pg_shadow.usecatupd is set. (This is to let superusers protect * 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)) && if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemClass(classForm) &&
IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) && classForm->relkind != RELKIND_VIEW &&
!usecatupd) !usecatupd &&
!allowSystemTableMods)
{ {
#ifdef ACLDEBUG #ifdef ACLDEBUG
elog(DEBUG2, "permission denied for system catalog update"); elog(DEBUG2, "permission denied for system catalog update");
...@@ -1084,9 +1091,8 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode) ...@@ -1084,9 +1091,8 @@ pg_class_aclcheck(Oid table_oid, AclId userid, AclMode mode)
if (isNull) if (isNull)
{ {
/* No ACL, so build default ACL */ /* 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); acl = acldefault(ACL_OBJECT_RELATION, ownerId);
aclDatum = (Datum) 0; aclDatum = (Datum) 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment