• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef CONFIG_SHAREFS_SUPPORT_OVERRIDE
41 const struct cred *sharefs_override_file_fsids(struct inode *dir,
42 				 __u16 *_perm);
43 void sharefs_revert_fsids(const struct cred *old_cred);
44 #endif
45 
is_read_only_auth(__u16 perm)46 static inline bool is_read_only_auth(__u16 perm)
47 {
48 	return (perm & SHAREFS_DIR_TYPE_MASK) == SHAREFS_DIR_TYPE_READONLY;
49 }
50 
is_read_write_auth(__u16 perm)51 static inline bool is_read_write_auth(__u16 perm)
52 {
53 	return (perm & SHAREFS_DIR_TYPE_MASK) == SHAREFS_DIR_TYPE_READWRITE;
54 }
55 
sharefs_set_read_perm(struct inode * inode)56 static inline void sharefs_set_read_perm(struct inode *inode)
57 {
58 	if (S_ISDIR(inode->i_mode))
59 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READONLY_DIR;
60 	else
61 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READONLY_FILE;
62 }
63 
sharefs_set_read_write_perm(struct inode * inode)64 static inline void sharefs_set_read_write_perm(struct inode *inode)
65 {
66 	if (S_ISDIR(inode->i_mode))
67 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READWRITE_DIR;
68 	else
69 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READWRITE_FILE;
70 }
71 
get_bundle_uid(struct sharefs_sb_info * sbi,const char * bname)72 static inline int get_bundle_uid(struct sharefs_sb_info *sbi, const char *bname)
73 {
74 	return sbi->user_id * BASE_USER_RANGE + get_bid_config(bname);
75 }
76