8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.51 2000/10/16 17:08:08 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.52 2000/11/03 19:01:36 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -212,8 +212,7 @@ makeacl(int n)
212
212
if (n < 0 )
213
213
elog (ERROR , "makeacl: invalid size: %d" , n );
214
214
size = ACL_N_SIZE (n );
215
- if (!(new_acl = (Acl * ) palloc (size )))
216
- elog (ERROR , "makeacl: palloc failed on %d" , size );
215
+ new_acl = (Acl * ) palloc (size );
217
216
MemSet ((char * ) new_acl , 0 , size );
218
217
new_acl -> size = size ;
219
218
new_acl -> ndim = 1 ;
@@ -382,7 +381,7 @@ aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg)
382
381
383
382
/* These checks for null input are probably dead code, but... */
384
383
if (!old_acl || ACL_NUM (old_acl ) < 1 )
385
- old_acl = makeacl (0 );
384
+ old_acl = makeacl (1 );
386
385
if (!mod_aip )
387
386
{
388
387
new_acl = makeacl (ACL_NUM (old_acl ));
@@ -402,12 +401,13 @@ aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg)
402
401
/* find the first element not less than the element to be inserted */
403
402
for (dst = 0 ; dst < num && aclitemgt (mod_aip , old_aip + dst ); ++ dst )
404
403
;
404
+
405
405
if (dst < num && aclitemeq (mod_aip , old_aip + dst ))
406
406
{
407
407
/* modify in-place */
408
- new_acl = makeacl (ACL_NUM (old_acl ));
409
- memcpy ((char * ) new_acl , (char * ) old_acl , ACL_SIZE (old_acl ));
408
+ new_acl = makeacl (num );
410
409
new_aip = ACL_DAT (new_acl );
410
+ memcpy ((char * ) new_acl , (char * ) old_acl , ACL_SIZE (old_acl ));
411
411
src = dst ;
412
412
}
413
413
else
@@ -420,24 +420,26 @@ aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg)
420
420
}
421
421
else if (dst >= num )
422
422
{ /* end */
423
- memmove ((char * ) new_aip ,
424
- (char * ) old_aip ,
425
- num * sizeof (AclItem ));
423
+ memcpy ((char * ) new_aip ,
424
+ (char * ) old_aip ,
425
+ num * sizeof (AclItem ));
426
426
}
427
427
else
428
428
{ /* middle */
429
- memmove ((char * ) new_aip ,
430
- (char * ) old_aip ,
431
- dst * sizeof (AclItem ));
432
- memmove ((char * ) (new_aip + dst + 1 ),
433
- (char * ) (old_aip + dst ),
434
- (num - dst ) * sizeof (AclItem ));
429
+ memcpy ((char * ) new_aip ,
430
+ (char * ) old_aip ,
431
+ dst * sizeof (AclItem ));
432
+ memcpy ((char * ) (new_aip + dst + 1 ),
433
+ (char * ) (old_aip + dst ),
434
+ (num - dst ) * sizeof (AclItem ));
435
435
}
436
436
new_aip [dst ].ai_id = mod_aip -> ai_id ;
437
437
new_aip [dst ].ai_idtype = mod_aip -> ai_idtype ;
438
438
num ++ ; /* set num to the size of new_acl */
439
- src = 0 ; /* world entry */
439
+ src = 0 ; /* if add or del, start from world entry */
440
440
}
441
+
442
+ /* apply the permissions mod */
441
443
switch (modechg )
442
444
{
443
445
case ACL_MODECHG_ADD :
@@ -452,11 +454,11 @@ aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg)
452
454
}
453
455
454
456
/*
455
- * if the newly added entry has no permissions, delete it from the
457
+ * if the adjusted entry has no permissions, delete it from the
456
458
* list. For example, this helps in removing entries for users who no
457
- * longer exist.. .
459
+ * longer exist. EXCEPTION: never remove the world entry .
458
460
*/
459
- if (new_aip [dst ].ai_mode == 0 )
461
+ if (new_aip [dst ].ai_mode == 0 && dst > 0 )
460
462
{
461
463
int i ;
462
464
@@ -467,7 +469,7 @@ aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg)
467
469
new_aip [i - 1 ].ai_mode = new_aip [i ].ai_mode ;
468
470
}
469
471
ARR_DIMS (new_acl )[0 ] = num - 1 ;
470
- /* Adjust also the array size because it is used for memmove */
472
+ /* Adjust also the array size because it is used for memcpy */
471
473
ARR_SIZE (new_acl ) -= sizeof (AclItem );
472
474
}
473
475
@@ -500,7 +502,7 @@ aclremove(PG_FUNCTION_ARGS)
500
502
501
503
/* These checks for null input should be dead code, but... */
502
504
if (!old_acl || ACL_NUM (old_acl ) < 1 )
503
- old_acl = makeacl (0 );
505
+ old_acl = makeacl (1 );
504
506
if (!mod_aip )
505
507
{
506
508
new_acl = makeacl (ACL_NUM (old_acl ));
@@ -511,11 +513,14 @@ aclremove(PG_FUNCTION_ARGS)
511
513
old_num = ACL_NUM (old_acl );
512
514
old_aip = ACL_DAT (old_acl );
513
515
516
+ /* Search for the matching entry */
514
517
for (dst = 0 ; dst < old_num && !aclitemeq (mod_aip , old_aip + dst ); ++ dst )
515
518
;
519
+
516
520
if (dst >= old_num )
517
- { /* not found or empty */
518
- new_acl = makeacl (ACL_NUM (old_acl ));
521
+ {
522
+ /* Not found, so return copy of source ACL */
523
+ new_acl = makeacl (old_num );
519
524
memcpy ((char * ) new_acl , (char * ) old_acl , ACL_SIZE (old_acl ));
520
525
}
521
526
else
@@ -529,20 +534,21 @@ aclremove(PG_FUNCTION_ARGS)
529
534
}
530
535
else if (dst == old_num - 1 )
531
536
{ /* end */
532
- memmove ((char * ) new_aip ,
533
- (char * ) old_aip ,
534
- new_num * sizeof (AclItem ));
537
+ memcpy ((char * ) new_aip ,
538
+ (char * ) old_aip ,
539
+ new_num * sizeof (AclItem ));
535
540
}
536
541
else
537
542
{ /* middle */
538
- memmove ((char * ) new_aip ,
539
- (char * ) old_aip ,
540
- dst * sizeof (AclItem ));
541
- memmove ((char * ) (new_aip + dst ),
542
- (char * ) (old_aip + dst + 1 ),
543
- (new_num - dst ) * sizeof (AclItem ));
543
+ memcpy ((char * ) new_aip ,
544
+ (char * ) old_aip ,
545
+ dst * sizeof (AclItem ));
546
+ memcpy ((char * ) (new_aip + dst ),
547
+ (char * ) (old_aip + dst + 1 ),
548
+ (new_num - dst ) * sizeof (AclItem ));
544
549
}
545
550
}
551
+
546
552
PG_RETURN_ACL_P (new_acl );
547
553
}
548
554
0 commit comments