1 /*
2 File: acl_free.c
3
4 Copyright (C) 1999, 2000
5 Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 #include "config.h"
23 #include "libacl.h"
24
25
26 void
27 __acl_free_acl_obj(acl_obj *acl_obj_p)
28 {
29 acl_entry_obj *entry_obj_p;
30 while (acl_obj_p->anext != (acl_entry_obj *)acl_obj_p) {
31 entry_obj_p = acl_obj_p->anext;
32 acl_obj_p->anext = acl_obj_p->anext->enext;
33 free_obj_p(entry_obj_p);
34 }
35 free(acl_obj_p->aprealloc);
36 free_obj_p(acl_obj_p);
37 }
38
39
40 /* 23.4.12 */
41 int
42 acl_free(void *obj_p)
43 {
44 obj_prefix *int_p = ((obj_prefix *)obj_p)-1;
45 if (!obj_p || !int_p) {
46 errno = EINVAL;
47 return -1;
48 }
49
50
51 switch(int_p->p_magic) {
52 case acl_MAGIC:
53 __acl_free_acl_obj((acl_obj *)int_p);
54 return 0;
55 case qualifier_MAGIC:
56 case string_MAGIC:
57 free_obj_p(int_p);
58 return 0;
59 case acl_entry_MAGIC:
60 case acl_permset_MAGIC:
61 #ifdef LIBACL_DEBUG
62 fprintf(stderr, "object (magic=0x%X) "
63 "at %p cannot be freed\n",
64 int_p->p_magic, int_p);
65 #endif
66 break;
67 default:
68 #ifdef LIBACL_DEBUG
69 fprintf(stderr, "invalid object (magic=0x%X) "
70 "at %p\n", int_p->p_magic, int_p);
71 #endif
72 break;
73 }
74 errno = EINVAL;
75 return -1;
76 }
77