Commit 03a542ba authored by Tom Lane's avatar Tom Lane

Avoid unnecessary fetch from pg_shadow in the normal case in

pg_class_aclmask().  We only need to do this when we have to check
pg_shadow.usecatupd, and that's not relevant unless the target table
is a system catalog.  So we can usually avoid one syscache lookup.
parent 140b078d
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.111 2005/04/14 20:03:23 tgl Exp $ * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.112 2005/05/29 23:38:05 tgl Exp $
* *
* NOTES * NOTES
* See acl.h. * See acl.h.
...@@ -1310,6 +1310,29 @@ aclcheck_error(AclResult aclerr, AclObjectKind objectkind, ...@@ -1310,6 +1310,29 @@ aclcheck_error(AclResult aclerr, AclObjectKind objectkind,
} }
/* Check if given userid has usecatupd privilege according to pg_shadow */
static bool
has_usecatupd(AclId userid)
{
bool usecatupd;
HeapTuple tuple;
tuple = SearchSysCache(SHADOWSYSID,
ObjectIdGetDatum(userid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("user with ID %u does not exist", userid)));
usecatupd = ((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd;
ReleaseSysCache(tuple);
return usecatupd;
}
/* /*
* Exported routine for examining a user's privileges for a table * Exported routine for examining a user's privileges for a table
* *
...@@ -1325,8 +1348,6 @@ pg_class_aclmask(Oid table_oid, AclId userid, ...@@ -1325,8 +1348,6 @@ pg_class_aclmask(Oid table_oid, AclId userid,
AclMode mask, AclMaskHow how) AclMode mask, AclMaskHow how)
{ {
AclMode result; AclMode result;
bool usesuper,
usecatupd;
HeapTuple tuple; HeapTuple tuple;
Form_pg_class classForm; Form_pg_class classForm;
Datum aclDatum; Datum aclDatum;
...@@ -1335,24 +1356,7 @@ pg_class_aclmask(Oid table_oid, AclId userid, ...@@ -1335,24 +1356,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
AclId ownerId; AclId ownerId;
/* /*
* Validate userid, find out if he is superuser, also get usecatupd * Must get the relation's tuple from pg_class
*/
tuple = SearchSysCache(SHADOWSYSID,
ObjectIdGetDatum(userid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("user with ID %u does not exist", userid)));
usecatupd = ((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd;
ReleaseSysCache(tuple);
usesuper = superuser_arg(userid);
/*
* Now get the relation's tuple from pg_class
*/ */
tuple = SearchSysCache(RELOID, tuple = SearchSysCache(RELOID,
ObjectIdGetDatum(table_oid), ObjectIdGetDatum(table_oid),
...@@ -1377,7 +1381,7 @@ pg_class_aclmask(Oid table_oid, AclId userid, ...@@ -1377,7 +1381,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
if ((mask & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) && if ((mask & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
IsSystemClass(classForm) && IsSystemClass(classForm) &&
classForm->relkind != RELKIND_VIEW && classForm->relkind != RELKIND_VIEW &&
!usecatupd && !has_usecatupd(userid) &&
!allowSystemTableMods) !allowSystemTableMods)
{ {
#ifdef ACLDEBUG #ifdef ACLDEBUG
...@@ -1389,7 +1393,7 @@ pg_class_aclmask(Oid table_oid, AclId userid, ...@@ -1389,7 +1393,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
/* /*
* Otherwise, superusers bypass all permission-checking. * Otherwise, superusers bypass all permission-checking.
*/ */
if (usesuper) if (superuser_arg(userid))
{ {
#ifdef ACLDEBUG #ifdef ACLDEBUG
elog(DEBUG2, "%u is superuser, home free", userid); elog(DEBUG2, "%u is superuser, home free", userid);
......
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