acl_entry.c revision 192966
1254721Semaste/*
2254721Semaste * Copyright (c) 2001-2002 Chris D. Faulhaber
3254721Semaste * All rights reserved.
4254721Semaste *
5254721Semaste * Redistribution and use in source and binary forms, with or without
6254721Semaste * modification, are permitted provided that the following conditions
7254721Semaste * are met:
8254721Semaste * 1. Redistributions of source code must retain the above copyright
9254721Semaste *    notice, this list of conditions and the following disclaimer.
10254721Semaste * 2. Redistributions in binary form must reproduce the above copyright
11254721Semaste *    notice, this list of conditions and the following disclaimer in the
12254721Semaste *    documentation and/or other materials provided with the distribution.
13254721Semaste *
14254721Semaste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15254721Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17254721Semaste * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18254721Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19254721Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20254721Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21254721Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22254721Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23254721Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24254721Semaste * SUCH DAMAGE.
25254721Semaste */
26254721Semaste
27254721Semaste#include <sys/cdefs.h>
28254721Semaste__FBSDID("$FreeBSD: head/lib/libc/posix1e/acl_entry.c 192966 2009-05-28 07:20:52Z trasz $");
29254721Semaste
30254721Semaste#include <sys/types.h>
31254721Semaste#include "namespace.h"
32254721Semaste#include <sys/acl.h>
33254721Semaste#include "un-namespace.h"
34254721Semaste
35254721Semaste#include <errno.h>
36254721Semaste#include <stdlib.h>
37254721Semaste
38254721Semaste/*
39254721Semaste * acl_create_entry() (23.4.7): create a new ACL entry in the ACL pointed
40254721Semaste * to by acl_p.
41254721Semaste */
42254721Semasteint
43263363Semasteacl_create_entry(acl_t *acl_p, acl_entry_t *entry_p)
44263363Semaste{
45254721Semaste	struct acl *acl_int;
46263363Semaste
47254721Semaste	if (acl_p == NULL) {
48254721Semaste		errno = EINVAL;
49254721Semaste		return (-1);
50263363Semaste	}
51254721Semaste
52263363Semaste	acl_int = &(*acl_p)->ats_acl;
53254721Semaste
54254721Semaste	/*
55254721Semaste	 * +1, because we are checking if there is space left for one more
56263363Semaste	 * entry.
57254721Semaste	 */
58263363Semaste	if ((acl_int->acl_cnt + 1 >= ACL_MAX_ENTRIES) ||
59254721Semaste	    (acl_int->acl_cnt < 0)) {
60254721Semaste		errno = EINVAL;
61254721Semaste		return (-1);
62263363Semaste	}
63254721Semaste
64254721Semaste	*entry_p = &acl_int->acl_entry[acl_int->acl_cnt++];
65254721Semaste
66254721Semaste	(**entry_p).ae_tag  = ACL_UNDEFINED_TAG;
67254721Semaste	(**entry_p).ae_id   = ACL_UNDEFINED_ID;
68254721Semaste	(**entry_p).ae_perm = ACL_PERM_NONE;
69254721Semaste	(**entry_p).ae_entry_type = 0;
70254721Semaste	(**entry_p).ae_flags = 0;
71254721Semaste
72254721Semaste	(*acl_p)->ats_cur_entry = 0;
73254721Semaste
74254721Semaste	return (0);
75254721Semaste}
76254721Semaste
77254721Semaste/*
78254721Semaste * acl_get_entry() (23.4.14): returns an ACL entry from an ACL
79254721Semaste * indicated by entry_id.
80254721Semaste */
81254721Semasteint
82254721Semasteacl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p)
83254721Semaste{
84254721Semaste	struct acl *acl_int;
85254721Semaste
86254721Semaste	if (acl == NULL) {
87254721Semaste		errno = EINVAL;
88254721Semaste		return (-1);
89254721Semaste	}
90254721Semaste	acl_int = &acl->ats_acl;
91254721Semaste
92254721Semaste	switch(entry_id) {
93254721Semaste	case ACL_FIRST_ENTRY:
94254721Semaste		acl->ats_cur_entry = 0;
95254721Semaste		/* PASSTHROUGH */
96254721Semaste	case ACL_NEXT_ENTRY:
97254721Semaste		if (acl->ats_cur_entry >= acl->ats_acl.acl_cnt)
98254721Semaste			return 0;
99254721Semaste		*entry_p = &acl_int->acl_entry[acl->ats_cur_entry++];
100254721Semaste		return (1);
101254721Semaste	}
102254721Semaste
103254721Semaste	errno = EINVAL;
104254721Semaste	return (-1);
105254721Semaste}
106254721Semaste