acl_valid.c revision 75928
1/*-
2 * Copyright (c) 1999, 2000, 20001 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/libc/posix1e/acl_valid.c 75928 2001-04-24 22:45:41Z jedgar $
27 */
28/*
29 * acl_valid -- POSIX.1e ACL check routine
30 */
31
32#include <sys/types.h>
33#include "namespace.h"
34#include <sys/acl.h>
35#include "un-namespace.h"
36#include <sys/errno.h>
37
38#include "acl_support.h"
39
40/*
41 * acl_valid: accepts an ACL, returns 0 on valid ACL, -1 for invalid,
42 * and errno set to EINVAL.
43 *
44 * Implemented by calling the acl_check routine in acl_support, which
45 * requires ordering.  We call acl_support's _posix1e_acl_sort to make this
46 * true.  POSIX.1e allows acl_valid() to reorder the ACL as it sees fit.
47 *
48 * This call is deprecated, as it doesn't ask whether the ACL is valid
49 * for a particular target.  However, this call is standardized, unlike
50 * the other two forms.
51 */
52int
53acl_valid(acl_t acl)
54{
55	int	error;
56
57	_posix1e_acl_sort(acl);
58	error = _posix1e_acl_check(acl);
59	if (error) {
60		errno = error;
61		return (-1);
62	} else {
63		return (0);
64	}
65}
66
67
68int
69acl_valid_file_np(const char *pathp, acl_type_t type, acl_t acl)
70{
71	int	error;
72
73	if (_posix1e_acl(acl, type)) {
74		error = _posix1e_acl_sort(acl);
75		if (error) {
76			errno = error;
77			return (-1);
78		}
79	}
80
81	return (__acl_aclcheck_file(pathp, type, &acl->ats_acl));
82}
83
84
85int
86acl_valid_fd_np(int fd, acl_type_t type, acl_t acl)
87{
88	int	error;
89
90	if (_posix1e_acl(acl, type)) {
91		error = _posix1e_acl_sort(acl);
92		if (error) {
93			errno = error;
94			return (-1);
95		}
96	}
97
98	acl->ats_cur_entry = 0;
99
100
101	return (___acl_aclcheck_fd(fd, type, &acl->ats_acl));
102}
103