1169695Skan/*- 2169695Skan * Copyright (c) 1999, 2000, 2001 Robert N. M. Watson 3169695Skan * All rights reserved. 4169695Skan * 5169695Skan * Redistribution and use in source and binary forms, with or without 6169695Skan * modification, are permitted provided that the following conditions 7169695Skan * are met: 8169695Skan * 1. Redistributions of source code must retain the above copyright 9169695Skan * notice, this list of conditions and the following disclaimer. 10169695Skan * 2. Redistributions in binary form must reproduce the above copyright 11169695Skan * notice, this list of conditions and the following disclaimer in the 12169695Skan * documentation and/or other materials provided with the distribution. 13169695Skan * 14169695Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15169695Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16169695Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17169695Skan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18169695Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19169695Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20169695Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21169695Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22169695Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23169695Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24169695Skan * SUCH DAMAGE. 25169695Skan */ 26169695Skan/* 27169695Skan * acl_init -- return a fresh acl structure 28169695Skan * acl_dup -- duplicate an acl and return the new copy 29169695Skan */ 30169695Skan 31169695Skan#include <sys/cdefs.h> 32169695Skan__FBSDID("$FreeBSD$"); 33169695Skan 34169695Skan#include <sys/types.h> 35169695Skan#include "namespace.h" 36169695Skan#include <sys/acl.h> 37169695Skan#include "un-namespace.h" 38169695Skan#include <errno.h> 39169695Skan#include <stdlib.h> 40169695Skan#include <string.h> 41169695Skan#include <assert.h> 42169695Skan 43169695Skan#include "acl_support.h" 44169695Skan 45169695Skan#ifndef CTASSERT 46169695Skan#define CTASSERT(x) _CTASSERT(x, __LINE__) 47169695Skan#define _CTASSERT(x, y) __CTASSERT(x, y) 48169695Skan#define __CTASSERT(x, y) typedef char __assert_ ## y [(x) ? 1 : -1] 49169695Skan#endif 50169695Skan 51169695SkanCTASSERT(1 << _ACL_T_ALIGNMENT_BITS > sizeof(struct acl_t_struct)); 52169695Skan 53169695Skanacl_t 54169695Skanacl_init(int count) 55169695Skan{ 56169695Skan int error; 57169695Skan acl_t acl; 58169695Skan 59169695Skan if (count > ACL_MAX_ENTRIES) { 60169695Skan errno = ENOMEM; 61169695Skan return (NULL); 62169695Skan } 63169695Skan if (count < 0) { 64169695Skan errno = EINVAL; 65169695Skan return (NULL); 66169695Skan } 67169695Skan 68169695Skan error = posix_memalign((void *)&acl, 1 << _ACL_T_ALIGNMENT_BITS, 69169695Skan sizeof(struct acl_t_struct)); 70169695Skan if (error) 71169695Skan return (NULL); 72169695Skan 73169695Skan bzero(acl, sizeof(struct acl_t_struct)); 74169695Skan acl->ats_brand = ACL_BRAND_UNKNOWN; 75169695Skan acl->ats_acl.acl_maxcnt = ACL_MAX_ENTRIES; 76169695Skan 77169695Skan return (acl); 78169695Skan} 79169695Skan 80169695Skanacl_t 81169695Skanacl_dup(acl_t acl) 82169695Skan{ 83169695Skan acl_t acl_new; 84169695Skan 85169695Skan acl_new = acl_init(ACL_MAX_ENTRIES); 86169695Skan if (acl_new != NULL) { 87169695Skan *acl_new = *acl; 88169695Skan acl->ats_cur_entry = 0; 89169695Skan acl_new->ats_cur_entry = 0; 90169695Skan } 91169695Skan 92169695Skan return (acl_new); 93169695Skan} 94169695Skan