cifsacl.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* SPDX-License-Identifier: LGPL-2.1 */
  2. /*
  3. *
  4. * Copyright (c) International Business Machines Corp., 2007
  5. * Author(s): Steve French ([email protected])
  6. *
  7. */
  8. #ifndef _CIFSACL_H
  9. #define _CIFSACL_H
  10. #define NUM_AUTHS (6) /* number of authority fields */
  11. #define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
  12. #define READ_BIT 0x4
  13. #define WRITE_BIT 0x2
  14. #define EXEC_BIT 0x1
  15. #define ACL_OWNER_MASK 0700
  16. #define ACL_GROUP_MASK 0070
  17. #define ACL_EVERYONE_MASK 0007
  18. #define UBITSHIFT 6
  19. #define GBITSHIFT 3
  20. #define ACCESS_ALLOWED 0
  21. #define ACCESS_DENIED 1
  22. #define SIDOWNER 1
  23. #define SIDGROUP 2
  24. /*
  25. * Security Descriptor length containing DACL with 3 ACEs (one each for
  26. * owner, group and world).
  27. */
  28. #define DEFAULT_SEC_DESC_LEN (sizeof(struct cifs_ntsd) + \
  29. sizeof(struct cifs_acl) + \
  30. (sizeof(struct cifs_ace) * 4))
  31. /*
  32. * Maximum size of a string representation of a SID:
  33. *
  34. * The fields are unsigned values in decimal. So:
  35. *
  36. * u8: max 3 bytes in decimal
  37. * u32: max 10 bytes in decimal
  38. *
  39. * "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
  40. *
  41. * For authority field, max is when all 6 values are non-zero and it must be
  42. * represented in hex. So "-0x" + 12 hex digits.
  43. *
  44. * Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
  45. */
  46. #define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
  47. #define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
  48. struct cifs_ntsd {
  49. __le16 revision; /* revision level */
  50. __le16 type;
  51. __le32 osidoffset;
  52. __le32 gsidoffset;
  53. __le32 sacloffset;
  54. __le32 dacloffset;
  55. } __attribute__((packed));
  56. struct cifs_sid {
  57. __u8 revision; /* revision level */
  58. __u8 num_subauth;
  59. __u8 authority[NUM_AUTHS];
  60. __le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
  61. } __attribute__((packed));
  62. /* size of a struct cifs_sid, sans sub_auth array */
  63. #define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
  64. struct cifs_acl {
  65. __le16 revision; /* revision level */
  66. __le16 size;
  67. __le32 num_aces;
  68. } __attribute__((packed));
  69. /* ACE types - see MS-DTYP 2.4.4.1 */
  70. #define ACCESS_ALLOWED_ACE_TYPE 0x00
  71. #define ACCESS_DENIED_ACE_TYPE 0x01
  72. #define SYSTEM_AUDIT_ACE_TYPE 0x02
  73. #define SYSTEM_ALARM_ACE_TYPE 0x03
  74. #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
  75. #define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
  76. #define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
  77. #define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
  78. #define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
  79. #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
  80. #define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
  81. #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
  82. #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C
  83. #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D
  84. #define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E /* Reserved */
  85. #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
  86. #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */
  87. #define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
  88. #define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
  89. #define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
  90. /* ACE flags */
  91. #define OBJECT_INHERIT_ACE 0x01
  92. #define CONTAINER_INHERIT_ACE 0x02
  93. #define NO_PROPAGATE_INHERIT_ACE 0x04
  94. #define INHERIT_ONLY_ACE 0x08
  95. #define INHERITED_ACE 0x10
  96. #define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
  97. #define FAILED_ACCESS_ACE_FLAG 0x80
  98. struct cifs_ace {
  99. __u8 type; /* see above and MS-DTYP 2.4.4.1 */
  100. __u8 flags;
  101. __le16 size;
  102. __le32 access_req;
  103. struct cifs_sid sid; /* ie UUID of user or group who gets these perms */
  104. } __attribute__((packed));
  105. /*
  106. * The current SMB3 form of security descriptor is similar to what was used for
  107. * cifs (see above) but some fields are split, and fields in the struct below
  108. * matches names of fields to the spec, MS-DTYP (see sections 2.4.5 and
  109. * 2.4.6). Note that "CamelCase" fields are used in this struct in order to
  110. * match the MS-DTYP and MS-SMB2 specs which define the wire format.
  111. */
  112. struct smb3_sd {
  113. __u8 Revision; /* revision level, MUST be one */
  114. __u8 Sbz1; /* only meaningful if 'RM' flag set below */
  115. __le16 Control;
  116. __le32 OffsetOwner;
  117. __le32 OffsetGroup;
  118. __le32 OffsetSacl;
  119. __le32 OffsetDacl;
  120. } __packed;
  121. /* Meaning of 'Control' field flags */
  122. #define ACL_CONTROL_SR 0x8000 /* Self relative */
  123. #define ACL_CONTROL_RM 0x4000 /* Resource manager control bits */
  124. #define ACL_CONTROL_PS 0x2000 /* SACL protected from inherits */
  125. #define ACL_CONTROL_PD 0x1000 /* DACL protected from inherits */
  126. #define ACL_CONTROL_SI 0x0800 /* SACL Auto-Inherited */
  127. #define ACL_CONTROL_DI 0x0400 /* DACL Auto-Inherited */
  128. #define ACL_CONTROL_SC 0x0200 /* SACL computed through inheritance */
  129. #define ACL_CONTROL_DC 0x0100 /* DACL computed through inheritence */
  130. #define ACL_CONTROL_SS 0x0080 /* Create server ACL */
  131. #define ACL_CONTROL_DT 0x0040 /* DACL provided by trusted source */
  132. #define ACL_CONTROL_SD 0x0020 /* SACL defaulted */
  133. #define ACL_CONTROL_SP 0x0010 /* SACL is present on object */
  134. #define ACL_CONTROL_DD 0x0008 /* DACL defaulted */
  135. #define ACL_CONTROL_DP 0x0004 /* DACL is present on object */
  136. #define ACL_CONTROL_GD 0x0002 /* Group was defaulted */
  137. #define ACL_CONTROL_OD 0x0001 /* User was defaulted */
  138. /* Meaning of AclRevision flags */
  139. #define ACL_REVISION 0x02 /* See section 2.4.4.1 of MS-DTYP */
  140. #define ACL_REVISION_DS 0x04 /* Additional AceTypes allowed */
  141. struct smb3_acl {
  142. u8 AclRevision; /* revision level */
  143. u8 Sbz1; /* MBZ */
  144. __le16 AclSize;
  145. __le16 AceCount;
  146. __le16 Sbz2; /* MBZ */
  147. } __packed;
  148. /*
  149. * Used to store the special 'NFS SIDs' used to persist the POSIX uid and gid
  150. * See http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx
  151. */
  152. struct owner_sid {
  153. u8 Revision;
  154. u8 NumAuth;
  155. u8 Authority[6];
  156. __le32 SubAuthorities[3];
  157. } __packed;
  158. struct owner_group_sids {
  159. struct owner_sid owner;
  160. struct owner_sid group;
  161. } __packed;
  162. /*
  163. * Minimum security identifier can be one for system defined Users
  164. * and Groups such as NULL SID and World or Built-in accounts such
  165. * as Administrator and Guest and consists of
  166. * Revision + Num (Sub)Auths + Authority + Domain (one Subauthority)
  167. */
  168. #define MIN_SID_LEN (1 + 1 + 6 + 4) /* in bytes */
  169. /*
  170. * Minimum security descriptor can be one without any SACL and DACL and can
  171. * consist of revision, type, and two sids of minimum size for owner and group
  172. */
  173. #define MIN_SEC_DESC_LEN (sizeof(struct cifs_ntsd) + (2 * MIN_SID_LEN))
  174. #endif /* _CIFSACL_H */