8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.40 2000/09/06 14:15:15 petere Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.41 2000/10/02 04:49:28 tgl Exp $
12
12
*
13
13
* NOTES
14
14
* See acl.h.
36
36
static int32 aclcheck (char * relname , Acl * acl , AclId id ,
37
37
AclIdType idtype , AclMode mode );
38
38
39
- /*
40
- * Enable use of user relations in place of real system catalogs.
41
- */
42
- /*#define ACLDEBUG*/
43
-
44
- #ifdef ACLDEBUG
45
- /*
46
- * Fool the code below into thinking that "pgacls" is pg_class.
47
- * relname and relowner are in the same place, happily.
48
- */
49
- #undef Anum_pg_class_relacl
50
- #define Anum_pg_class_relacl 3
51
- #undef Natts_pg_class
52
- #define Natts_pg_class 3
53
- #undef Name_pg_class
54
- #define Name_pg_class "pgacls"
55
- #undef Name_pg_group
56
- #define Name_pg_group "pggroup"
57
- #endif
58
-
59
39
/* warning messages, now more explicit. */
60
- /* should correspond to the order of the ACLCHK_* result codes above . */
40
+ /* MUST correspond to the order of the ACLCHK_* result codes in acl.h . */
61
41
char * aclcheck_error_strings [] = {
62
42
"No error." ,
63
43
"Permission denied." ,
64
44
"Table does not exist." ,
65
45
"Must be table owner."
66
46
};
67
47
48
+
68
49
#ifdef ACLDEBUG_TRACE
69
50
static
70
51
dumpacl (Acl * acl )
@@ -84,7 +65,7 @@ dumpacl(Acl *acl)
84
65
#endif
85
66
86
67
/*
87
- *
68
+ * ChangeAcl
88
69
*/
89
70
void
90
71
ChangeAcl (char * relname ,
@@ -96,12 +77,12 @@ ChangeAcl(char *relname,
96
77
* new_acl ;
97
78
Relation relation ;
98
79
HeapTuple tuple ;
80
+ Datum aclDatum ;
99
81
Datum values [Natts_pg_class ];
100
82
char nulls [Natts_pg_class ];
101
83
char replaces [Natts_pg_class ];
102
84
Relation idescs [Num_pg_class_indices ];
103
85
bool isNull ;
104
- bool free_old_acl = false;
105
86
106
87
/*
107
88
* Find the pg_class tuple matching 'relname' and extract the ACL. If
@@ -118,29 +99,20 @@ ChangeAcl(char *relname,
118
99
relname );
119
100
}
120
101
121
- old_acl = (Acl * ) heap_getattr (tuple ,
122
- Anum_pg_class_relacl ,
123
- RelationGetDescr (relation ),
124
- & isNull );
102
+ aclDatum = SysCacheGetAttr (RELNAME , tuple , Anum_pg_class_relacl ,
103
+ & isNull );
125
104
if (isNull )
126
105
{
127
- #ifdef ACLDEBUG_TRACE
128
- elog (DEBUG , "ChangeAcl: using default ACL" );
129
- #endif
130
- old_acl = acldefault (relname );
131
- free_old_acl = true;
132
- }
133
-
134
- /* Need to detoast the old ACL for modification */
135
- old_acl = DatumGetAclP (PointerGetDatum (old_acl ));
106
+ /* No ACL, so build default ACL for rel */
107
+ AclId ownerId ;
136
108
137
- if (ACL_NUM (old_acl ) < 1 )
109
+ ownerId = ((Form_pg_class ) GETSTRUCT (tuple ))-> relowner ;
110
+ old_acl = acldefault (relname , ownerId );
111
+ }
112
+ else
138
113
{
139
- #ifdef ACLDEBUG_TRACE
140
- elog (DEBUG , "ChangeAcl: old ACL has zero length" );
141
- #endif
142
- old_acl = acldefault (relname );
143
- free_old_acl = true;
114
+ /* get a detoasted copy of the rel's ACL */
115
+ old_acl = DatumGetAclPCopy (aclDatum );
144
116
}
145
117
146
118
#ifdef ACLDEBUG_TRACE
@@ -173,8 +145,8 @@ ChangeAcl(char *relname,
173
145
CatalogCloseIndices (Num_pg_class_indices , idescs );
174
146
175
147
heap_close (relation , RowExclusiveLock );
176
- if ( free_old_acl )
177
- pfree (old_acl );
148
+
149
+ pfree (old_acl );
178
150
pfree (new_acl );
179
151
}
180
152
@@ -264,9 +236,15 @@ aclcheck(char *relname, Acl *acl, AclId id, AclIdType idtype, AclMode mode)
264
236
unsigned num ,
265
237
found_group ;
266
238
267
- /* if no acl is found, use world default */
239
+ /*
240
+ * If ACL is null, default to "OK" --- this should not happen,
241
+ * since caller should have inserted appropriate default
242
+ */
268
243
if (!acl )
269
- acl = acldefault (relname );
244
+ {
245
+ elog (DEBUG , "aclcheck: null ACL, returning 1" );
246
+ return ACLCHECK_OK ;
247
+ }
270
248
271
249
num = ACL_NUM (acl );
272
250
aidat = ACL_DAT (acl );
@@ -278,9 +256,7 @@ aclcheck(char *relname, Acl *acl, AclId id, AclIdType idtype, AclMode mode)
278
256
*/
279
257
if (num < 1 )
280
258
{
281
- #if defined(ACLDEBUG_TRACE ) || 1
282
259
elog (DEBUG , "aclcheck: zero-length ACL, returning 1" );
283
- #endif
284
260
return ACLCHECK_OK ;
285
261
}
286
262
@@ -357,11 +333,12 @@ aclcheck(char *relname, Acl *acl, AclId id, AclIdType idtype, AclMode mode)
357
333
int32
358
334
pg_aclcheck (char * relname , Oid userid , AclMode mode )
359
335
{
360
- HeapTuple tuple ;
361
- Acl * acl = (Acl * ) NULL ;
362
336
int32 result ;
337
+ HeapTuple tuple ;
363
338
char * usename ;
364
- Relation relation ;
339
+ Datum aclDatum ;
340
+ bool isNull ;
341
+ Acl * acl ;
365
342
366
343
tuple = SearchSysCacheTuple (SHADOWSYSID ,
367
344
ObjectIdGetDatum (userid ),
@@ -399,53 +376,31 @@ pg_aclcheck(char *relname, Oid userid, AclMode mode)
399
376
return ACLCHECK_OK ;
400
377
}
401
378
402
- #ifndef ACLDEBUG
403
- relation = heap_openr (RelationRelationName , RowExclusiveLock );
379
+ /*
380
+ * Normal case: get the relation's ACL from pg_class
381
+ */
404
382
tuple = SearchSysCacheTuple (RELNAME ,
405
383
PointerGetDatum (relname ),
406
384
0 , 0 , 0 );
407
385
if (!HeapTupleIsValid (tuple ))
408
- {
409
- elog (ERROR , "pg_aclcheck: class \"%s\" not found" ,
410
- relname );
411
- }
412
- if (!heap_attisnull (tuple , Anum_pg_class_relacl ))
413
- {
414
- /* get a detoasted copy of the ACL */
415
- acl = DatumGetAclPCopy (heap_getattr (tuple ,
416
- Anum_pg_class_relacl ,
417
- RelationGetDescr (relation ),
418
- (bool * ) NULL ));
419
- }
420
- else
421
- {
386
+ elog (ERROR , "pg_aclcheck: class \"%s\" not found" , relname );
422
387
423
- /*
424
- * if the acl is null, by default the owner can do whatever he
425
- * wants to with it
426
- */
388
+ aclDatum = SysCacheGetAttr (RELNAME , tuple , Anum_pg_class_relacl ,
389
+ & isNull );
390
+ if (isNull )
391
+ {
392
+ /* No ACL, so build default ACL for rel */
427
393
AclId ownerId ;
428
394
429
395
ownerId = ((Form_pg_class ) GETSTRUCT (tuple ))-> relowner ;
430
- acl = aclownerdefault (relname , ownerId );
396
+ acl = acldefault (relname , ownerId );
431
397
}
432
- heap_close (relation , RowExclusiveLock );
433
- #else
434
- relation = heap_openr (RelationRelationName , RowExclusiveLock );
435
- tuple = SearchSysCacheTuple (RELNAME ,
436
- PointerGetDatum (relname ),
437
- 0 , 0 , 0 );
438
- if (HeapTupleIsValid (tuple ) &&
439
- !heap_attisnull (tuple , Anum_pg_class_relacl ))
398
+ else
440
399
{
441
- /* get a detoasted copy of the ACL */
442
- acl = DatumGetAclPCopy (heap_getattr (tuple ,
443
- Anum_pg_class_relacl ,
444
- RelationGetDescr (relation ),
445
- (bool * ) NULL ));
400
+ /* get a detoasted copy of the rel's ACL */
401
+ acl = DatumGetAclPCopy (aclDatum );
446
402
}
447
- heap_close (relation , RowExclusiveLock );
448
- #endif
403
+
449
404
result = aclcheck (relname , acl , userid , (AclIdType ) ACL_IDTYPE_UID , mode );
450
405
if (acl )
451
406
pfree (acl );
0 commit comments