Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 */
0002 /*
0003  *
0004  *   Copyright (c) International Business Machines  Corp., 2007
0005  *   Author(s): Steve French (sfrench@us.ibm.com)
0006  *
0007  */
0008 
0009 #ifndef _CIFSACL_H
0010 #define _CIFSACL_H
0011 
0012 #define NUM_AUTHS (6)   /* number of authority fields */
0013 #define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
0014 
0015 #define READ_BIT        0x4
0016 #define WRITE_BIT       0x2
0017 #define EXEC_BIT        0x1
0018 
0019 #define ACL_OWNER_MASK 0700
0020 #define ACL_GROUP_MASK 0070
0021 #define ACL_EVERYONE_MASK 0007
0022 
0023 #define UBITSHIFT   6
0024 #define GBITSHIFT   3
0025 
0026 #define ACCESS_ALLOWED  0
0027 #define ACCESS_DENIED   1
0028 
0029 #define SIDOWNER 1
0030 #define SIDGROUP 2
0031 
0032 /*
0033  * Security Descriptor length containing DACL with 3 ACEs (one each for
0034  * owner, group and world).
0035  */
0036 #define DEFAULT_SEC_DESC_LEN (sizeof(struct cifs_ntsd) + \
0037                   sizeof(struct cifs_acl) + \
0038                   (sizeof(struct cifs_ace) * 4))
0039 
0040 /*
0041  * Maximum size of a string representation of a SID:
0042  *
0043  * The fields are unsigned values in decimal. So:
0044  *
0045  * u8:  max 3 bytes in decimal
0046  * u32: max 10 bytes in decimal
0047  *
0048  * "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
0049  *
0050  * For authority field, max is when all 6 values are non-zero and it must be
0051  * represented in hex. So "-0x" + 12 hex digits.
0052  *
0053  * Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
0054  */
0055 #define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
0056 #define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
0057 
0058 struct cifs_ntsd {
0059     __le16 revision; /* revision level */
0060     __le16 type;
0061     __le32 osidoffset;
0062     __le32 gsidoffset;
0063     __le32 sacloffset;
0064     __le32 dacloffset;
0065 } __attribute__((packed));
0066 
0067 struct cifs_sid {
0068     __u8 revision; /* revision level */
0069     __u8 num_subauth;
0070     __u8 authority[NUM_AUTHS];
0071     __le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
0072 } __attribute__((packed));
0073 
0074 /* size of a struct cifs_sid, sans sub_auth array */
0075 #define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
0076 
0077 struct cifs_acl {
0078     __le16 revision; /* revision level */
0079     __le16 size;
0080     __le32 num_aces;
0081 } __attribute__((packed));
0082 
0083 /* ACE types - see MS-DTYP 2.4.4.1 */
0084 #define ACCESS_ALLOWED_ACE_TYPE 0x00
0085 #define ACCESS_DENIED_ACE_TYPE  0x01
0086 #define SYSTEM_AUDIT_ACE_TYPE   0x02
0087 #define SYSTEM_ALARM_ACE_TYPE   0x03
0088 #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
0089 #define ACCESS_ALLOWED_OBJECT_ACE_TYPE  0x05
0090 #define ACCESS_DENIED_OBJECT_ACE_TYPE   0x06
0091 #define SYSTEM_AUDIT_OBJECT_ACE_TYPE    0x07
0092 #define SYSTEM_ALARM_OBJECT_ACE_TYPE    0x08
0093 #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
0094 #define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
0095 #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
0096 #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE  0x0C
0097 #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE  0x0D
0098 #define SYSTEM_ALARM_CALLBACK_ACE_TYPE  0x0E /* Reserved */
0099 #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
0100 #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */
0101 #define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
0102 #define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
0103 #define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
0104 
0105 /* ACE flags */
0106 #define OBJECT_INHERIT_ACE  0x01
0107 #define CONTAINER_INHERIT_ACE   0x02
0108 #define NO_PROPAGATE_INHERIT_ACE 0x04
0109 #define INHERIT_ONLY_ACE    0x08
0110 #define INHERITED_ACE       0x10
0111 #define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
0112 #define FAILED_ACCESS_ACE_FLAG  0x80
0113 
0114 struct cifs_ace {
0115     __u8 type; /* see above and MS-DTYP 2.4.4.1 */
0116     __u8 flags;
0117     __le16 size;
0118     __le32 access_req;
0119     struct cifs_sid sid; /* ie UUID of user or group who gets these perms */
0120 } __attribute__((packed));
0121 
0122 /*
0123  * The current SMB3 form of security descriptor is similar to what was used for
0124  * cifs (see above) but some fields are split, and fields in the struct below
0125  * matches names of fields to the spec, MS-DTYP (see sections 2.4.5 and
0126  * 2.4.6). Note that "CamelCase" fields are used in this struct in order to
0127  * match the MS-DTYP and MS-SMB2 specs which define the wire format.
0128  */
0129 struct smb3_sd {
0130     __u8 Revision; /* revision level, MUST be one */
0131     __u8 Sbz1; /* only meaningful if 'RM' flag set below */
0132     __le16 Control;
0133     __le32 OffsetOwner;
0134     __le32 OffsetGroup;
0135     __le32 OffsetSacl;
0136     __le32 OffsetDacl;
0137 } __packed;
0138 
0139 /* Meaning of 'Control' field flags */
0140 #define ACL_CONTROL_SR  0x8000  /* Self relative */
0141 #define ACL_CONTROL_RM  0x4000  /* Resource manager control bits */
0142 #define ACL_CONTROL_PS  0x2000  /* SACL protected from inherits */
0143 #define ACL_CONTROL_PD  0x1000  /* DACL protected from inherits */
0144 #define ACL_CONTROL_SI  0x0800  /* SACL Auto-Inherited */
0145 #define ACL_CONTROL_DI  0x0400  /* DACL Auto-Inherited */
0146 #define ACL_CONTROL_SC  0x0200  /* SACL computed through inheritance */
0147 #define ACL_CONTROL_DC  0x0100  /* DACL computed through inheritence */
0148 #define ACL_CONTROL_SS  0x0080  /* Create server ACL */
0149 #define ACL_CONTROL_DT  0x0040  /* DACL provided by trusted source */
0150 #define ACL_CONTROL_SD  0x0020  /* SACL defaulted */
0151 #define ACL_CONTROL_SP  0x0010  /* SACL is present on object */
0152 #define ACL_CONTROL_DD  0x0008  /* DACL defaulted */
0153 #define ACL_CONTROL_DP  0x0004  /* DACL is present on object */
0154 #define ACL_CONTROL_GD  0x0002  /* Group was defaulted */
0155 #define ACL_CONTROL_OD  0x0001  /* User was defaulted */
0156 
0157 /* Meaning of AclRevision flags */
0158 #define ACL_REVISION    0x02 /* See section 2.4.4.1 of MS-DTYP */
0159 #define ACL_REVISION_DS 0x04 /* Additional AceTypes allowed */
0160 
0161 struct smb3_acl {
0162     u8 AclRevision; /* revision level */
0163     u8 Sbz1; /* MBZ */
0164     __le16 AclSize;
0165     __le16 AceCount;
0166     __le16 Sbz2; /* MBZ */
0167 } __packed;
0168 
0169 /*
0170  * Used to store the special 'NFS SIDs' used to persist the POSIX uid and gid
0171  * See http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx
0172  */
0173 struct owner_sid {
0174     u8 Revision;
0175     u8 NumAuth;
0176     u8 Authority[6];
0177     __le32 SubAuthorities[3];
0178 } __packed;
0179 
0180 struct owner_group_sids {
0181     struct owner_sid owner;
0182     struct owner_sid group;
0183 } __packed;
0184 
0185 /*
0186  * Minimum security identifier can be one for system defined Users
0187  * and Groups such as NULL SID and World or Built-in accounts such
0188  * as Administrator and Guest and consists of
0189  * Revision + Num (Sub)Auths + Authority + Domain (one Subauthority)
0190  */
0191 #define MIN_SID_LEN  (1 + 1 + 6 + 4) /* in bytes */
0192 
0193 /*
0194  * Minimum security descriptor can be one without any SACL and DACL and can
0195  * consist of revision, type, and two sids of minimum size for owner and group
0196  */
0197 #define MIN_SEC_DESC_LEN  (sizeof(struct cifs_ntsd) + (2 * MIN_SID_LEN))
0198 
0199 #endif /* _CIFSACL_H */