acl_entry.c revision 192966
1116744Ssam/* 2185522Ssam * Copyright (c) 2001-2002 Chris D. Faulhaber 3116744Ssam * All rights reserved. 4116744Ssam * 5116744Ssam * Redistribution and use in source and binary forms, with or without 6116744Ssam * modification, are permitted provided that the following conditions 7116744Ssam * are met: 8116744Ssam * 1. Redistributions of source code must retain the above copyright 9116744Ssam * notice, this list of conditions and the following disclaimer. 10116744Ssam * 2. Redistributions in binary form must reproduce the above copyright 11116744Ssam * notice, this list of conditions and the following disclaimer in the 12116744Ssam * documentation and/or other materials provided with the distribution. 13116744Ssam * 14116744Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15116744Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16116744Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17116744Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18116744Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19116744Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20116744Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21116744Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22116744Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23116744Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24116744Ssam * SUCH DAMAGE. 25116744Ssam */ 26116744Ssam 27116744Ssam#include <sys/cdefs.h> 28116744Ssam__FBSDID("$FreeBSD: head/lib/libc/posix1e/acl_entry.c 192966 2009-05-28 07:20:52Z trasz $"); 29116744Ssam 30116744Ssam#include <sys/types.h> 31116744Ssam#include "namespace.h" 32186094Ssam#include <sys/acl.h> 33116744Ssam#include "un-namespace.h" 34186094Ssam 35186094Ssam#include <errno.h> 36186094Ssam#include <stdlib.h> 37186094Ssam 38219185Sadrian/* 39219185Sadrian * acl_create_entry() (23.4.7): create a new ACL entry in the ACL pointed 40186094Ssam * to by acl_p. 41203286Srpaulo */ 42190571Ssamint 43186094Ssamacl_create_entry(acl_t *acl_p, acl_entry_t *entry_p) 44186094Ssam{ 45186094Ssam struct acl *acl_int; 46186094Ssam 47186094Ssam if (acl_p == NULL) { 48186094Ssam errno = EINVAL; 49185522Ssam return (-1); 50185522Ssam } 51185522Ssam 52186094Ssam acl_int = &(*acl_p)->ats_acl; 53186094Ssam 54186094Ssam /* 55186094Ssam * +1, because we are checking if there is space left for one more 56186094Ssam * entry. 57186094Ssam */ 58186094Ssam if ((acl_int->acl_cnt + 1 >= ACL_MAX_ENTRIES) || 59185522Ssam (acl_int->acl_cnt < 0)) { 60185522Ssam errno = EINVAL; 61186094Ssam return (-1); 62186094Ssam } 63186094Ssam 64186094Ssam *entry_p = &acl_int->acl_entry[acl_int->acl_cnt++]; 65186094Ssam 66186094Ssam (**entry_p).ae_tag = ACL_UNDEFINED_TAG; 67185522Ssam (**entry_p).ae_id = ACL_UNDEFINED_ID; 68185522Ssam (**entry_p).ae_perm = ACL_PERM_NONE; 69186094Ssam (**entry_p).ae_entry_type = 0; 70186094Ssam (**entry_p).ae_flags = 0; 71186094Ssam 72186094Ssam (*acl_p)->ats_cur_entry = 0; 73186094Ssam 74186094Ssam return (0); 75186094Ssam} 76186094Ssam 77186094Ssam/* 78186094Ssam * acl_get_entry() (23.4.14): returns an ACL entry from an ACL 79186094Ssam * indicated by entry_id. 80186094Ssam */ 81186094Ssamint 82186094Ssamacl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p) 83186094Ssam{ 84186094Ssam struct acl *acl_int; 85186094Ssam 86203286Srpaulo if (acl == NULL) { 87185522Ssam errno = EINVAL; 88185522Ssam return (-1); 89185522Ssam } 90185522Ssam acl_int = &acl->ats_acl; 91186094Ssam 92217631Sadrian switch(entry_id) { 93217631Sadrian case ACL_FIRST_ENTRY: 94217631Sadrian acl->ats_cur_entry = 0; 95217631Sadrian /* PASSTHROUGH */ 96217631Sadrian case ACL_NEXT_ENTRY: 97186094Ssam if (acl->ats_cur_entry >= acl->ats_acl.acl_cnt) 98217631Sadrian return 0; 99217631Sadrian *entry_p = &acl_int->acl_entry[acl->ats_cur_entry++]; 100219393Sadrian return (1); 101204656Srpaulo } 102185522Ssam 103186094Ssam errno = EINVAL; 104186094Ssam return (-1); 105186094Ssam} 106190571Ssam