10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51507Sgjelinek * Common Development and Distribution License (the "License"). 61507Sgjelinek * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*8547SMark.Shellenbaum@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_ACL_H 270Sstevel@tonic-gate #define _SYS_ACL_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 305331Samw #include <sys/acl_impl.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate #define MAX_ACL_ENTRIES (1024) /* max entries of each type */ 370Sstevel@tonic-gate typedef struct acl { 380Sstevel@tonic-gate int a_type; /* the type of ACL entry */ 390Sstevel@tonic-gate uid_t a_id; /* the entry in -uid or gid */ 400Sstevel@tonic-gate o_mode_t a_perm; /* the permission field */ 410Sstevel@tonic-gate } aclent_t; 420Sstevel@tonic-gate 430Sstevel@tonic-gate typedef struct ace { 440Sstevel@tonic-gate uid_t a_who; /* uid or gid */ 45789Sahrens uint32_t a_access_mask; /* read,write,... */ 460Sstevel@tonic-gate uint16_t a_flags; /* see below */ 470Sstevel@tonic-gate uint16_t a_type; /* allow or deny */ 480Sstevel@tonic-gate } ace_t; 490Sstevel@tonic-gate 50789Sahrens typedef struct acl_info acl_t; 51789Sahrens 520Sstevel@tonic-gate /* 530Sstevel@tonic-gate * The following are Defined types for an aclent_t. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate #define USER_OBJ (0x01) /* object owner */ 560Sstevel@tonic-gate #define USER (0x02) /* additional users */ 570Sstevel@tonic-gate #define GROUP_OBJ (0x04) /* owning group of the object */ 580Sstevel@tonic-gate #define GROUP (0x08) /* additional groups */ 590Sstevel@tonic-gate #define CLASS_OBJ (0x10) /* file group class and mask entry */ 600Sstevel@tonic-gate #define OTHER_OBJ (0x20) /* other entry for the object */ 610Sstevel@tonic-gate #define ACL_DEFAULT (0x1000) /* default flag */ 620Sstevel@tonic-gate /* default object owner */ 630Sstevel@tonic-gate #define DEF_USER_OBJ (ACL_DEFAULT | USER_OBJ) 645331Samw /* default additional users */ 650Sstevel@tonic-gate #define DEF_USER (ACL_DEFAULT | USER) 660Sstevel@tonic-gate /* default owning group */ 670Sstevel@tonic-gate #define DEF_GROUP_OBJ (ACL_DEFAULT | GROUP_OBJ) 680Sstevel@tonic-gate /* default additional groups */ 690Sstevel@tonic-gate #define DEF_GROUP (ACL_DEFAULT | GROUP) 700Sstevel@tonic-gate /* default mask entry */ 710Sstevel@tonic-gate #define DEF_CLASS_OBJ (ACL_DEFAULT | CLASS_OBJ) 720Sstevel@tonic-gate /* default other entry */ 730Sstevel@tonic-gate #define DEF_OTHER_OBJ (ACL_DEFAULT | OTHER_OBJ) 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * The following are defined for ace_t. 770Sstevel@tonic-gate */ 78789Sahrens #define ACE_READ_DATA 0x00000001 79789Sahrens #define ACE_LIST_DIRECTORY 0x00000001 80789Sahrens #define ACE_WRITE_DATA 0x00000002 81789Sahrens #define ACE_ADD_FILE 0x00000002 82789Sahrens #define ACE_APPEND_DATA 0x00000004 83789Sahrens #define ACE_ADD_SUBDIRECTORY 0x00000004 84789Sahrens #define ACE_READ_NAMED_ATTRS 0x00000008 85789Sahrens #define ACE_WRITE_NAMED_ATTRS 0x00000010 86789Sahrens #define ACE_EXECUTE 0x00000020 87789Sahrens #define ACE_DELETE_CHILD 0x00000040 88789Sahrens #define ACE_READ_ATTRIBUTES 0x00000080 89789Sahrens #define ACE_WRITE_ATTRIBUTES 0x00000100 90789Sahrens #define ACE_DELETE 0x00010000 91789Sahrens #define ACE_READ_ACL 0x00020000 92789Sahrens #define ACE_WRITE_ACL 0x00040000 93789Sahrens #define ACE_WRITE_OWNER 0x00080000 94789Sahrens #define ACE_SYNCHRONIZE 0x00100000 95789Sahrens 960Sstevel@tonic-gate #define ACE_FILE_INHERIT_ACE 0x0001 970Sstevel@tonic-gate #define ACE_DIRECTORY_INHERIT_ACE 0x0002 98789Sahrens #define ACE_NO_PROPAGATE_INHERIT_ACE 0x0004 990Sstevel@tonic-gate #define ACE_INHERIT_ONLY_ACE 0x0008 100789Sahrens #define ACE_SUCCESSFUL_ACCESS_ACE_FLAG 0x0010 101789Sahrens #define ACE_FAILED_ACCESS_ACE_FLAG 0x0020 102789Sahrens #define ACE_IDENTIFIER_GROUP 0x0040 1035331Samw #define ACE_INHERITED_ACE 0x0080 104789Sahrens #define ACE_OWNER 0x1000 105789Sahrens #define ACE_GROUP 0x2000 106789Sahrens #define ACE_EVERYONE 0x4000 107789Sahrens 108789Sahrens #define ACE_ACCESS_ALLOWED_ACE_TYPE 0x0000 109789Sahrens #define ACE_ACCESS_DENIED_ACE_TYPE 0x0001 110789Sahrens #define ACE_SYSTEM_AUDIT_ACE_TYPE 0x0002 111789Sahrens #define ACE_SYSTEM_ALARM_ACE_TYPE 0x0003 112789Sahrens 1135331Samw #define ACL_AUTO_INHERIT 0x0001 1145331Samw #define ACL_PROTECTED 0x0002 1155331Samw #define ACL_DEFAULTED 0x0004 1165331Samw #define ACL_FLAGS_ALL (ACL_AUTO_INHERIT|ACL_PROTECTED| \ 1175331Samw ACL_DEFAULTED) 1185331Samw 1195331Samw #ifdef _KERNEL 1205331Samw 1215331Samw /* 1225331Samw * These are only applicable in a CIFS context. 1235331Samw */ 1245331Samw #define ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04 1255331Samw #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 1265331Samw #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 1275331Samw #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 1285331Samw #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 1295331Samw #define ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09 1305331Samw #define ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A 1315331Samw #define ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B 1325331Samw #define ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C 1335331Samw #define ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D 1345331Samw #define ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E 1355331Samw #define ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F 1365331Samw #define ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 1375331Samw 1385331Samw #define ACE_ALL_TYPES 0x001F 1395331Samw 1405331Samw typedef struct ace_object { 1415331Samw uid_t a_who; /* uid or gid */ 1425331Samw uint32_t a_access_mask; /* read,write,... */ 1435331Samw uint16_t a_flags; /* see below */ 1445331Samw uint16_t a_type; /* allow or deny */ 1455331Samw uint8_t a_obj_type[16]; /* obj type */ 1465331Samw uint8_t a_inherit_obj_type[16]; /* inherit obj */ 1475331Samw } ace_object_t; 1485331Samw 1495331Samw #endif 1505331Samw 151789Sahrens #define ACE_ALL_PERMS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \ 152789Sahrens ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \ 153789Sahrens ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \ 154789Sahrens ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \ 155789Sahrens ACE_WRITE_OWNER|ACE_SYNCHRONIZE) 156789Sahrens 157*8547SMark.Shellenbaum@Sun.COM #define ACE_ALL_WRITE_PERMS (ACE_WRITE_DATA|ACE_APPEND_DATA| \ 158*8547SMark.Shellenbaum@Sun.COM ACE_WRITE_ATTRIBUTES|ACE_WRITE_NAMED_ATTRS|ACE_WRITE_ACL| \ 159*8547SMark.Shellenbaum@Sun.COM ACE_WRITE_OWNER|ACE_DELETE|ACE_DELETE_CHILD) 160*8547SMark.Shellenbaum@Sun.COM 1617057Smarks #define ACE_READ_PERMS (ACE_READ_DATA|ACE_READ_ACL|ACE_READ_ATTRIBUTES| \ 1627057Smarks ACE_READ_NAMED_ATTRS) 1637057Smarks 1647057Smarks #define ACE_WRITE_PERMS (ACE_WRITE_DATA|ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES| \ 1657057Smarks ACE_WRITE_NAMED_ATTRS) 1667057Smarks 1677057Smarks #define ACE_MODIFY_PERMS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \ 1687057Smarks ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \ 1697057Smarks ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \ 1707057Smarks ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_SYNCHRONIZE) 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * The following flags are supported by both NFSv4 ACLs and ace_t. 1730Sstevel@tonic-gate */ 1740Sstevel@tonic-gate #define ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \ 1750Sstevel@tonic-gate ACE_DIRECTORY_INHERIT_ACE | \ 176789Sahrens ACE_NO_PROPAGATE_INHERIT_ACE | \ 177789Sahrens ACE_INHERIT_ONLY_ACE | \ 178789Sahrens ACE_IDENTIFIER_GROUP) 1790Sstevel@tonic-gate 1805331Samw #define ACE_TYPE_FLAGS (ACE_OWNER|ACE_GROUP|ACE_EVERYONE| \ 1815331Samw ACE_IDENTIFIER_GROUP) 1825331Samw #define ACE_INHERIT_FLAGS (ACE_FILE_INHERIT_ACE| \ 1835331Samw ACE_DIRECTORY_INHERIT_ACE|ACE_NO_PROPAGATE_INHERIT_ACE|ACE_INHERIT_ONLY_ACE) 1841420Smarks 1850Sstevel@tonic-gate /* cmd args to acl(2) for aclent_t */ 1860Sstevel@tonic-gate #define GETACL 1 1870Sstevel@tonic-gate #define SETACL 2 1880Sstevel@tonic-gate #define GETACLCNT 3 1890Sstevel@tonic-gate 190789Sahrens /* cmd's to manipulate ace acls. */ 1910Sstevel@tonic-gate #define ACE_GETACL 4 1920Sstevel@tonic-gate #define ACE_SETACL 5 1930Sstevel@tonic-gate #define ACE_GETACLCNT 6 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate /* minimal acl entries from GETACLCNT */ 1960Sstevel@tonic-gate #define MIN_ACL_ENTRIES 4 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate #if !defined(_KERNEL) 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* acl check errors */ 2010Sstevel@tonic-gate #define GRP_ERROR 1 2020Sstevel@tonic-gate #define USER_ERROR 2 2030Sstevel@tonic-gate #define OTHER_ERROR 3 2040Sstevel@tonic-gate #define CLASS_ERROR 4 2050Sstevel@tonic-gate #define DUPLICATE_ERROR 5 2060Sstevel@tonic-gate #define MISS_ERROR 6 2070Sstevel@tonic-gate #define MEM_ERROR 7 2080Sstevel@tonic-gate #define ENTRY_ERROR 8 2090Sstevel@tonic-gate 210789Sahrens 2110Sstevel@tonic-gate /* 2120Sstevel@tonic-gate * similar to ufs_acl.h: changed to char type for user commands (tar, cpio) 2130Sstevel@tonic-gate * Attribute types 2140Sstevel@tonic-gate */ 2150Sstevel@tonic-gate #define UFSD_FREE ('0') /* Free entry */ 2160Sstevel@tonic-gate #define UFSD_ACL ('1') /* Access Control Lists */ 2170Sstevel@tonic-gate #define UFSD_DFACL ('2') /* reserved for future use */ 218789Sahrens #define ACE_ACL ('3') /* ace_t style acls */ 219789Sahrens 220789Sahrens /* 221789Sahrens * flag to [f]acl_get() 222789Sahrens * controls whether a trivial acl should be returned. 223789Sahrens */ 224789Sahrens #define ACL_NO_TRIVIAL 0x2 225789Sahrens 2261420Smarks 2271420Smarks /* 2281420Smarks * Flags to control acl_totext() 2291420Smarks */ 2301420Smarks 2311420Smarks #define ACL_APPEND_ID 0x1 /* append uid/gid to user/group entries */ 2321420Smarks #define ACL_COMPACT_FMT 0x2 /* build ACL in ls -V format */ 2331507Sgjelinek #define ACL_NORESOLVE 0x4 /* don't do name service lookups */ 2347057Smarks #define ACL_SID_FMT 0x8 /* use usersid/groupsid when appropriate */ 2351420Smarks 236789Sahrens /* 237789Sahrens * Legacy aclcheck errors for aclent_t ACLs 238789Sahrens */ 239789Sahrens #define EACL_GRP_ERROR GRP_ERROR 240789Sahrens #define EACL_USER_ERROR USER_ERROR 241789Sahrens #define EACL_OTHER_ERROR OTHER_ERROR 242789Sahrens #define EACL_CLASS_ERROR CLASS_ERROR 243789Sahrens #define EACL_DUPLICATE_ERROR DUPLICATE_ERROR 244789Sahrens #define EACL_MISS_ERROR MISS_ERROR 245789Sahrens #define EACL_MEM_ERROR MEM_ERROR 246789Sahrens #define EACL_ENTRY_ERROR ENTRY_ERROR 247789Sahrens 248789Sahrens #define EACL_INHERIT_ERROR 9 /* invalid inherit flags */ 249789Sahrens #define EACL_FLAGS_ERROR 10 /* unknown flag value */ 250789Sahrens #define EACL_PERM_MASK_ERROR 11 /* unknown permission */ 251789Sahrens #define EACL_COUNT_ERROR 12 /* invalid acl count */ 252789Sahrens 253789Sahrens #define EACL_INVALID_SLOT 13 /* invalid acl slot */ 254789Sahrens #define EACL_NO_ACL_ENTRY 14 /* Entry doesn't exist */ 255789Sahrens #define EACL_DIFF_TYPE 15 /* acls aren't same type */ 256789Sahrens 257789Sahrens #define EACL_INVALID_USER_GROUP 16 /* need user/group name */ 258789Sahrens #define EACL_INVALID_STR 17 /* invalid acl string */ 259789Sahrens #define EACL_FIELD_NOT_BLANK 18 /* can't have blank field */ 260789Sahrens #define EACL_INVALID_ACCESS_TYPE 19 /* invalid access type */ 261789Sahrens #define EACL_UNKNOWN_DATA 20 /* Unrecognized data in ACL */ 262789Sahrens #define EACL_MISSING_FIELDS 21 /* missing fields in acl */ 263789Sahrens 264789Sahrens #define EACL_INHERIT_NOTDIR 22 /* Need dir for inheritance */ 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate extern int aclcheck(aclent_t *, int, int *); 2670Sstevel@tonic-gate extern int acltomode(aclent_t *, int, mode_t *); 2680Sstevel@tonic-gate extern int aclfrommode(aclent_t *, int, mode_t *); 2690Sstevel@tonic-gate extern int aclsort(int, int, aclent_t *); 2700Sstevel@tonic-gate extern char *acltotext(aclent_t *, int); 2710Sstevel@tonic-gate extern aclent_t *aclfromtext(char *, int *); 272789Sahrens extern void acl_free(acl_t *); 273789Sahrens extern int acl_get(const char *, int, acl_t **); 274789Sahrens extern int facl_get(int, int, acl_t **); 275789Sahrens extern int acl_set(const char *, acl_t *acl); 276789Sahrens extern int facl_set(int, acl_t *acl); 277789Sahrens extern int acl_strip(const char *, uid_t, gid_t, mode_t); 278789Sahrens extern int acl_trivial(const char *); 2791420Smarks extern char *acl_totext(acl_t *, int); 280789Sahrens extern int acl_fromtext(const char *, acl_t **); 281789Sahrens extern int acl_check(acl_t *, int); 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate #else /* !defined(_KERNEL) */ 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate extern void ksort(caddr_t, int, int, int (*)(void *, void *)); 2860Sstevel@tonic-gate extern int cmp2acls(void *, void *); 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate #endif /* !defined(_KERNEL) */ 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate #if defined(__STDC__) 2910Sstevel@tonic-gate extern int acl(const char *path, int cmd, int cnt, void *buf); 2920Sstevel@tonic-gate extern int facl(int fd, int cmd, int cnt, void *buf); 2930Sstevel@tonic-gate #else /* !__STDC__ */ 2940Sstevel@tonic-gate extern int acl(); 2950Sstevel@tonic-gate extern int facl(); 2960Sstevel@tonic-gate #endif /* defined(__STDC__) */ 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate #ifdef __cplusplus 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate #endif 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate #endif /* _SYS_ACL_H */ 303