diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/landlock.h | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/src/include/landlock.h b/src/include/landlock.h deleted file mode 100644 index 5d6b0260e..000000000 --- a/src/include/landlock.h +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | #define _GNU_SOURCE | ||
2 | #include <stdio.h> | ||
3 | #include <stddef.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <unistd.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <sys/syscall.h> | ||
8 | #include <sys/types.h> | ||
9 | #include <linux/landlock.h> | ||
10 | |||
11 | int landlock_create_ruleset(struct landlock_ruleset_attr *rsattr,size_t size,__u32 flags) { | ||
12 | return syscall(__NR_landlock_create_ruleset,rsattr,size,flags); | ||
13 | } | ||
14 | |||
15 | int landlock_add_rule(int fd,enum landlock_rule_type t,void *attr,__u32 flags) { | ||
16 | return syscall(__NR_landlock_add_rule,fd,t,attr,flags); | ||
17 | } | ||
18 | |||
19 | int landlock_restrict_self(int fd,__u32 flags) { | ||
20 | int result = syscall(__NR_landlock_restrict_self,fd,flags); | ||
21 | if (result!=0) return result; | ||
22 | else { | ||
23 | close(fd); | ||
24 | return 0; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | int create_full_ruleset() { | ||
29 | struct landlock_ruleset_attr attr; | ||
30 | attr.handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK | LANDLOCK_ACCESS_FS_MAKE_SYM | LANDLOCK_ACCESS_FS_EXECUTE; | ||
31 | return landlock_create_ruleset(&attr,sizeof(attr),0); | ||
32 | } | ||
33 | |||
34 | int add_read_access_rule_by_path(int rset_fd,char *allowed_path) { | ||
35 | int result; | ||
36 | int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
37 | struct landlock_path_beneath_attr target; | ||
38 | target.parent_fd = allowed_fd; | ||
39 | target.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR; | ||
40 | result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
41 | close(allowed_fd); | ||
42 | return result; | ||
43 | } | ||
44 | |||
45 | int add_write_access_rule_by_path(int rset_fd,char *allowed_path,int restricted) { | ||
46 | int result; | ||
47 | int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
48 | struct landlock_path_beneath_attr target; | ||
49 | target.parent_fd = allowed_fd; | ||
50 | if (restricted==0) target.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
51 | else if (restricted==1) target.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
52 | else { | ||
53 | close(allowed_fd); | ||
54 | return -1; | ||
55 | } | ||
56 | result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
57 | close(allowed_fd); | ||
58 | return result; | ||
59 | } | ||
60 | |||
61 | int add_execute_rule_by_path(int rset_fd,char *allowed_path) { | ||
62 | int result; | ||
63 | int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
64 | struct landlock_path_beneath_attr target; | ||
65 | target.parent_fd = allowed_fd; | ||
66 | target.allowed_access = LANDLOCK_ACCESS_FS_EXECUTE; | ||
67 | result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
68 | close(allowed_fd); | ||
69 | return result; | ||
70 | } | ||