1/* 2 File: acl_free.c 3 4 Copyright (C) 1999, 2000 5 Andreas Gruenbacher <a.gruenbacher@computer.org> 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Library General Public 9 License as published by the Free Software Foundation; either 10 version 2 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 Library General Public License for more details. 16 17 You should have received a copy of the GNU Library 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 "libacl.h" 23 24 25void 26__acl_free_acl_obj(acl_obj *acl_obj_p) 27{ 28 acl_entry_obj *entry_obj_p; 29 while (acl_obj_p->anext != (acl_entry_obj *)acl_obj_p) { 30 entry_obj_p = acl_obj_p->anext; 31 acl_obj_p->anext = acl_obj_p->anext->enext; 32 free_obj_p(entry_obj_p); 33 } 34 free(acl_obj_p->aprealloc); 35 free_obj_p(acl_obj_p); 36} 37 38 39/* 23.4.12 */ 40int 41acl_free(void *obj_p) 42{ 43 obj_prefix *int_p = ((obj_prefix *)obj_p)-1; 44 if (!obj_p || !int_p) { 45 errno = EINVAL; 46 return -1; 47 } 48 49 50 switch(int_p->p_magic) { 51 case acl_MAGIC: 52 __acl_free_acl_obj((acl_obj *)int_p); 53 return 0; 54 case qualifier_MAGIC: 55 case string_MAGIC: 56 free_obj_p(int_p); 57 return 0; 58 case acl_entry_MAGIC: 59 case acl_permset_MAGIC: 60#ifdef LIBACL_DEBUG 61 fprintf(stderr, "object (magic=0x%X) " 62 "at %p cannot be freed\n", 63 int_p->p_magic, int_p); 64#endif 65 break; 66 default: 67#ifdef LIBACL_DEBUG 68 fprintf(stderr, "invalid object (magic=0x%X) " 69 "at %p\n", int_p->p_magic, int_p); 70#endif 71 break; 72 } 73 errno = EINVAL; 74 return -1; 75} 76 77