1 /*- 2 * Copyright (c) 1999-2001 Robert N. M. Watson 3 * Copyright (c) 2008 Edward Tomasz Napierała <trasz@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Robert Watson for the TrustedBSD Project. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: head/sys/sys/acl.h 287445 2015-09-04 00:14:20Z delphij $ 30 */ 31 /* 32 * Developed by the TrustedBSD Project. 33 * Support for POSIX.1e and NFSv4 access control lists. 34 */ 35 36 #ifndef _FREEBSD_SYS_ACL_H_ 37 #define _FREEBSD_SYS_ACL_H_ 38 39 /* 40 * This file contains the FreeBSD native <sys/acl.h>. 41 * In FreeBSD, this file is a wrapper which pulls in osnet one 42 * and that one pulls in the FreeBSD native one for the kernel. 43 * But since NetBSD has no native ACLs yet, the contents are 44 * swapped around for now. 45 */ 46 #include_next <sys/acl.h> 47 48 #ifdef _KERNEL 49 50 #include <sys/param.h> 51 #include <sys/queue.h> 52 53 /* 54 * POSIX.1e and NFSv4 ACL types and related constants. 55 */ 56 57 typedef uint32_t acl_tag_t; 58 typedef uint32_t acl_perm_t; 59 typedef uint16_t acl_entry_type_t; 60 typedef uint16_t acl_flag_t; 61 typedef int acl_type_t; 62 typedef int *acl_permset_t; 63 typedef uint16_t *acl_flagset_t; 64 65 /* 66 * With 254 entries, "struct acl_t_struct" is exactly one 4kB page big. 67 * Note that with NFSv4 ACLs, the maximum number of ACL entries one 68 * may set on file or directory is about half of ACL_MAX_ENTRIES. 69 * 70 * If you increase this, you might also need to increase 71 * _ACL_T_ALIGNMENT_BITS in lib/libc/posix1e/acl_support.h. 72 * 73 * The maximum number of POSIX.1e ACLs is controlled 74 * by OLDACL_MAX_ENTRIES. Changing that one will break binary 75 * compatibility with pre-8.0 userland and change on-disk ACL layout. 76 */ 77 #define ACL_MAX_ENTRIES 254 78 79 #if defined(_KERNEL) || defined(_ACL_PRIVATE) 80 81 #define POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM 82 #define POSIX1E_ACL_ACCESS_EXTATTR_NAME "posix1e.acl_access" 83 #define POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM 84 #define POSIX1E_ACL_DEFAULT_EXTATTR_NAME "posix1e.acl_default" 85 #define NFS4_ACL_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM 86 #define NFS4_ACL_EXTATTR_NAME "nfs4.acl" 87 #define OLDACL_MAX_ENTRIES 32 88 89 /* 90 * "struct oldacl" is used in compatibility ACL syscalls and for on-disk 91 * storage of POSIX.1e ACLs. 92 */ 93 typedef int oldacl_tag_t; 94 typedef mode_t oldacl_perm_t; 95 96 struct oldacl_entry { 97 oldacl_tag_t ae_tag; 98 uid_t ae_id; 99 oldacl_perm_t ae_perm; 100 }; 101 typedef struct oldacl_entry *oldacl_entry_t; 102 103 struct oldacl { 104 int acl_cnt; 105 struct oldacl_entry acl_entry[OLDACL_MAX_ENTRIES]; 106 }; 107 108 /* 109 * Current "struct acl". 110 */ 111 struct acl_entry { 112 acl_tag_t ae_tag; 113 uid_t ae_id; 114 acl_perm_t ae_perm; 115 /* NFSv4 entry type, "allow" or "deny". Unused in POSIX.1e ACLs. */ 116 acl_entry_type_t ae_entry_type; 117 /* NFSv4 ACL inheritance. Unused in POSIX.1e ACLs. */ 118 acl_flag_t ae_flags; 119 }; 120 typedef struct acl_entry *acl_entry_t; 121 122 /* 123 * Internal ACL structure, used in libc, kernel APIs and for on-disk 124 * storage of NFSv4 ACLs. POSIX.1e ACLs use "struct oldacl" for on-disk 125 * storage. 126 */ 127 struct acl { 128 unsigned int acl_maxcnt; 129 unsigned int acl_cnt; 130 /* Will be required e.g. to implement NFSv4.1 ACL inheritance. */ 131 int acl_spare[4]; 132 struct acl_entry acl_entry[ACL_MAX_ENTRIES]; 133 }; 134 135 /* 136 * ACL structure internal to libc. 137 */ 138 struct acl_t_struct { 139 struct acl ats_acl; 140 int ats_cur_entry; 141 /* 142 * ats_brand is for libc internal bookkeeping only. 143 * Applications should use acl_get_brand_np(3). 144 * Kernel code should use the "type" argument passed 145 * to VOP_SETACL, VOP_GETACL or VOP_ACLCHECK calls; 146 * ACL_TYPE_ACCESS or ACL_TYPE_DEFAULT mean POSIX.1e 147 * ACL, ACL_TYPE_NFS4 means NFSv4 ACL. 148 */ 149 int ats_brand; 150 }; 151 typedef struct acl_t_struct *acl_t; 152 153 #else /* _KERNEL || _ACL_PRIVATE */ 154 155 typedef void *acl_entry_t; 156 typedef void *acl_t; 157 158 #endif /* !_KERNEL && !_ACL_PRIVATE */ 159 160 /* 161 * Possible valid values for ats_brand field. 162 */ 163 #define ACL_BRAND_UNKNOWN 0 164 #define ACL_BRAND_POSIX 1 165 #define ACL_BRAND_NFS4 2 166 167 /* 168 * Possible valid values for ae_tag field. For explanation, see acl(9). 169 */ 170 #define ACL_UNDEFINED_TAG 0x00000000 171 #define ACL_USER_OBJ 0x00000001 172 #define ACL_USER 0x00000002 173 #define ACL_GROUP_OBJ 0x00000004 174 #define ACL_GROUP 0x00000008 175 #define ACL_MASK 0x00000010 176 #define ACL_OTHER 0x00000020 177 #define ACL_OTHER_OBJ ACL_OTHER 178 #define ACL_EVERYONE 0x00000040 179 180 /* 181 * Possible valid values for ae_entry_type field, valid only for NFSv4 ACLs. 182 */ 183 #define ACL_ENTRY_TYPE_ALLOW 0x0100 184 #define ACL_ENTRY_TYPE_DENY 0x0200 185 #define ACL_ENTRY_TYPE_AUDIT 0x0400 186 #define ACL_ENTRY_TYPE_ALARM 0x0800 187 188 /* 189 * Possible valid values for acl_type_t arguments. First two 190 * are provided only for backwards binary compatibility. 191 */ 192 #define ACL_TYPE_ACCESS_OLD 0x00000000 193 #define ACL_TYPE_DEFAULT_OLD 0x00000001 194 #define ACL_TYPE_ACCESS 0x00000002 195 #define ACL_TYPE_DEFAULT 0x00000003 196 #define ACL_TYPE_NFS4 0x00000004 197 198 /* 199 * Possible bits in ae_perm field for POSIX.1e ACLs. Note 200 * that ACL_EXECUTE may be used in both NFSv4 and POSIX.1e ACLs. 201 */ 202 #define ACL_EXECUTE 0x0001 203 #define ACL_WRITE 0x0002 204 #define ACL_READ 0x0004 205 #define ACL_PERM_NONE 0x0000 206 #define ACL_PERM_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) 207 #define ACL_POSIX1E_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) 208 209 /* 210 * Possible bits in ae_perm field for NFSv4 ACLs. 211 */ 212 #define ACL_READ_DATA 0x00000008 213 #define ACL_LIST_DIRECTORY 0x00000008 214 #define ACL_WRITE_DATA 0x00000010 215 #define ACL_ADD_FILE 0x00000010 216 #define ACL_APPEND_DATA 0x00000020 217 #define ACL_ADD_SUBDIRECTORY 0x00000020 218 #define ACL_READ_NAMED_ATTRS 0x00000040 219 #define ACL_WRITE_NAMED_ATTRS 0x00000080 220 /* ACL_EXECUTE is defined above. */ 221 #define ACL_DELETE_CHILD 0x00000100 222 #define ACL_READ_ATTRIBUTES 0x00000200 223 #define ACL_WRITE_ATTRIBUTES 0x00000400 224 #define ACL_DELETE 0x00000800 225 #define ACL_READ_ACL 0x00001000 226 #define ACL_WRITE_ACL 0x00002000 227 #define ACL_WRITE_OWNER 0x00004000 228 #define ACL_SYNCHRONIZE 0x00008000 229 230 #define ACL_FULL_SET (ACL_READ_DATA | ACL_WRITE_DATA | \ 231 ACL_APPEND_DATA | ACL_READ_NAMED_ATTRS | ACL_WRITE_NAMED_ATTRS | \ 232 ACL_EXECUTE | ACL_DELETE_CHILD | ACL_READ_ATTRIBUTES | \ 233 ACL_WRITE_ATTRIBUTES | ACL_DELETE | ACL_READ_ACL | ACL_WRITE_ACL | \ 234 ACL_WRITE_OWNER | ACL_SYNCHRONIZE) 235 236 #define ACL_MODIFY_SET (ACL_FULL_SET & \ 237 ~(ACL_WRITE_ACL | ACL_WRITE_OWNER)) 238 239 #define ACL_READ_SET (ACL_READ_DATA | ACL_READ_NAMED_ATTRS | \ 240 ACL_READ_ATTRIBUTES | ACL_READ_ACL) 241 242 #define ACL_WRITE_SET (ACL_WRITE_DATA | ACL_APPEND_DATA | \ 243 ACL_WRITE_NAMED_ATTRS | ACL_WRITE_ATTRIBUTES) 244 245 #define ACL_NFS4_PERM_BITS ACL_FULL_SET 246 247 /* 248 * Possible entry_id values for acl_get_entry(3). 249 */ 250 #define ACL_FIRST_ENTRY 0 251 #define ACL_NEXT_ENTRY 1 252 253 /* 254 * Possible values in ae_flags field; valid only for NFSv4 ACLs. 255 */ 256 #define ACL_ENTRY_FILE_INHERIT 0x0001 257 #define ACL_ENTRY_DIRECTORY_INHERIT 0x0002 258 #define ACL_ENTRY_NO_PROPAGATE_INHERIT 0x0004 259 #define ACL_ENTRY_INHERIT_ONLY 0x0008 260 #define ACL_ENTRY_SUCCESSFUL_ACCESS 0x0010 261 #define ACL_ENTRY_FAILED_ACCESS 0x0020 262 #define ACL_ENTRY_INHERITED 0x0080 263 264 #define ACL_FLAGS_BITS (ACL_ENTRY_FILE_INHERIT | \ 265 ACL_ENTRY_DIRECTORY_INHERIT | ACL_ENTRY_NO_PROPAGATE_INHERIT | \ 266 ACL_ENTRY_INHERIT_ONLY | ACL_ENTRY_SUCCESSFUL_ACCESS | \ 267 ACL_ENTRY_FAILED_ACCESS | ACL_ENTRY_INHERITED) 268 269 /* 270 * Undefined value in ae_id field. ae_id should be set to this value 271 * iff ae_tag is ACL_USER_OBJ, ACL_GROUP_OBJ, ACL_OTHER or ACL_EVERYONE. 272 */ 273 #define ACL_UNDEFINED_ID ((uid_t)-1) 274 275 /* 276 * Possible values for _flags parameter in acl_to_text_np(3). 277 */ 278 #define ACL_TEXT_VERBOSE 0x01 279 #define ACL_TEXT_NUMERIC_IDS 0x02 280 #define ACL_TEXT_APPEND_ID 0x04 281 282 /* 283 * POSIX.1e ACLs are capable of expressing the read, write, and execute bits 284 * of the POSIX mode field. We provide two masks: one that defines the bits 285 * the ACL will replace in the mode, and the other that defines the bits that 286 * must be preseved when an ACL is updating a mode. 287 */ 288 #define ACL_OVERRIDE_MASK (S_IRWXU | S_IRWXG | S_IRWXO) 289 #define ACL_PRESERVE_MASK (~ACL_OVERRIDE_MASK) 290 291 #ifdef _KERNEL 292 293 /* 294 * Filesystem-independent code to move back and forth between POSIX mode and 295 * POSIX.1e ACL representations. 296 */ 297 acl_perm_t acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode); 298 struct acl_entry acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, 299 gid_t gid, mode_t mode); 300 mode_t acl_posix1e_perms_to_mode( 301 struct acl_entry *acl_user_obj_entry, 302 struct acl_entry *acl_group_obj_entry, 303 struct acl_entry *acl_other_entry); 304 mode_t acl_posix1e_acl_to_mode(struct acl *acl); 305 mode_t acl_posix1e_newfilemode(mode_t cmode, 306 struct acl *dacl); 307 struct acl *acl_alloc(int flags); 308 void acl_free(struct acl *aclp); 309 310 void acl_nfs4_sync_acl_from_mode(struct acl *aclp, 311 mode_t mode, int file_owner_id); 312 void acl_nfs4_sync_mode_from_acl(mode_t *mode, 313 const struct acl *aclp); 314 int acl_nfs4_is_trivial(const struct acl *aclp, 315 int file_owner_id); 316 void acl_nfs4_compute_inherited_acl( 317 const struct acl *parent_aclp, 318 struct acl *child_aclp, mode_t mode, 319 int file_owner_id, int is_directory); 320 int acl_copy_oldacl_into_acl(const struct oldacl *source, 321 struct acl *dest); 322 int acl_copy_acl_into_oldacl(const struct acl *source, 323 struct oldacl *dest); 324 325 #if 0 326 /* 327 * To allocate 'struct acl', use acl_alloc()/acl_free() instead of this. 328 */ 329 MALLOC_DECLARE(M_ACL); 330 #endif 331 /* 332 * Filesystem-independent syntax check for a POSIX.1e ACL. 333 */ 334 int acl_posix1e_check(struct acl *acl); 335 int acl_nfs4_check(const struct acl *aclp, int is_directory); 336 337 #else /* !_KERNEL */ 338 339 #if defined(_ACL_PRIVATE) 340 341 /* 342 * Syscall interface -- use the library calls instead as the syscalls have 343 * strict ACL entry ordering requirements. 344 */ 345 __BEGIN_DECLS 346 int __acl_aclcheck_fd(int _filedes, acl_type_t _type, struct acl *_aclp); 347 int __acl_aclcheck_file(const char *_path, acl_type_t _type, 348 struct acl *_aclp); 349 int __acl_aclcheck_link(const char *_path, acl_type_t _type, 350 struct acl *_aclp); 351 int __acl_delete_fd(int _filedes, acl_type_t _type); 352 int __acl_delete_file(const char *_path_p, acl_type_t _type); 353 int __acl_delete_link(const char *_path_p, acl_type_t _type); 354 int __acl_get_fd(int _filedes, acl_type_t _type, struct acl *_aclp); 355 int __acl_get_file(const char *_path, acl_type_t _type, struct acl *_aclp); 356 int __acl_get_link(const char *_path, acl_type_t _type, struct acl *_aclp); 357 int __acl_set_fd(int _filedes, acl_type_t _type, struct acl *_aclp); 358 int __acl_set_file(const char *_path, acl_type_t _type, struct acl *_aclp); 359 int __acl_set_link(const char *_path, acl_type_t _type, struct acl *_aclp); 360 __END_DECLS 361 362 #endif /* _ACL_PRIVATE */ 363 364 /* 365 * Supported POSIX.1e ACL manipulation and assignment/retrieval API _np calls 366 * are local extensions that reflect an environment capable of opening file 367 * descriptors of directories, and allowing additional ACL type for different 368 * filesystems (i.e., AFS). 369 */ 370 __BEGIN_DECLS 371 int acl_add_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); 372 int acl_add_perm(acl_permset_t _permset_d, acl_perm_t _perm); 373 int acl_calc_mask(acl_t *_acl_p); 374 int acl_clear_flags_np(acl_flagset_t _flagset_d); 375 int acl_clear_perms(acl_permset_t _permset_d); 376 int acl_copy_entry(acl_entry_t _dest_d, acl_entry_t _src_d); 377 ssize_t acl_copy_ext(void *_buf_p, acl_t _acl, ssize_t _size); 378 acl_t acl_copy_int(const void *_buf_p); 379 int acl_create_entry(acl_t *_acl_p, acl_entry_t *_entry_p); 380 int acl_create_entry_np(acl_t *_acl_p, acl_entry_t *_entry_p, int _index); 381 int acl_delete_entry(acl_t _acl, acl_entry_t _entry_d); 382 int acl_delete_entry_np(acl_t _acl, int _index); 383 int acl_delete_fd_np(int _filedes, acl_type_t _type); 384 int acl_delete_file_np(const char *_path_p, acl_type_t _type); 385 int acl_delete_link_np(const char *_path_p, acl_type_t _type); 386 int acl_delete_def_file(const char *_path_p); 387 int acl_delete_def_link_np(const char *_path_p); 388 int acl_delete_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); 389 int acl_delete_perm(acl_permset_t _permset_d, acl_perm_t _perm); 390 acl_t acl_dup(acl_t _acl); 391 int acl_free(void *_obj_p); 392 acl_t acl_from_text(const char *_buf_p); 393 int acl_get_brand_np(acl_t _acl, int *_brand_p); 394 int acl_get_entry(acl_t _acl, int _entry_id, acl_entry_t *_entry_p); 395 acl_t acl_get_fd(int _fd); 396 acl_t acl_get_fd_np(int fd, acl_type_t _type); 397 acl_t acl_get_file(const char *_path_p, acl_type_t _type); 398 int acl_get_entry_type_np(acl_entry_t _entry_d, acl_entry_type_t *_entry_type_p); 399 acl_t acl_get_link_np(const char *_path_p, acl_type_t _type); 400 void *acl_get_qualifier(acl_entry_t _entry_d); 401 int acl_get_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag); 402 int acl_get_perm_np(acl_permset_t _permset_d, acl_perm_t _perm); 403 int acl_get_flagset_np(acl_entry_t _entry_d, acl_flagset_t *_flagset_p); 404 int acl_get_permset(acl_entry_t _entry_d, acl_permset_t *_permset_p); 405 int acl_get_tag_type(acl_entry_t _entry_d, acl_tag_t *_tag_type_p); 406 acl_t acl_init(int _count); 407 int acl_set_fd(int _fd, acl_t _acl); 408 int acl_set_fd_np(int _fd, acl_t _acl, acl_type_t _type); 409 int acl_set_file(const char *_path_p, acl_type_t _type, acl_t _acl); 410 int acl_set_entry_type_np(acl_entry_t _entry_d, acl_entry_type_t _entry_type); 411 int acl_set_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); 412 int acl_set_flagset_np(acl_entry_t _entry_d, acl_flagset_t _flagset_d); 413 int acl_set_permset(acl_entry_t _entry_d, acl_permset_t _permset_d); 414 int acl_set_qualifier(acl_entry_t _entry_d, const void *_tag_qualifier_p); 415 int acl_set_tag_type(acl_entry_t _entry_d, acl_tag_t _tag_type); 416 ssize_t acl_size(acl_t _acl); 417 char *acl_to_text(acl_t _acl, ssize_t *_len_p); 418 char *acl_to_text_np(acl_t _acl, ssize_t *_len_p, int _flags); 419 int acl_valid(acl_t _acl); 420 int acl_valid_fd_np(int _fd, acl_type_t _type, acl_t _acl); 421 int acl_valid_file_np(const char *_path_p, acl_type_t _type, acl_t _acl); 422 int acl_valid_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); 423 int acl_is_trivial_np(const acl_t _acl, int *_trivialp); 424 acl_t acl_strip_np(const acl_t _acl, int recalculate_mask); 425 __END_DECLS 426 427 #endif /* !_KERNEL */ 428 429 #endif /* _KERNEL */ 430 431 #endif /* !_FREEBSD_SYS_ACL_H_ */ 432