diff options
Diffstat (limited to 'src/backend/catalog/aclchk.c')
-rw-r--r-- | src/backend/catalog/aclchk.c | 61 |
1 files changed, 15 insertions, 46 deletions
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index d98ebdda4f8..6c16fd6a6e2 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.159 2010/01/02 16:57:36 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.160 2010/01/05 21:53:58 rhaas Exp $ * * NOTES * See acl.h. @@ -2783,18 +2783,11 @@ ExecGrant_Tablespace(InternalGrant *istmt) int nnewmembers; Oid *oldmembers; Oid *newmembers; - ScanKeyData entry[1]; - SysScanDesc scan; HeapTuple tuple; - /* There's no syscache for pg_tablespace, so must look the hard way */ - ScanKeyInit(&entry[0], - ObjectIdAttributeNumber, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(tblId)); - scan = systable_beginscan(relation, TablespaceOidIndexId, true, - SnapshotNow, 1, entry); - tuple = systable_getnext(scan); + /* Search syscache for pg_tablespace */ + tuple = SearchSysCache(TABLESPACEOID, ObjectIdGetDatum(tblId), + 0, 0, 0); if (!HeapTupleIsValid(tuple)) elog(ERROR, "cache lookup failed for tablespace %u", tblId); @@ -2865,8 +2858,7 @@ ExecGrant_Tablespace(InternalGrant *istmt) noldmembers, oldmembers, nnewmembers, newmembers); - systable_endscan(scan); - + ReleaseSysCache(tuple); pfree(new_acl); /* prevent error when processing duplicate objects */ @@ -3696,9 +3688,6 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid, AclMode mask, AclMaskHow how) { AclMode result; - Relation pg_tablespace; - ScanKeyData entry[1]; - SysScanDesc scan; HeapTuple tuple; Datum aclDatum; bool isNull; @@ -3711,17 +3700,9 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid, /* * Get the tablespace's ACL from pg_tablespace - * - * There's no syscache for pg_tablespace, so must look the hard way */ - pg_tablespace = heap_open(TableSpaceRelationId, AccessShareLock); - ScanKeyInit(&entry[0], - ObjectIdAttributeNumber, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(spc_oid)); - scan = systable_beginscan(pg_tablespace, TablespaceOidIndexId, true, - SnapshotNow, 1, entry); - tuple = systable_getnext(scan); + tuple = SearchSysCache(TABLESPACEOID, ObjectIdGetDatum(spc_oid), + 0, 0, 0); if (!HeapTupleIsValid(tuple)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), @@ -3729,8 +3710,9 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid, ownerId = ((Form_pg_tablespace) GETSTRUCT(tuple))->spcowner; - aclDatum = heap_getattr(tuple, Anum_pg_tablespace_spcacl, - RelationGetDescr(pg_tablespace), &isNull); + aclDatum = SysCacheGetAttr(TABLESPACEOID, tuple, + Anum_pg_tablespace_spcacl, + &isNull); if (isNull) { @@ -3750,8 +3732,7 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid, if (acl && (Pointer) acl != DatumGetPointer(aclDatum)) pfree(acl); - systable_endscan(scan); - heap_close(pg_tablespace, AccessShareLock); + ReleaseSysCache(tuple); return result; } @@ -4338,9 +4319,6 @@ pg_namespace_ownercheck(Oid nsp_oid, Oid roleid) bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid) { - Relation pg_tablespace; - ScanKeyData entry[1]; - SysScanDesc scan; HeapTuple spctuple; Oid spcowner; @@ -4348,17 +4326,9 @@ pg_tablespace_ownercheck(Oid spc_oid, Oid roleid) if (superuser_arg(roleid)) return true; - /* There's no syscache for pg_tablespace, so must look the hard way */ - pg_tablespace = heap_open(TableSpaceRelationId, AccessShareLock); - ScanKeyInit(&entry[0], - ObjectIdAttributeNumber, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(spc_oid)); - scan = systable_beginscan(pg_tablespace, TablespaceOidIndexId, true, - SnapshotNow, 1, entry); - - spctuple = systable_getnext(scan); - + /* Search syscache for pg_tablespace */ + spctuple = SearchSysCache(TABLESPACEOID, ObjectIdGetDatum(spc_oid), + 0, 0, 0); if (!HeapTupleIsValid(spctuple)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), @@ -4366,8 +4336,7 @@ pg_tablespace_ownercheck(Oid spc_oid, Oid roleid) spcowner = ((Form_pg_tablespace) GETSTRUCT(spctuple))->spcowner; - systable_endscan(scan); - heap_close(pg_tablespace, AccessShareLock); + ReleaseSysCache(spctuple); return has_privs_of_role(roleid, spcowner); } |