aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2018-04-01 07:48:11 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2018-04-01 07:48:11 -0400
commit1fb1bfe20fbde64d769e846b1581ce021d03e864 (patch)
treeb284305324ca31fa5c0b2b318a9dbeaae146da55
parentmerges (diff)
downloadfirejail-1fb1bfe20fbde64d769e846b1581ce021d03e864.tar.gz
firejail-1fb1bfe20fbde64d769e846b1581ce021d03e864.tar.zst
firejail-1fb1bfe20fbde64d769e846b1581ce021d03e864.zip
testing
-rw-r--r--src/fnetfilter/main.c41
-rwxr-xr-xtest/environment/csh.exp14
-rwxr-xr-xtest/environment/zsh.exp14
-rwxr-xr-xtest/network/netfilter-template.exp23
-rwxr-xr-xtest/utils/audit.exp60
-rwxr-xr-xtest/utils/command.exp23
-rwxr-xr-xtest/utils/name.exp174
-rwxr-xr-xtest/utils/profile_print.exp27
-rwxr-xr-xtest/utils/utils.sh9
9 files changed, 361 insertions, 24 deletions
diff --git a/src/fnetfilter/main.c b/src/fnetfilter/main.c
index 828b30d40..ba58ba3c9 100644
--- a/src/fnetfilter/main.c
+++ b/src/fnetfilter/main.c
@@ -50,19 +50,20 @@ static void usage(void) {
50 printf("\tfnetfilter netfilter-command destination-file\n"); 50 printf("\tfnetfilter netfilter-command destination-file\n");
51} 51}
52 52
53static void err_exit_cannot_open_file(const char *fname) {
54 fprintf(stderr, "Error fnetfilter: cannot open %s\n", fname);
55 exit(1);
56}
57
53 58
54static void copy(const char *src, const char *dest) { 59static void copy(const char *src, const char *dest) {
55 FILE *fp1 = fopen(src, "r"); 60 FILE *fp1 = fopen(src, "r");
56 if (!fp1) { 61 if (!fp1)
57 fprintf(stderr, "Error fnetfilter: cannot open %s\n", src); 62 err_exit_cannot_open_file(src);
58 exit(1);
59 }
60 63
61 FILE *fp2 = fopen(dest, "w"); 64 FILE *fp2 = fopen(dest, "w");
62 if (!fp2) { 65 if (!fp2)
63 fprintf(stderr, "Error fnetfilter: cannot open %s\n", dest); 66 err_exit_cannot_open_file(dest);
64 exit(1);
65 }
66 67
67 char buf[MAXBUF]; 68 char buf[MAXBUF];
68 while (fgets(buf, MAXBUF, fp1)) 69 while (fgets(buf, MAXBUF, fp1))
@@ -106,16 +107,12 @@ for (i = 0; i < argcnt; i++)
106 107
107 // open the files 108 // open the files
108 FILE *fp1 = fopen(src, "r"); 109 FILE *fp1 = fopen(src, "r");
109 if (!fp1) { 110 if (!fp1)
110 fprintf(stderr, "Error fnetfilter: cannot open %s\n", src); 111 err_exit_cannot_open_file(src);
111 exit(1);
112 }
113 112
114 FILE *fp2 = fopen(dest, "w"); 113 FILE *fp2 = fopen(dest, "w");
115 if (!fp2) { 114 if (!fp2)
116 fprintf(stderr, "Error fnetfilter: cannot open %s\n", dest); 115 err_exit_cannot_open_file(dest);
117 exit(1);
118 }
119 116
120 int line = 0; 117 int line = 0;
121 char buf[MAXBUF]; 118 char buf[MAXBUF];
@@ -186,19 +183,15 @@ printf("\n");
186//printf("destfile %s\n", destfile); 183//printf("destfile %s\n", destfile);
187 // destfile is a real filename 184 // destfile is a real filename
188 int len = strlen(destfile); 185 int len = strlen(destfile);
189 if (strcspn(destfile, "\\&!?\"'<>%^(){};,*[]") != (size_t)len) { 186 if (strcspn(destfile, "\\&!?\"'<>%^(){};,*[]") != (size_t)len)
190 fprintf(stderr, "Error fnetfilter: invalid destination file in netfilter command\n"); 187 err_exit_cannot_open_file(destfile);
191 exit(1);
192 }
193 188
194 // handle default config (command = NULL, destfile) 189 // handle default config (command = NULL, destfile)
195 if (command == NULL) { 190 if (command == NULL) {
196 // create a default filter file 191 // create a default filter file
197 FILE *fp = fopen(destfile, "w"); 192 FILE *fp = fopen(destfile, "w");
198 if (!fp) { 193 if (!fp)
199 fprintf(stderr, "Error fnetfilter: cannot open %s\n", destfile); 194 err_exit_cannot_open_file(destfile);
200 exit(1);
201 }
202 fprintf(fp, "%s\n", default_filter); 195 fprintf(fp, "%s\n", default_filter);
203 fclose(fp); 196 fclose(fp);
204 } 197 }
diff --git a/test/environment/csh.exp b/test/environment/csh.exp
index 7b9fe7dc4..10a278ebc 100755
--- a/test/environment/csh.exp
+++ b/test/environment/csh.exp
@@ -30,6 +30,20 @@ expect {
30 "/bin/csh" 30 "/bin/csh"
31} 31}
32send -- "exit\r" 32send -- "exit\r"
33sleep 1
34
35send -- "firejail --shell=none --csh\r"
36expect {
37 timeout {puts "TESTING ERROR 3\n";exit}
38 "shell=none was already specified"
39}
40after 100
41
42send -- "firejail --csh --shell=none\r"
43expect {
44 timeout {puts "TESTING ERROR 4\n";exit}
45 "a shell was already specified"
46}
33after 100 47after 100
34 48
35puts "\n" 49puts "\n"
diff --git a/test/environment/zsh.exp b/test/environment/zsh.exp
index 65fe440c7..e7f610e98 100755
--- a/test/environment/zsh.exp
+++ b/test/environment/zsh.exp
@@ -30,6 +30,20 @@ expect {
30 "/bin/zsh" 30 "/bin/zsh"
31} 31}
32send -- "exit\r" 32send -- "exit\r"
33sleep 1
34
35send -- "firejail --shell=none --zsh\r"
36expect {
37 timeout {puts "TESTING ERROR 3\n";exit}
38 "shell=none was already specified"
39}
40after 100
41
42send -- "firejail --zsh --shell=none\r"
43expect {
44 timeout {puts "TESTING ERROR 4\n";exit}
45 "a shell was already specified"
46}
33after 100 47after 100
34 48
35puts "\nall done\n" 49puts "\nall done\n"
diff --git a/test/network/netfilter-template.exp b/test/network/netfilter-template.exp
index 1ad28a103..5a15152d3 100755
--- a/test/network/netfilter-template.exp
+++ b/test/network/netfilter-template.exp
@@ -7,6 +7,14 @@ set timeout 10
7spawn $env(SHELL) 7spawn $env(SHELL)
8match_max 100000 8match_max 100000
9 9
10
11send -- "firejail --net=br1 --ip=10.10.30.10 --name=test1 --netfilter=/etc/firejail/blablabla\r"
12expect {
13 timeout {puts "TESTING ERROR 0\n";exit}
14 "invalid network filter file"
15}
16sleep 1
17
10send -- "firejail --net=br1 --ip=10.10.30.10 --name=test1 --netfilter=/etc/firejail/tcpserver.net,5555 ./tcpserver 5555\r" 18send -- "firejail --net=br1 --ip=10.10.30.10 --name=test1 --netfilter=/etc/firejail/tcpserver.net,5555 ./tcpserver 5555\r"
11expect { 19expect {
12 timeout {puts "TESTING ERROR 1\n";exit} 20 timeout {puts "TESTING ERROR 1\n";exit}
@@ -15,6 +23,21 @@ expect {
15sleep 1 23sleep 1
16 24
17spawn $env(SHELL) 25spawn $env(SHELL)
26send -- "firejail --netfilter.print=test1\r"
27expect {
28 timeout {puts "TESTING ERROR 1.1\n";exit}
29 "Chain INPUT"
30}
31expect {
32 timeout {puts "TESTING ERROR 1.2\n";exit}
33 "Chain FORWARD"
34}
35expect {
36 timeout {puts "TESTING ERROR 1.3\n";exit}
37 "Chain OUTPUT"
38}
39sleep 1
40
18send -- "telnet 10.10.30.10 5555\r" 41send -- "telnet 10.10.30.10 5555\r"
19expect { 42expect {
20 timeout {puts "TESTING ERROR 2\n";exit} 43 timeout {puts "TESTING ERROR 2\n";exit}
diff --git a/test/utils/audit.exp b/test/utils/audit.exp
index 684886af7..6352dc62d 100755
--- a/test/utils/audit.exp
+++ b/test/utils/audit.exp
@@ -96,4 +96,64 @@ expect {
96} 96}
97after 100 97after 100
98 98
99# test seccomp
100send -- "firejail --seccomp.drop=mkdir --audit\r"
101expect {
102 timeout {puts "TESTING ERROR 17\n";exit}
103 "Firejail Audit"
104}
105expect {
106 timeout {puts "TESTING ERROR 18\n";exit}
107 "GOOD: seccomp BPF enabled"
108}
109expect {
110 timeout {puts "TESTING ERROR 19\n";exit}
111 "UGLY: mount syscall permitted"
112}
113expect {
114 timeout {puts "TESTING ERROR 20\n";exit}
115 "UGLY: umount2 syscall permitted"
116}
117expect {
118 timeout {puts "TESTING ERROR 21\n";exit}
119 "UGLY: ptrace syscall permitted"
120}
121expect {
122 timeout {puts "TESTING ERROR 22\n";exit}
123 "UGLY: swapon syscall permitted"
124}
125expect {
126 timeout {puts "TESTING ERROR 23\n";exit}
127 "UGLY: swapoff syscall permitted"
128}
129expect {
130 timeout {puts "TESTING ERROR 24\n";exit}
131 "UGLY: init_module syscall permitted"
132}
133expect {
134 timeout {puts "TESTING ERROR 25\n";exit}
135 "UGLY: delete_module syscall permitted"
136}
137expect {
138 timeout {puts "TESTING ERROR 26\n";exit}
139 "UGLY: chroot syscall permitted"
140}
141expect {
142 timeout {puts "TESTING ERROR 27\n";exit}
143 "UGLY: pivot_root syscall permitted"
144}
145expect {
146 timeout {puts "TESTING ERROR 28\n";exit}
147 "UGLY: iopl syscall permitted"
148}
149expect {
150 timeout {puts "TESTING ERROR 29\n";exit}
151 "UGLY: ioperm syscall permitted"
152}
153expect {
154 timeout {puts "TESTING ERROR 30\n";exit}
155 "GOOD: all capabilities are disabled"
156}
157after 100
158
99puts "\nall done\n" 159puts "\nall done\n"
diff --git a/test/utils/command.exp b/test/utils/command.exp
new file mode 100755
index 000000000..3b18540db
--- /dev/null
+++ b/test/utils/command.exp
@@ -0,0 +1,23 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2018 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --quiet --private-etc=passwd,group -c ls -al /etc\r"
11expect {
12 timeout {puts "TESTING ERROR 1\n";exit}
13 "cron" {puts "TESTING ERROR 2\n";exit}
14 "group"
15}
16expect {
17 timeout {puts "TESTING ERROR 3\n";exit}
18 "passwd"
19}
20
21
22after 100
23puts "\nall done\n"
diff --git a/test/utils/name.exp b/test/utils/name.exp
new file mode 100755
index 000000000..f00b5866e
--- /dev/null
+++ b/test/utils/name.exp
@@ -0,0 +1,174 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2018 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10
11send -- "firejail --name=ftest\r"
12expect {
13 timeout {puts "TESTING ERROR 0\n";exit}
14 "Child process initialized"
15}
16after 100
17
18spawn $env(SHELL)
19send -- "firejail --name=ftest\r"
20expect {
21 timeout {puts "TESTING ERROR 1\n";exit}
22 "Child process initialized"
23}
24after 100
25
26spawn $env(SHELL)
27send -- "firejail --name=ftest\r"
28expect {
29 timeout {puts "TESTING ERROR 2\n";exit}
30 "Child process initialized"
31}
32after 100
33
34spawn $env(SHELL)
35send -- "firejail --name=ftest\r"
36expect {
37 timeout {puts "TESTING ERROR 3\n";exit}
38 "Child process initialized"
39}
40after 100
41
42spawn $env(SHELL)
43send -- "firejail --name=ftest\r"
44expect {
45 timeout {puts "TESTING ERROR 4\n";exit}
46 "Child process initialized"
47}
48after 100
49
50spawn $env(SHELL)
51send -- "firejail --name=ftest\r"
52expect {
53 timeout {puts "TESTING ERROR 5\n";exit}
54 "Child process initialized"
55}
56after 100
57
58spawn $env(SHELL)
59send -- "firejail --name=ftest\r"
60expect {
61 timeout {puts "TESTING ERROR 6\n";exit}
62 "Child process initialized"
63}
64after 100
65
66spawn $env(SHELL)
67send -- "firejail --name=ftest\r"
68expect {
69 timeout {puts "TESTING ERROR 7\n";exit}
70 "Child process initialized"
71}
72after 100
73
74spawn $env(SHELL)
75send -- "firejail --name=ftest\r"
76expect {
77 timeout {puts "TESTING ERROR 8\n";exit}
78 "Child process initialized"
79}
80after 100
81
82spawn $env(SHELL)
83send -- "firejail --name=ftest\r"
84expect {
85 timeout {puts "TESTING ERROR 9\n";exit}
86 "Child process initialized"
87}
88after 100
89
90spawn $env(SHELL)
91send -- "firejail --name=ftest\r"
92expect {
93 timeout {puts "TESTING ERROR 10\n";exit}
94 "Child process initialized"
95}
96after 100
97
98spawn $env(SHELL)
99send -- "firejail --name=ftest\r"
100expect {
101 timeout {puts "TESTING ERROR 11\n";exit}
102 "Child process initialized"
103}
104after 100
105
106spawn $env(SHELL)
107send -- "firejail --list\r"
108expect {
109 timeout {puts "TESTING ERROR 12\n";exit}
110 ":ftest:"
111}
112expect {
113 timeout {puts "TESTING ERROR 13\n";exit}
114 ":ftest-1:"
115}
116expect {
117 timeout {puts "TESTING ERROR 14\n";exit}
118 ":ftest-2:"
119}
120expect {
121 timeout {puts "TESTING ERROR 15\n";exit}
122 ":ftest-3:"
123}
124expect {
125 timeout {puts "TESTING ERROR 16\n";exit}
126 ":ftest-4:"
127}
128expect {
129 timeout {puts "TESTING ERROR 17\n";exit}
130 ":ftest-5:"
131}
132expect {
133 timeout {puts "TESTING ERROR 18\n";exit}
134 ":ftest-6:"
135}
136expect {
137 timeout {puts "TESTING ERROR 19\n";exit}
138 ":ftest-7:"
139}
140expect {
141 timeout {puts "TESTING ERROR 20\n";exit}
142 ":ftest-8:"
143}
144expect {
145 timeout {puts "TESTING ERROR 21\n";exit}
146 ":ftest-9:"
147}
148expect {
149 timeout {puts "TESTING ERROR 22\n";exit}
150 ":ftest-"
151}
152expect {
153 timeout {puts "TESTING ERROR 23\n";exit}
154 ":ftest-"
155}
156after 100
157
158send -- "firejail --shutdown=ftest-5\r"
159expect {
160 timeout {puts "TESTING ERROR 11\n";exit}
161 "Sending SIGTERM"
162}
163sleep 1
164
165spawn $env(SHELL)
166send -- "firejail --list\r"
167expect {
168 timeout {puts "TESTING ERROR 12\n";exit}
169 ":ftest-5:" {puts "TESTING ERROR 15\n";exit}
170 ":ftest-9:"
171}
172
173after 100
174puts "all done\n"
diff --git a/test/utils/profile_print.exp b/test/utils/profile_print.exp
new file mode 100755
index 000000000..20d88a264
--- /dev/null
+++ b/test/utils/profile_print.exp
@@ -0,0 +1,27 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2018 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10
11send -- "firejail --name=ftest\r"
12expect {
13 timeout {puts "TESTING ERROR 0\n";exit}
14 "Child process initialized"
15}
16after 100
17
18spawn $env(SHELL)
19send -- "firejail --profile.print=ftest\r"
20expect {
21 timeout {puts "TESTING ERROR 1\n";exit}
22 "/etc/firejail/default.profile"
23}
24
25
26after 100
27puts "all done\n"
diff --git a/test/utils/utils.sh b/test/utils/utils.sh
index d72cc2269..9259ee33a 100755
--- a/test/utils/utils.sh
+++ b/test/utils/utils.sh
@@ -20,6 +20,15 @@ rm -f ~/firejail-test-file-7699
20echo "TESTING: audit (test/utils/audit.exp)" 20echo "TESTING: audit (test/utils/audit.exp)"
21./audit.exp 21./audit.exp
22 22
23echo "TESTING: name (test/utils/name.exp)"
24./name.exp
25
26echo "TESTING: command (test/utils/command.exp)"
27./command.exp
28
29echo "TESTING: profile.print (test/utils/profile_print.exp)"
30./profile_print.exp
31
23echo "TESTING: version (test/utils/version.exp)" 32echo "TESTING: version (test/utils/version.exp)"
24./version.exp 33./version.exp
25 34