Path: blob/main/lib/libc/posix1e/acl_extended_file_np.c
39476 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Gleb Popov4* 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*/27/*28* acl_extended_file_np: Check if the file has extended ACLs set.29*/3031#include <sys/param.h>32#include <sys/errno.h>33#include <sys/acl.h>3435#include <unistd.h>3637typedef acl_t (*acl_get_func)(const char *, acl_type_t);38typedef long (*pathconf_func)(const char *, int);3940static int41_acl_extended_file(acl_get_func f, pathconf_func pathconf_f, const char* path_p);4243int44acl_extended_file_np(const char *path_p)45{46return (_acl_extended_file(acl_get_file, pathconf, path_p));47}4849int50acl_extended_file_nofollow_np(const char *path_p)51{52return (_acl_extended_file(acl_get_link_np, lpathconf, path_p));53}5455int56acl_extended_link_np(const char *path_p)57{58return (_acl_extended_file(acl_get_link_np, lpathconf, path_p));59}6061int62_acl_extended_file(acl_get_func acl_get, pathconf_func pathconf_f, const char* path_p)63{64acl_t acl;65int retval, istrivial, acltype = ACL_TYPE_ACCESS;6667retval = pathconf_f(path_p, _PC_ACL_NFS4);68if (retval > 0)69acltype = ACL_TYPE_NFS4;7071acl = acl_get(path_p, acltype);72if (acl == NULL)73return (-1);7475retval = acl_is_trivial_np(acl, &istrivial);76acl_free(acl);77if (retval == -1)78return (-1);7980return (!istrivial);81}828384