オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Contents of /branches/kernel_test/ccs_new_file_test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2313 - (show annotations) (download) (as text)
Wed Mar 25 04:27:33 2009 UTC (15 years, 2 months ago) by kumaneko
Original Path: trunk/1.6.x/ccs-tools/ccstools/kernel_test/tomoyo_new_file_test.c
File MIME type: text/x-csrc
File size: 19652 byte(s)


1 /*
2 * tomoyo_file_test.c
3 *
4 * Testing program for fs/tomoyo_file.c
5 *
6 * Copyright (C) 2005-2009 NTT DATA CORPORATION
7 *
8 * Version: 1.6.7-rc 2009/03/04
9 *
10 */
11 #include "include.h"
12
13 static int domain_fd = EOF;
14 static int exception_fd = EOF;
15 static const char *policy = "";
16 static char self_domain[4096] = "";
17 static _Bool has_cond = 1;
18
19 static int write_policy(void)
20 {
21 FILE *fp;
22 char buffer[8192];
23 char *cp;
24 int domain_found = 0;
25 int policy_found = 0;
26 memset(buffer, 0, sizeof(buffer));
27 cp = "255-MAC_FOR_FILE=disabled\n";
28 write(profile_fd, cp, strlen(cp));
29 fp = fopen(proc_policy_domain_policy, "r");
30 cp = "255-MAC_FOR_FILE=enforcing\n";
31 write(profile_fd, cp, strlen(cp));
32 write(domain_fd, policy, strlen(policy));
33 write(domain_fd, "\n", 1);
34 if (!fp) {
35 printf("%s : BUG: policy read failed\n", policy);
36 return 0;
37 }
38 while (fgets(buffer, sizeof(buffer) - 1, fp)) {
39 cp = strchr(buffer, '\n');
40 if (cp)
41 *cp = '\0';
42 if (!strncmp(buffer, "<kernel>", 8))
43 domain_found = !strcmp(self_domain, buffer);
44 if (domain_found) {
45 /* printf("<%s>\n", buffer); */
46 if (!strcmp(buffer, policy)) {
47 policy_found = 1;
48 break;
49 }
50 }
51 }
52 fclose(fp);
53 if (!policy_found) {
54 printf("%s : BUG: policy write failed\n", policy);
55 return 0;
56 }
57 errno = 0;
58 return 1;
59 }
60
61 static void delete_policy(void)
62 {
63 write(domain_fd, "delete ", 7);
64 write(domain_fd, policy, strlen(policy));
65 write(domain_fd, "\n", 1);
66 }
67
68 static void show_result(int result, char should_success)
69 {
70 int err = errno;
71 printf("%s : ", policy);
72 if (should_success) {
73 if (result != EOF)
74 printf("OK\n");
75 else
76 printf("FAILED: %s\n", strerror(err));
77 } else {
78 if (result == EOF) {
79 if (err == EPERM)
80 printf("OK: Permission denied.\n");
81 else
82 printf("FAILED: %s\n", strerror(err));
83 } else {
84 printf("BUG: didn't fail.\n");
85 }
86 }
87 }
88
89 static void create2(const char *pathname)
90 {
91 const char *cp = "255-MAC_FOR_FILE=disabled\n";
92 write(profile_fd, cp, strlen(cp));
93 close(creat(pathname, 0600));
94 cp = "255-MAC_FOR_FILE=enforcing\n";
95 write(profile_fd, cp, strlen(cp));
96 errno = 0;
97 }
98
99 static void mkdir2(const char *pathname)
100 {
101 const char *cp = "255-MAC_FOR_FILE=disabled\n";
102 write(profile_fd, cp, strlen(cp));
103 mkdir(pathname, 0600);
104 cp = "255-MAC_FOR_FILE=enforcing\n";
105 write(profile_fd, cp, strlen(cp));
106 errno = 0;
107 }
108
109 static void unlink2(const char *pathname)
110 {
111 const char *cp = "255-MAC_FOR_FILE=disabled\n";
112 write(profile_fd, cp, strlen(cp));
113 unlink(pathname);
114 cp = "255-MAC_FOR_FILE=enforcing\n";
115 write(profile_fd, cp, strlen(cp));
116 errno = 0;
117 }
118
119 static void rmdir2(const char *pathname)
120 {
121 const char *cp = "255-MAC_FOR_FILE=disabled\n";
122 write(profile_fd, cp, strlen(cp));
123 rmdir(pathname);
124 cp = "255-MAC_FOR_FILE=enforcing\n";
125 write(profile_fd, cp, strlen(cp));
126 errno = 0;
127 }
128
129 static void stage_file_test(void)
130 {
131 char *filename = "";
132 policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range "
133 "if task.uid=0 task.gid=0";
134 if (!has_cond)
135 policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range";
136 if (write_policy()) {
137 static int name[] = { CTL_NET, NET_IPV4,
138 NET_IPV4_LOCAL_PORT_RANGE };
139 int buffer[2] = { 32768, 61000 };
140 size_t size = sizeof(buffer);
141 show_result(sysctl(name, 3, buffer, &size, 0, 0), 1);
142 delete_policy();
143 show_result(sysctl(name, 3, buffer, &size, 0, 0), 0);
144 }
145 policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range "
146 "if task.euid=0 0=0 1-100=10-1000";
147 if (!has_cond)
148 policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range";
149 if (write_policy()) {
150 static int name[] = { CTL_NET, NET_IPV4,
151 NET_IPV4_LOCAL_PORT_RANGE };
152 int buffer[2] = { 32768, 61000 };
153 size_t size = sizeof(buffer);
154 show_result(sysctl(name, 3, 0, 0, buffer, size), 1);
155 delete_policy();
156 show_result(sysctl(name, 3, 0, 0, buffer, size), 0);
157 }
158 policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range "
159 "if 1!=10-100";
160 if (!has_cond)
161 policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range";
162 if (write_policy()) {
163 static int name[] = { CTL_NET, NET_IPV4,
164 NET_IPV4_LOCAL_PORT_RANGE };
165 int buffer[2] = { 32768, 61000 };
166 size_t size = sizeof(buffer);
167 show_result(sysctl(name, 3, buffer, &size, buffer, size), 1);
168 delete_policy();
169 show_result(sysctl(name, 3, buffer, &size, buffer, size), 0);
170 }
171
172 policy = "allow_read /bin/true "
173 "if path1.uid=0 path1.parent.uid=0 10=10-100";
174 if (!has_cond)
175 policy = "allow_read /bin/true";
176 if (write_policy()) {
177 show_result(uselib("/bin/true"), 1);
178 delete_policy();
179 show_result(uselib("/bin/true"), 0);
180 }
181
182 policy = "allow_execute /bin/true if task.uid!=10 path1.parent.uid=0";
183 if (!has_cond)
184 policy = "allow_execute /bin/true";
185 if (write_policy()) {
186 int pipe_fd[2] = { EOF, EOF };
187 int err = 0;
188 fflush(stdout);
189 fflush(stderr);
190 pipe(pipe_fd);
191 if (fork() == 0) {
192 execl("/bin/true", "/bin/true", NULL);
193 err = errno;
194 write(pipe_fd[1], &err, sizeof(err));
195 _exit(0);
196 }
197 close(pipe_fd[1]);
198 read(pipe_fd[0], &err, sizeof(err));
199 close(pipe_fd[0]);
200 wait(NULL);
201 errno = err;
202 show_result(err ? EOF : 0, 1);
203 delete_policy();
204 fflush(stdout);
205 fflush(stderr);
206 pipe(pipe_fd);
207 if (fork() == 0) {
208 execl("/bin/true", "/bin/true", NULL);
209 err = errno;
210 write(pipe_fd[1], &err, sizeof(err));
211 _exit(0);
212 }
213 close(pipe_fd[1]);
214 read(pipe_fd[0], &err, sizeof(err));
215 close(pipe_fd[0]);
216 wait(NULL);
217 errno = err;
218 show_result(err ? EOF : 0, 0);
219 }
220
221 policy = "allow_read /dev/null if path1.type=char path1.dev_major=1 "
222 "path1.dev_minor=3";
223 if (!has_cond)
224 policy = "allow_read /dev/null";
225 if (write_policy()) {
226 int fd = open("/dev/null", O_RDONLY);
227 show_result(fd, 1);
228 if (fd != EOF)
229 close(fd);
230 delete_policy();
231 fd = open("/dev/null", O_RDONLY);
232 show_result(fd, 0);
233 if (fd != EOF)
234 close(fd);
235 }
236
237 policy = "allow_read /dev/null if path1.perm=0666";
238 if (!has_cond)
239 policy = "allow_read /dev/null";
240 if (write_policy()) {
241 int fd = open("/dev/null", O_RDONLY);
242 show_result(fd, 1);
243 if (fd != EOF)
244 close(fd);
245 delete_policy();
246 fd = open("/dev/null", O_RDONLY);
247 show_result(fd, 0);
248 if (fd != EOF)
249 close(fd);
250 }
251
252 policy = "allow_read /dev/null if path1.perm!=0777";
253 if (!has_cond)
254 policy = "allow_read /dev/null";
255 if (write_policy()) {
256 int fd = open("/dev/null", O_RDONLY);
257 show_result(fd, 1);
258 if (fd != EOF)
259 close(fd);
260 delete_policy();
261 fd = open("/dev/null", O_RDONLY);
262 show_result(fd, 0);
263 if (fd != EOF)
264 close(fd);
265 }
266
267 policy = "allow_read /dev/null if path1.perm=owner_read "
268 "path1.perm=owner_write path1.perm!=owner_execute "
269 "path1.perm=group_read path1.perm=group_write "
270 "path1.perm!=group_execute path1.perm=others_read "
271 "path1.perm=others_write path1.perm!=others_execute "
272 "path1.perm!=setuid path1.perm!=setgid path1.perm!=sticky";
273 if (!has_cond)
274 policy = "allow_read /dev/null";
275 if (write_policy()) {
276 int fd = open("/dev/null", O_RDONLY);
277 show_result(fd, 1);
278 if (fd != EOF)
279 close(fd);
280 delete_policy();
281 fd = open("/dev/null", O_RDONLY);
282 show_result(fd, 0);
283 if (fd != EOF)
284 close(fd);
285 }
286
287 policy = "allow_mkfifo /tmp/mknod_fifo_test "
288 "if path1.parent.perm=01777 path1.parent.perm=sticky "
289 "path1.parent.uid=0 path1.parent.gid=0";
290 if (!has_cond)
291 policy = "allow_mkfifo /tmp/mknod_fifo_test";
292 if (write_policy()) {
293 filename = "/tmp/mknod_fifo_test";
294 show_result(mknod(filename, S_IFIFO, 0), 1);
295 delete_policy();
296 unlink2(filename);
297 show_result(mknod(filename, S_IFIFO, 0), 0);
298 }
299
300 {
301 char buffer[1024];
302 struct stat sbuf;
303 memset(buffer, 0, sizeof(buffer));
304 memset(&sbuf, 0, sizeof(sbuf));
305 filename = "/dev/null";
306 stat(filename, &sbuf);
307 snprintf(buffer, sizeof(buffer) - 1,
308 "allow_write %s if path1.major=%u path1.minor=%u",
309 filename, (unsigned int) MAJOR(sbuf.st_dev),
310 (unsigned int) MINOR(sbuf.st_dev));
311 if (!has_cond)
312 snprintf(buffer, sizeof(buffer) - 1,
313 "allow_write %s", filename);
314 policy = buffer;
315 if (write_policy()) {
316 int fd = open(filename, O_WRONLY);
317 show_result(fd, 1);
318 if (fd != EOF)
319 close(fd);
320 delete_policy();
321 fd = open(filename, O_WRONLY);
322 show_result(fd, 0);
323 if (fd != EOF)
324 close(fd);
325 }
326 }
327
328 policy = "allow_read /dev/initctl if path1.type=fifo";
329 if (!has_cond)
330 policy = "allow_read /dev/initctl";
331 if (write_policy()) {
332 int fd = open("/dev/initctl", O_RDONLY);
333 show_result(fd, 1);
334 if (fd != EOF)
335 close(fd);
336 delete_policy();
337 fd = open("/dev/initctl", O_RDONLY);
338 show_result(fd, 0);
339 if (fd != EOF)
340 close(fd);
341 }
342
343 policy = "allow_read /dev/null if path1.parent.ino=path1.parent.ino";
344 if (!has_cond)
345 policy = "allow_read /dev/null";
346 if (write_policy()) {
347 int fd = open("/dev/null", O_RDONLY);
348 show_result(fd, 1);
349 if (fd != EOF)
350 close(fd);
351 delete_policy();
352 fd = open("/dev/null", O_RDONLY);
353 show_result(fd, 0);
354 if (fd != EOF)
355 close(fd);
356 }
357
358 policy = "allow_write /dev/null if path1.uid=path1.gid";
359 if (!has_cond)
360 policy = "allow_write /dev/null";
361 if (write_policy()) {
362 int fd = open("/dev/null", O_WRONLY);
363 show_result(fd, 1);
364 if (fd != EOF)
365 close(fd);
366 delete_policy();
367 fd = open("/dev/null", O_WRONLY);
368 show_result(fd, 0);
369 if (fd != EOF)
370 close(fd);
371 }
372
373 policy = "allow_read/write /dev/null if task.uid=path1.parent.uid";
374 if (!has_cond)
375 policy = "allow_read/write /dev/null";
376 if (write_policy()) {
377 int fd = open("/dev/null", O_RDWR);
378 show_result(fd, 1);
379 if (fd != EOF)
380 close(fd);
381 delete_policy();
382 fd = open("/dev/null", O_RDWR);
383 show_result(fd, 0);
384 if (fd != EOF)
385 close(fd);
386 }
387
388 policy = "allow_create /tmp/open_test if path1.parent.uid=task.uid";
389 if (!has_cond)
390 policy = "allow_create /tmp/open_test";
391 if (write_policy()) {
392 policy = "allow_write /tmp/open_test if path1.parent.uid=0";
393 if (!has_cond)
394 policy = "allow_write /tmp/open_test";
395 if (write_policy()) {
396 int fd = open("/tmp/open_test",
397 O_WRONLY | O_CREAT | O_EXCL, 0666);
398 show_result(fd, 1);
399 if (fd != EOF)
400 close(fd);
401 unlink2("/tmp/open_test");
402 delete_policy();
403 fd = open("/tmp/open_test",
404 O_WRONLY | O_CREAT | O_EXCL, 0666);
405 show_result(fd, 0);
406 if (fd != EOF)
407 close(fd);
408 unlink2("/tmp/open_test");
409 }
410 policy = "allow_create /tmp/open_test "
411 "if path1.parent.uid=task.uid";
412 if (!has_cond)
413 policy = "allow_create /tmp/open_test";
414 delete_policy();
415 }
416
417 policy = "allow_write /tmp/open_test if task.uid=0 path1.ino!=0";
418 if (!has_cond)
419 policy = "allow_write /tmp/open_test";
420 if (write_policy()) {
421 policy = "allow_create /tmp/open_test if 0=0";
422 if (!has_cond)
423 policy = "allow_create /tmp/open_test";
424 if (write_policy()) {
425 int fd = open("/tmp/open_test",
426 O_WRONLY | O_CREAT | O_EXCL, 0666);
427 show_result(fd, 1);
428 if (fd != EOF)
429 close(fd);
430 unlink2("/tmp/open_test");
431 delete_policy();
432 fd = open("/tmp/open_test",
433 O_WRONLY | O_CREAT | O_EXCL, 0666);
434 show_result(fd, 0);
435 if (fd != EOF)
436 close(fd);
437 unlink2("/tmp/open_test");
438 }
439 policy = "allow_write /tmp/open_test "
440 "if task.uid=0 path1.ino!=0";
441 if (!has_cond)
442 policy = "allow_write /tmp/open_test";
443 delete_policy();
444 }
445
446 filename = "/tmp/truncate_test";
447 create2(filename);
448
449 policy = "allow_truncate /tmp/truncate_test if task.uid=path1.uid";
450 if (!has_cond)
451 policy = "allow_truncate /tmp/truncate_test";
452 if (write_policy()) {
453 policy = "allow_write /tmp/truncate_test if 1!=100-1000000";
454 if (!has_cond)
455 policy = "allow_write /tmp/truncate_test";
456 if (write_policy()) {
457 int fd = open(filename, O_WRONLY | O_TRUNC);
458 show_result(fd, 1);
459 if (fd != EOF)
460 close(fd);
461 delete_policy();
462 fd = open(filename, O_WRONLY | O_TRUNC);
463 show_result(fd, 0);
464 if (fd != EOF)
465 close(fd);
466 }
467 policy = "allow_truncate /tmp/truncate_test "
468 "if task.uid=path1.uid";
469 if (!has_cond)
470 policy = "allow_truncate /tmp/truncate_test";
471 delete_policy();
472 }
473
474 policy = "allow_write /tmp/truncate_test";
475 if (write_policy()) {
476 policy = "allow_truncate /tmp/truncate_test";
477 if (write_policy()) {
478 int fd = open(filename, O_WRONLY | O_TRUNC);
479 show_result(fd, 1);
480 if (fd != EOF)
481 close(fd);
482 delete_policy();
483 fd = open(filename, O_WRONLY | O_TRUNC);
484 show_result(fd, 0);
485 if (fd != EOF)
486 close(fd);
487 }
488 policy = "allow_write /tmp/truncate_test";
489 delete_policy();
490 }
491
492 policy = "allow_truncate /tmp/truncate_test";
493 if (write_policy()) {
494 show_result(truncate(filename, 0), 1);
495 delete_policy();
496 show_result(truncate(filename, 0), 0);
497 }
498
499 policy = "allow_truncate /tmp/truncate_test";
500 if (write_policy()) {
501 int fd;
502 const char *cp = "255-MAC_FOR_FILE=disabled\n";
503 write(profile_fd, cp, strlen(cp));
504 fd = open(filename, O_WRONLY);
505 cp = "255-MAC_FOR_FILE=enforcing\n";
506 write(profile_fd, cp, strlen(cp));
507 show_result(ftruncate(fd, 0), 1);
508 delete_policy();
509 show_result(ftruncate(fd, 0), 0);
510 if (fd != EOF)
511 close(fd);
512 }
513
514 unlink2(filename);
515
516 policy = "allow_create /tmp/mknod_reg_test";
517 if (write_policy()) {
518 filename = "/tmp/mknod_reg_test";
519 show_result(mknod(filename, S_IFREG, 0), 1);
520 delete_policy();
521 unlink2(filename);
522 show_result(mknod(filename, S_IFREG, 0), 0);
523 }
524
525 policy = "allow_mkchar /tmp/mknod_chr_test";
526 if (write_policy()) {
527 filename = "/tmp/mknod_chr_test";
528 show_result(mknod(filename, S_IFCHR, MKDEV(1, 3)), 1);
529 delete_policy();
530 unlink2(filename);
531 show_result(mknod(filename, S_IFCHR, MKDEV(1, 3)), 0);
532 }
533
534 policy = "allow_mkblock /tmp/mknod_blk_test";
535 if (write_policy()) {
536 filename = "/tmp/mknod_blk_test";
537 show_result(mknod(filename, S_IFBLK, MKDEV(1, 0)), 1);
538 delete_policy();
539 unlink2(filename);
540 show_result(mknod(filename, S_IFBLK, MKDEV(1, 0)), 0);
541 }
542
543 policy = "allow_mkfifo /tmp/mknod_fifo_test";
544 if (write_policy()) {
545 filename = "/tmp/mknod_fifo_test";
546 show_result(mknod(filename, S_IFIFO, 0), 1);
547 delete_policy();
548 unlink2(filename);
549 show_result(mknod(filename, S_IFIFO, 0), 0);
550 }
551
552 policy = "allow_mksock /tmp/mknod_sock_test";
553 if (write_policy()) {
554 filename = "/tmp/mknod_sock_test";
555 show_result(mknod(filename, S_IFSOCK, 0), 1);
556 delete_policy();
557 unlink2(filename);
558 show_result(mknod(filename, S_IFSOCK, 0), 0);
559 }
560
561 policy = "allow_mkdir /tmp/mkdir_test/";
562 if (write_policy()) {
563 filename = "/tmp/mkdir_test";
564 show_result(mkdir(filename, 0600), 1);
565 delete_policy();
566 rmdir2(filename);
567 show_result(mkdir(filename, 0600), 0);
568 }
569
570 policy = "allow_rmdir /tmp/rmdir_test/";
571 if (write_policy()) {
572 filename = "/tmp/rmdir_test";
573 mkdir2(filename);
574 show_result(rmdir(filename), 1);
575 delete_policy();
576 mkdir2(filename);
577 show_result(rmdir(filename), 0);
578 rmdir2(filename);
579 }
580
581 policy = "allow_unlink /tmp/unlink_test";
582 if (write_policy()) {
583 filename = "/tmp/unlink_test";
584 create2(filename);
585 show_result(unlink(filename), 1);
586 delete_policy();
587 create2(filename);
588 show_result(unlink(filename), 0);
589 unlink2(filename);
590 }
591
592 policy = "allow_symlink /tmp/symlink_source_test";
593 if (write_policy()) {
594 filename = "/tmp/symlink_source_test";
595 show_result(symlink("/tmp/symlink_dest_test", filename), 1);
596 delete_policy();
597 unlink2(filename);
598 show_result(symlink("/tmp/symlink_dest_test", filename), 0);
599 }
600
601 policy = "allow_link /tmp/link_source_test /tmp/link_dest_test";
602 if (write_policy()) {
603 filename = "/tmp/link_source_test";
604 create2(filename);
605 show_result(link(filename, "/tmp/link_dest_test"), 1);
606 delete_policy();
607 unlink2("/tmp/link_dest_test");
608 show_result(link(filename, "/tmp/link_dest_test"), 0);
609 unlink2(filename);
610 }
611
612 policy = "allow_rename /tmp/rename_source_test /tmp/rename_dest_test";
613 if (write_policy()) {
614 filename = "/tmp/rename_source_test";
615 create2(filename);
616 show_result(rename(filename, "/tmp/rename_dest_test"), 1);
617 delete_policy();
618 unlink2("/tmp/rename_dest_test");
619 create2(filename);
620 show_result(rename(filename, "/tmp/rename_dest_test"), 0);
621 unlink2(filename);
622 }
623
624 policy = "allow_mksock /tmp/socket_test";
625 if (write_policy()) {
626 struct sockaddr_un addr;
627 int fd;
628 filename = "/tmp/socket_test";
629 memset(&addr, 0, sizeof(addr));
630 addr.sun_family = AF_UNIX;
631 strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1);
632 fd = socket(AF_UNIX, SOCK_STREAM, 0);
633 show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)),
634 1);
635 if (fd != EOF)
636 close(fd);
637 delete_policy();
638 unlink2(filename);
639 fd = socket(AF_UNIX, SOCK_STREAM, 0);
640 show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)),
641 0);
642 if (fd != EOF)
643 close(fd);
644 }
645
646 filename = "/tmp/rewrite_test";
647 create2(filename);
648 policy = "allow_read/write /tmp/rewrite_test";
649 if (write_policy()) {
650 char *cp = "deny_rewrite /tmp/rewrite_test\n";
651 write(exception_fd, cp, strlen(cp));
652 policy = "allow_truncate /tmp/rewrite_test";
653 if (write_policy()) {
654 int fd;
655
656 fd = open(filename, O_RDONLY);
657 show_result(fd, 1);
658 if (fd != EOF)
659 close(fd);
660
661 fd = open(filename, O_WRONLY | O_APPEND);
662 show_result(fd, 1);
663 if (fd != EOF)
664 close(fd);
665
666 fd = open(filename, O_WRONLY);
667 show_result(fd, 0);
668 if (fd != EOF)
669 close(fd);
670
671 fd = open(filename, O_WRONLY | O_TRUNC);
672 show_result(fd, 0);
673 if (fd != EOF)
674 close(fd);
675
676 fd = open(filename, O_WRONLY | O_TRUNC | O_APPEND);
677 show_result(fd, 0);
678 if (fd != EOF)
679 close(fd);
680
681 show_result(truncate(filename, 0), 0);
682
683 cp = "255-MAC_FOR_FILE=disabled\n";
684 write(profile_fd, cp, strlen(cp));
685 fd = open(filename, O_WRONLY | O_APPEND);
686 cp = "255-MAC_FOR_FILE=enforcing\n";
687 write(profile_fd, cp, strlen(cp));
688 show_result(ftruncate(fd, 0), 0);
689
690 show_result(fcntl(fd, F_SETFL,
691 fcntl(fd, F_GETFL) & ~O_APPEND), 0);
692 if (fd != EOF)
693 close(fd);
694
695 delete_policy();
696 }
697 policy = "allow_read/write /tmp/rewrite_test";
698 delete_policy();
699 cp = "delete deny_rewrite /tmp/rewrite_test\n";
700 write(exception_fd, cp, strlen(cp));
701 }
702 unlink2(filename);
703
704 if (has_cond) {
705 const char *cp = "255-MAC_FOR_IOCTL=enforcing\n";
706 write(profile_fd, cp, strlen(cp));
707 policy = "allow_ioctl socket:[family=2:type=2:protocol=17] "
708 "35122-35124 if task.uid=0";
709 if (write_policy()) {
710 struct ifreq ifreq;
711 int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
712 memset(&ifreq, 0, sizeof(ifreq));
713 snprintf(ifreq.ifr_name, sizeof(ifreq.ifr_name) - 1, "lo");
714 show_result(ioctl(fd, 35123, &ifreq), 1);
715 delete_policy();
716 policy = "allow_ioctl socket:[family=2:type=2:protocol=17] "
717 "0-35122";
718 if (write_policy()) {
719 show_result(ioctl(fd, 35123, &ifreq), 0);
720 delete_policy();
721 }
722 if (fd != EOF)
723 close(fd);
724 }
725 cp = "255-MAC_FOR_IOCTL=disabled\n";
726 write(profile_fd, cp, strlen(cp));
727 }
728 }
729
730 int main(int argc, char *argv[])
731 {
732 char *cp;
733 ccs_test_init();
734 domain_fd = open(proc_policy_domain_policy, O_WRONLY);
735 if (domain_fd == EOF && errno == ENOENT)
736 return 1;
737 exception_fd = open(proc_policy_exception_policy, O_WRONLY);
738 {
739 int self_fd = open(proc_policy_self_domain, O_RDONLY);
740 memset(self_domain, 0, sizeof(self_domain));
741 read(self_fd, self_domain, sizeof(self_domain) - 1);
742 close(self_fd);
743 write(domain_fd, self_domain, strlen(self_domain));
744 cp = " /bin/true\n";
745 write(domain_fd, cp, strlen(cp));
746 write(domain_fd, self_domain, strlen(self_domain));
747 write(domain_fd, "\n", 1);
748 cp = "use_profile 255\n";
749 write(domain_fd, cp, strlen(cp));
750 }
751 has_cond = !access("/proc/ccs/version", F_OK);
752 cp = "255-MAX_REJECT_LOG=1024\n";
753 write(profile_fd, cp, strlen(cp));
754 stage_file_test();
755 cp = "use_profile 0\n";
756 write(domain_fd, cp, strlen(cp));
757 clear_status();
758 return 0;
759 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26