138c8a9a5SSteve French /* SPDX-License-Identifier: GPL-2.0-or-later */ 238c8a9a5SSteve French /* 338c8a9a5SSteve French * Copyright (C) 2021 Samsung Electronics Co., Ltd. 438c8a9a5SSteve French */ 538c8a9a5SSteve French 638c8a9a5SSteve French #ifndef __XATTR_H__ 738c8a9a5SSteve French #define __XATTR_H__ 838c8a9a5SSteve French 938c8a9a5SSteve French /* 1038c8a9a5SSteve French * These are on-disk structures to store additional metadata into xattr to 1138c8a9a5SSteve French * reproduce windows filesystem semantics. And they are encoded with NDR to 1238c8a9a5SSteve French * compatible with samba's xattr meta format. The compatibility with samba 1338c8a9a5SSteve French * is important because it can lose the information(file attribute, 1438c8a9a5SSteve French * creation time, acls) about the existing files when switching between 1538c8a9a5SSteve French * ksmbd and samba. 1638c8a9a5SSteve French */ 1738c8a9a5SSteve French 1838c8a9a5SSteve French /* 1938c8a9a5SSteve French * Dos attribute flags used for what variable is valid. 2038c8a9a5SSteve French */ 2138c8a9a5SSteve French enum { 2238c8a9a5SSteve French XATTR_DOSINFO_ATTRIB = 0x00000001, 2338c8a9a5SSteve French XATTR_DOSINFO_EA_SIZE = 0x00000002, 2438c8a9a5SSteve French XATTR_DOSINFO_SIZE = 0x00000004, 2538c8a9a5SSteve French XATTR_DOSINFO_ALLOC_SIZE = 0x00000008, 2638c8a9a5SSteve French XATTR_DOSINFO_CREATE_TIME = 0x00000010, 2738c8a9a5SSteve French XATTR_DOSINFO_CHANGE_TIME = 0x00000020, 2838c8a9a5SSteve French XATTR_DOSINFO_ITIME = 0x00000040 2938c8a9a5SSteve French }; 3038c8a9a5SSteve French 3138c8a9a5SSteve French /* 3238c8a9a5SSteve French * Dos attribute structure which is compatible with samba's one. 3338c8a9a5SSteve French * Storing it into the xattr named "DOSATTRIB" separately from inode 3438c8a9a5SSteve French * allows ksmbd to faithfully reproduce windows filesystem semantics 3538c8a9a5SSteve French * on top of a POSIX filesystem. 3638c8a9a5SSteve French */ 3738c8a9a5SSteve French struct xattr_dos_attrib { 3838c8a9a5SSteve French __u16 version; /* version 3 or version 4 */ 3938c8a9a5SSteve French __u32 flags; /* valid flags */ 4038c8a9a5SSteve French __u32 attr; /* Dos attribute */ 4138c8a9a5SSteve French __u32 ea_size; /* EA size */ 4238c8a9a5SSteve French __u64 size; 4338c8a9a5SSteve French __u64 alloc_size; 4438c8a9a5SSteve French __u64 create_time; /* File creation time */ 4538c8a9a5SSteve French __u64 change_time; /* File change time */ 4638c8a9a5SSteve French __u64 itime; /* Invented/Initial time */ 4738c8a9a5SSteve French }; 4838c8a9a5SSteve French 4938c8a9a5SSteve French /* 5038c8a9a5SSteve French * Enumeration is used for computing posix acl hash. 5138c8a9a5SSteve French */ 5238c8a9a5SSteve French enum { 5338c8a9a5SSteve French SMB_ACL_TAG_INVALID = 0, 5438c8a9a5SSteve French SMB_ACL_USER, 5538c8a9a5SSteve French SMB_ACL_USER_OBJ, 5638c8a9a5SSteve French SMB_ACL_GROUP, 5738c8a9a5SSteve French SMB_ACL_GROUP_OBJ, 5838c8a9a5SSteve French SMB_ACL_OTHER, 5938c8a9a5SSteve French SMB_ACL_MASK 6038c8a9a5SSteve French }; 6138c8a9a5SSteve French 6238c8a9a5SSteve French #define SMB_ACL_READ 4 6338c8a9a5SSteve French #define SMB_ACL_WRITE 2 6438c8a9a5SSteve French #define SMB_ACL_EXECUTE 1 6538c8a9a5SSteve French 6638c8a9a5SSteve French struct xattr_acl_entry { 6738c8a9a5SSteve French int type; 6838c8a9a5SSteve French uid_t uid; 6938c8a9a5SSteve French gid_t gid; 7038c8a9a5SSteve French mode_t perm; 7138c8a9a5SSteve French }; 7238c8a9a5SSteve French 7338c8a9a5SSteve French /* 7438c8a9a5SSteve French * xattr_smb_acl structure is used for computing posix acl hash. 7538c8a9a5SSteve French */ 7638c8a9a5SSteve French struct xattr_smb_acl { 7738c8a9a5SSteve French int count; 7838c8a9a5SSteve French int next; 79*8d8d2447SThorsten Blum struct xattr_acl_entry entries[] __counted_by(count); 8038c8a9a5SSteve French }; 8138c8a9a5SSteve French 8238c8a9a5SSteve French /* 64bytes hash in xattr_ntacl is computed with sha256 */ 8338c8a9a5SSteve French #define XATTR_SD_HASH_TYPE_SHA256 0x1 8438c8a9a5SSteve French #define XATTR_SD_HASH_SIZE 64 8538c8a9a5SSteve French 8638c8a9a5SSteve French /* 8738c8a9a5SSteve French * xattr_ntacl is used for storing ntacl and hashes. 8838c8a9a5SSteve French * Hash is used for checking valid posix acl and ntacl in xattr. 8938c8a9a5SSteve French */ 9038c8a9a5SSteve French struct xattr_ntacl { 9138c8a9a5SSteve French __u16 version; /* version 4*/ 9238c8a9a5SSteve French void *sd_buf; 9338c8a9a5SSteve French __u32 sd_size; 9438c8a9a5SSteve French __u16 hash_type; /* hash type */ 9538c8a9a5SSteve French __u8 desc[10]; /* posix_acl description */ 9638c8a9a5SSteve French __u16 desc_len; 9738c8a9a5SSteve French __u64 current_time; 9838c8a9a5SSteve French __u8 hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for ntacl */ 9938c8a9a5SSteve French __u8 posix_acl_hash[XATTR_SD_HASH_SIZE]; /* 64bytes hash for posix acl */ 10038c8a9a5SSteve French }; 10138c8a9a5SSteve French 10238c8a9a5SSteve French /* DOS ATTRIBUITE XATTR PREFIX */ 10338c8a9a5SSteve French #define DOS_ATTRIBUTE_PREFIX "DOSATTRIB" 10438c8a9a5SSteve French #define DOS_ATTRIBUTE_PREFIX_LEN (sizeof(DOS_ATTRIBUTE_PREFIX) - 1) 10538c8a9a5SSteve French #define XATTR_NAME_DOS_ATTRIBUTE (XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX) 10638c8a9a5SSteve French #define XATTR_NAME_DOS_ATTRIBUTE_LEN \ 10738c8a9a5SSteve French (sizeof(XATTR_USER_PREFIX DOS_ATTRIBUTE_PREFIX) - 1) 10838c8a9a5SSteve French 10938c8a9a5SSteve French /* STREAM XATTR PREFIX */ 11038c8a9a5SSteve French #define STREAM_PREFIX "DosStream." 11138c8a9a5SSteve French #define STREAM_PREFIX_LEN (sizeof(STREAM_PREFIX) - 1) 11238c8a9a5SSteve French #define XATTR_NAME_STREAM (XATTR_USER_PREFIX STREAM_PREFIX) 11338c8a9a5SSteve French #define XATTR_NAME_STREAM_LEN (sizeof(XATTR_NAME_STREAM) - 1) 11438c8a9a5SSteve French 11538c8a9a5SSteve French /* SECURITY DESCRIPTOR(NTACL) XATTR PREFIX */ 11638c8a9a5SSteve French #define SD_PREFIX "NTACL" 11738c8a9a5SSteve French #define SD_PREFIX_LEN (sizeof(SD_PREFIX) - 1) 11838c8a9a5SSteve French #define XATTR_NAME_SD (XATTR_SECURITY_PREFIX SD_PREFIX) 11938c8a9a5SSteve French #define XATTR_NAME_SD_LEN \ 12038c8a9a5SSteve French (sizeof(XATTR_SECURITY_PREFIX SD_PREFIX) - 1) 12138c8a9a5SSteve French 12238c8a9a5SSteve French #endif /* __XATTR_H__ */ 123