138c8a9a5SSteve French /* SPDX-License-Identifier: LGPL-2.1 */ 238c8a9a5SSteve French /* 338c8a9a5SSteve French * 438c8a9a5SSteve French * Copyright (c) International Business Machines Corp., 2007 538c8a9a5SSteve French * Author(s): Steve French (sfrench@us.ibm.com) 638c8a9a5SSteve French * 738c8a9a5SSteve French */ 838c8a9a5SSteve French 938c8a9a5SSteve French #ifndef _CIFSACL_H 1038c8a9a5SSteve French #define _CIFSACL_H 1138c8a9a5SSteve French 1238c8a9a5SSteve French #define NUM_AUTHS (6) /* number of authority fields */ 1338c8a9a5SSteve French #define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */ 1438c8a9a5SSteve French 1538c8a9a5SSteve French #define READ_BIT 0x4 1638c8a9a5SSteve French #define WRITE_BIT 0x2 1738c8a9a5SSteve French #define EXEC_BIT 0x1 1838c8a9a5SSteve French 1938c8a9a5SSteve French #define ACL_OWNER_MASK 0700 2038c8a9a5SSteve French #define ACL_GROUP_MASK 0070 2138c8a9a5SSteve French #define ACL_EVERYONE_MASK 0007 2238c8a9a5SSteve French 2338c8a9a5SSteve French #define UBITSHIFT 6 2438c8a9a5SSteve French #define GBITSHIFT 3 2538c8a9a5SSteve French 2638c8a9a5SSteve French #define ACCESS_ALLOWED 0 2738c8a9a5SSteve French #define ACCESS_DENIED 1 2838c8a9a5SSteve French 2938c8a9a5SSteve French #define SIDOWNER 1 3038c8a9a5SSteve French #define SIDGROUP 2 3138c8a9a5SSteve French 3238c8a9a5SSteve French /* 3338c8a9a5SSteve French * Security Descriptor length containing DACL with 3 ACEs (one each for 3438c8a9a5SSteve French * owner, group and world). 3538c8a9a5SSteve French */ 36386660bdSChenXiaoSong #define DEFAULT_SEC_DESC_LEN (sizeof(struct smb_ntsd) + \ 37298e73acSChenXiaoSong sizeof(struct smb_acl) + \ 38*d6442904SChenXiaoSong (sizeof(struct smb_ace) * 4)) 3938c8a9a5SSteve French 4038c8a9a5SSteve French /* 4138c8a9a5SSteve French * Maximum size of a string representation of a SID: 4238c8a9a5SSteve French * 4338c8a9a5SSteve French * The fields are unsigned values in decimal. So: 4438c8a9a5SSteve French * 4538c8a9a5SSteve French * u8: max 3 bytes in decimal 4638c8a9a5SSteve French * u32: max 10 bytes in decimal 4738c8a9a5SSteve French * 4838c8a9a5SSteve French * "S-" + 3 bytes for version field + 15 for authority field + NULL terminator 4938c8a9a5SSteve French * 5038c8a9a5SSteve French * For authority field, max is when all 6 values are non-zero and it must be 5138c8a9a5SSteve French * represented in hex. So "-0x" + 12 hex digits. 5238c8a9a5SSteve French * 5338c8a9a5SSteve French * Add 11 bytes for each subauthority field (10 bytes each + 1 for '-') 5438c8a9a5SSteve French */ 5538c8a9a5SSteve French #define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1) 5638c8a9a5SSteve French #define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */ 5738c8a9a5SSteve French 58386660bdSChenXiaoSong struct smb_ntsd { 5938c8a9a5SSteve French __le16 revision; /* revision level */ 6038c8a9a5SSteve French __le16 type; 6138c8a9a5SSteve French __le32 osidoffset; 6238c8a9a5SSteve French __le32 gsidoffset; 6338c8a9a5SSteve French __le32 sacloffset; 6438c8a9a5SSteve French __le32 dacloffset; 6538c8a9a5SSteve French } __attribute__((packed)); 6638c8a9a5SSteve French 6746c22d37SChenXiaoSong struct smb_sid { 6838c8a9a5SSteve French __u8 revision; /* revision level */ 6938c8a9a5SSteve French __u8 num_subauth; 7038c8a9a5SSteve French __u8 authority[NUM_AUTHS]; 7138c8a9a5SSteve French __le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */ 7238c8a9a5SSteve French } __attribute__((packed)); 7338c8a9a5SSteve French 7446c22d37SChenXiaoSong /* size of a struct smb_sid, sans sub_auth array */ 7538c8a9a5SSteve French #define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS) 7638c8a9a5SSteve French 77298e73acSChenXiaoSong struct smb_acl { 7838c8a9a5SSteve French __le16 revision; /* revision level */ 7938c8a9a5SSteve French __le16 size; 8038c8a9a5SSteve French __le32 num_aces; 8138c8a9a5SSteve French } __attribute__((packed)); 8238c8a9a5SSteve French 8338c8a9a5SSteve French /* ACE types - see MS-DTYP 2.4.4.1 */ 8438c8a9a5SSteve French #define ACCESS_ALLOWED_ACE_TYPE 0x00 8538c8a9a5SSteve French #define ACCESS_DENIED_ACE_TYPE 0x01 8638c8a9a5SSteve French #define SYSTEM_AUDIT_ACE_TYPE 0x02 8738c8a9a5SSteve French #define SYSTEM_ALARM_ACE_TYPE 0x03 8838c8a9a5SSteve French #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04 8938c8a9a5SSteve French #define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 9038c8a9a5SSteve French #define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 9138c8a9a5SSteve French #define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 9238c8a9a5SSteve French #define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 9338c8a9a5SSteve French #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09 9438c8a9a5SSteve French #define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A 9538c8a9a5SSteve French #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B 9638c8a9a5SSteve French #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C 9738c8a9a5SSteve French #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D 9838c8a9a5SSteve French #define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E /* Reserved */ 9938c8a9a5SSteve French #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F 10038c8a9a5SSteve French #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */ 10138c8a9a5SSteve French #define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11 10238c8a9a5SSteve French #define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12 10338c8a9a5SSteve French #define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13 10438c8a9a5SSteve French 10538c8a9a5SSteve French /* ACE flags */ 10638c8a9a5SSteve French #define OBJECT_INHERIT_ACE 0x01 10738c8a9a5SSteve French #define CONTAINER_INHERIT_ACE 0x02 10838c8a9a5SSteve French #define NO_PROPAGATE_INHERIT_ACE 0x04 10938c8a9a5SSteve French #define INHERIT_ONLY_ACE 0x08 11038c8a9a5SSteve French #define INHERITED_ACE 0x10 11138c8a9a5SSteve French #define SUCCESSFUL_ACCESS_ACE_FLAG 0x40 11238c8a9a5SSteve French #define FAILED_ACCESS_ACE_FLAG 0x80 11338c8a9a5SSteve French 114*d6442904SChenXiaoSong struct smb_ace { 11538c8a9a5SSteve French __u8 type; /* see above and MS-DTYP 2.4.4.1 */ 11638c8a9a5SSteve French __u8 flags; 11738c8a9a5SSteve French __le16 size; 11838c8a9a5SSteve French __le32 access_req; 11946c22d37SChenXiaoSong struct smb_sid sid; /* ie UUID of user or group who gets these perms */ 12038c8a9a5SSteve French } __attribute__((packed)); 12138c8a9a5SSteve French 12238c8a9a5SSteve French /* 12338c8a9a5SSteve French * The current SMB3 form of security descriptor is similar to what was used for 12438c8a9a5SSteve French * cifs (see above) but some fields are split, and fields in the struct below 12538c8a9a5SSteve French * matches names of fields to the spec, MS-DTYP (see sections 2.4.5 and 12638c8a9a5SSteve French * 2.4.6). Note that "CamelCase" fields are used in this struct in order to 12738c8a9a5SSteve French * match the MS-DTYP and MS-SMB2 specs which define the wire format. 12838c8a9a5SSteve French */ 12938c8a9a5SSteve French struct smb3_sd { 13038c8a9a5SSteve French __u8 Revision; /* revision level, MUST be one */ 13138c8a9a5SSteve French __u8 Sbz1; /* only meaningful if 'RM' flag set below */ 13238c8a9a5SSteve French __le16 Control; 13338c8a9a5SSteve French __le32 OffsetOwner; 13438c8a9a5SSteve French __le32 OffsetGroup; 13538c8a9a5SSteve French __le32 OffsetSacl; 13638c8a9a5SSteve French __le32 OffsetDacl; 13738c8a9a5SSteve French } __packed; 13838c8a9a5SSteve French 13938c8a9a5SSteve French /* Meaning of 'Control' field flags */ 14038c8a9a5SSteve French #define ACL_CONTROL_SR 0x8000 /* Self relative */ 14138c8a9a5SSteve French #define ACL_CONTROL_RM 0x4000 /* Resource manager control bits */ 14238c8a9a5SSteve French #define ACL_CONTROL_PS 0x2000 /* SACL protected from inherits */ 14338c8a9a5SSteve French #define ACL_CONTROL_PD 0x1000 /* DACL protected from inherits */ 14438c8a9a5SSteve French #define ACL_CONTROL_SI 0x0800 /* SACL Auto-Inherited */ 14538c8a9a5SSteve French #define ACL_CONTROL_DI 0x0400 /* DACL Auto-Inherited */ 14638c8a9a5SSteve French #define ACL_CONTROL_SC 0x0200 /* SACL computed through inheritance */ 14738c8a9a5SSteve French #define ACL_CONTROL_DC 0x0100 /* DACL computed through inheritence */ 14838c8a9a5SSteve French #define ACL_CONTROL_SS 0x0080 /* Create server ACL */ 14938c8a9a5SSteve French #define ACL_CONTROL_DT 0x0040 /* DACL provided by trusted source */ 15038c8a9a5SSteve French #define ACL_CONTROL_SD 0x0020 /* SACL defaulted */ 15138c8a9a5SSteve French #define ACL_CONTROL_SP 0x0010 /* SACL is present on object */ 15238c8a9a5SSteve French #define ACL_CONTROL_DD 0x0008 /* DACL defaulted */ 15338c8a9a5SSteve French #define ACL_CONTROL_DP 0x0004 /* DACL is present on object */ 15438c8a9a5SSteve French #define ACL_CONTROL_GD 0x0002 /* Group was defaulted */ 15538c8a9a5SSteve French #define ACL_CONTROL_OD 0x0001 /* User was defaulted */ 15638c8a9a5SSteve French 15738c8a9a5SSteve French /* Meaning of AclRevision flags */ 15838c8a9a5SSteve French #define ACL_REVISION 0x02 /* See section 2.4.4.1 of MS-DTYP */ 15938c8a9a5SSteve French #define ACL_REVISION_DS 0x04 /* Additional AceTypes allowed */ 16038c8a9a5SSteve French 16138c8a9a5SSteve French struct smb3_acl { 16238c8a9a5SSteve French u8 AclRevision; /* revision level */ 16338c8a9a5SSteve French u8 Sbz1; /* MBZ */ 16438c8a9a5SSteve French __le16 AclSize; 16538c8a9a5SSteve French __le16 AceCount; 16638c8a9a5SSteve French __le16 Sbz2; /* MBZ */ 16738c8a9a5SSteve French } __packed; 16838c8a9a5SSteve French 16938c8a9a5SSteve French /* 17038c8a9a5SSteve French * Used to store the special 'NFS SIDs' used to persist the POSIX uid and gid 17138c8a9a5SSteve French * See http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx 17238c8a9a5SSteve French */ 17338c8a9a5SSteve French struct owner_sid { 17438c8a9a5SSteve French u8 Revision; 17538c8a9a5SSteve French u8 NumAuth; 17638c8a9a5SSteve French u8 Authority[6]; 17738c8a9a5SSteve French __le32 SubAuthorities[3]; 17838c8a9a5SSteve French } __packed; 17938c8a9a5SSteve French 18038c8a9a5SSteve French struct owner_group_sids { 18138c8a9a5SSteve French struct owner_sid owner; 18238c8a9a5SSteve French struct owner_sid group; 18338c8a9a5SSteve French } __packed; 18438c8a9a5SSteve French 18538c8a9a5SSteve French /* 18638c8a9a5SSteve French * Minimum security identifier can be one for system defined Users 18738c8a9a5SSteve French * and Groups such as NULL SID and World or Built-in accounts such 18838c8a9a5SSteve French * as Administrator and Guest and consists of 18938c8a9a5SSteve French * Revision + Num (Sub)Auths + Authority + Domain (one Subauthority) 19038c8a9a5SSteve French */ 19138c8a9a5SSteve French #define MIN_SID_LEN (1 + 1 + 6 + 4) /* in bytes */ 19238c8a9a5SSteve French 19338c8a9a5SSteve French /* 19438c8a9a5SSteve French * Minimum security descriptor can be one without any SACL and DACL and can 19538c8a9a5SSteve French * consist of revision, type, and two sids of minimum size for owner and group 19638c8a9a5SSteve French */ 197386660bdSChenXiaoSong #define MIN_SEC_DESC_LEN (sizeof(struct smb_ntsd) + (2 * MIN_SID_LEN)) 19838c8a9a5SSteve French 19938c8a9a5SSteve French #endif /* _CIFSACL_H */ 200