1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 * Copyright (c) International Business Machines Corp., 2007
4 * Author(s): Steve French (sfrench@us.ibm.com)
5 * Modified by Namjae Jeon (linkinjeon@kernel.org)
12 #include <linux/namei.h>
13 #include <linux/posix_acl.h>
15 #include "mgmt/tree_connect.h"
17 #define NUM_AUTHS (6) /* number of authority fields */
18 #define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
21 * ACE types - see MS-DTYP 2.4.4.1
43 /* Revision for ACLs */
46 /* Control flags for Security Descriptor */
47 #define OWNER_DEFAULTED 0x0001
48 #define GROUP_DEFAULTED 0x0002
49 #define DACL_PRESENT 0x0004
50 #define DACL_DEFAULTED 0x0008
51 #define SACL_PRESENT 0x0010
52 #define SACL_DEFAULTED 0x0020
53 #define DACL_TRUSTED 0x0040
54 #define SERVER_SECURITY 0x0080
55 #define DACL_AUTO_INHERIT_REQ 0x0100
56 #define SACL_AUTO_INHERIT_REQ 0x0200
57 #define DACL_AUTO_INHERITED 0x0400
58 #define SACL_AUTO_INHERITED 0x0800
59 #define DACL_PROTECTED 0x1000
60 #define SACL_PROTECTED 0x2000
61 #define RM_CONTROL_VALID 0x4000
62 #define SELF_RELATIVE 0x8000
64 /* ACE types - see MS-DTYP 2.4.4.1 */
65 #define ACCESS_ALLOWED_ACE_TYPE 0x00
66 #define ACCESS_DENIED_ACE_TYPE 0x01
67 #define SYSTEM_AUDIT_ACE_TYPE 0x02
68 #define SYSTEM_ALARM_ACE_TYPE 0x03
69 #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
70 #define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
71 #define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
72 #define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
73 #define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
74 #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
75 #define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
76 #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
77 #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C
78 #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D
79 #define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E /* Reserved */
80 #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
81 #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */
82 #define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
83 #define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
84 #define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
87 #define OBJECT_INHERIT_ACE 0x01
88 #define CONTAINER_INHERIT_ACE 0x02
89 #define NO_PROPAGATE_INHERIT_ACE 0x04
90 #define INHERIT_ONLY_ACE 0x08
91 #define INHERITED_ACE 0x10
92 #define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
93 #define FAILED_ACCESS_ACE_FLAG 0x80
96 * Maximum size of a string representation of a SID:
98 * The fields are unsigned values in decimal. So:
100 * u8: max 3 bytes in decimal
101 * u32: max 10 bytes in decimal
103 * "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
105 * For authority field, max is when all 6 values are non-zero and it must be
106 * represented in hex. So "-0x" + 12 hex digits.
108 * Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
110 #define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
111 #define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
113 #define DOMAIN_USER_RID_LE cpu_to_le32(513)
118 __le16 revision; /* revision level */
127 __u8 revision; /* revision level */
129 __u8 authority[NUM_AUTHS];
130 __le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
133 /* size of a struct cifs_sid, sans sub_auth array */
134 #define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
137 __le16 revision; /* revision level */
147 struct smb_sid sid; /* ie UUID of user or group who gets these perms */
155 struct posix_acl *cf_acls;
156 struct posix_acl *cf_dacls;
159 struct posix_ace_state {
164 struct posix_user_ace_state {
169 struct posix_ace_state perms;
172 struct posix_ace_state_array {
174 struct posix_user_ace_state aces[];
178 * while processing the nfsv4 ace, this maintains the partial permissions
182 struct posix_acl_state {
183 struct posix_ace_state owner;
184 struct posix_ace_state group;
185 struct posix_ace_state other;
186 struct posix_ace_state everyone;
187 struct posix_ace_state mask; /* deny unused in this case */
188 struct posix_ace_state_array *users;
189 struct posix_ace_state_array *groups;
192 int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
193 int acl_len, struct smb_fattr *fattr);
194 int build_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
195 struct smb_ntsd *ppntsd, int addition_info,
196 __u32 *secdesclen, struct smb_fattr *fattr);
197 int init_acl_state(struct posix_acl_state *state, int cnt);
198 void free_acl_state(struct posix_acl_state *state);
199 void posix_state_to_acl(struct posix_acl_state *state,
200 struct posix_acl_entry *pace);
201 int compare_sids(const struct smb_sid *ctsid, const struct smb_sid *cwsid);
202 bool smb_inherit_flags(int flags, bool is_dir);
203 int smb_inherit_dacl(struct ksmbd_conn *conn, struct path *path,
204 unsigned int uid, unsigned int gid);
205 int smb_check_perm_dacl(struct ksmbd_conn *conn, struct path *path,
206 __le32 *pdaccess, int uid);
207 int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
208 struct path *path, struct smb_ntsd *pntsd, int ntsd_len,
210 void id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid);
211 void ksmbd_init_domain(u32 *sub_auth);
212 #endif /* _SMBACL_H */