/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2001-2002 Chris D. Faulhaber4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/types.h>29#include "namespace.h"30#include <sys/acl.h>31#include "un-namespace.h"3233#include <errno.h>34#include <stdlib.h>3536/*37* acl_create_entry() (23.4.7): create a new ACL entry in the ACL pointed38* to by acl_p.39*/40int41acl_create_entry(acl_t *acl_p, acl_entry_t *entry_p)42{43struct acl *acl_int;4445if (acl_p == NULL) {46errno = EINVAL;47return (-1);48}4950acl_int = &(*acl_p)->ats_acl;5152/*53* +1, because we are checking if there is space left for one more54* entry.55*/56if (acl_int->acl_cnt + 1 >= ACL_MAX_ENTRIES) {57errno = EINVAL;58return (-1);59}6061*entry_p = &acl_int->acl_entry[acl_int->acl_cnt++];6263(**entry_p).ae_tag = ACL_UNDEFINED_TAG;64(**entry_p).ae_id = ACL_UNDEFINED_ID;65(**entry_p).ae_perm = ACL_PERM_NONE;66(**entry_p).ae_entry_type = 0;67(**entry_p).ae_flags = 0;6869(*acl_p)->ats_cur_entry = 0;7071return (0);72}7374int75acl_create_entry_np(acl_t *acl_p, acl_entry_t *entry_p, int offset)76{77int i;78struct acl *acl_int;7980if (acl_p == NULL) {81errno = EINVAL;82return (-1);83}8485acl_int = &(*acl_p)->ats_acl;8687if (acl_int->acl_cnt + 1 >= ACL_MAX_ENTRIES) {88errno = EINVAL;89return (-1);90}9192if (offset < 0 || offset > acl_int->acl_cnt) {93errno = EINVAL;94return (-1);95}9697/* Make room for the new entry. */98for (i = acl_int->acl_cnt; i > offset; i--)99acl_int->acl_entry[i] = acl_int->acl_entry[i - 1];100101acl_int->acl_cnt++;102103*entry_p = &acl_int->acl_entry[offset];104105(**entry_p).ae_tag = ACL_UNDEFINED_TAG;106(**entry_p).ae_id = ACL_UNDEFINED_ID;107(**entry_p).ae_perm = ACL_PERM_NONE;108(**entry_p).ae_entry_type = 0;109(**entry_p).ae_flags= 0;110111(*acl_p)->ats_cur_entry = 0;112113return (0);114}115116/*117* acl_get_entry() (23.4.14): returns an ACL entry from an ACL118* indicated by entry_id.119*/120int121acl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p)122{123struct acl *acl_int;124125if (acl == NULL) {126errno = EINVAL;127return (-1);128}129acl_int = &acl->ats_acl;130131switch(entry_id) {132case ACL_FIRST_ENTRY:133acl->ats_cur_entry = 0;134/* PASSTHROUGH */135case ACL_NEXT_ENTRY:136if (acl->ats_cur_entry >= acl->ats_acl.acl_cnt)137return 0;138*entry_p = &acl_int->acl_entry[acl->ats_cur_entry++];139return (1);140}141142errno = EINVAL;143return (-1);144}145146147