aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/acl.h
blob: 3a13fab54214e56e3af5be1c851f2441c368b0c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*-
 * Copyright (c) 1999 Robert N. M. Watson
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */
/* 
 * Userland/kernel interface for Access Control Lists
 *
 * This code from the FreeBSD POSIX.1e implementation.  Not all of the ACL
 * code is committed yet; in order to use the library routines listed
 * below, you'll need to download libposix1e_acl from the POSIX.1e
 * implementation page, or possibly update to a more recent version of
 * FreeBSD, as the code may have been committed.
 *
 * The POSIX.1e implementation page may be reached at:
 *   http://www.watson.org/fbsd-hardening/posix1e/
 *
 * However, all syscalls will pass through to appropriate VFS vnops, so
 * file systems implementing the vnops are accessible through the syscalls.
 */

#ifndef _SYS_ACL_H
#define _SYS_ACL_H

/*
 * POSIX.1e ACL types
 */

#define MAX_ACL_ENTRIES 32    /* maximum entries in an ACL */
#define _POSIX_ACL_PATH_MAX     MAX_ACL_ENTRIES

typedef int	acl_type_t;
typedef int	acl_tag_t;
typedef mode_t	acl_perm_t;

struct acl_entry {
	acl_tag_t	ae_tag;
	uid_t		ae_id;
	acl_perm_t	ae_perm;
};
typedef struct acl_entry	*acl_entry_t;

struct acl {
	int			acl_cnt;
	struct acl_entry	acl_entry[MAX_ACL_ENTRIES];
};
typedef struct acl	*acl_t;

/*
 * Possible valid values for a_type of acl_entry_t
 */
#define ACL_USER_OBJ	0x00000001
#define ACL_USER	0x00000002
#define ACL_GROUP_OBJ	0x00000004
#define ACL_GROUP	0x00000008
#define ACL_MASK	0x00000010
#define ACL_OTHER	0x00000020
#define ACL_OTHER_OBJ	ACL_OTHER
#define ACL_AFS_ID	0x00000040

#define ACL_TYPE_ACCESS		0x00000000
#define ACL_TYPE_DEFAULT	0x00000001

/*
 * Possible flags in a_perm field
 */
#define ACL_PERM_EXEC		0x0001
#define ACL_PERM_WRITE		0x0002
#define ACL_PERM_READ		0x0004
#define ACL_PERM_NONE		0x0000
#define ACL_PERM_BITS		(ACL_PERM_EXEC | ACL_PERM_WRITE | ACL_PERM_READ)
#define ACL_POSIX1E_BITS	(ACL_PERM_EXEC | ACL_PERM_WRITE | ACL_PERM_READ)

#ifdef KERNEL
/*
 * Storage for ACLs and support structures
 */
#ifdef MALLOC_DECLARE
MALLOC_DECLARE(M_ACL);
#endif

/*
 * Dummy declarations so that we can expose acl_access all over the place
 * without worrying about including ucred and friends.  vnode.h does the
 * same thing.
 */
struct ucred;
struct proc;

/*
 * POSIX.1e and generic kernel/vfs semantics functions--not currently in the
 * base distribution, but will be soon.
 */
struct vattr;
struct vop_getacl_args;
struct vop_aclcheck_args;

int	posix1e_acl_access(struct acl *a_acl, int a_mode, struct ucred *a_cred,
			   struct proc *a_p);
void	generic_attr_to_posix1e_acl(struct acl *a_acl, struct vattr *vattr);
int	generic_vop_getacl(struct vop_getacl_args *ap);
int	generic_vop_aclcheck(struct vop_aclcheck_args *ap);
int	posix1e_vop_aclcheck(struct vop_aclcheck_args *ap);

#else /* KERNEL */

/*
 * Syscall interface -- use the library calls instead as the syscalls
 * have strict acl entry ordering requirements
 */
int	acl_syscall_get_file(char *path, acl_type_t type, struct acl *aclp);
int	acl_syscall_set_file(char *path, acl_type_t type, struct acl *aclp);
int	acl_syscall_get_fd(int filedes, acl_type_t type, struct acl *aclp);
int	acl_syscall_set_fd(int filedes, acl_type_t type, struct acl *aclp);
int	acl_syscall_delete_file(const char *path_p, acl_type_t type);
int	acl_syscall_delete_fd(int filedes, acl_type_t type);
int	acl_syscall_aclcheck_file(char *path, acl_type_t type,
				  struct acl *aclp);
int	acl_syscall_aclcheck_fd(int filedes, acl_type_t type,
				struct acl *aclp);

/*
 * Supported POSIX.1e ACL manipulation and assignment/retrieval API
 * These are currently provided by libposix1e_acl, which is not shipped
 * with the base distribution, but will be soon.  Some of these are
 * from POSIX.1e-extensions.
 *
 * Not all POSIX.1e ACL functions are listed here yet, but more will
 * be soon.
 */
int	acl_calc_mask(acl_t *acl_p);
int	acl_delete_def_file(const char *path_p);
int	acl_delete_def_fd(int filedes);
acl_t	acl_from_text(const char *buf_p);
acl_t	acl_get_fd(int fd, acl_type_t type);
acl_t	acl_get_file(const char *path_p, acl_type_t type);
acl_t	acl_init(int count);
int	acl_set_fd(int fd, acl_t acl, acl_type_t type);
int	acl_set_file(const char *path_p, acl_type_t type, acl_t acl);
char	*acl_to_text(acl_t acl, ssize_t *len_p);
int	acl_valid(acl_t acl);
int	acl_valid_file(const char *path_p, acl_type_t type, acl_t acl);
int	acl_valid_fd(int fd, acl_type_t type, acl_t acl);
int	acl_free(void *obj_p);

#endif /* KERNEL */
#endif /* _SYS_ACL_H */