1*38c8a9a5SSteve French /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*38c8a9a5SSteve French /* 3*38c8a9a5SSteve French * Copyright (C) 2021 Samsung Electronics Co., Ltd. 4*38c8a9a5SSteve French */ 5*38c8a9a5SSteve French 6*38c8a9a5SSteve French #ifndef __XATTR_H__ 7*38c8a9a5SSteve French #define __XATTR_H__ 8*38c8a9a5SSteve French 9*38c8a9a5SSteve French /* 10*38c8a9a5SSteve French * These are on-disk structures to store additional metadata into xattr to 11*38c8a9a5SSteve French * reproduce windows filesystem semantics. And they are encoded with NDR to 12*38c8a9a5SSteve French * compatible with samba's xattr meta format. The compatibility with samba 13*38c8a9a5SSteve French * is important because it can lose the information(file attribute, 14*38c8a9a5SSteve French * creation time, acls) about the existing files when switching between 15*38c8a9a5SSteve French * ksmbd and samba. 16*38c8a9a5SSteve French */ 17*38c8a9a5SSteve French 18*38c8a9a5SSteve French /* 19*38c8a9a5SSteve French * Dos attribute flags used for what variable is valid. 20*38c8a9a5SSteve French */ 21*38c8a9a5SSteve French enum { 22*38c8a9a5SSteve French XATTR_DOSINFO_ATTRIB = 0x00000001, 23*38c8a9a5SSteve French XATTR_DOSINFO_EA_SIZE = 0x00000002, 24*38c8a9a5SSteve French XATTR_DOSINFO_SIZE = 0x00000004, 25*38c8a9a5SSteve French XATTR_DOSINFO_ALLOC_SIZE = 0x00000008, 26*38c8a9a5SSteve French XATTR_DOSINFO_CREATE_TIME = 0x00000010, 27*38c8a9a5SSteve French XATTR_DOSINFO_CHANGE_TIME = 0x00000020, 28*38c8a9a5SSteve French XATTR_DOSINFO_ITIME = 0x00000040 29*38c8a9a5SSteve French }; 30*38c8a9a5SSteve French 31*38c8a9a5SSteve French /* 32*38c8a9a5SSteve French * Dos attribute structure which is compatible with samba's one. 33*38c8a9a5SSteve French * Storing it into the xattr named "DOSATTRIB" separately from inode 34*38c8a9a5SSteve French * allows ksmbd to faithfully reproduce windows filesystem semantics 35*38c8a9a5SSteve French * on top of a POSIX filesystem. 36*38c8a9a5SSteve French */ 37*38c8a9a5SSteve French struct xattr_dos_attrib { 38*38c8a9a5SSteve French __u16 version; /* version 3 or version 4 */ 39*38c8a9a5SSteve French __u32 flags; /* valid flags */ 40*38c8a9a5SSteve French __u32 attr; /* Dos attribute */ 41*38c8a9a5SSteve French __u32 ea_size; /* EA size */ 42*38c8a9a5SSteve French __u64 size; 43*38c8a9a5SSteve French __u64 alloc_size; 44*38c8a9a5SSteve French __u64 create_time; /* File creation time */ 45*38c8a9a5SSteve French __u64 change_time; /* File change time */ 46*38c8a9a5SSteve French __u64 itime; /* Invented/Initial time */ 47*38c8a9a5SSteve French }; 48*38c8a9a5SSteve French 49*38c8a9a5SSteve French /* 50*38c8a9a5SSteve French * Enumeration is used for computing posix acl hash. 51*38c8a9a5SSteve French */ 52*38c8a9a5SSteve French enum { 53*38c8a9a5SSteve French SMB_ACL_TAG_INVALID = 0, 54*38c8a9a5SSteve French SMB_ACL_USER, 55*38c8a9a5SSteve French SMB_ACL_USER_OBJ, 56*38c8a9a5SSteve French SMB_ACL_GROUP, 57*38c8a9a5SSteve French SMB_ACL_GROUP_OBJ, 58*38c8a9a5SSteve French SMB_ACL_OTHER, 59*38c8a9a5SSteve French SMB_ACL_MASK 60*38c8a9a5SSteve French }; 61*38c8a9a5SSteve French 62*38c8a9a5SSteve French #define SMB_ACL_READ 4 63*38c8a9a5SSteve French #define SMB_ACL_WRITE 2 64*38c8a9a5SSteve French #define SMB_ACL_EXECUTE 1 65*38c8a9a5SSteve French 66*38c8a9a5SSteve French struct xattr_acl_entry { 67*38c8a9a5SSteve French int type; 68*38c8a9a5SSteve French uid_t uid; 69*38c8a9a5SSteve French gid_t gid; 70*38c8a9a5SSteve French mode_t perm; 71*38c8a9a5SSteve French }; 72*38c8a9a5SSteve French 73*38c8a9a5SSteve French /* 74*38c8a9a5SSteve French * xattr_smb_acl structure is used for computing posix acl hash. 75*38c8a9a5SSteve French */ 76*38c8a9a5SSteve French struct xattr_smb_acl { 77*38c8a9a5SSteve French int count; 78*38c8a9a5SSteve French int next; 79*38c8a9a5SSteve French struct xattr_acl_entry entries[]; 80*38c8a9a5SSteve French }; 81*38c8a9a5SSteve French 82*38c8a9a5SSteve French /* 64bytes hash in xattr_ntacl is computed with sha256 */ 83*38c8a9a5SSteve French #define XATTR_SD_HASH_TYPE_SHA256 0x1 84*38c8a9a5SSteve French #define XATTR_SD_HASH_SIZE 64 85*38c8a9a5SSteve French 86*38c8a9a5SSteve French /* 87*38c8a9a5SSteve French * xattr_ntacl is used for storing ntacl and hashes. 88*38c8a9a5SSteve French * Hash is used for checking valid posix acl and ntacl in xattr. 89*38c8a9a5SSteve French */ 90*38c8a9a5SSteve French struct xattr_ntacl { 91*38c8a9a5SSteve French __u16 version; /* version 4*/ 92*38c8a9a5SSteve French void *sd_buf; 93*38c8a9a5SSteve French __u32 sd_size; 94*38c8a9a5SSteve French __u16 hash_type; /* hash type */ 95*38c8a9a5SSteve French __u8 desc[10]; /* posix_acl description */ 96*38c8a9a5SSteve French __u16 desc_len; 97*38c8a9a5SSteve French __u64 current_time; 98*38c8a9a5SSteve French __u8 hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for ntacl */ 99*38c8a9a5SSteve French __u8 posix_acl_hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for posix acl */ 100*38c8a9a5SSteve French }; 101*38c8a9a5SSteve French 102*38c8a9a5SSteve French /* DOS ATTRIBUITE XATTR PREFIX */ 103*38c8a9a5SSteve French #define DOS_ATTRIBUTE_PREFIX "DOSATTRIB" 104*38c8a9a5SSteve French #define DOS_ATTRIBUTE_PREFIX_LEN (sizeof(DOS_ATTRIBUTE_PREFIX) - 1) 105*38c8a9a5SSteve French #define XATTR_NAME_DOS_ATTRIBUTE (XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX) 106*38c8a9a5SSteve French #define XATTR_NAME_DOS_ATTRIBUTE_LEN \ 107*38c8a9a5SSteve French (sizeof(XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX) - 1) 108*38c8a9a5SSteve French 109*38c8a9a5SSteve French /* STREAM XATTR PREFIX */ 110*38c8a9a5SSteve French #define STREAM_PREFIX "DosStream." 111*38c8a9a5SSteve French #define STREAM_PREFIX_LEN (sizeof(STREAM_PREFIX) - 1) 112*38c8a9a5SSteve French #define XATTR_NAME_STREAM (XATTR_USER_PREFIX STREAM_PREFIX) 113*38c8a9a5SSteve French #define XATTR_NAME_STREAM_LEN (sizeof(XATTR_NAME_STREAM) - 1) 114*38c8a9a5SSteve French 115*38c8a9a5SSteve French /* SECURITY DESCRIPTOR(NTACL) XATTR PREFIX */ 116*38c8a9a5SSteve French #define SD_PREFIX "NTACL" 117*38c8a9a5SSteve French #define SD_PREFIX_LEN (sizeof(SD_PREFIX) - 1) 118*38c8a9a5SSteve French #define XATTR_NAME_SD (XATTR_SECURITY_PREFIX SD_PREFIX) 119*38c8a9a5SSteve French #define XATTR_NAME_SD_LEN \ 120*38c8a9a5SSteve French (sizeof(XATTR_SECURITY_PREFIX SD_PREFIX) - 1) 121*38c8a9a5SSteve French 122*38c8a9a5SSteve French #endif /* __XATTR_H__ */ 123