acl_get.c revision 75185
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 75185 2001-04-04 18:00:52Z tmm $ 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) 3274667Sjedgar * acl_get_permset() returns the permission set in the ACL entry 3374667Sjedgar * acl_get_qualifier() retrieves the qualifier of the tag from the ACL entry 3474667Sjedgar * acl_get_tag_type() returns the tag type for the ACL entry entry_d 3556055Srwatson */ 3656055Srwatson 3756055Srwatson#include <sys/types.h> 3875185Stmm#include "namespace.h" 3956055Srwatson#include <sys/acl.h> 4075185Stmm#include "un-namespace.h" 4174667Sjedgar 4274667Sjedgar#include <errno.h> 4356055Srwatson#include <stdlib.h> 4474667Sjedgar#include <string.h> 4556055Srwatson 4656055Srwatsonacl_t 4756055Srwatsonacl_get_file(const char *path_p, acl_type_t type) 4856055Srwatson{ 4956055Srwatson struct acl *aclp; 5056055Srwatson int error; 5156055Srwatson 5256274Srwatson aclp = acl_init(ACL_MAX_ENTRIES); 5356055Srwatson if (!aclp) { 5471142Srwatson return (NULL); 5556055Srwatson } 5656055Srwatson 5756274Srwatson error = __acl_get_file(path_p, type, aclp); 5856055Srwatson if (error) { 5956055Srwatson acl_free(aclp); 6071142Srwatson return (NULL); 6156055Srwatson } 6256055Srwatson 6356055Srwatson return (aclp); 6456055Srwatson} 6556055Srwatson 6656625Srwatsonacl_t 6756625Srwatsonacl_get_fd(int fd) 6856625Srwatson{ 6956625Srwatson struct acl *aclp; 7056625Srwatson int error; 7156055Srwatson 7256625Srwatson aclp = acl_init(ACL_MAX_ENTRIES); 7356625Srwatson if (!aclp) { 7471142Srwatson return (NULL); 7556625Srwatson } 7656625Srwatson 7775185Stmm error = ___acl_get_fd(fd, ACL_TYPE_ACCESS, aclp); 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{ 8956055Srwatson struct acl *aclp; 9056055Srwatson int error; 9156055Srwatson 9256274Srwatson aclp = acl_init(ACL_MAX_ENTRIES); 9356055Srwatson if (!aclp) { 9471142Srwatson return (NULL); 9556055Srwatson } 9656055Srwatson 9775185Stmm error = ___acl_get_fd(fd, type, aclp); 9856055Srwatson if (error) { 9956055Srwatson acl_free(aclp); 10071142Srwatson return (NULL); 10156055Srwatson } 10256055Srwatson 10356055Srwatson return (aclp); 10456055Srwatson} 10574667Sjedgar 10674667Sjedgarint 10774667Sjedgaracl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p) 10874667Sjedgar{ 10974667Sjedgar 11074667Sjedgar if (!entry_d || !permset_p) { 11174667Sjedgar errno = EINVAL; 11274667Sjedgar return -1; 11374667Sjedgar } 11474667Sjedgar 11574667Sjedgar *permset_p = &entry_d->ae_perm; 11674667Sjedgar 11774667Sjedgar return 0; 11874667Sjedgar} 11974667Sjedgar 12074667Sjedgarvoid * 12174667Sjedgaracl_get_qualifier(acl_entry_t entry_d) 12274667Sjedgar{ 12374667Sjedgar uid_t *retval; 12474667Sjedgar 12574667Sjedgar if (!entry_d) { 12674667Sjedgar errno = EINVAL; 12774667Sjedgar return NULL; 12874667Sjedgar } 12974667Sjedgar 13074667Sjedgar switch(entry_d->ae_tag) { 13174667Sjedgar case ACL_USER: 13274667Sjedgar case ACL_GROUP: 13374667Sjedgar retval = malloc(sizeof(uid_t)); 13474667Sjedgar if (retval) { 13574667Sjedgar *retval = entry_d->ae_id; 13674667Sjedgar return retval; 13774667Sjedgar } 13874667Sjedgar } 13974667Sjedgar 14074667Sjedgar errno = EINVAL; 14174667Sjedgar return NULL; 14274667Sjedgar} 14374667Sjedgar 14474667Sjedgarint 14574667Sjedgaracl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p) 14674667Sjedgar{ 14774667Sjedgar 14874667Sjedgar if (!entry_d || !tag_type_p) { 14974667Sjedgar errno = EINVAL; 15074667Sjedgar return -1; 15174667Sjedgar } 15274667Sjedgar 15374667Sjedgar *tag_type_p = entry_d->ae_tag; 15474667Sjedgar 15574667Sjedgar return 0; 15674667Sjedgar} 157