acl_get.c revision 91034
156055Srwatson/*- 274191Srwatson * Copyright (c) 1999, 2000, 2001 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 * 2674191Srwatson * $FreeBSD: head/lib/libc/posix1e/acl_get.c 91034 2002-02-21 23:17:19Z jedgar $ 2756055Srwatson */ 2856055Srwatson/* 2956055Srwatson * acl_get_file - syscall wrapper for retrieving ACL by filename 3056625Srwatson * acl_get_fd - syscall wrapper for retrieving access ACL by fd 3156625Srwatson * acl_get_fd_np - syscall wrapper for retrieving ACL by fd (non-POSIX) 3275492Sjedgar * acl_get_perm_np() checks if a permission is in the specified 3375492Sjedgar * permset (non-POSIX) 3474667Sjedgar * acl_get_permset() returns the permission set in the ACL entry 3574667Sjedgar * acl_get_qualifier() retrieves the qualifier of the tag from the ACL entry 3674667Sjedgar * acl_get_tag_type() returns the tag type for the ACL entry entry_d 3756055Srwatson */ 3856055Srwatson 3956055Srwatson#include <sys/types.h> 4075185Stmm#include "namespace.h" 4156055Srwatson#include <sys/acl.h> 4275185Stmm#include "un-namespace.h" 4374667Sjedgar 4474667Sjedgar#include <errno.h> 4556055Srwatson#include <stdlib.h> 4674667Sjedgar#include <string.h> 4756055Srwatson 4856055Srwatsonacl_t 4956055Srwatsonacl_get_file(const char *path_p, acl_type_t type) 5056055Srwatson{ 5175928Sjedgar acl_t aclp; 5256055Srwatson int error; 5356055Srwatson 5456274Srwatson aclp = acl_init(ACL_MAX_ENTRIES); 5591034Sjedgar if (aclp == NULL) 5671142Srwatson return (NULL); 5756055Srwatson 5875928Sjedgar error = __acl_get_file(path_p, type, &aclp->ats_acl); 5956055Srwatson if (error) { 6056055Srwatson acl_free(aclp); 6171142Srwatson return (NULL); 6256055Srwatson } 6356055Srwatson 6456055Srwatson return (aclp); 6556055Srwatson} 6656055Srwatson 6756625Srwatsonacl_t 6856625Srwatsonacl_get_fd(int fd) 6956625Srwatson{ 7075928Sjedgar acl_t aclp; 7156625Srwatson int error; 7256055Srwatson 7356625Srwatson aclp = acl_init(ACL_MAX_ENTRIES); 7491034Sjedgar if (aclp == NULL) 7571142Srwatson return (NULL); 7656625Srwatson 7775928Sjedgar error = ___acl_get_fd(fd, ACL_TYPE_ACCESS, &aclp->ats_acl); 7856625Srwatson if (error) { 7956625Srwatson acl_free(aclp); 8071142Srwatson return (NULL); 8156625Srwatson } 8256625Srwatson 8356625Srwatson return (aclp); 8456625Srwatson} 8556625Srwatson 8656055Srwatsonacl_t 8756625Srwatsonacl_get_fd_np(int fd, acl_type_t type) 8856055Srwatson{ 8975928Sjedgar acl_t aclp; 9056055Srwatson int error; 9156055Srwatson 9256274Srwatson aclp = acl_init(ACL_MAX_ENTRIES); 9391034Sjedgar if (aclp == NULL) 9471142Srwatson return (NULL); 9556055Srwatson 9675928Sjedgar error = ___acl_get_fd(fd, type, &aclp->ats_acl); 9756055Srwatson if (error) { 9856055Srwatson acl_free(aclp); 9971142Srwatson return (NULL); 10056055Srwatson } 10156055Srwatson 10256055Srwatson return (aclp); 10356055Srwatson} 10474667Sjedgar 10574667Sjedgarint 10675492Sjedgaracl_get_perm_np(acl_permset_t permset_d, acl_perm_t perm) 10775492Sjedgar{ 10875492Sjedgar 10991034Sjedgar if (permset_d == NULL) { 11075928Sjedgar errno = EINVAL; 11191034Sjedgar return (-1); 11275928Sjedgar } 11375928Sjedgar 11475492Sjedgar switch(perm) { 11575492Sjedgar case ACL_READ: 11675492Sjedgar case ACL_WRITE: 11775492Sjedgar case ACL_EXECUTE: 11875492Sjedgar if (*permset_d & perm) 11991034Sjedgar return (1); 12075492Sjedgar break; 12175492Sjedgar default: 12275492Sjedgar errno = EINVAL; 12391034Sjedgar return (-1); 12475492Sjedgar } 12575492Sjedgar 12691034Sjedgar return (0); 12775492Sjedgar} 12875492Sjedgar 12975928Sjedgar/* 13075928Sjedgar * acl_get_permset() (23.4.17): return via permset_p a descriptor to 13175928Sjedgar * the permission set in the ACL entry entry_d. 13275928Sjedgar */ 13375492Sjedgarint 13474667Sjedgaracl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p) 13574667Sjedgar{ 13674667Sjedgar 13791034Sjedgar if (entry_d == NULL || permset_p == NULL) { 13874667Sjedgar errno = EINVAL; 13991034Sjedgar return (-1); 14074667Sjedgar } 14174667Sjedgar 14274667Sjedgar *permset_p = &entry_d->ae_perm; 14374667Sjedgar 14491034Sjedgar return (0); 14574667Sjedgar} 14674667Sjedgar 14775928Sjedgar/* 14875928Sjedgar * acl_get_qualifier() (23.4.18): retrieve the qualifier of the tag 14975928Sjedgar * for the ACL entry entry_d. 15075928Sjedgar */ 15174667Sjedgarvoid * 15274667Sjedgaracl_get_qualifier(acl_entry_t entry_d) 15374667Sjedgar{ 15474667Sjedgar uid_t *retval; 15574667Sjedgar 15691034Sjedgar if (entry_d == NULL) { 15774667Sjedgar errno = EINVAL; 15891034Sjedgar return (NULL); 15974667Sjedgar } 16074667Sjedgar 16174667Sjedgar switch(entry_d->ae_tag) { 16274667Sjedgar case ACL_USER: 16374667Sjedgar case ACL_GROUP: 16474667Sjedgar retval = malloc(sizeof(uid_t)); 16591034Sjedgar if (retval == NULL) 16691034Sjedgar return (NULL); 16775928Sjedgar *retval = entry_d->ae_id; 16891034Sjedgar return (retval); 16974667Sjedgar } 17074667Sjedgar 17174667Sjedgar errno = EINVAL; 17291034Sjedgar return (NULL); 17374667Sjedgar} 17474667Sjedgar 17575928Sjedgar/* 17675928Sjedgar * acl_get_tag_type() (23.4.19): return the tag type for the ACL 17775928Sjedgar * entry entry_p. 17875928Sjedgar */ 17974667Sjedgarint 18074667Sjedgaracl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p) 18174667Sjedgar{ 18274667Sjedgar 18391034Sjedgar if (entry_d == NULL || tag_type_p == NULL) { 18474667Sjedgar errno = EINVAL; 18591034Sjedgar return (-1); 18674667Sjedgar } 18774667Sjedgar 18874667Sjedgar *tag_type_p = entry_d->ae_tag; 18974667Sjedgar 19091034Sjedgar return (0); 19174667Sjedgar} 192