8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.111 2005/04/14 20:03:23 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.112 2005/05/29 23:38:05 tgl Exp $
12
12
*
13
13
* NOTES
14
14
* See acl.h.
@@ -1310,6 +1310,29 @@ aclcheck_error(AclResult aclerr, AclObjectKind objectkind,
1310
1310
}
1311
1311
1312
1312
1313
+ /* Check if given userid has usecatupd privilege according to pg_shadow */
1314
+ static bool
1315
+ has_usecatupd (AclId userid )
1316
+ {
1317
+ bool usecatupd ;
1318
+ HeapTuple tuple ;
1319
+
1320
+ tuple = SearchSysCache (SHADOWSYSID ,
1321
+ ObjectIdGetDatum (userid ),
1322
+ 0 , 0 , 0 );
1323
+ if (!HeapTupleIsValid (tuple ))
1324
+ ereport (ERROR ,
1325
+ (errcode (ERRCODE_UNDEFINED_OBJECT ),
1326
+ errmsg ("user with ID %u does not exist" , userid )));
1327
+
1328
+ usecatupd = ((Form_pg_shadow ) GETSTRUCT (tuple ))-> usecatupd ;
1329
+
1330
+ ReleaseSysCache (tuple );
1331
+
1332
+ return usecatupd ;
1333
+ }
1334
+
1335
+
1313
1336
/*
1314
1337
* Exported routine for examining a user's privileges for a table
1315
1338
*
@@ -1325,8 +1348,6 @@ pg_class_aclmask(Oid table_oid, AclId userid,
1325
1348
AclMode mask , AclMaskHow how )
1326
1349
{
1327
1350
AclMode result ;
1328
- bool usesuper ,
1329
- usecatupd ;
1330
1351
HeapTuple tuple ;
1331
1352
Form_pg_class classForm ;
1332
1353
Datum aclDatum ;
@@ -1335,24 +1356,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
1335
1356
AclId ownerId ;
1336
1357
1337
1358
/*
1338
- * Validate userid, find out if he is superuser, also get usecatupd
1339
- */
1340
- tuple = SearchSysCache (SHADOWSYSID ,
1341
- ObjectIdGetDatum (userid ),
1342
- 0 , 0 , 0 );
1343
- if (!HeapTupleIsValid (tuple ))
1344
- ereport (ERROR ,
1345
- (errcode (ERRCODE_UNDEFINED_OBJECT ),
1346
- errmsg ("user with ID %u does not exist" , userid )));
1347
-
1348
- usecatupd = ((Form_pg_shadow ) GETSTRUCT (tuple ))-> usecatupd ;
1349
-
1350
- ReleaseSysCache (tuple );
1351
-
1352
- usesuper = superuser_arg (userid );
1353
-
1354
- /*
1355
- * Now get the relation's tuple from pg_class
1359
+ * Must get the relation's tuple from pg_class
1356
1360
*/
1357
1361
tuple = SearchSysCache (RELOID ,
1358
1362
ObjectIdGetDatum (table_oid ),
@@ -1377,7 +1381,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
1377
1381
if ((mask & (ACL_INSERT | ACL_UPDATE | ACL_DELETE )) &&
1378
1382
IsSystemClass (classForm ) &&
1379
1383
classForm -> relkind != RELKIND_VIEW &&
1380
- !usecatupd &&
1384
+ !has_usecatupd ( userid ) &&
1381
1385
!allowSystemTableMods )
1382
1386
{
1383
1387
#ifdef ACLDEBUG
@@ -1389,7 +1393,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
1389
1393
/*
1390
1394
* Otherwise, superusers bypass all permission-checking.
1391
1395
*/
1392
- if (usesuper )
1396
+ if (superuser_arg ( userid ) )
1393
1397
{
1394
1398
#ifdef ACLDEBUG
1395
1399
elog (DEBUG2 , "%u is superuser, home free" , userid );
0 commit comments