cifsacl.h 6.8 KB

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