aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2023-02-24 20:44:48 -0500
committerLibravatar GitHub <noreply@github.com>2023-02-24 20:44:48 -0500
commitd657245f7353f692c22db2801ac64f7d807eb415 (patch)
tree5494cbde66f9fb6220df8a72415a6160f130a6b9 /test
parentMerge pull request #5677 from kmk3/print-failed-long-arg (diff)
parenteditorconfig: add indentation rules (diff)
downloadfirejail-d657245f7353f692c22db2801ac64f7d807eb415.tar.gz
firejail-d657245f7353f692c22db2801ac64f7d807eb415.tar.zst
firejail-d657245f7353f692c22db2801ac64f7d807eb415.zip
Merge pull request #5674 from kmk3/fix-ws-add-editorconfig
build: Fix whitespace and add .editorconfig
Diffstat (limited to 'test')
-rw-r--r--test/filters/namespaces.c130
-rwxr-xr-xtest/fs/private-whitelist.exp6
-rwxr-xr-xtest/network/firemon-route.exp2
-rwxr-xr-xtest/private-etc/private-etc.sh1
-rwxr-xr-xtest/private-lib/private-lib.sh1
-rw-r--r--test/profiles/test2.profile8
-rwxr-xr-xtest/sysutils/sysutils.sh1
7 files changed, 73 insertions, 76 deletions
diff --git a/test/filters/namespaces.c b/test/filters/namespaces.c
index 06dfa4edf..ecf0fdcd1 100644
--- a/test/filters/namespaces.c
+++ b/test/filters/namespaces.c
@@ -15,82 +15,82 @@
15#define STACK_SIZE 1024 * 1024 15#define STACK_SIZE 1024 * 1024
16 16
17static int usage() { 17static int usage() {
18 fprintf(stderr, "Usage: namespaces <system call>[clone,unshare] <list of namespaces>[cgroup,ipc,mnt,net,pid,time,user,uts]\n"); 18 fprintf(stderr, "Usage: namespaces <system call>[clone,unshare] <list of namespaces>[cgroup,ipc,mnt,net,pid,time,user,uts]\n");
19 exit(1); 19 exit(1);
20} 20}
21 21
22static void die(const char *msg) { 22static void die(const char *msg) {
23 fprintf(stderr, "Error: %s: %s\n", msg, strerror(errno)); 23 fprintf(stderr, "Error: %s: %s\n", msg, strerror(errno));
24 exit(1); 24 exit(1);
25} 25}
26 26
27static int ns_flags(const char *list) { 27static int ns_flags(const char *list) {
28 int flags = 0; 28 int flags = 0;
29 29
30 char *dup = strdup(list); 30 char *dup = strdup(list);
31 if (!dup) 31 if (!dup)
32 die("cannot allocate memory"); 32 die("cannot allocate memory");
33 33
34 char *token = strtok(dup, ","); 34 char *token = strtok(dup, ",");
35 while (token) { 35 while (token) {
36 if (strcmp(token, "cgroup") == 0) 36 if (strcmp(token, "cgroup") == 0)
37 flags |= CLONE_NEWCGROUP; 37 flags |= CLONE_NEWCGROUP;
38 else if (strcmp(token, "ipc") == 0) 38 else if (strcmp(token, "ipc") == 0)
39 flags |= CLONE_NEWIPC; 39 flags |= CLONE_NEWIPC;
40 else if (strcmp(token, "net") == 0) 40 else if (strcmp(token, "net") == 0)
41 flags |= CLONE_NEWNET; 41 flags |= CLONE_NEWNET;
42 else if (strcmp(token, "mnt") == 0) 42 else if (strcmp(token, "mnt") == 0)
43 flags |= CLONE_NEWNS; 43 flags |= CLONE_NEWNS;
44 else if (strcmp(token, "pid") == 0) 44 else if (strcmp(token, "pid") == 0)
45 flags |= CLONE_NEWPID; 45 flags |= CLONE_NEWPID;
46 else if (strcmp(token, "time") == 0) 46 else if (strcmp(token, "time") == 0)
47 flags |= CLONE_NEWTIME; 47 flags |= CLONE_NEWTIME;
48 else if (strcmp(token, "user") == 0) 48 else if (strcmp(token, "user") == 0)
49 flags |= CLONE_NEWUSER; 49 flags |= CLONE_NEWUSER;
50 else if (strcmp(token, "uts") == 0) 50 else if (strcmp(token, "uts") == 0)
51 flags |= CLONE_NEWUTS; 51 flags |= CLONE_NEWUTS;
52 else 52 else
53 usage(); 53 usage();
54 54
55 token = strtok(NULL, ","); 55 token = strtok(NULL, ",");
56 } 56 }
57 57
58 free(dup); 58 free(dup);
59 return flags; 59 return flags;
60} 60}
61 61
62static int child(void *arg) { 62static int child(void *arg) {
63 (void) arg; 63 (void) arg;
64 64
65 fprintf(stderr, "clone successful\n"); 65 fprintf(stderr, "clone successful\n");
66 return 0; 66 return 0;
67} 67}
68 68
69int main (int argc, char **argv) { 69int main (int argc, char **argv) {
70 if (argc != 3) 70 if (argc != 3)
71 usage(); 71 usage();
72 72
73 int flags = ns_flags(argv[2]); 73 int flags = ns_flags(argv[2]);
74 if (getuid() != 0) 74 if (getuid() != 0)
75 flags |= CLONE_NEWUSER; 75 flags |= CLONE_NEWUSER;
76 76
77 if (strcmp(argv[1], "clone") == 0) { 77 if (strcmp(argv[1], "clone") == 0) {
78 void *stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, 78 void *stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
79 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 79 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
80 if (stack == MAP_FAILED) 80 if (stack == MAP_FAILED)
81 die("mmap"); 81 die("mmap");
82 82
83 if (clone(child, stack + STACK_SIZE, flags | SIGCHLD, NULL) < 0) 83 if (clone(child, stack + STACK_SIZE, flags | SIGCHLD, NULL) < 0)
84 die("clone"); 84 die("clone");
85 } 85 }
86 else if (strcmp(argv[1], "unshare") == 0) { 86 else if (strcmp(argv[1], "unshare") == 0) {
87 if (unshare(flags)) 87 if (unshare(flags))
88 die("unshare"); 88 die("unshare");
89 89
90 fprintf(stderr, "unshare successful\n"); 90 fprintf(stderr, "unshare successful\n");
91 } 91 }
92 else 92 else
93 usage(); 93 usage();
94 94
95 return 0; 95 return 0;
96} 96}
diff --git a/test/fs/private-whitelist.exp b/test/fs/private-whitelist.exp
index eaad5700d..bf95e40dd 100755
--- a/test/fs/private-whitelist.exp
+++ b/test/fs/private-whitelist.exp
@@ -32,9 +32,9 @@ send -- "ls -a ~ | wc -l\r"
32expect { 32expect {
33 timeout {puts "TESTING ERROR 4\n";exit} 33 timeout {puts "TESTING ERROR 4\n";exit}
34 "3" {puts "3\n"} 34 "3" {puts "3\n"}
35 "4" {puts "4\n"} 35 "4" {puts "4\n"}
36 "5" {puts "5\n"} 36 "5" {puts "5\n"}
37 "6" {puts "6\n"} 37 "6" {puts "6\n"}
38} 38}
39 39
40sleep 1 40sleep 1
diff --git a/test/network/firemon-route.exp b/test/network/firemon-route.exp
index 707217eea..69cccfeae 100755
--- a/test/network/firemon-route.exp
+++ b/test/network/firemon-route.exp
@@ -33,7 +33,7 @@ expect {
33 "0.0.0.0/0 via 192.168.1.1, dev eth0, metric 0" {puts "Debian testing\n";} 33 "0.0.0.0/0 via 192.168.1.1, dev eth0, metric 0" {puts "Debian testing\n";}
34 "0.0.0.0/0 via 192.168.1.1, dev enp0s3, metric 1024" {puts "Centos 7 testing\n";} 34 "0.0.0.0/0 via 192.168.1.1, dev enp0s3, metric 1024" {puts "Centos 7 testing\n";}
35 "0.0.0.0/0 via 192.168.1.1, dev enp0s3, metric 0" {puts "OpenSUSE testing\n";} 35 "0.0.0.0/0 via 192.168.1.1, dev enp0s3, metric 0" {puts "OpenSUSE testing\n";}
36 "0.0.0.0/0 via 192.168.1.1, dev enp0s3, metric 100" {puts "Arch testing\n";} 36 "0.0.0.0/0 via 192.168.1.1, dev enp0s3, metric 100" {puts "Arch testing\n";}
37} 37}
38expect { 38expect {
39 timeout {puts "TESTING ERROR 4\n";exit} 39 timeout {puts "TESTING ERROR 4\n";exit}
diff --git a/test/private-etc/private-etc.sh b/test/private-etc/private-etc.sh
index 8488611b9..c46b684af 100755
--- a/test/private-etc/private-etc.sh
+++ b/test/private-etc/private-etc.sh
@@ -18,4 +18,3 @@ echo "TESTING: groups (test/private-etc/groups.exp)"
18 18
19echo "TESTING: etc-cleanup (test/private-etc/etc-cleanup.exp)" 19echo "TESTING: etc-cleanup (test/private-etc/etc-cleanup.exp)"
20./etc-cleanup.exp 20./etc-cleanup.exp
21
diff --git a/test/private-lib/private-lib.sh b/test/private-lib/private-lib.sh
index 0ef18b79d..5c67b16c5 100755
--- a/test/private-lib/private-lib.sh
+++ b/test/private-lib/private-lib.sh
@@ -29,4 +29,3 @@ if [[ $(uname -m) == "x86_64" ]]; then
29else 29else
30 echo "TESTING SKIP: private-lib test implemented only for x86_64." 30 echo "TESTING SKIP: private-lib test implemented only for x86_64."
31fi 31fi
32
diff --git a/test/profiles/test2.profile b/test/profiles/test2.profile
index 9fbd5219a..9504f5085 100644
--- a/test/profiles/test2.profile
+++ b/test/profiles/test2.profile
@@ -1,6 +1,6 @@
1caps 1caps
2seccomp 2seccomp
3 private 3private
4 include test.profile 4include test.profile
5 include test.local 5include test.local
6 include test25.profile 6include test25.profile
diff --git a/test/sysutils/sysutils.sh b/test/sysutils/sysutils.sh
index 231f5afa8..f5567ff02 100755
--- a/test/sysutils/sysutils.sh
+++ b/test/sysutils/sysutils.sh
@@ -150,4 +150,3 @@ then
150else 150else
151 echo "TESTING SKIP: whois not found" 151 echo "TESTING SKIP: whois not found"
152fi 152fi
153