• 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 #ifndef AUTHENTICATION_H
9 #define AUTHENTICATION_H
10 
11 #include "sharefs.h"
12 
13 #define OID_ROOT             	0
14 
15 #define SHAREFS_PERM_MASK     0x000F
16 
17 #define SHAREFS_PERM_FIX           0
18 #define SHAREFS_PERM_MNT           1
19 #define SHAREFS_PERM_DFS           2
20 #define SHAREFS_PERM_OTHER         3
21 
22 #define SHAREFS_READ_DIR  "r"
23 #define SHAREFS_READWRITE_DIR "rw"
24 
25 #define BASE_USER_RANGE     200000 /* offset for uid ranges for each user */
26 
27 
28 #define SHAREFS_DIR_TYPE_MASK	       0x00F0
29 #define SHAREFS_DIR_TYPE_READONLY      0x0010
30 #define SHAREFS_DIR_TYPE_READWRITE     0x0020
31 
32 #define SHAREFS_PERM_READONLY_DIR   00550
33 #define SHAREFS_PERM_READONLY_FILE  00440
34 #define SHAREFS_PERM_READWRITE_DIR  00550
35 #define SHAREFS_PERM_READWRITE_FILE 00660
36 
37 extern int get_bid_config(const char *bname);
38 extern int __init sharefs_init_configfs(void);
39 extern void sharefs_exit_configfs(void);
40 
41 void sharefs_root_inode_perm_init(struct inode *root_inode);
42 void fixup_perm_from_level(struct inode *dir, struct dentry *dentry);
43 #ifdef CONFIG_SHAREFS_SUPPORT_OVERRIDE
44 const struct cred *sharefs_override_file_fsids(struct inode *dir,
45 				 __u16 *_perm);
46 void sharefs_revert_fsids(const struct cred *old_cred);
47 #endif
48 
is_read_only_auth(__u16 perm)49 static inline bool is_read_only_auth(__u16 perm)
50 {
51 	return (perm & SHAREFS_DIR_TYPE_MASK) == SHAREFS_DIR_TYPE_READONLY;
52 }
53 
is_read_write_auth(__u16 perm)54 static inline bool is_read_write_auth(__u16 perm)
55 {
56 	return (perm & SHAREFS_DIR_TYPE_MASK) == SHAREFS_DIR_TYPE_READWRITE;
57 }
58 
sharefs_set_read_perm(struct inode * inode)59 static inline void sharefs_set_read_perm(struct inode *inode)
60 {
61 	if (S_ISDIR(inode->i_mode))
62 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READONLY_DIR;
63 	else
64 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READONLY_FILE;
65 }
66 
sharefs_set_read_write_perm(struct inode * inode)67 static inline void sharefs_set_read_write_perm(struct inode *inode)
68 {
69 	if (S_ISDIR(inode->i_mode))
70 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READWRITE_DIR;
71 	else
72 		inode->i_mode = (inode->i_mode & S_IFMT) | SHAREFS_PERM_READWRITE_FILE;
73 }
74 
get_bundle_uid(struct sharefs_sb_info * sbi,const char * bname)75 static inline int get_bundle_uid(struct sharefs_sb_info *sbi, const char *bname)
76 {
77 	return sbi->user_id * BASE_USER_RANGE + get_bid_config(bname);
78 }
79 
80 #endif //_AUTHENTICATION_H_