1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * fs/sharefs/authentication.h 4 * 5 * Copyright (c) 2023 Huawei Device Co., Ltd. 6 */ 7 8 #include "sharefs.h" 9 10 #define OID_ROOT 0 11 12 #define SHAREFS_PERM_MASK 0x000F 13 14 #define SHAREFS_PERM_FIX 0 15 #define SHAREFS_PERM_MNT 1 16 #define SHAREFS_PERM_DFS 2 17 #define SHAREFS_PERM_OTHER 3 18 19 #define SHAREFS_READ_DIR "r" 20 #define SHAREFS_READWRITE_DIR "rw" 21 22 #define BASE_USER_RANGE 200000 /* offset for uid ranges for each user */ 23 24 25 #define SHAREFS_DIR_TYPE_MASK 0x00F0 26 #define SHAREFS_DIR_TYPE_READONLY 0x0010 27 #define SHAREFS_DIR_TYPE_READWRITE 0x0020 28 29 #define SHAREFS_PERM_READONLY_DIR 00550 30 #define SHAREFS_PERM_READONLY_FILE 00440 31 #define SHAREFS_PERM_READWRITE_DIR 00550 32 #define SHAREFS_PERM_READWRITE_FILE 00660 33 34 extern int get_bid_config(const char *bname); 35 extern int __init sharefs_init_configfs(void); 36 extern void sharefs_exit_configfs(void); 37 38 void sharefs_root_inode_perm_init(struct inode *root_inode); 39 void fixup_perm_from_level(struct inode *dir, struct dentry *dentry); 40 is_read_only_auth(__u16 perm)41static inline bool is_read_only_auth(__u16 perm) 42 { 43 return (perm & SHAREFS_DIR_TYPE_MASK) == SHAREFS_DIR_TYPE_READONLY; 44 } 45 is_read_write_auth(__u16 perm)46static inline bool is_read_write_auth(__u16 perm) 47 { 48 return (perm & SHAREFS_DIR_TYPE_MASK) == SHAREFS_DIR_TYPE_READWRITE; 49 } 50 sharefs_set_read_perm(struct inode * inode)51static inline void sharefs_set_read_perm(struct inode *inode) { 52 if (S_ISDIR(inode->i_mode)) 53 inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READONLY_DIR; 54 else 55 inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READONLY_FILE; 56 } 57 sharefs_set_read_write_perm(struct inode * inode)58static inline void sharefs_set_read_write_perm(struct inode *inode) { 59 if (S_ISDIR(inode->i_mode)) 60 inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READWRITE_DIR; 61 else 62 inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READWRITE_FILE; 63 } 64 get_bundle_uid(struct sharefs_sb_info * sbi,const char * bname)65static inline int get_bundle_uid(struct sharefs_sb_info *sbi, const char *bname) 66 { 67 return sbi->user_id * BASE_USER_RANGE + get_bid_config(bname); 68 } 69