acl_valid.c revision 56055
156055Srwatson/*-
256055Srwatson * Copyright (c) 1999 Robert N. M. Watson
356055Srwatson * All rights reserved.
456055Srwatson *
556055Srwatson * Redistribution and use in source and binary forms, with or without
656055Srwatson * modification, are permitted provided that the following conditions
756055Srwatson * are met:
856055Srwatson * 1. Redistributions of source code must retain the above copyright
956055Srwatson *    notice, this list of conditions and the following disclaimer.
1056055Srwatson * 2. Redistributions in binary form must reproduce the above copyright
1156055Srwatson *    notice, this list of conditions and the following disclaimer in the
1256055Srwatson *    documentation and/or other materials provided with the distribution.
1356055Srwatson *
1456055Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1556055Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1656055Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1756055Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1856055Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1956055Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2056055Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2156055Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2256055Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2356055Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2456055Srwatson * SUCH DAMAGE.
2556055Srwatson *
2656055Srwatson *	$FreeBSD: head/lib/libc/posix1e/acl_valid.c 56055 2000-01-15 19:44:27Z rwatson $
2756055Srwatson */
2856055Srwatson/*
2956055Srwatson * acl_valid -- POSIX.1e ACL check routine
3056055Srwatson */
3156055Srwatson
3256055Srwatson#include <sys/types.h>
3356055Srwatson#include <sys/acl.h>
3456055Srwatson#include <sys/errno.h>
3556055Srwatson
3656055Srwatson#include "acl_support.h"
3756055Srwatson
3856055Srwatson/*
3956055Srwatson * acl_valid: accepts an ACL, returns 0 on valid ACL, -1 for invalid,
4056055Srwatson * and errno set to EINVAL.
4156055Srwatson *
4256055Srwatson * Implemented by calling the acl_check routine in acl_support, which
4356055Srwatson * requires ordering.  We call acl_support's acl_sort to make this
4456055Srwatson * true.
4556055Srwatson *
4656055Srwatson * POSIX.1e allows acl_valid() to reorder the ACL as it sees fit.
4756055Srwatson *
4856055Srwatson * This call is deprecated, as it doesn't ask whether the ACL is valid
4956055Srwatson * for a particular target.
5056055Srwatson */
5156055Srwatsonint
5256055Srwatsonacl_valid(acl_t acl)
5356055Srwatson{
5456055Srwatson	int	error;
5556055Srwatson
5656055Srwatson	acl_sort(acl);
5756055Srwatson	error = acl_check(acl);
5856055Srwatson	if (error) {
5956055Srwatson		errno = error;
6056055Srwatson		return (-1);
6156055Srwatson	} else {
6256055Srwatson		return (0);
6356055Srwatson	}
6456055Srwatson}
6556055Srwatson
6656055Srwatson
6756055Srwatsonint
6856055Srwatsonacl_valid_file(const char *pathp, acl_type_t type, acl_t acl)
6956055Srwatson{
7056055Srwatson	int	error;
7156055Srwatson
7256055Srwatson	if (acl_posix1e(acl)) {
7356055Srwatson		error = acl_sort(acl);
7456055Srwatson		if (error) {
7556055Srwatson			errno = error;
7656055Srwatson			return (-1);
7756055Srwatson		}
7856055Srwatson	}
7956055Srwatson
8056055Srwatson	return (acl_syscall_aclcheck_file(pathp, type, acl));
8156055Srwatson}
8256055Srwatson
8356055Srwatson
8456055Srwatsonint
8556055Srwatsonacl_valid_fd(int fd, acl_type_t type, acl_t acl)
8656055Srwatson{
8756055Srwatson	int	error;
8856055Srwatson
8956055Srwatson	if (acl_posix1e(acl)) {
9056055Srwatson		error = acl_sort(acl);
9156055Srwatson		if (error) {
9256055Srwatson			errno = error;
9356055Srwatson			return (-1);
9456055Srwatson		}
9556055Srwatson	}
9656055Srwatson
9756055Srwatson	return (acl_syscall_aclcheck_fd(fd, type, acl));
9856055Srwatson}
99