1 |
kumaneko |
1066 |
/* |
2 |
kumaneko |
3071 |
* ccs_new_file_test.c |
3 |
kumaneko |
1066 |
* |
4 |
kumaneko |
3871 |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
kumaneko |
1066 |
* |
6 |
kumaneko |
3871 |
* Version: 1.8.0-pre 2010/08/01 |
7 |
kumaneko |
1066 |
* |
8 |
kumaneko |
3906 |
* This program is free software; you can redistribute it and/or modify it |
9 |
|
|
* under the terms of the GNU General Public License v2 as published by the |
10 |
|
|
* Free Software Foundation. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
13 |
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
15 |
|
|
* more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License along with |
18 |
|
|
* this program; if not, write to the Free Software Foundation, Inc., |
19 |
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20 |
kumaneko |
1066 |
*/ |
21 |
|
|
#include "include.h" |
22 |
|
|
|
23 |
|
|
static const char *policy = ""; |
24 |
|
|
|
25 |
kumaneko |
2943 |
#if 0 |
26 |
kumaneko |
1726 |
static int write_policy(void) |
27 |
|
|
{ |
28 |
kumaneko |
1066 |
FILE *fp; |
29 |
|
|
char buffer[8192]; |
30 |
|
|
int domain_found = 0; |
31 |
|
|
int policy_found = 0; |
32 |
|
|
memset(buffer, 0, sizeof(buffer)); |
33 |
kumaneko |
2943 |
set_profile(0, "file::open"); |
34 |
kumaneko |
1066 |
fp = fopen(proc_policy_domain_policy, "r"); |
35 |
kumaneko |
2943 |
set_profile(3, "file::open"); |
36 |
kumaneko |
2908 |
fprintf(domain_fp, "%s\n", policy); |
37 |
kumaneko |
1066 |
if (!fp) { |
38 |
|
|
printf("%s : BUG: policy read failed\n", policy); |
39 |
|
|
return 0; |
40 |
|
|
} |
41 |
|
|
while (fgets(buffer, sizeof(buffer) - 1, fp)) { |
42 |
kumaneko |
2908 |
char *cp = strchr(buffer, '\n'); |
43 |
kumaneko |
1726 |
if (cp) |
44 |
|
|
*cp = '\0'; |
45 |
|
|
if (!strncmp(buffer, "<kernel>", 8)) |
46 |
|
|
domain_found = !strcmp(self_domain, buffer); |
47 |
kumaneko |
2908 |
if (!domain_found) |
48 |
|
|
continue; |
49 |
|
|
/* printf("<%s>\n", buffer); */ |
50 |
|
|
if (!strcmp(buffer, policy)) { |
51 |
|
|
policy_found = 1; |
52 |
|
|
break; |
53 |
kumaneko |
1066 |
} |
54 |
|
|
} |
55 |
|
|
fclose(fp); |
56 |
|
|
if (!policy_found) { |
57 |
|
|
printf("%s : BUG: policy write failed\n", policy); |
58 |
|
|
return 0; |
59 |
|
|
} |
60 |
|
|
errno = 0; |
61 |
|
|
return 1; |
62 |
|
|
} |
63 |
kumaneko |
2943 |
#endif |
64 |
kumaneko |
1066 |
|
65 |
kumaneko |
1726 |
static void show_result(int result, char should_success) |
66 |
|
|
{ |
67 |
kumaneko |
1066 |
int err = errno; |
68 |
|
|
printf("%s : ", policy); |
69 |
|
|
if (should_success) { |
70 |
kumaneko |
1726 |
if (result != EOF) |
71 |
|
|
printf("OK\n"); |
72 |
|
|
else |
73 |
|
|
printf("FAILED: %s\n", strerror(err)); |
74 |
kumaneko |
1066 |
} else { |
75 |
|
|
if (result == EOF) { |
76 |
kumaneko |
1726 |
if (err == EPERM) |
77 |
|
|
printf("OK: Permission denied.\n"); |
78 |
|
|
else |
79 |
|
|
printf("FAILED: %s\n", strerror(err)); |
80 |
kumaneko |
1066 |
} else { |
81 |
|
|
printf("BUG: didn't fail.\n"); |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
} |
85 |
|
|
|
86 |
kumaneko |
1726 |
static void create2(const char *pathname) |
87 |
|
|
{ |
88 |
kumaneko |
2943 |
set_profile(0, "file::create"); |
89 |
|
|
set_profile(0, "file::open"); |
90 |
kumaneko |
1066 |
close(creat(pathname, 0600)); |
91 |
kumaneko |
2943 |
set_profile(3, "file::create"); |
92 |
|
|
set_profile(3, "file::open"); |
93 |
kumaneko |
1148 |
errno = 0; |
94 |
kumaneko |
1066 |
} |
95 |
|
|
|
96 |
kumaneko |
1726 |
static void mkdir2(const char *pathname) |
97 |
|
|
{ |
98 |
kumaneko |
2943 |
set_profile(0, "file::mkdir"); |
99 |
kumaneko |
1066 |
mkdir(pathname, 0600); |
100 |
kumaneko |
2943 |
set_profile(3, "file::mkdir"); |
101 |
kumaneko |
1148 |
errno = 0; |
102 |
kumaneko |
1066 |
} |
103 |
|
|
|
104 |
kumaneko |
1726 |
static void unlink2(const char *pathname) |
105 |
|
|
{ |
106 |
kumaneko |
2943 |
set_profile(0, "file::unlink"); |
107 |
kumaneko |
1066 |
unlink(pathname); |
108 |
kumaneko |
2943 |
set_profile(3, "file::unlink"); |
109 |
kumaneko |
1148 |
errno = 0; |
110 |
kumaneko |
1726 |
} |
111 |
kumaneko |
1066 |
|
112 |
kumaneko |
1726 |
static void rmdir2(const char *pathname) |
113 |
|
|
{ |
114 |
kumaneko |
2943 |
set_profile(0, "file::rmdir"); |
115 |
kumaneko |
1066 |
rmdir(pathname); |
116 |
kumaneko |
2943 |
set_profile(3, "file::rmdir"); |
117 |
kumaneko |
1148 |
errno = 0; |
118 |
kumaneko |
1066 |
} |
119 |
|
|
|
120 |
kumaneko |
2563 |
static void mkfifo2(const char *pathname) |
121 |
|
|
{ |
122 |
kumaneko |
2943 |
set_profile(0, "file::mkfifo"); |
123 |
kumaneko |
2563 |
mkfifo(pathname, 0600); |
124 |
kumaneko |
2943 |
set_profile(3, "file::mkfifo"); |
125 |
kumaneko |
2563 |
errno = 0; |
126 |
|
|
} |
127 |
|
|
|
128 |
kumaneko |
1744 |
static void stage_file_test(void) |
129 |
kumaneko |
1726 |
{ |
130 |
kumaneko |
2943 |
static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE }; |
131 |
|
|
int buffer[2] = { 32768, 61000 }; |
132 |
|
|
size_t size = sizeof(buffer); |
133 |
|
|
int pipe_fd[2] = { EOF, EOF }; |
134 |
|
|
int err = 0; |
135 |
|
|
int fd; |
136 |
|
|
char pbuffer[1024]; |
137 |
|
|
struct stat sbuf; |
138 |
|
|
struct sockaddr_un addr; |
139 |
|
|
struct ifreq ifreq; |
140 |
kumaneko |
1066 |
char *filename = ""; |
141 |
kumaneko |
2943 |
set_profile(3, "file::execute"); |
142 |
|
|
set_profile(3, "file::open"); |
143 |
|
|
set_profile(3, "file::create"); |
144 |
|
|
set_profile(3, "file::unlink"); |
145 |
|
|
set_profile(3, "file::mkdir"); |
146 |
|
|
set_profile(3, "file::rmdir"); |
147 |
|
|
set_profile(3, "file::mkfifo"); |
148 |
|
|
set_profile(3, "file::mksock"); |
149 |
|
|
set_profile(3, "file::truncate"); |
150 |
|
|
set_profile(3, "file::symlink"); |
151 |
|
|
set_profile(3, "file::mkblock"); |
152 |
|
|
set_profile(3, "file::mkchar"); |
153 |
|
|
set_profile(3, "file::link"); |
154 |
|
|
set_profile(3, "file::rename"); |
155 |
|
|
set_profile(3, "file::chmod"); |
156 |
|
|
set_profile(3, "file::chown"); |
157 |
|
|
set_profile(3, "file::chgrp"); |
158 |
|
|
set_profile(3, "file::ioctl"); |
159 |
|
|
set_profile(3, "file::chroot"); |
160 |
|
|
set_profile(3, "file::mount"); |
161 |
|
|
set_profile(3, "file::umount"); |
162 |
|
|
set_profile(3, "file::pivot_root"); |
163 |
kumaneko |
2984 |
|
164 |
kumaneko |
3821 |
policy = "file read proc:/sys/net/ipv4/ip_local_port_range " |
165 |
kumaneko |
3952 |
"task.uid=0 task.gid=0"; |
166 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
167 |
|
|
show_result(sysctl(name, 3, buffer, &size, 0, 0), 1); |
168 |
|
|
write_domain_policy(policy, 1); |
169 |
|
|
show_result(sysctl(name, 3, buffer, &size, 0, 0), 0); |
170 |
kumaneko |
2984 |
|
171 |
kumaneko |
3821 |
policy = "file write proc:/sys/net/ipv4/ip_local_port_range " |
172 |
kumaneko |
3952 |
"task.euid=0 0=0 1-100=10-1000"; |
173 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
174 |
|
|
show_result(sysctl(name, 3, 0, 0, buffer, size), 1); |
175 |
|
|
write_domain_policy(policy, 1); |
176 |
|
|
show_result(sysctl(name, 3, 0, 0, buffer, size), 0); |
177 |
kumaneko |
2984 |
|
178 |
kumaneko |
3821 |
policy = "file read proc:/sys/net/ipv4/ip_local_port_range " |
179 |
kumaneko |
3952 |
"1!=10-100"; |
180 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
181 |
kumaneko |
3821 |
policy = "file write proc:/sys/net/ipv4/ip_local_port_range " |
182 |
kumaneko |
3952 |
"1!=10-100"; |
183 |
kumaneko |
3808 |
write_domain_policy(policy, 0); |
184 |
kumaneko |
2943 |
show_result(sysctl(name, 3, buffer, &size, buffer, size), 1); |
185 |
kumaneko |
3821 |
policy = "file read proc:/sys/net/ipv4/ip_local_port_range " |
186 |
kumaneko |
3952 |
"1!=10-100"; |
187 |
kumaneko |
2943 |
write_domain_policy(policy, 1); |
188 |
kumaneko |
3821 |
policy = "file write proc:/sys/net/ipv4/ip_local_port_range " |
189 |
kumaneko |
3952 |
"1!=10-100"; |
190 |
kumaneko |
3808 |
write_domain_policy(policy, 1); |
191 |
kumaneko |
2943 |
show_result(sysctl(name, 3, buffer, &size, buffer, size), 0); |
192 |
kumaneko |
2984 |
|
193 |
kumaneko |
3808 |
policy = "file read /bin/true " |
194 |
kumaneko |
3952 |
"path1.uid=0 path1.parent.uid=0 10=10-100"; |
195 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
196 |
|
|
show_result(uselib("/bin/true"), 1); |
197 |
|
|
write_domain_policy(policy, 1); |
198 |
|
|
show_result(uselib("/bin/true"), 0); |
199 |
kumaneko |
2984 |
|
200 |
kumaneko |
3952 |
policy = "file execute /bin/true task.uid!=10 path1.parent.uid=0"; |
201 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
202 |
|
|
fflush(stdout); |
203 |
|
|
fflush(stderr); |
204 |
|
|
pipe(pipe_fd); |
205 |
|
|
if (fork() == 0) { |
206 |
|
|
execl("/bin/true", "/bin/true", NULL); |
207 |
|
|
err = errno; |
208 |
|
|
write(pipe_fd[1], &err, sizeof(err)); |
209 |
|
|
_exit(0); |
210 |
kumaneko |
1066 |
} |
211 |
kumaneko |
2943 |
close(pipe_fd[1]); |
212 |
|
|
read(pipe_fd[0], &err, sizeof(err)); |
213 |
|
|
close(pipe_fd[0]); |
214 |
|
|
wait(NULL); |
215 |
|
|
errno = err; |
216 |
|
|
show_result(err ? EOF : 0, 1); |
217 |
|
|
write_domain_policy(policy, 1); |
218 |
|
|
fflush(stdout); |
219 |
|
|
fflush(stderr); |
220 |
|
|
pipe(pipe_fd); |
221 |
|
|
if (fork() == 0) { |
222 |
|
|
execl("/bin/true", "/bin/true", NULL); |
223 |
|
|
err = errno; |
224 |
|
|
write(pipe_fd[1], &err, sizeof(err)); |
225 |
|
|
_exit(0); |
226 |
|
|
} |
227 |
|
|
close(pipe_fd[1]); |
228 |
|
|
read(pipe_fd[0], &err, sizeof(err)); |
229 |
|
|
close(pipe_fd[0]); |
230 |
|
|
wait(NULL); |
231 |
|
|
errno = err; |
232 |
|
|
show_result(err ? EOF : 0, 0); |
233 |
kumaneko |
1066 |
|
234 |
kumaneko |
3952 |
policy = "file read /dev/null path1.type=char path1.dev_major=1 " |
235 |
kumaneko |
1996 |
"path1.dev_minor=3"; |
236 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
237 |
|
|
fd = open("/dev/null", O_RDONLY); |
238 |
|
|
show_result(fd, 1); |
239 |
|
|
if (fd != EOF) |
240 |
|
|
close(fd); |
241 |
|
|
write_domain_policy(policy, 1); |
242 |
|
|
fd = open("/dev/null", O_RDONLY); |
243 |
|
|
show_result(fd, 0); |
244 |
|
|
if (fd != EOF) |
245 |
|
|
close(fd); |
246 |
kumaneko |
2984 |
|
247 |
kumaneko |
3952 |
policy = "file read /dev/null path1.perm=0666"; |
248 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
249 |
|
|
fd = open("/dev/null", O_RDONLY); |
250 |
|
|
show_result(fd, 1); |
251 |
|
|
if (fd != EOF) |
252 |
|
|
close(fd); |
253 |
|
|
write_domain_policy(policy, 1); |
254 |
|
|
fd = open("/dev/null", O_RDONLY); |
255 |
|
|
show_result(fd, 0); |
256 |
|
|
if (fd != EOF) |
257 |
|
|
close(fd); |
258 |
kumaneko |
1995 |
|
259 |
kumaneko |
3952 |
policy = "file read /dev/null path1.perm!=0777"; |
260 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
261 |
|
|
fd = open("/dev/null", O_RDONLY); |
262 |
|
|
show_result(fd, 1); |
263 |
|
|
if (fd != EOF) |
264 |
|
|
close(fd); |
265 |
|
|
write_domain_policy(policy, 1); |
266 |
|
|
fd = open("/dev/null", O_RDONLY); |
267 |
|
|
show_result(fd, 0); |
268 |
|
|
if (fd != EOF) |
269 |
|
|
close(fd); |
270 |
kumaneko |
1995 |
|
271 |
kumaneko |
3952 |
policy = "file read /dev/null path1.perm=owner_read " |
272 |
kumaneko |
1996 |
"path1.perm=owner_write path1.perm!=owner_execute " |
273 |
|
|
"path1.perm=group_read path1.perm=group_write " |
274 |
|
|
"path1.perm!=group_execute path1.perm=others_read " |
275 |
|
|
"path1.perm=others_write path1.perm!=others_execute " |
276 |
|
|
"path1.perm!=setuid path1.perm!=setgid path1.perm!=sticky"; |
277 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
278 |
|
|
fd = open("/dev/null", O_RDONLY); |
279 |
|
|
show_result(fd, 1); |
280 |
|
|
if (fd != EOF) |
281 |
|
|
close(fd); |
282 |
|
|
write_domain_policy(policy, 1); |
283 |
|
|
fd = open("/dev/null", O_RDONLY); |
284 |
|
|
show_result(fd, 0); |
285 |
|
|
if (fd != EOF) |
286 |
|
|
close(fd); |
287 |
kumaneko |
1996 |
|
288 |
kumaneko |
2943 |
set_profile(3, "file::mkfifo"); |
289 |
kumaneko |
3808 |
policy = "file mkfifo /tmp/mknod_fifo_test 0644 " |
290 |
kumaneko |
3952 |
"path1.parent.perm=01777 path1.parent.perm=sticky " |
291 |
kumaneko |
1996 |
"path1.parent.uid=0 path1.parent.gid=0"; |
292 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
293 |
|
|
filename = "/tmp/mknod_fifo_test"; |
294 |
|
|
show_result(mknod(filename, S_IFIFO | 0644, 0), 1); |
295 |
|
|
write_domain_policy(policy, 1); |
296 |
|
|
unlink2(filename); |
297 |
|
|
show_result(mknod(filename, S_IFIFO | 0644, 0), 0); |
298 |
kumaneko |
1996 |
|
299 |
kumaneko |
2943 |
memset(pbuffer, 0, sizeof(pbuffer)); |
300 |
|
|
memset(&sbuf, 0, sizeof(sbuf)); |
301 |
|
|
filename = "/dev/null"; |
302 |
|
|
stat(filename, &sbuf); |
303 |
|
|
snprintf(pbuffer, sizeof(pbuffer) - 1, |
304 |
kumaneko |
3952 |
"file write %s path1.major=%u path1.minor=%u", |
305 |
kumaneko |
2943 |
filename, (unsigned int) MAJOR(sbuf.st_dev), |
306 |
|
|
(unsigned int) MINOR(sbuf.st_dev)); |
307 |
|
|
policy = pbuffer; |
308 |
|
|
write_domain_policy(policy, 0); |
309 |
|
|
fd = open(filename, O_WRONLY); |
310 |
|
|
show_result(fd, 1); |
311 |
|
|
if (fd != EOF) |
312 |
|
|
close(fd); |
313 |
|
|
write_domain_policy(policy, 1); |
314 |
|
|
fd = open(filename, O_WRONLY); |
315 |
|
|
show_result(fd, 0); |
316 |
|
|
if (fd != EOF) |
317 |
|
|
close(fd); |
318 |
kumaneko |
1996 |
|
319 |
kumaneko |
3952 |
policy = "file read/write /tmp/fifo path1.type=fifo"; |
320 |
kumaneko |
2563 |
mkfifo2("/tmp/fifo"); |
321 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
322 |
|
|
fd = open("/tmp/fifo", O_RDWR); |
323 |
|
|
show_result(fd, 1); |
324 |
|
|
if (fd != EOF) |
325 |
|
|
close(fd); |
326 |
|
|
write_domain_policy(policy, 1); |
327 |
|
|
fd = open("/tmp/fifo", O_RDWR); |
328 |
|
|
show_result(fd, 0); |
329 |
|
|
if (fd != EOF) |
330 |
|
|
close(fd); |
331 |
kumaneko |
1996 |
|
332 |
kumaneko |
3952 |
policy = "file read /dev/null path1.parent.ino=path1.parent.ino"; |
333 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
334 |
|
|
fd = open("/dev/null", O_RDONLY); |
335 |
|
|
show_result(fd, 1); |
336 |
|
|
if (fd != EOF) |
337 |
|
|
close(fd); |
338 |
|
|
write_domain_policy(policy, 1); |
339 |
|
|
fd = open("/dev/null", O_RDONLY); |
340 |
|
|
show_result(fd, 0); |
341 |
|
|
if (fd != EOF) |
342 |
|
|
close(fd); |
343 |
kumaneko |
1066 |
|
344 |
kumaneko |
3952 |
policy = "file write /dev/null path1.uid=path1.gid"; |
345 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
346 |
|
|
fd = open("/dev/null", O_WRONLY); |
347 |
|
|
show_result(fd, 1); |
348 |
|
|
if (fd != EOF) |
349 |
|
|
close(fd); |
350 |
|
|
write_domain_policy(policy, 1); |
351 |
|
|
fd = open("/dev/null", O_WRONLY); |
352 |
|
|
show_result(fd, 0); |
353 |
|
|
if (fd != EOF) |
354 |
|
|
close(fd); |
355 |
kumaneko |
1066 |
|
356 |
kumaneko |
3952 |
policy = "file read/write /dev/null task.uid=path1.parent.uid"; |
357 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
358 |
|
|
fd = open("/dev/null", O_RDWR); |
359 |
|
|
show_result(fd, 1); |
360 |
|
|
if (fd != EOF) |
361 |
|
|
close(fd); |
362 |
|
|
write_domain_policy(policy, 1); |
363 |
|
|
fd = open("/dev/null", O_RDWR); |
364 |
|
|
show_result(fd, 0); |
365 |
|
|
if (fd != EOF) |
366 |
|
|
close(fd); |
367 |
kumaneko |
1066 |
|
368 |
kumaneko |
3808 |
policy = "file create /tmp/open_test 0644 " |
369 |
kumaneko |
3952 |
"path1.parent.uid=task.uid"; |
370 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
371 |
kumaneko |
3952 |
policy = "file write /tmp/open_test path1.parent.uid=0"; |
372 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
373 |
|
|
fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); |
374 |
|
|
show_result(fd, 1); |
375 |
|
|
if (fd != EOF) |
376 |
|
|
close(fd); |
377 |
|
|
unlink2("/tmp/open_test"); |
378 |
|
|
write_domain_policy(policy, 1); |
379 |
|
|
fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); |
380 |
|
|
show_result(fd, 0); |
381 |
|
|
if (fd != EOF) |
382 |
|
|
close(fd); |
383 |
|
|
unlink2("/tmp/open_test"); |
384 |
kumaneko |
1066 |
|
385 |
kumaneko |
3808 |
policy = "file create /tmp/open_test 0644 " |
386 |
kumaneko |
3952 |
"path1.parent.uid=task.uid"; |
387 |
kumaneko |
2943 |
write_domain_policy(policy, 1); |
388 |
|
|
|
389 |
kumaneko |
3952 |
policy = "file write /tmp/open_test task.uid=0 path1.ino!=0"; |
390 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
391 |
kumaneko |
3952 |
policy = "file create /tmp/open_test 0644 0=0"; |
392 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
393 |
|
|
fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); |
394 |
|
|
show_result(fd, 1); |
395 |
|
|
if (fd != EOF) |
396 |
|
|
close(fd); |
397 |
|
|
unlink2("/tmp/open_test"); |
398 |
|
|
write_domain_policy(policy, 1); |
399 |
|
|
fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644); |
400 |
|
|
show_result(fd, 0); |
401 |
|
|
if (fd != EOF) |
402 |
|
|
close(fd); |
403 |
|
|
unlink2("/tmp/open_test"); |
404 |
kumaneko |
3952 |
policy = "file write /tmp/open_test task.uid=0 path1.ino!=0"; |
405 |
kumaneko |
2943 |
write_domain_policy(policy, 1); |
406 |
kumaneko |
1066 |
|
407 |
|
|
filename = "/tmp/truncate_test"; |
408 |
|
|
create2(filename); |
409 |
|
|
|
410 |
kumaneko |
3952 |
policy = "file truncate /tmp/truncate_test task.uid=path1.uid"; |
411 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
412 |
kumaneko |
3952 |
policy = "file write /tmp/truncate_test 1!=100-1000000"; |
413 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
414 |
|
|
fd = open(filename, O_WRONLY | O_TRUNC); |
415 |
|
|
show_result(fd, 1); |
416 |
|
|
if (fd != EOF) |
417 |
|
|
close(fd); |
418 |
|
|
write_domain_policy(policy, 1); |
419 |
|
|
fd = open(filename, O_WRONLY | O_TRUNC); |
420 |
|
|
show_result(fd, 0); |
421 |
|
|
if (fd != EOF) |
422 |
|
|
close(fd); |
423 |
kumaneko |
3808 |
policy = "file truncate /tmp/truncate_test " |
424 |
kumaneko |
3952 |
"task.uid=path1.uid"; |
425 |
kumaneko |
2943 |
write_domain_policy(policy, 1); |
426 |
kumaneko |
1066 |
|
427 |
kumaneko |
3808 |
policy = "file write /tmp/truncate_test"; |
428 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
429 |
kumaneko |
3808 |
policy = "file truncate /tmp/truncate_test"; |
430 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
431 |
|
|
fd = open(filename, O_WRONLY | O_TRUNC); |
432 |
|
|
show_result(fd, 1); |
433 |
|
|
if (fd != EOF) |
434 |
|
|
close(fd); |
435 |
|
|
write_domain_policy(policy, 1); |
436 |
|
|
fd = open(filename, O_WRONLY | O_TRUNC); |
437 |
|
|
show_result(fd, 0); |
438 |
|
|
if (fd != EOF) |
439 |
|
|
close(fd); |
440 |
kumaneko |
3808 |
policy = "file write /tmp/truncate_test"; |
441 |
kumaneko |
2943 |
write_domain_policy(policy, 1); |
442 |
kumaneko |
1726 |
|
443 |
kumaneko |
3808 |
policy = "file truncate /tmp/truncate_test"; |
444 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
445 |
|
|
show_result(truncate(filename, 0), 1); |
446 |
|
|
write_domain_policy(policy, 1); |
447 |
|
|
show_result(truncate(filename, 0), 0); |
448 |
kumaneko |
1066 |
|
449 |
kumaneko |
3808 |
policy = "file truncate /tmp/truncate_test"; |
450 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
451 |
|
|
set_profile(0, "file::open"); |
452 |
|
|
fd = open(filename, O_WRONLY); |
453 |
|
|
set_profile(3, "file::open"); |
454 |
|
|
show_result(ftruncate(fd, 0), 1); |
455 |
|
|
write_domain_policy(policy, 1); |
456 |
|
|
show_result(ftruncate(fd, 0), 0); |
457 |
|
|
if (fd != EOF) |
458 |
|
|
close(fd); |
459 |
kumaneko |
1726 |
|
460 |
kumaneko |
1066 |
unlink2(filename); |
461 |
kumaneko |
1726 |
|
462 |
kumaneko |
3808 |
policy = "file create /tmp/mknod_reg_test 0644"; |
463 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
464 |
|
|
filename = "/tmp/mknod_reg_test"; |
465 |
|
|
show_result(mknod(filename, S_IFREG | 0644, 0), 1); |
466 |
|
|
write_domain_policy(policy, 1); |
467 |
|
|
unlink2(filename); |
468 |
|
|
show_result(mknod(filename, S_IFREG | 0644, 0), 0); |
469 |
kumaneko |
1066 |
|
470 |
kumaneko |
3808 |
policy = "file mkchar /tmp/mknod_chr_test 0644 1 3"; |
471 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
472 |
|
|
filename = "/tmp/mknod_chr_test"; |
473 |
|
|
show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 1); |
474 |
|
|
write_domain_policy(policy, 1); |
475 |
|
|
unlink2(filename); |
476 |
|
|
show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 0); |
477 |
kumaneko |
1066 |
|
478 |
kumaneko |
3808 |
policy = "file mkblock /tmp/mknod_blk_test 0644 1 0"; |
479 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
480 |
|
|
filename = "/tmp/mknod_blk_test"; |
481 |
|
|
show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 1); |
482 |
|
|
write_domain_policy(policy, 1); |
483 |
|
|
unlink2(filename); |
484 |
|
|
show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 0); |
485 |
kumaneko |
1066 |
|
486 |
kumaneko |
3808 |
policy = "file mkfifo /tmp/mknod_fifo_test 0644"; |
487 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
488 |
|
|
filename = "/tmp/mknod_fifo_test"; |
489 |
|
|
show_result(mknod(filename, S_IFIFO | 0644, 0), 1); |
490 |
|
|
write_domain_policy(policy, 1); |
491 |
|
|
unlink2(filename); |
492 |
|
|
show_result(mknod(filename, S_IFIFO | 0644, 0), 0); |
493 |
kumaneko |
1066 |
|
494 |
kumaneko |
3808 |
policy = "file mksock /tmp/mknod_sock_test 0644"; |
495 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
496 |
|
|
filename = "/tmp/mknod_sock_test"; |
497 |
|
|
show_result(mknod(filename, S_IFSOCK | 0644, 0), 1); |
498 |
|
|
write_domain_policy(policy, 1); |
499 |
|
|
unlink2(filename); |
500 |
|
|
show_result(mknod(filename, S_IFSOCK | 0644, 0), 0); |
501 |
kumaneko |
1726 |
|
502 |
kumaneko |
3808 |
policy = "file mkdir /tmp/mkdir_test/ 0600"; |
503 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
504 |
|
|
filename = "/tmp/mkdir_test"; |
505 |
|
|
show_result(mkdir(filename, 0600), 1); |
506 |
|
|
write_domain_policy(policy, 1); |
507 |
|
|
rmdir2(filename); |
508 |
|
|
show_result(mkdir(filename, 0600), 0); |
509 |
kumaneko |
1726 |
|
510 |
kumaneko |
3808 |
policy = "file rmdir /tmp/rmdir_test/"; |
511 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
512 |
|
|
filename = "/tmp/rmdir_test"; |
513 |
|
|
mkdir2(filename); |
514 |
|
|
show_result(rmdir(filename), 1); |
515 |
|
|
write_domain_policy(policy, 1); |
516 |
|
|
mkdir2(filename); |
517 |
|
|
show_result(rmdir(filename), 0); |
518 |
|
|
rmdir2(filename); |
519 |
kumaneko |
1726 |
|
520 |
kumaneko |
3808 |
policy = "file unlink /tmp/unlink_test"; |
521 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
522 |
|
|
filename = "/tmp/unlink_test"; |
523 |
|
|
create2(filename); |
524 |
|
|
show_result(unlink(filename), 1); |
525 |
|
|
write_domain_policy(policy, 1); |
526 |
|
|
create2(filename); |
527 |
|
|
show_result(unlink(filename), 0); |
528 |
|
|
unlink2(filename); |
529 |
kumaneko |
1726 |
|
530 |
kumaneko |
3808 |
policy = "file symlink /tmp/symlink_source_test"; |
531 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
532 |
|
|
filename = "/tmp/symlink_source_test"; |
533 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 1); |
534 |
|
|
write_domain_policy(policy, 1); |
535 |
|
|
unlink2(filename); |
536 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 0); |
537 |
kumaneko |
1726 |
|
538 |
kumaneko |
3808 |
policy = "file symlink /tmp/symlink_source_test " |
539 |
kumaneko |
3952 |
"symlink.target=\"/tmp/symlink_\\*_test\""; |
540 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
541 |
|
|
filename = "/tmp/symlink_source_test"; |
542 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 1); |
543 |
|
|
write_domain_policy(policy, 1); |
544 |
|
|
unlink2(filename); |
545 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 0); |
546 |
kumaneko |
2563 |
|
547 |
kumaneko |
3808 |
policy = "file symlink /tmp/symlink_source_test " |
548 |
kumaneko |
3952 |
"task.uid=0 symlink.target=\"/tmp/symlink_\\*_test\""; |
549 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
550 |
|
|
filename = "/tmp/symlink_source_test"; |
551 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 1); |
552 |
|
|
write_domain_policy(policy, 1); |
553 |
|
|
unlink2(filename); |
554 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 0); |
555 |
kumaneko |
2563 |
|
556 |
kumaneko |
3808 |
policy = "file symlink /tmp/symlink_source_test " |
557 |
kumaneko |
3952 |
"symlink.target!=\"\\*\""; |
558 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
559 |
|
|
filename = "/tmp/symlink_source_test"; |
560 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 1); |
561 |
|
|
write_domain_policy(policy, 1); |
562 |
|
|
unlink2(filename); |
563 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 0); |
564 |
kumaneko |
2563 |
|
565 |
kumaneko |
3808 |
policy = "file symlink /tmp/symlink_source_test " |
566 |
kumaneko |
3952 |
"symlink.target!=\"/tmp/symlink_\\*_test\""; |
567 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
568 |
|
|
filename = "/tmp/symlink_source_test"; |
569 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 0); |
570 |
|
|
write_domain_policy(policy, 1); |
571 |
|
|
unlink2(filename); |
572 |
|
|
show_result(symlink("/tmp/symlink_dest_test", filename), 0); |
573 |
kumaneko |
2563 |
|
574 |
kumaneko |
3808 |
policy = "file link /tmp/link_source_test /tmp/link_dest_test"; |
575 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
576 |
|
|
filename = "/tmp/link_source_test"; |
577 |
|
|
create2(filename); |
578 |
|
|
show_result(link(filename, "/tmp/link_dest_test"), 1); |
579 |
|
|
write_domain_policy(policy, 1); |
580 |
|
|
unlink2("/tmp/link_dest_test"); |
581 |
|
|
show_result(link(filename, "/tmp/link_dest_test"), 0); |
582 |
|
|
unlink2(filename); |
583 |
kumaneko |
1066 |
|
584 |
kumaneko |
3808 |
policy = "file rename /tmp/rename_source_test /tmp/rename_dest_test"; |
585 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
586 |
|
|
filename = "/tmp/rename_source_test"; |
587 |
|
|
create2(filename); |
588 |
|
|
show_result(rename(filename, "/tmp/rename_dest_test"), 1); |
589 |
|
|
write_domain_policy(policy, 1); |
590 |
|
|
unlink2("/tmp/rename_dest_test"); |
591 |
|
|
create2(filename); |
592 |
|
|
show_result(rename(filename, "/tmp/rename_dest_test"), 0); |
593 |
|
|
unlink2(filename); |
594 |
kumaneko |
1066 |
|
595 |
kumaneko |
3808 |
policy = "file mksock /tmp/socket_test 0755"; |
596 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
597 |
|
|
filename = "/tmp/socket_test"; |
598 |
|
|
memset(&addr, 0, sizeof(addr)); |
599 |
|
|
addr.sun_family = AF_UNIX; |
600 |
|
|
strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1); |
601 |
|
|
fd = socket(AF_UNIX, SOCK_STREAM, 0); |
602 |
|
|
show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)), |
603 |
|
|
1); |
604 |
|
|
if (fd != EOF) |
605 |
|
|
close(fd); |
606 |
|
|
write_domain_policy(policy, 1); |
607 |
|
|
unlink2(filename); |
608 |
|
|
fd = socket(AF_UNIX, SOCK_STREAM, 0); |
609 |
|
|
show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)), |
610 |
|
|
0); |
611 |
|
|
if (fd != EOF) |
612 |
|
|
close(fd); |
613 |
kumaneko |
1067 |
unlink2(filename); |
614 |
kumaneko |
2301 |
|
615 |
kumaneko |
3808 |
policy = "file ioctl socket:[family=2:type=2:protocol=17] " |
616 |
kumaneko |
3952 |
"35122-35124 task.uid=0"; |
617 |
kumaneko |
2943 |
write_domain_policy(policy, 0); |
618 |
|
|
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
619 |
|
|
memset(&ifreq, 0, sizeof(ifreq)); |
620 |
|
|
snprintf(ifreq.ifr_name, sizeof(ifreq.ifr_name) - 1, |
621 |
|
|
"lo"); |
622 |
|
|
show_result(ioctl(fd, 35123, &ifreq), 1); |
623 |
|
|
write_domain_policy(policy, 1); |
624 |
kumaneko |
3808 |
policy = "file ioctl " |
625 |
kumaneko |
2943 |
"socket:[family=2:type=2:protocol=17] 0-35122"; |
626 |
|
|
write_domain_policy(policy, 0); |
627 |
|
|
show_result(ioctl(fd, 35123, &ifreq), 0); |
628 |
|
|
write_domain_policy(policy, 1); |
629 |
|
|
if (fd != EOF) |
630 |
|
|
close(fd); |
631 |
kumaneko |
1066 |
} |
632 |
|
|
|
633 |
kumaneko |
1726 |
int main(int argc, char *argv[]) |
634 |
|
|
{ |
635 |
kumaneko |
1744 |
ccs_test_init(); |
636 |
kumaneko |
2908 |
fprintf(domain_fp, "%s /bin/true\n", self_domain); |
637 |
|
|
fprintf(domain_fp, "use_profile 255\n"); |
638 |
|
|
fprintf(domain_fp, "select pid=%u\n", pid); |
639 |
kumaneko |
3961 |
fprintf(profile_fp, "PREFERENCE::audit={ max_reject_log=1024 }\n"); |
640 |
kumaneko |
1744 |
stage_file_test(); |
641 |
kumaneko |
2908 |
fprintf(domain_fp, "use_profile 0\n"); |
642 |
kumaneko |
1744 |
clear_status(); |
643 |
kumaneko |
1066 |
return 0; |
644 |
|
|
} |