acl_get.c revision 71142
11573Srgrimes/*-
21573Srgrimes * Copyright (c) 1999 Robert N. M. Watson
31573Srgrimes * All rights reserved.
41573Srgrimes *
51573Srgrimes * Redistribution and use in source and binary forms, with or without
61573Srgrimes * modification, are permitted provided that the following conditions
71573Srgrimes * are met:
81573Srgrimes * 1. Redistributions of source code must retain the above copyright
91573Srgrimes *    notice, this list of conditions and the following disclaimer.
101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111573Srgrimes *    notice, this list of conditions and the following disclaimer in the
121573Srgrimes *    documentation and/or other materials provided with the distribution.
131573Srgrimes *
141573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241573Srgrimes * SUCH DAMAGE.
251573Srgrimes *
261573Srgrimes *	$FreeBSD: head/lib/libc/posix1e/acl_get.c 71142 2001-01-17 02:40:39Z rwatson $
271573Srgrimes */
281573Srgrimes/*
291573Srgrimes * acl_get_file - syscall wrapper for retrieving ACL by filename
301573Srgrimes * acl_get_fd - syscall wrapper for retrieving access ACL by fd
311573Srgrimes * acl_get_fd_np - syscall wrapper for retrieving ACL by fd (non-POSIX)
321573Srgrimes */
331573Srgrimes
341573Srgrimes#include <sys/types.h>
351573Srgrimes#include <sys/acl.h>
361573Srgrimes#include <sys/errno.h>
371573Srgrimes#include <stdlib.h>
3855127Speter
391573Srgrimesacl_t
401573Srgrimesacl_get_file(const char *path_p, acl_type_t type)
411573Srgrimes{
421573Srgrimes	struct acl	*aclp;
431573Srgrimes	int	error;
441573Srgrimes
451573Srgrimes	aclp = acl_init(ACL_MAX_ENTRIES);
461573Srgrimes	if (!aclp) {
471573Srgrimes		return (NULL);
481573Srgrimes	}
491573Srgrimes
501573Srgrimes	error = __acl_get_file(path_p, type, aclp);
511573Srgrimes	if (error) {
521573Srgrimes		acl_free(aclp);
5350331Sbde		return (NULL);
541856Sdg	}
551573Srgrimes
561573Srgrimes	return (aclp);
571573Srgrimes}
581573Srgrimes
591573Srgrimesacl_t
6012682Speteracl_get_fd(int fd)
611573Srgrimes{
621573Srgrimes	struct acl	*aclp;
631573Srgrimes	int	error;
641573Srgrimes
651573Srgrimes	aclp = acl_init(ACL_MAX_ENTRIES);
661573Srgrimes	if (!aclp) {
671573Srgrimes		return (NULL);
681573Srgrimes	}
691573Srgrimes
701573Srgrimes	error = __acl_get_fd(fd, ACL_TYPE_ACCESS, aclp);
711573Srgrimes	if (error) {
721573Srgrimes		acl_free(aclp);
7392941Sobrien		return (NULL);
7492941Sobrien	}
7592917Sobrien
7692917Sobrien	return (aclp);
7792917Sobrien}
7892917Sobrien
7992917Sobrienacl_t
8092917Sobrienacl_get_fd_np(int fd, acl_type_t type)
8192941Sobrien{
8292941Sobrien	struct acl	*aclp;
8392917Sobrien	int	error;
84
85	aclp = acl_init(ACL_MAX_ENTRIES);
86	if (!aclp) {
87		return (NULL);
88	}
89
90	error = __acl_get_fd(fd, type, aclp);
91	if (error) {
92		acl_free(aclp);
93		return (NULL);
94	}
95
96	return (aclp);
97}
98