acl_entry.c revision 90781
174667Sjedgar/* 290781Sjedgar * Copyright (c) 2001-2002 Chris D. Faulhaber 374667Sjedgar * All rights reserved. 474667Sjedgar * 574667Sjedgar * Redistribution and use in source and binary forms, with or without 674667Sjedgar * modification, are permitted provided that the following conditions 774667Sjedgar * are met: 874667Sjedgar * 1. Redistributions of source code must retain the above copyright 974667Sjedgar * notice, this list of conditions and the following disclaimer. 1074667Sjedgar * 2. Redistributions in binary form must reproduce the above copyright 1174667Sjedgar * notice, this list of conditions and the following disclaimer in the 1274667Sjedgar * documentation and/or other materials provided with the distribution. 1374667Sjedgar * 1474667Sjedgar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1574667Sjedgar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1674667Sjedgar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1774667Sjedgar * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1874667Sjedgar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1974667Sjedgar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2074667Sjedgar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2174667Sjedgar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2274667Sjedgar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2374667Sjedgar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2474667Sjedgar * SUCH DAMAGE. 2574667Sjedgar * 2674667Sjedgar * $FreeBSD: head/lib/libc/posix1e/acl_entry.c 90781 2002-02-17 20:05:20Z jedgar $ 2774667Sjedgar */ 2874667Sjedgar 2974667Sjedgar#include <sys/types.h> 3075185Stmm#include "namespace.h" 3174667Sjedgar#include <sys/acl.h> 3275185Stmm#include "un-namespace.h" 3374667Sjedgar 3474667Sjedgar#include <errno.h> 3574667Sjedgar#include <stdlib.h> 3674667Sjedgar 3775928Sjedgar/* 3875928Sjedgar * acl_create_entry() (23.4.7): create a new ACL entry in the ACL pointed 3975928Sjedgar * to by acl_p. 4075928Sjedgar */ 4174667Sjedgarint 4274667Sjedgaracl_create_entry(acl_t *acl_p, acl_entry_t *entry_p) 4374667Sjedgar{ 4475928Sjedgar struct acl *acl_int; 4574667Sjedgar 4690781Sjedgar if (acl_p == NULL) { 4774667Sjedgar errno = EINVAL; 4890781Sjedgar return (-1); 4974667Sjedgar } 5074667Sjedgar 5175928Sjedgar acl_int = &(*acl_p)->ats_acl; 5274667Sjedgar 5375928Sjedgar if ((acl_int->acl_cnt >= ACL_MAX_ENTRIES) || (acl_int->acl_cnt < 0)) { 5475928Sjedgar errno = EINVAL; 5590781Sjedgar return (-1); 5675928Sjedgar } 5774667Sjedgar 5875928Sjedgar *entry_p = &acl_int->acl_entry[acl_int->acl_cnt++]; 5975928Sjedgar 6074667Sjedgar (**entry_p).ae_tag = ACL_UNDEFINED_TAG; 6174667Sjedgar (**entry_p).ae_id = ACL_UNDEFINED_ID; 6274667Sjedgar (**entry_p).ae_perm = ACL_PERM_NONE; 6374667Sjedgar 6475928Sjedgar (*acl_p)->ats_cur_entry = 0; 6575928Sjedgar 6690781Sjedgar return (0); 6774667Sjedgar} 6874667Sjedgar 6975928Sjedgar/* 7075928Sjedgar * acl_get_entry() (23.4.14): returns an ACL entry from an ACL 7175928Sjedgar * indicated by entry_id. 7275928Sjedgar */ 7374667Sjedgarint 7474667Sjedgaracl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p) 7574667Sjedgar{ 7675928Sjedgar struct acl *acl_int; 7774667Sjedgar 7890781Sjedgar if (acl == NULL) { 7975928Sjedgar errno = EINVAL; 8090781Sjedgar return (-1); 8175928Sjedgar } 8275928Sjedgar acl_int = &acl->ats_acl; 8375928Sjedgar 8475928Sjedgar switch(entry_id) { 8575928Sjedgar case ACL_FIRST_ENTRY: 8675928Sjedgar acl->ats_cur_entry = 0; 8775928Sjedgar /* PASSTHROUGH */ 8875928Sjedgar case ACL_NEXT_ENTRY: 8975928Sjedgar if (acl->ats_cur_entry >= acl->ats_acl.acl_cnt) 9075928Sjedgar return 0; 9175928Sjedgar *entry_p = &acl_int->acl_entry[acl->ats_cur_entry++]; 9290781Sjedgar return (1); 9375928Sjedgar } 9475928Sjedgar 9575928Sjedgar errno = EINVAL; 9690781Sjedgar return (-1); 9774667Sjedgar} 98