8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.38 2000/04/12 17:14:55 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.39 2000/07/31 22:39:13 tgl Exp $
12
12
*
13
13
* NOTES
14
14
* See acl.h.
33
33
#include "utils/acl.h"
34
34
#include "utils/syscache.h"
35
35
36
- static int32 aclcheck (char * relname , Acl * acl , AclId id , AclIdType idtype , AclMode mode );
36
+ static int32 aclcheck (char * relname , Acl * acl , AclId id ,
37
+ AclIdType idtype , AclMode mode );
37
38
38
39
/*
39
40
* Enable use of user relations in place of real system catalogs.
@@ -68,14 +69,16 @@ char *aclcheck_error_strings[] = {
68
69
static
69
70
dumpacl (Acl * acl )
70
71
{
71
- unsigned i ;
72
+ int i ;
72
73
AclItem * aip ;
73
74
74
75
elog (DEBUG , "acl size = %d, # acls = %d" ,
75
76
ACL_SIZE (acl ), ACL_NUM (acl ));
76
- aip = ( AclItem * ) ACL_DAT (acl );
77
+ aip = ACL_DAT (acl );
77
78
for (i = 0 ; i < ACL_NUM (acl ); ++ i )
78
- elog (DEBUG , " acl[%d]: %s" , i , aclitemout (aip + i ));
79
+ elog (DEBUG , " acl[%d]: %s" , i ,
80
+ DatumGetCString (DirectFunctionCall1 (aclitemout ,
81
+ PointerGetDatum (aip + i ))));
79
82
}
80
83
81
84
#endif
@@ -89,22 +92,20 @@ ChangeAcl(char *relname,
89
92
unsigned modechg )
90
93
{
91
94
unsigned i ;
92
- Acl * old_acl = ( Acl * ) NULL ,
95
+ Acl * old_acl ,
93
96
* new_acl ;
94
97
Relation relation ;
95
98
HeapTuple tuple ;
96
99
Datum values [Natts_pg_class ];
97
100
char nulls [Natts_pg_class ];
98
101
char replaces [Natts_pg_class ];
99
102
Relation idescs [Num_pg_class_indices ];
100
- int free_old_acl = 0 ;
103
+ bool isNull ;
104
+ bool free_old_acl = false;
101
105
102
106
/*
103
107
* Find the pg_class tuple matching 'relname' and extract the ACL. If
104
108
* there's no ACL, create a default using the pg_class.relowner field.
105
- *
106
- * We can't use the syscache here, since we need to do a heap_update on
107
- * the tuple we find.
108
109
*/
109
110
relation = heap_openr (RelationRelationName , RowExclusiveLock );
110
111
tuple = SearchSysCacheTuple (RELNAME ,
@@ -117,25 +118,37 @@ ChangeAcl(char *relname,
117
118
relname );
118
119
}
119
120
120
- if (!heap_attisnull (tuple , Anum_pg_class_relacl ))
121
- old_acl = (Acl * ) heap_getattr (tuple ,
122
- Anum_pg_class_relacl ,
123
- RelationGetDescr (relation ),
124
- (bool * ) NULL );
125
- if (!old_acl || ACL_NUM (old_acl ) < 1 )
121
+ old_acl = (Acl * ) heap_getattr (tuple ,
122
+ Anum_pg_class_relacl ,
123
+ RelationGetDescr (relation ),
124
+ & isNull );
125
+ if (isNull )
126
126
{
127
127
#ifdef ACLDEBUG_TRACE
128
128
elog (DEBUG , "ChangeAcl: using default ACL" );
129
129
#endif
130
- /* old_acl = acldefault(((Form_pg_class) GETSTRUCT(tuple))->relowner); */
131
130
old_acl = acldefault (relname );
132
- free_old_acl = 1 ;
131
+ free_old_acl = true;
132
+ }
133
+
134
+ /* Need to detoast the old ACL for modification */
135
+ old_acl = DatumGetAclP (PointerGetDatum (old_acl ));
136
+
137
+ if (ACL_NUM (old_acl ) < 1 )
138
+ {
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;
133
144
}
134
145
135
146
#ifdef ACLDEBUG_TRACE
136
147
dumpacl (old_acl );
137
148
#endif
149
+
138
150
new_acl = aclinsert3 (old_acl , mod_aip , modechg );
151
+
139
152
#ifdef ACLDEBUG_TRACE
140
153
dumpacl (new_acl );
141
154
#endif
@@ -148,7 +161,7 @@ ChangeAcl(char *relname,
148
161
* anyway */
149
162
}
150
163
replaces [Anum_pg_class_relacl - 1 ] = 'r' ;
151
- values [Anum_pg_class_relacl - 1 ] = ( Datum ) new_acl ;
164
+ values [Anum_pg_class_relacl - 1 ] = PointerGetDatum ( new_acl ) ;
152
165
tuple = heap_modifytuple (tuple , relation , values , nulls , replaces );
153
166
154
167
heap_update (relation , & tuple -> t_self , tuple , NULL );
@@ -193,20 +206,20 @@ get_groname(AclId grosysid)
193
206
if (HeapTupleIsValid (tuple ))
194
207
name = NameStr (((Form_pg_group ) GETSTRUCT (tuple ))-> groname );
195
208
else
196
- elog (NOTICE , "get_groname: group %d not found" , grosysid );
209
+ elog (NOTICE , "get_groname: group %u not found" , grosysid );
197
210
return name ;
198
211
}
199
212
200
- static int32
213
+ static bool
201
214
in_group (AclId uid , AclId gid )
202
215
{
203
216
Relation relation ;
204
217
HeapTuple tuple ;
205
218
Acl * tmp ;
206
- unsigned i ,
219
+ int i ,
207
220
num ;
208
221
AclId * aidp ;
209
- int32 found = 0 ;
222
+ bool found = false ;
210
223
211
224
relation = heap_openr (GroupRelationName , RowExclusiveLock );
212
225
tuple = SearchSysCacheTuple (GROSYSID ,
@@ -219,13 +232,15 @@ in_group(AclId uid, AclId gid)
219
232
Anum_pg_group_grolist ,
220
233
RelationGetDescr (relation ),
221
234
(bool * ) NULL );
235
+ /* be sure the IdList is not toasted */
236
+ tmp = DatumGetIdListP (PointerGetDatum (tmp ));
222
237
/* XXX make me a function */
223
238
num = IDLIST_NUM (tmp );
224
239
aidp = IDLIST_DAT (tmp );
225
240
for (i = 0 ; i < num ; ++ i )
226
241
if (aidp [i ] == uid )
227
242
{
228
- found = 1 ;
243
+ found = true ;
229
244
break ;
230
245
}
231
246
}
@@ -344,8 +359,7 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
344
359
{
345
360
HeapTuple tuple ;
346
361
AclId id ;
347
- Acl * acl = (Acl * ) NULL ,
348
- * tmp ;
362
+ Acl * acl = (Acl * ) NULL ;
349
363
int32 result ;
350
364
Relation relation ;
351
365
@@ -396,12 +410,11 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
396
410
}
397
411
if (!heap_attisnull (tuple , Anum_pg_class_relacl ))
398
412
{
399
- tmp = (Acl * ) heap_getattr (tuple ,
400
- Anum_pg_class_relacl ,
401
- RelationGetDescr (relation ),
402
- (bool * ) NULL );
403
- acl = makeacl (ACL_NUM (tmp ));
404
- memmove ((char * ) acl , (char * ) tmp , ACL_SIZE (tmp ));
413
+ /* get a detoasted copy of the ACL */
414
+ acl = DatumGetAclPCopy (heap_getattr (tuple ,
415
+ Anum_pg_class_relacl ,
416
+ RelationGetDescr (relation ),
417
+ (bool * ) NULL ));
405
418
}
406
419
else
407
420
{
@@ -410,13 +423,10 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
410
423
* if the acl is null, by default the owner can do whatever he
411
424
* wants to with it
412
425
*/
413
- int4 ownerId ;
426
+ AclId ownerId ;
414
427
415
- ownerId = (int4 ) heap_getattr (tuple ,
416
- Anum_pg_class_relowner ,
417
- RelationGetDescr (relation ),
418
- (bool * ) NULL );
419
- acl = aclownerdefault (relname , (AclId ) ownerId );
428
+ ownerId = ((Form_pg_class ) GETSTRUCT (tuple ))-> relowner ;
429
+ acl = aclownerdefault (relname , ownerId );
420
430
}
421
431
heap_close (relation , RowExclusiveLock );
422
432
#else
@@ -427,12 +437,11 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
427
437
if (HeapTupleIsValid (tuple ) &&
428
438
!heap_attisnull (tuple , Anum_pg_class_relacl ))
429
439
{
430
- tmp = (Acl * ) heap_getattr (tuple ,
431
- Anum_pg_class_relacl ,
432
- RelationGetDescr (relation ),
433
- (bool * ) NULL );
434
- acl = makeacl (ACL_NUM (tmp ));
435
- memmove ((char * ) acl , (char * ) tmp , ACL_SIZE (tmp ));
440
+ /* get a detoasted copy of the ACL */
441
+ acl = DatumGetAclPCopy (heap_getattr (tuple ,
442
+ Anum_pg_class_relacl ,
443
+ RelationGetDescr (relation ),
444
+ (bool * ) NULL ));
436
445
}
437
446
heap_close (relation , RowExclusiveLock );
438
447
#endif
0 commit comments