diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index 43b4638c4..907882301 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,9 @@ +2015-12-21 Corinna Vinschen + + * setfacl.cc (delace): New helper function to delete a single ACE. + (delacl): Call delace. + (modacl): Ditto, if entry is supposed to get deleted. Align comments. + 2015-12-21 Corinna Vinschen * setfacl.cc (modacl): Move recomputing mask into new function. diff --git a/winsup/utils/setfacl.c b/winsup/utils/setfacl.c index 75b5120fc..3169e63c5 100644 --- a/winsup/utils/setfacl.c +++ b/winsup/utils/setfacl.c @@ -241,6 +241,17 @@ searchace (aclent_t *aclp, int nentries, int type, int id) return -1; } +int +delace (aclent_t *tgt, int tcnt, int t) +{ + int i; + + for (i = t + 1; i < tcnt; ++i) + tgt[i - 1] = tgt[i]; + --tcnt; + return tcnt; +} + int delacl (aclent_t *tgt, int tcnt, aclent_t *src, int scnt) { @@ -253,11 +264,7 @@ delacl (aclent_t *tgt, int tcnt, aclent_t *src, int scnt) if (t < 0) return -1; if (t < tcnt) - { - for (i = t + 1; i < tcnt; ++i) - tgt[i - 1] = tgt[i]; - --tcnt; - } + tcnt = delace (tgt, tcnt, t); } return tcnt; } @@ -267,16 +274,22 @@ modacl (aclent_t *tgt, int tcnt, aclent_t *src, int scnt) { int t, s; - /* Replace or add given acl entries. */ + /* Delete, replace or add given acl entries. */ for (s = 0; s < scnt; ++s) { t = searchace (tgt, MAX_ACL_ENTRIES, src[s].a_type, (src[s].a_type & (USER | GROUP)) ? src[s].a_id : -1); if (t < 0) return -1; - tgt[t] = src[s]; - if (t >= tcnt) - ++tcnt; + /* ILLEGAL_MODE means "delete". */ + if (src[s].a_perm == ILLEGAL_MODE && t < tcnt) + tcnt = delace (tgt, tcnt, t); + else + { + tgt[t] = src[s]; + if (t >= tcnt) + ++tcnt; + } } return tcnt; }