acl_entry.c revision 208782
1177633Sdfr/* 2177633Sdfr * Copyright (c) 2001-2002 Chris D. Faulhaber 3177633Sdfr * All rights reserved. 4177633Sdfr * 5177633Sdfr * Redistribution and use in source and binary forms, with or without 6177633Sdfr * modification, are permitted provided that the following conditions 7177633Sdfr * are met: 8177633Sdfr * 1. Redistributions of source code must retain the above copyright 9177633Sdfr * notice, this list of conditions and the following disclaimer. 10177633Sdfr * 2. Redistributions in binary form must reproduce the above copyright 11177633Sdfr * notice, this list of conditions and the following disclaimer in the 12177633Sdfr * documentation and/or other materials provided with the distribution. 13177633Sdfr * 14177633Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15177633Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16177633Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17177633Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18177633Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19177633Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20177633Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21177633Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22177633Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23177633Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24177633Sdfr * SUCH DAMAGE. 25177633Sdfr */ 26177633Sdfr 27177633Sdfr#include <sys/cdefs.h> 28177633Sdfr__FBSDID("$FreeBSD: head/lib/libc/posix1e/acl_entry.c 208782 2010-06-03 14:15:08Z trasz $"); 29177633Sdfr 30177633Sdfr#include <sys/types.h> 31177633Sdfr#include "namespace.h" 32177633Sdfr#include <sys/acl.h> 33177633Sdfr#include "un-namespace.h" 34177633Sdfr 35177633Sdfr#include <errno.h> 36177633Sdfr#include <stdlib.h> 37177633Sdfr 38177633Sdfr/* 39177633Sdfr * acl_create_entry() (23.4.7): create a new ACL entry in the ACL pointed 40177633Sdfr * to by acl_p. 41177633Sdfr */ 42177633Sdfrint 43177633Sdfracl_create_entry(acl_t *acl_p, acl_entry_t *entry_p) 44177633Sdfr{ 45177633Sdfr struct acl *acl_int; 46177633Sdfr 47177633Sdfr if (acl_p == NULL) { 48177633Sdfr errno = EINVAL; 49177633Sdfr return (-1); 50177633Sdfr } 51193650Srwatson 52177633Sdfr acl_int = &(*acl_p)->ats_acl; 53177633Sdfr 54177633Sdfr /* 55177633Sdfr * +1, because we are checking if there is space left for one more 56184588Sdfr * entry. 57184588Sdfr */ 58184588Sdfr if ((acl_int->acl_cnt + 1 >= ACL_MAX_ENTRIES) || 59184588Sdfr (acl_int->acl_cnt < 0)) { 60184588Sdfr errno = EINVAL; 61184588Sdfr return (-1); 62184588Sdfr } 63177633Sdfr 64177633Sdfr *entry_p = &acl_int->acl_entry[acl_int->acl_cnt++]; 65177633Sdfr 66177633Sdfr (**entry_p).ae_tag = ACL_UNDEFINED_TAG; 67177633Sdfr (**entry_p).ae_id = ACL_UNDEFINED_ID; 68177633Sdfr (**entry_p).ae_perm = ACL_PERM_NONE; 69177633Sdfr (**entry_p).ae_entry_type = 0; 70177633Sdfr (**entry_p).ae_flags = 0; 71177633Sdfr 72177633Sdfr (*acl_p)->ats_cur_entry = 0; 73177633Sdfr 74177633Sdfr return (0); 75177633Sdfr} 76177633Sdfr 77177633Sdfrint 78177633Sdfracl_create_entry_np(acl_t *acl_p, acl_entry_t *entry_p, int offset) 79177633Sdfr{ 80177633Sdfr int i; 81177633Sdfr struct acl *acl_int; 82177633Sdfr 83177633Sdfr if (acl_p == NULL) { 84177633Sdfr errno = EINVAL; 85177633Sdfr return (-1); 86177633Sdfr } 87177633Sdfr 88184588Sdfr acl_int = &(*acl_p)->ats_acl; 89184588Sdfr 90177633Sdfr if (acl_int->acl_cnt + 1 >= ACL_MAX_ENTRIES) { 91177633Sdfr errno = EINVAL; 92177633Sdfr return (-1); 93177633Sdfr } 94177633Sdfr 95177633Sdfr if (offset < 0 || offset >= acl_int->acl_cnt) { 96177633Sdfr errno = EINVAL; 97177633Sdfr return (-1); 98177633Sdfr } 99177633Sdfr 100177633Sdfr /* Make room for the new entry. */ 101184588Sdfr for (i = acl_int->acl_cnt; i > offset; i--) 102184588Sdfr acl_int->acl_entry[i] = acl_int->acl_entry[i - 1]; 103184588Sdfr 104184588Sdfr acl_int->acl_cnt++; 105184588Sdfr 106177633Sdfr *entry_p = &acl_int->acl_entry[offset]; 107177633Sdfr 108177633Sdfr (**entry_p).ae_tag = ACL_UNDEFINED_TAG; 109177633Sdfr (**entry_p).ae_id = ACL_UNDEFINED_ID; 110177633Sdfr (**entry_p).ae_perm = ACL_PERM_NONE; 111177633Sdfr (**entry_p).ae_entry_type = 0; 112177633Sdfr (**entry_p).ae_flags= 0; 113184588Sdfr 114184588Sdfr (*acl_p)->ats_cur_entry = 0; 115184588Sdfr 116184588Sdfr return (0); 117184588Sdfr} 118184588Sdfr 119184588Sdfr/* 120184588Sdfr * acl_get_entry() (23.4.14): returns an ACL entry from an ACL 121184588Sdfr * indicated by entry_id. 122184588Sdfr */ 123184588Sdfrint 124184588Sdfracl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p) 125184588Sdfr{ 126184588Sdfr struct acl *acl_int; 127184588Sdfr 128184588Sdfr if (acl == NULL) { 129184588Sdfr errno = EINVAL; 130184588Sdfr return (-1); 131184588Sdfr } 132184588Sdfr acl_int = &acl->ats_acl; 133184588Sdfr 134184588Sdfr switch(entry_id) { 135184588Sdfr case ACL_FIRST_ENTRY: 136184588Sdfr acl->ats_cur_entry = 0; 137184588Sdfr /* PASSTHROUGH */ 138184588Sdfr case ACL_NEXT_ENTRY: 139184588Sdfr if (acl->ats_cur_entry >= acl->ats_acl.acl_cnt) 140184588Sdfr return 0; 141184588Sdfr *entry_p = &acl_int->acl_entry[acl->ats_cur_entry++]; 142184588Sdfr return (1); 143177633Sdfr } 144177633Sdfr 145177633Sdfr errno = EINVAL; 146177633Sdfr return (-1); 147184588Sdfr} 148184588Sdfr