1194955Strasz/*- 2194955Strasz * Copyright (c) 2008, 2009 Edward Tomasz Napiera��a <trasz@FreeBSD.org> 3194955Strasz * All rights reserved. 4194955Strasz * 5194955Strasz * Redistribution and use in source and binary forms, with or without 6194955Strasz * modification, are permitted provided that the following conditions 7194955Strasz * are met: 8194955Strasz * 1. Redistributions of source code must retain the above copyright 9194955Strasz * notice, this list of conditions and the following disclaimer. 10194955Strasz * 2. Redistributions in binary form must reproduce the above copyright 11194955Strasz * notice, this list of conditions and the following disclaimer in the 12194955Strasz * documentation and/or other materials provided with the distribution. 13194955Strasz * 14194955Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15194955Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16194955Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17194955Strasz * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18194955Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19194955Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20194955Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21194955Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22194955Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23194955Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24194955Strasz * SUCH DAMAGE. 25194955Strasz */ 26194955Strasz 27194955Strasz#include <sys/cdefs.h> 28194955Strasz__FBSDID("$FreeBSD$"); 29194955Strasz 30194955Strasz#include <stdio.h> 31194955Strasz#include <errno.h> 32194955Strasz#include <sys/acl.h> 33194955Strasz 34194955Strasz#include "acl_support.h" 35194955Strasz 36194955Straszstatic int 37194955Strasz_flag_is_invalid(acl_flag_t flag) 38194955Strasz{ 39194955Strasz 40194955Strasz if ((flag & ACL_FLAGS_BITS) == flag) 41194955Strasz return (0); 42194955Strasz 43194955Strasz errno = EINVAL; 44194955Strasz 45194955Strasz return (1); 46194955Strasz} 47194955Strasz 48194955Straszint 49194955Straszacl_add_flag_np(acl_flagset_t flagset_d, acl_flag_t flag) 50194955Strasz{ 51194955Strasz 52194955Strasz if (flagset_d == NULL) { 53194955Strasz errno = EINVAL; 54194955Strasz return (-1); 55194955Strasz } 56194955Strasz 57194955Strasz if (_flag_is_invalid(flag)) 58194955Strasz return (-1); 59194955Strasz 60194955Strasz *flagset_d |= flag; 61194955Strasz 62194955Strasz return (0); 63194955Strasz} 64194955Strasz 65194955Straszint 66194955Straszacl_clear_flags_np(acl_flagset_t flagset_d) 67194955Strasz{ 68194955Strasz 69194955Strasz if (flagset_d == NULL) { 70194955Strasz errno = EINVAL; 71194955Strasz return (-1); 72194955Strasz } 73194955Strasz 74194955Strasz *flagset_d |= 0; 75194955Strasz 76194955Strasz return (0); 77194955Strasz} 78194955Strasz 79194955Straszint 80194955Straszacl_delete_flag_np(acl_flagset_t flagset_d, acl_flag_t flag) 81194955Strasz{ 82194955Strasz 83194955Strasz if (flagset_d == NULL) { 84194955Strasz errno = EINVAL; 85194955Strasz return (-1); 86194955Strasz } 87194955Strasz 88194955Strasz if (_flag_is_invalid(flag)) 89194955Strasz return (-1); 90194955Strasz 91194955Strasz *flagset_d &= ~flag; 92194955Strasz 93194955Strasz return (0); 94194955Strasz} 95194955Strasz 96194955Straszint 97194955Straszacl_get_flag_np(acl_flagset_t flagset_d, acl_flag_t flag) 98194955Strasz{ 99194955Strasz 100194955Strasz if (flagset_d == NULL) { 101194955Strasz errno = EINVAL; 102194955Strasz return (-1); 103194955Strasz } 104194955Strasz 105194955Strasz if (_flag_is_invalid(flag)) 106194955Strasz return (-1); 107194955Strasz 108194955Strasz if (*flagset_d & flag) 109194955Strasz return (1); 110194955Strasz 111194955Strasz return (0); 112194955Strasz} 113194955Strasz 114194955Straszint 115194955Straszacl_get_flagset_np(acl_entry_t entry_d, acl_flagset_t *flagset_p) 116194955Strasz{ 117194955Strasz 118194955Strasz if (entry_d == NULL || flagset_p == NULL) { 119194955Strasz errno = EINVAL; 120194955Strasz return (-1); 121194955Strasz } 122194955Strasz 123194955Strasz if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) { 124194955Strasz errno = EINVAL; 125194955Strasz return (-1); 126194955Strasz } 127194955Strasz 128194955Strasz *flagset_p = &entry_d->ae_flags; 129194955Strasz 130194955Strasz return (0); 131194955Strasz} 132194955Strasz 133194955Straszint 134194955Straszacl_set_flagset_np(acl_entry_t entry_d, acl_flagset_t flagset_d) 135194955Strasz{ 136194955Strasz 137194955Strasz if (entry_d == NULL) { 138194955Strasz errno = EINVAL; 139194955Strasz return (-1); 140194955Strasz } 141194955Strasz 142194955Strasz if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) { 143194955Strasz errno = EINVAL; 144194955Strasz return (-1); 145194955Strasz } 146194955Strasz 147194955Strasz _entry_brand_as(entry_d, ACL_BRAND_NFS4); 148194955Strasz 149194955Strasz if (_flag_is_invalid(*flagset_d)) 150194955Strasz return (-1); 151194955Strasz 152194955Strasz entry_d->ae_flags = *flagset_d; 153194955Strasz 154194955Strasz return (0); 155194955Strasz} 156