acl_entry.c revision 90781
1238384Sjkim/*
2238384Sjkim * Copyright (c) 2001-2002 Chris D. Faulhaber
3238384Sjkim * All rights reserved.
4238384Sjkim *
5238384Sjkim * Redistribution and use in source and binary forms, with or without
6238384Sjkim * modification, are permitted provided that the following conditions
7238384Sjkim * are met:
8238384Sjkim * 1. Redistributions of source code must retain the above copyright
9238384Sjkim *    notice, this list of conditions and the following disclaimer.
10238384Sjkim * 2. Redistributions in binary form must reproduce the above copyright
11238384Sjkim *    notice, this list of conditions and the following disclaimer in the
12238384Sjkim *    documentation and/or other materials provided with the distribution.
13238384Sjkim *
14238384Sjkim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15238384Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16238384Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17238384Sjkim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18238384Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19238384Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20238384Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21238384Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22238384Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23238384Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24238384Sjkim * SUCH DAMAGE.
25238384Sjkim *
26238384Sjkim * $FreeBSD: head/lib/libc/posix1e/acl_entry.c 90781 2002-02-17 20:05:20Z jedgar $
27238384Sjkim */
28238384Sjkim
29238384Sjkim#include <sys/types.h>
30238384Sjkim#include "namespace.h"
31238384Sjkim#include <sys/acl.h>
32238384Sjkim#include "un-namespace.h"
33238384Sjkim
34238384Sjkim#include <errno.h>
35238384Sjkim#include <stdlib.h>
36238384Sjkim
37238384Sjkim/*
38238384Sjkim * acl_create_entry() (23.4.7): create a new ACL entry in the ACL pointed
39238384Sjkim * to by acl_p.
40238384Sjkim */
41238384Sjkimint
42238384Sjkimacl_create_entry(acl_t *acl_p, acl_entry_t *entry_p)
43238384Sjkim{
44238384Sjkim	struct acl *acl_int;
45238384Sjkim
46238384Sjkim	if (acl_p == NULL) {
47238384Sjkim		errno = EINVAL;
48238384Sjkim		return (-1);
49238384Sjkim	}
50238384Sjkim
51238384Sjkim	acl_int = &(*acl_p)->ats_acl;
52238384Sjkim
53238384Sjkim	if ((acl_int->acl_cnt >= ACL_MAX_ENTRIES) || (acl_int->acl_cnt < 0)) {
54238384Sjkim		errno = EINVAL;
55238384Sjkim		return (-1);
56238384Sjkim	}
57238384Sjkim
58238384Sjkim	*entry_p = &acl_int->acl_entry[acl_int->acl_cnt++];
59238384Sjkim
60238384Sjkim	(**entry_p).ae_tag  = ACL_UNDEFINED_TAG;
61238384Sjkim	(**entry_p).ae_id   = ACL_UNDEFINED_ID;
62238384Sjkim	(**entry_p).ae_perm = ACL_PERM_NONE;
63238384Sjkim
64238384Sjkim	(*acl_p)->ats_cur_entry = 0;
65238384Sjkim
66238384Sjkim	return (0);
67238384Sjkim}
68238384Sjkim
69238384Sjkim/*
70238384Sjkim * acl_get_entry() (23.4.14): returns an ACL entry from an ACL
71238384Sjkim * indicated by entry_id.
72238384Sjkim */
73238384Sjkimint
74238384Sjkimacl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p)
75238384Sjkim{
76238384Sjkim	struct acl *acl_int;
77238384Sjkim
78238384Sjkim	if (acl == NULL) {
79238384Sjkim		errno = EINVAL;
80238384Sjkim		return (-1);
81238384Sjkim	}
82238384Sjkim	acl_int = &acl->ats_acl;
83238384Sjkim
84238384Sjkim	switch(entry_id) {
85238384Sjkim	case ACL_FIRST_ENTRY:
86238384Sjkim		acl->ats_cur_entry = 0;
87238384Sjkim		/* PASSTHROUGH */
88238384Sjkim	case ACL_NEXT_ENTRY:
89238384Sjkim		if (acl->ats_cur_entry >= acl->ats_acl.acl_cnt)
90238384Sjkim			return 0;
91238384Sjkim		*entry_p = &acl_int->acl_entry[acl->ats_cur_entry++];
92238384Sjkim		return (1);
93238384Sjkim	}
94238384Sjkim
95238384Sjkim	errno = EINVAL;
96238384Sjkim	return (-1);
97238384Sjkim}
98238384Sjkim