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

Subversion リポジトリの参照

Annotation of /branches/ccs-tools/ccstools/kernel_test/ccs_new_file_test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2706 - (hide annotations) (download) (as text)
Tue Jun 30 05:06:54 2009 UTC (14 years, 10 months ago) by kumaneko
Original Path: branches/kernel_test/ccs_new_file_test.c
File MIME type: text/x-csrc
File size: 21408 byte(s)


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

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