acl_valid.c revision 208785
1202375Srdivacky/*- 2202375Srdivacky * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson 3202375Srdivacky * All rights reserved. 4202375Srdivacky * 5202375Srdivacky * This software was developed by Robert Watson for the TrustedBSD Project. 6202375Srdivacky * 7202375Srdivacky * Redistribution and use in source and binary forms, with or without 8202375Srdivacky * modification, are permitted provided that the following conditions 9202375Srdivacky * are met: 10202375Srdivacky * 1. Redistributions of source code must retain the above copyright 11202375Srdivacky * notice, this list of conditions and the following disclaimer. 12202375Srdivacky * 2. Redistributions in binary form must reproduce the above copyright 13202375Srdivacky * notice, this list of conditions and the following disclaimer in the 14202375Srdivacky * documentation and/or other materials provided with the distribution. 15263508Sdim * 16202375Srdivacky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17249423Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18202375Srdivacky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19202375Srdivacky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20202375Srdivacky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21202375Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22202375Srdivacky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23249423Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24249423Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25249423Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26249423Sdim * SUCH DAMAGE. 27249423Sdim */ 28251662Sdim/* 29249423Sdim * acl_valid -- POSIX.1e ACL check routine 30251662Sdim */ 31249423Sdim 32249423Sdim#include <sys/cdefs.h> 33249423Sdim__FBSDID("$FreeBSD: head/lib/libc/posix1e/acl_valid.c 208785 2010-06-03 14:29:17Z trasz $"); 34249423Sdim 35249423Sdim#include <sys/types.h> 36249423Sdim#include "namespace.h" 37249423Sdim#include <sys/acl.h> 38249423Sdim#include "un-namespace.h" 39249423Sdim#include <sys/errno.h> 40249423Sdim#include <stdlib.h> 41251662Sdim 42249423Sdim#include "acl_support.h" 43249423Sdim 44249423Sdim/* 45249423Sdim * acl_valid: accepts an ACL, returns 0 on valid ACL, -1 for invalid, 46251662Sdim * and errno set to EINVAL. 47249423Sdim * 48249423Sdim * Implemented by calling the acl_check routine in acl_support, which 49249423Sdim * requires ordering. We call acl_support's _posix1e_acl_sort to make this 50251662Sdim * true. POSIX.1e allows acl_valid() to reorder the ACL as it sees fit. 51249423Sdim * 52249423Sdim * This call is deprecated, as it doesn't ask whether the ACL is valid 53251662Sdim * for a particular target. However, this call is standardized, unlike 54249423Sdim * the other two forms. 55249423Sdim */ 56249423Sdimint 57249423Sdimacl_valid(acl_t acl) 58249423Sdim{ 59249423Sdim int error; 60251662Sdim 61249423Sdim if (acl == NULL) { 62249423Sdim errno = EINVAL; 63249423Sdim return (-1); 64249423Sdim } 65251662Sdim if (!_acl_brand_may_be(acl, ACL_BRAND_POSIX)) { 66249423Sdim errno = EINVAL; 67249423Sdim return (-1); 68249423Sdim } 69249423Sdim _posix1e_acl_sort(acl); 70249423Sdim error = _posix1e_acl_check(acl); 71249423Sdim if (error) { 72249423Sdim errno = error; 73249423Sdim return (-1); 74249423Sdim } else { 75249423Sdim return (0); 76249423Sdim } 77249423Sdim} 78251662Sdim 79251662Sdimint 80251662Sdimacl_valid_file_np(const char *pathp, acl_type_t type, acl_t acl) 81251662Sdim{ 82251662Sdim 83249423Sdim if (pathp == NULL || acl == NULL) { 84249423Sdim errno = EINVAL; 85249423Sdim return (-1); 86251662Sdim } 87249423Sdim type = _acl_type_unold(type); 88249423Sdim if (_posix1e_acl(acl, type)) 89249423Sdim _posix1e_acl_sort(acl); 90249423Sdim 91251662Sdim return (__acl_aclcheck_file(pathp, type, &acl->ats_acl)); 92249423Sdim} 93249423Sdim 94249423Sdimint 95249423Sdimacl_valid_link_np(const char *pathp, acl_type_t type, acl_t acl) 96251662Sdim{ 97249423Sdim 98249423Sdim if (pathp == NULL || acl == NULL) { 99251662Sdim errno = EINVAL; 100249423Sdim return (-1); 101249423Sdim } 102249423Sdim type = _acl_type_unold(type); 103249423Sdim if (_posix1e_acl(acl, type)) 104249423Sdim _posix1e_acl_sort(acl); 105249423Sdim 106249423Sdim return (__acl_aclcheck_link(pathp, type, &acl->ats_acl)); 107249423Sdim} 108251662Sdim 109249423Sdimint 110249423Sdimacl_valid_fd_np(int fd, acl_type_t type, acl_t acl) 111249423Sdim{ 112249423Sdim 113249423Sdim if (acl == NULL) { 114249423Sdim errno = EINVAL; 115249423Sdim return (-1); 116251662Sdim } 117249423Sdim type = _acl_type_unold(type); 118249423Sdim if (_posix1e_acl(acl, type)) 119251662Sdim _posix1e_acl_sort(acl); 120249423Sdim 121249423Sdim acl->ats_cur_entry = 0; 122249423Sdim 123249423Sdim return (___acl_aclcheck_fd(fd, type, &acl->ats_acl)); 124249423Sdim} 125249423Sdim