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 */ 2656055Srwatson/* 2756055Srwatson * acl_init -- return a fresh acl structure 2856625Srwatson * acl_dup -- duplicate an acl and return the new copy 2956055Srwatson */ 3056055Srwatson 3192986Sobrien#include <sys/cdefs.h> 3292986Sobrien__FBSDID("$FreeBSD$"); 3392986Sobrien 3456055Srwatson#include <sys/types.h> 3575185Stmm#include "namespace.h" 3656055Srwatson#include <sys/acl.h> 3775185Stmm#include "un-namespace.h" 3856055Srwatson#include <errno.h> 3956055Srwatson#include <stdlib.h> 4056055Srwatson#include <string.h> 41194955Strasz#include <assert.h> 4256055Srwatson 43194955Strasz#include "acl_support.h" 44194955Strasz 45194955Strasz#ifndef CTASSERT 46194955Strasz#define CTASSERT(x) _CTASSERT(x, __LINE__) 47194955Strasz#define _CTASSERT(x, y) __CTASSERT(x, y) 48194955Strasz#define __CTASSERT(x, y) typedef char __assert_ ## y [(x) ? 1 : -1] 49194955Strasz#endif 50194955Strasz 51194955StraszCTASSERT(1 << _ACL_T_ALIGNMENT_BITS > sizeof(struct acl_t_struct)); 52194955Strasz 5356055Srwatsonacl_t 5456055Srwatsonacl_init(int count) 5556055Srwatson{ 56194955Strasz int error; 5775928Sjedgar acl_t acl; 5856055Srwatson 5956274Srwatson if (count > ACL_MAX_ENTRIES) { 6056055Srwatson errno = ENOMEM; 6171142Srwatson return (NULL); 6256055Srwatson } 6375928Sjedgar if (count < 0) { 6475928Sjedgar errno = EINVAL; 6575928Sjedgar return (NULL); 6675928Sjedgar } 6756055Srwatson 68194955Strasz error = posix_memalign((void *)&acl, 1 << _ACL_T_ALIGNMENT_BITS, 69194955Strasz sizeof(struct acl_t_struct)); 70194955Strasz if (error) 71194955Strasz return (NULL); 7256055Srwatson 73194955Strasz bzero(acl, sizeof(struct acl_t_struct)); 74194955Strasz acl->ats_brand = ACL_BRAND_UNKNOWN; 75194955Strasz acl->ats_acl.acl_maxcnt = ACL_MAX_ENTRIES; 76194955Strasz 7756055Srwatson return (acl); 7856055Srwatson} 7956055Srwatson 8056625Srwatsonacl_t 8156625Srwatsonacl_dup(acl_t acl) 8256625Srwatson{ 8375928Sjedgar acl_t acl_new; 8456625Srwatson 8556625Srwatson acl_new = acl_init(ACL_MAX_ENTRIES); 8691034Sjedgar if (acl_new != NULL) { 8791034Sjedgar *acl_new = *acl; 8891034Sjedgar acl->ats_cur_entry = 0; 8991034Sjedgar acl_new->ats_cur_entry = 0; 9091034Sjedgar } 9156625Srwatson 9291034Sjedgar return (acl_new); 9356625Srwatson} 94