0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _SMBACL_H
0009 #define _SMBACL_H
0010
0011 #include <linux/fs.h>
0012 #include <linux/namei.h>
0013 #include <linux/posix_acl.h>
0014 #include <linux/mnt_idmapping.h>
0015
0016 #include "mgmt/tree_connect.h"
0017
0018 #define NUM_AUTHS (6)
0019 #define SID_MAX_SUB_AUTHORITIES (15)
0020
0021
0022
0023
0024 enum {
0025 ACCESS_ALLOWED,
0026 ACCESS_DENIED,
0027 };
0028
0029
0030
0031
0032 enum {
0033 SIDOWNER = 1,
0034 SIDGROUP,
0035 SIDCREATOR_OWNER,
0036 SIDCREATOR_GROUP,
0037 SIDUNIX_USER,
0038 SIDUNIX_GROUP,
0039 SIDNFS_USER,
0040 SIDNFS_GROUP,
0041 SIDNFS_MODE,
0042 };
0043
0044
0045 #define SD_REVISION 1
0046
0047
0048 #define OWNER_DEFAULTED 0x0001
0049 #define GROUP_DEFAULTED 0x0002
0050 #define DACL_PRESENT 0x0004
0051 #define DACL_DEFAULTED 0x0008
0052 #define SACL_PRESENT 0x0010
0053 #define SACL_DEFAULTED 0x0020
0054 #define DACL_TRUSTED 0x0040
0055 #define SERVER_SECURITY 0x0080
0056 #define DACL_AUTO_INHERIT_REQ 0x0100
0057 #define SACL_AUTO_INHERIT_REQ 0x0200
0058 #define DACL_AUTO_INHERITED 0x0400
0059 #define SACL_AUTO_INHERITED 0x0800
0060 #define DACL_PROTECTED 0x1000
0061 #define SACL_PROTECTED 0x2000
0062 #define RM_CONTROL_VALID 0x4000
0063 #define SELF_RELATIVE 0x8000
0064
0065
0066 #define ACCESS_ALLOWED_ACE_TYPE 0x00
0067 #define ACCESS_DENIED_ACE_TYPE 0x01
0068 #define SYSTEM_AUDIT_ACE_TYPE 0x02
0069 #define SYSTEM_ALARM_ACE_TYPE 0x03
0070 #define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
0071 #define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
0072 #define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
0073 #define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
0074 #define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
0075 #define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
0076 #define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
0077 #define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
0078 #define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C
0079 #define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D
0080 #define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E
0081 #define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
0082 #define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10
0083 #define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
0084 #define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
0085 #define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
0086
0087
0088 #define OBJECT_INHERIT_ACE 0x01
0089 #define CONTAINER_INHERIT_ACE 0x02
0090 #define NO_PROPAGATE_INHERIT_ACE 0x04
0091 #define INHERIT_ONLY_ACE 0x08
0092 #define INHERITED_ACE 0x10
0093 #define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
0094 #define FAILED_ACCESS_ACE_FLAG 0x80
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 #define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
0112 #define SID_STRING_SUBAUTH_SIZE (11)
0113
0114 #define DOMAIN_USER_RID_LE cpu_to_le32(513)
0115
0116 struct ksmbd_conn;
0117
0118 struct smb_ntsd {
0119 __le16 revision;
0120 __le16 type;
0121 __le32 osidoffset;
0122 __le32 gsidoffset;
0123 __le32 sacloffset;
0124 __le32 dacloffset;
0125 } __packed;
0126
0127 struct smb_sid {
0128 __u8 revision;
0129 __u8 num_subauth;
0130 __u8 authority[NUM_AUTHS];
0131 __le32 sub_auth[SID_MAX_SUB_AUTHORITIES];
0132 } __packed;
0133
0134
0135 #define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
0136
0137 struct smb_acl {
0138 __le16 revision;
0139 __le16 size;
0140 __le32 num_aces;
0141 } __packed;
0142
0143 struct smb_ace {
0144 __u8 type;
0145 __u8 flags;
0146 __le16 size;
0147 __le32 access_req;
0148 struct smb_sid sid;
0149 } __packed;
0150
0151 struct smb_fattr {
0152 kuid_t cf_uid;
0153 kgid_t cf_gid;
0154 umode_t cf_mode;
0155 __le32 daccess;
0156 struct posix_acl *cf_acls;
0157 struct posix_acl *cf_dacls;
0158 };
0159
0160 struct posix_ace_state {
0161 u32 allow;
0162 u32 deny;
0163 };
0164
0165 struct posix_user_ace_state {
0166 union {
0167 kuid_t uid;
0168 kgid_t gid;
0169 };
0170 struct posix_ace_state perms;
0171 };
0172
0173 struct posix_ace_state_array {
0174 int n;
0175 struct posix_user_ace_state aces[];
0176 };
0177
0178
0179
0180
0181
0182
0183 struct posix_acl_state {
0184 struct posix_ace_state owner;
0185 struct posix_ace_state group;
0186 struct posix_ace_state other;
0187 struct posix_ace_state everyone;
0188 struct posix_ace_state mask;
0189 struct posix_ace_state_array *users;
0190 struct posix_ace_state_array *groups;
0191 };
0192
0193 int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
0194 int acl_len, struct smb_fattr *fattr);
0195 int build_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
0196 struct smb_ntsd *ppntsd, int ppntsd_size, int addition_info,
0197 __u32 *secdesclen, struct smb_fattr *fattr);
0198 int init_acl_state(struct posix_acl_state *state, int cnt);
0199 void free_acl_state(struct posix_acl_state *state);
0200 void posix_state_to_acl(struct posix_acl_state *state,
0201 struct posix_acl_entry *pace);
0202 int compare_sids(const struct smb_sid *ctsid, const struct smb_sid *cwsid);
0203 bool smb_inherit_flags(int flags, bool is_dir);
0204 int smb_inherit_dacl(struct ksmbd_conn *conn, struct path *path,
0205 unsigned int uid, unsigned int gid);
0206 int smb_check_perm_dacl(struct ksmbd_conn *conn, struct path *path,
0207 __le32 *pdaccess, int uid);
0208 int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
0209 struct path *path, struct smb_ntsd *pntsd, int ntsd_len,
0210 bool type_check);
0211 void id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid);
0212 void ksmbd_init_domain(u32 *sub_auth);
0213
0214 static inline uid_t posix_acl_uid_translate(struct user_namespace *mnt_userns,
0215 struct posix_acl_entry *pace)
0216 {
0217 kuid_t kuid;
0218
0219
0220 kuid = mapped_kuid_fs(mnt_userns, &init_user_ns, pace->e_uid);
0221
0222
0223 return from_kuid(&init_user_ns, kuid);
0224 }
0225
0226 static inline gid_t posix_acl_gid_translate(struct user_namespace *mnt_userns,
0227 struct posix_acl_entry *pace)
0228 {
0229 kgid_t kgid;
0230
0231
0232 kgid = mapped_kgid_fs(mnt_userns, &init_user_ns, pace->e_gid);
0233
0234
0235 return from_kgid(&init_user_ns, kgid);
0236 }
0237
0238 #endif