2 File: __acl_reorder_obj_p.c
3 (Linux Access Control List Management, Posix Library Functions)
5 Copyright (C) 1999, 2000
6 Andreas Gruenbacher, <a.gruenbacher@bestbits.at>
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 __acl_entry_p_compare(const acl_entry_obj *a_p, const acl_entry_obj *b_p)
30 if (a_p->etag < b_p->etag)
32 else if (a_p->etag > b_p->etag)
35 if (a_p->eid.qid < b_p->eid.qid)
37 else if (a_p->eid.qid > b_p->eid.qid)
45 __acl_entry_pp_compare(const void *a, const void *b)
47 return __acl_entry_p_compare(*(const acl_entry_obj **)a,
48 *(const acl_entry_obj **)b);
53 Take an ACL entry form its current place in the entry ring,
54 and insert it at its proper place. Entries that are not valid
55 (yet) are not reordered.
58 __acl_reorder_entry_obj_p(acl_entry_obj *entry_obj_p)
60 acl_obj *acl_obj_p = entry_obj_p->econtainer;
61 acl_entry_obj *here_obj_p;
63 if (acl_obj_p->aused <= 1)
65 switch(entry_obj_p->etag) {
66 case ACL_UNDEFINED_TAG:
70 if (qualifier_obj_id(entry_obj_p->eid) ==
75 /* Remove entry from ring */
76 entry_obj_p->eprev->enext = entry_obj_p->enext;
77 entry_obj_p->enext->eprev = entry_obj_p->eprev;
79 /* Search for next greater entry */
80 FOREACH_ACL_ENTRY(here_obj_p, acl_obj_p) {
81 if (__acl_entry_p_compare(here_obj_p, entry_obj_p) > 0)
85 /* Re-insert entry into ring */
86 entry_obj_p->eprev = here_obj_p->eprev;
87 entry_obj_p->enext = here_obj_p;
88 entry_obj_p->eprev->enext = entry_obj_p;
89 entry_obj_p->enext->eprev = entry_obj_p;
96 Sort all ACL entries at once, after initializing them. This function is
97 only used when converting complete ACLs from external formats to ACLs;
98 the ACL entries are always kept in canonical order while an ACL is
102 __acl_reorder_obj_p(acl_obj *acl_obj_p)
104 acl_entry_obj **vector = alloca(sizeof(acl_entry_obj *) *
105 acl_obj_p->aused), **v, *x;
106 acl_entry_obj *entry_obj_p;
108 if (acl_obj_p->aused <= 1)
112 FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
116 qsort(vector, acl_obj_p->aused, sizeof(acl_entry_obj *),
117 __acl_entry_pp_compare);
119 x = (acl_entry_obj *)acl_obj_p;
120 for (v = vector; v != vector + acl_obj_p->aused; v++) {
124 acl_obj_p->aprev = *(vector + acl_obj_p->aused - 1);
126 x = (acl_entry_obj *)acl_obj_p;
127 for (v = vector + acl_obj_p->aused - 1; v != vector - 1; v--) {
131 acl_obj_p->anext = *vector;