/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008, 2009 Edward Tomasz Napierała <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include <stdio.h>28#include <errno.h>29#include <sys/acl.h>3031#include "acl_support.h"3233static int34_flag_is_invalid(acl_flag_t flag)35{3637if ((flag & ACL_FLAGS_BITS) == flag)38return (0);3940errno = EINVAL;4142return (1);43}4445int46acl_add_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)47{4849if (flagset_d == NULL) {50errno = EINVAL;51return (-1);52}5354if (_flag_is_invalid(flag))55return (-1);5657*flagset_d |= flag;5859return (0);60}6162int63acl_clear_flags_np(acl_flagset_t flagset_d)64{6566if (flagset_d == NULL) {67errno = EINVAL;68return (-1);69}7071*flagset_d = 0;7273return (0);74}7576int77acl_delete_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)78{7980if (flagset_d == NULL) {81errno = EINVAL;82return (-1);83}8485if (_flag_is_invalid(flag))86return (-1);8788*flagset_d &= ~flag;8990return (0);91}9293int94acl_get_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)95{9697if (flagset_d == NULL) {98errno = EINVAL;99return (-1);100}101102if (_flag_is_invalid(flag))103return (-1);104105if (*flagset_d & flag)106return (1);107108return (0);109}110111int112acl_get_flagset_np(acl_entry_t entry_d, acl_flagset_t *flagset_p)113{114115if (entry_d == NULL || flagset_p == NULL) {116errno = EINVAL;117return (-1);118}119120if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {121errno = EINVAL;122return (-1);123}124125*flagset_p = &entry_d->ae_flags;126127return (0);128}129130int131acl_set_flagset_np(acl_entry_t entry_d, acl_flagset_t flagset_d)132{133134if (entry_d == NULL) {135errno = EINVAL;136return (-1);137}138139if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {140errno = EINVAL;141return (-1);142}143144_entry_brand_as(entry_d, ACL_BRAND_NFS4);145146if (_flag_is_invalid(*flagset_d))147return (-1);148149entry_d->ae_flags = *flagset_d;150151return (0);152}153154155