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

Subversion リポジトリの参照

Annotation of /trunk/1.6.x/ccs-tools/ccstools/kernel_test/tomoyo_new_file_test.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2194 - (hide annotations) (download) (as text)
Tue Feb 24 04:19:38 2009 UTC (15 years, 3 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 18559 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 2086 * Version: 1.6.7-pre 2009/02/02
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 1744 static void stage_file_test(void)
130 kumaneko 1726 {
131 kumaneko 1066 char *filename = "";
132 kumaneko 1726 policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range "
133     "if task.uid=0 task.gid=0";
134 kumaneko 2194 if (!has_cond)
135     policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range";
136 kumaneko 1066 if (write_policy()) {
137 kumaneko 1726 static int name[] = { CTL_NET, NET_IPV4,
138     NET_IPV4_LOCAL_PORT_RANGE };
139 kumaneko 1066 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 kumaneko 1726 policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range "
146     "if task.euid=0 0=0 1-100=10-1000";
147 kumaneko 2194 if (!has_cond)
148     policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range";
149 kumaneko 1066 if (write_policy()) {
150 kumaneko 1726 static int name[] = { CTL_NET, NET_IPV4,
151     NET_IPV4_LOCAL_PORT_RANGE };
152 kumaneko 1066 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 kumaneko 1726 policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range "
159     "if 1!=10-100";
160 kumaneko 2194 if (!has_cond)
161     policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range";
162 kumaneko 1066 if (write_policy()) {
163 kumaneko 1726 static int name[] = { CTL_NET, NET_IPV4,
164     NET_IPV4_LOCAL_PORT_RANGE };
165 kumaneko 1066 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 kumaneko 1726 policy = "allow_read /bin/true "
173     "if path1.uid=0 path1.parent.uid=0 10=10-100";
174 kumaneko 2194 if (!has_cond)
175     policy = "allow_read /bin/true";
176 kumaneko 1066 if (write_policy()) {
177     show_result(uselib("/bin/true"), 1);
178     delete_policy();
179     show_result(uselib("/bin/true"), 0);
180     }
181    
182 kumaneko 1664 policy = "allow_execute /bin/true if task.uid!=10 path1.parent.uid=0";
183 kumaneko 2194 if (!has_cond)
184     policy = "allow_execute /bin/true";
185 kumaneko 1066 if (write_policy()) {
186     int pipe_fd[2] = { EOF, EOF };
187     int err = 0;
188 kumaneko 1726 fflush(stdout);
189     fflush(stderr);
190 kumaneko 1066 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 kumaneko 1726 fflush(stdout);
205     fflush(stderr);
206 kumaneko 1066 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 kumaneko 1996 policy = "allow_read /dev/null if path1.type=char path1.dev_major=1 "
222     "path1.dev_minor=3";
223 kumaneko 2194 if (!has_cond)
224     policy = "allow_read /dev/null";
225 kumaneko 1995 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 kumaneko 2194 if (!has_cond)
239     policy = "allow_read /dev/null";
240 kumaneko 1995 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 kumaneko 1996 policy = "allow_read /dev/null if path1.perm!=0777";
253 kumaneko 2194 if (!has_cond)
254     policy = "allow_read /dev/null";
255 kumaneko 1995 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 kumaneko 1996 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 kumaneko 2194 if (!has_cond)
274     policy = "allow_read /dev/null";
275 kumaneko 1996 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 kumaneko 2194 if (!has_cond)
291     policy = "allow_mkfifo /tmp/mknod_fifo_test";
292 kumaneko 1996 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 kumaneko 2194 if (!has_cond)
312     snprintf(buffer, sizeof(buffer) - 1,
313     "allow_write %s", filename);
314 kumaneko 1996 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 kumaneko 1995 policy = "allow_read /dev/initctl if path1.type=fifo";
329 kumaneko 2194 if (!has_cond)
330     policy = "allow_read /dev/initctl";
331 kumaneko 1995 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 kumaneko 1996
343 kumaneko 1664 policy = "allow_read /dev/null if path1.parent.ino=path1.parent.ino";
344 kumaneko 2194 if (!has_cond)
345     policy = "allow_read /dev/null";
346 kumaneko 1066 if (write_policy()) {
347     int fd = open("/dev/null", O_RDONLY);
348     show_result(fd, 1);
349 kumaneko 1726 if (fd != EOF)
350     close(fd);
351 kumaneko 1066 delete_policy();
352     fd = open("/dev/null", O_RDONLY);
353     show_result(fd, 0);
354 kumaneko 1726 if (fd != EOF)
355     close(fd);
356 kumaneko 1066 }
357    
358 kumaneko 1664 policy = "allow_write /dev/null if path1.uid=path1.gid";
359 kumaneko 2194 if (!has_cond)
360     policy = "allow_write /dev/null";
361 kumaneko 1066 if (write_policy()) {
362     int fd = open("/dev/null", O_WRONLY);
363     show_result(fd, 1);
364 kumaneko 1726 if (fd != EOF)
365     close(fd);
366 kumaneko 1066 delete_policy();
367     fd = open("/dev/null", O_WRONLY);
368     show_result(fd, 0);
369 kumaneko 1726 if (fd != EOF)
370     close(fd);
371 kumaneko 1066 }
372    
373 kumaneko 1664 policy = "allow_read/write /dev/null if task.uid=path1.parent.uid";
374 kumaneko 2194 if (!has_cond)
375     policy = "allow_read/write /dev/null if task.uid=path1.parent.uid";
376 kumaneko 1066 if (write_policy()) {
377     int fd = open("/dev/null", O_RDWR);
378     show_result(fd, 1);
379 kumaneko 1726 if (fd != EOF)
380     close(fd);
381 kumaneko 1066 delete_policy();
382     fd = open("/dev/null", O_RDWR);
383     show_result(fd, 0);
384 kumaneko 1726 if (fd != EOF)
385     close(fd);
386 kumaneko 1066 }
387    
388 kumaneko 1664 policy = "allow_create /tmp/open_test if path1.parent.uid=task.uid";
389 kumaneko 2194 if (!has_cond)
390     policy = "allow_create /tmp/open_test";
391 kumaneko 1066 if (write_policy()) {
392 kumaneko 1664 policy = "allow_write /tmp/open_test if path1.parent.uid=0";
393 kumaneko 2194 if (!has_cond)
394     policy = "allow_write /tmp/open_test";
395 kumaneko 1066 if (write_policy()) {
396 kumaneko 1726 int fd = open("/tmp/open_test",
397     O_WRONLY | O_CREAT | O_EXCL, 0666);
398 kumaneko 1066 show_result(fd, 1);
399 kumaneko 1726 if (fd != EOF)
400     close(fd);
401 kumaneko 1066 unlink2("/tmp/open_test");
402     delete_policy();
403 kumaneko 1726 fd = open("/tmp/open_test",
404     O_WRONLY | O_CREAT | O_EXCL, 0666);
405 kumaneko 1066 show_result(fd, 0);
406 kumaneko 1726 if (fd != EOF)
407     close(fd);
408 kumaneko 1066 unlink2("/tmp/open_test");
409     }
410 kumaneko 1726 policy = "allow_create /tmp/open_test "
411 kumaneko 2194 "if path1.parent.uid=task.uid";
412     if (!has_cond)
413     policy = "allow_create /tmp/open_test";
414 kumaneko 1066 delete_policy();
415     }
416    
417 kumaneko 1664 policy = "allow_write /tmp/open_test if task.uid=0 path1.ino!=0";
418 kumaneko 1066 if (write_policy()) {
419 kumaneko 1664 policy = "allow_create /tmp/open_test if 0=0";
420 kumaneko 1066 if (write_policy()) {
421 kumaneko 1726 int fd = open("/tmp/open_test",
422     O_WRONLY | O_CREAT | O_EXCL, 0666);
423 kumaneko 1066 show_result(fd, 1);
424 kumaneko 1726 if (fd != EOF)
425     close(fd);
426 kumaneko 1066 unlink2("/tmp/open_test");
427     delete_policy();
428 kumaneko 1726 fd = open("/tmp/open_test",
429     O_WRONLY | O_CREAT | O_EXCL, 0666);
430 kumaneko 1066 show_result(fd, 0);
431 kumaneko 1726 if (fd != EOF)
432     close(fd);
433 kumaneko 1066 unlink2("/tmp/open_test");
434     }
435 kumaneko 1726 policy = "allow_write /tmp/open_test "
436 kumaneko 2194 "if task.uid=0 path1.ino!=0";
437     if (!has_cond)
438     policy = "allow_write /tmp/open_test";
439 kumaneko 1066 delete_policy();
440     }
441    
442     filename = "/tmp/truncate_test";
443     create2(filename);
444    
445 kumaneko 1664 policy = "allow_truncate /tmp/truncate_test if task.uid=path1.uid";
446 kumaneko 1066 if (write_policy()) {
447 kumaneko 1664 policy = "allow_write /tmp/truncate_test if 1!=100-1000000";
448 kumaneko 1066 if (write_policy()) {
449     int fd = open(filename, O_WRONLY | O_TRUNC);
450     show_result(fd, 1);
451 kumaneko 1726 if (fd != EOF)
452     close(fd);
453 kumaneko 1066 delete_policy();
454     fd = open(filename, O_WRONLY | O_TRUNC);
455     show_result(fd, 0);
456 kumaneko 1726 if (fd != EOF)
457     close(fd);
458 kumaneko 1066 }
459 kumaneko 1726 policy = "allow_truncate /tmp/truncate_test "
460     "if task.uid=path1.uid";
461 kumaneko 1066 delete_policy();
462     }
463    
464     policy = "allow_write /tmp/truncate_test";
465     if (write_policy()) {
466     policy = "allow_truncate /tmp/truncate_test";
467     if (write_policy()) {
468     int fd = open(filename, O_WRONLY | O_TRUNC);
469     show_result(fd, 1);
470 kumaneko 1726 if (fd != EOF)
471     close(fd);
472 kumaneko 1066 delete_policy();
473     fd = open(filename, O_WRONLY | O_TRUNC);
474     show_result(fd, 0);
475 kumaneko 1726 if (fd != EOF)
476     close(fd);
477 kumaneko 1066 }
478 kumaneko 2194 policy = "allow_write /tmp/truncate_test";
479 kumaneko 1066 delete_policy();
480     }
481 kumaneko 1726
482 kumaneko 1066 policy = "allow_truncate /tmp/truncate_test";
483     if (write_policy()) {
484     show_result(truncate(filename, 0), 1);
485     delete_policy();
486     show_result(truncate(filename, 0), 0);
487     }
488    
489     policy = "allow_truncate /tmp/truncate_test";
490     if (write_policy()) {
491     int fd;
492     const char *cp = "255-MAC_FOR_FILE=disabled\n";
493     write(profile_fd, cp, strlen(cp));
494     fd = open(filename, O_WRONLY);
495     cp = "255-MAC_FOR_FILE=enforcing\n";
496     write(profile_fd, cp, strlen(cp));
497     show_result(ftruncate(fd, 0), 1);
498     delete_policy();
499     show_result(ftruncate(fd, 0), 0);
500 kumaneko 1726 if (fd != EOF)
501     close(fd);
502 kumaneko 1066 }
503 kumaneko 1726
504 kumaneko 1066 unlink2(filename);
505 kumaneko 1726
506 kumaneko 1066 policy = "allow_create /tmp/mknod_reg_test";
507     if (write_policy()) {
508     filename = "/tmp/mknod_reg_test";
509     show_result(mknod(filename, S_IFREG, 0), 1);
510     delete_policy();
511     unlink2(filename);
512     show_result(mknod(filename, S_IFREG, 0), 0);
513     }
514    
515     policy = "allow_mkchar /tmp/mknod_chr_test";
516     if (write_policy()) {
517     filename = "/tmp/mknod_chr_test";
518     show_result(mknod(filename, S_IFCHR, MKDEV(1, 3)), 1);
519     delete_policy();
520     unlink2(filename);
521     show_result(mknod(filename, S_IFCHR, MKDEV(1, 3)), 0);
522     }
523    
524     policy = "allow_mkblock /tmp/mknod_blk_test";
525     if (write_policy()) {
526     filename = "/tmp/mknod_blk_test";
527     show_result(mknod(filename, S_IFBLK, MKDEV(1, 0)), 1);
528     delete_policy();
529     unlink2(filename);
530     show_result(mknod(filename, S_IFBLK, MKDEV(1, 0)), 0);
531     }
532    
533     policy = "allow_mkfifo /tmp/mknod_fifo_test";
534     if (write_policy()) {
535     filename = "/tmp/mknod_fifo_test";
536     show_result(mknod(filename, S_IFIFO, 0), 1);
537     delete_policy();
538     unlink2(filename);
539     show_result(mknod(filename, S_IFIFO, 0), 0);
540     }
541    
542     policy = "allow_mksock /tmp/mknod_sock_test";
543     if (write_policy()) {
544     filename = "/tmp/mknod_sock_test";
545     show_result(mknod(filename, S_IFSOCK, 0), 1);
546     delete_policy();
547     unlink2(filename);
548     show_result(mknod(filename, S_IFSOCK, 0), 0);
549     }
550 kumaneko 1726
551 kumaneko 1066 policy = "allow_mkdir /tmp/mkdir_test/";
552     if (write_policy()) {
553     filename = "/tmp/mkdir_test";
554     show_result(mkdir(filename, 0600), 1);
555     delete_policy();
556     rmdir2(filename);
557     show_result(mkdir(filename, 0600), 0);
558     }
559 kumaneko 1726
560 kumaneko 1066 policy = "allow_rmdir /tmp/rmdir_test/";
561     if (write_policy()) {
562     filename = "/tmp/rmdir_test";
563     mkdir2(filename);
564     show_result(rmdir(filename), 1);
565     delete_policy();
566     mkdir2(filename);
567     show_result(rmdir(filename), 0);
568     rmdir2(filename);
569     }
570 kumaneko 1726
571 kumaneko 1066 policy = "allow_unlink /tmp/unlink_test";
572     if (write_policy()) {
573     filename = "/tmp/unlink_test";
574     create2(filename);
575     show_result(unlink(filename), 1);
576     delete_policy();
577     create2(filename);
578     show_result(unlink(filename), 0);
579     unlink2(filename);
580     }
581 kumaneko 1726
582 kumaneko 1066 policy = "allow_symlink /tmp/symlink_source_test";
583     if (write_policy()) {
584     filename = "/tmp/symlink_source_test";
585     show_result(symlink("/tmp/symlink_dest_test", filename), 1);
586     delete_policy();
587     unlink2(filename);
588     show_result(symlink("/tmp/symlink_dest_test", filename), 0);
589     }
590 kumaneko 1726
591 kumaneko 1066 policy = "allow_link /tmp/link_source_test /tmp/link_dest_test";
592     if (write_policy()) {
593     filename = "/tmp/link_source_test";
594     create2(filename);
595     show_result(link(filename, "/tmp/link_dest_test"), 1);
596     delete_policy();
597     unlink2("/tmp/link_dest_test");
598     show_result(link(filename, "/tmp/link_dest_test"), 0);
599     unlink2(filename);
600     }
601    
602     policy = "allow_rename /tmp/rename_source_test /tmp/rename_dest_test";
603     if (write_policy()) {
604     filename = "/tmp/rename_source_test";
605     create2(filename);
606     show_result(rename(filename, "/tmp/rename_dest_test"), 1);
607     delete_policy();
608     unlink2("/tmp/rename_dest_test");
609     create2(filename);
610     show_result(rename(filename, "/tmp/rename_dest_test"), 0);
611     unlink2(filename);
612     }
613    
614     policy = "allow_mksock /tmp/socket_test";
615     if (write_policy()) {
616     struct sockaddr_un addr;
617     int fd;
618     filename = "/tmp/socket_test";
619     memset(&addr, 0, sizeof(addr));
620     addr.sun_family = AF_UNIX;
621     strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1);
622     fd = socket(AF_UNIX, SOCK_STREAM, 0);
623 kumaneko 1726 show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)),
624     1);
625     if (fd != EOF)
626     close(fd);
627 kumaneko 1066 delete_policy();
628     unlink2(filename);
629     fd = socket(AF_UNIX, SOCK_STREAM, 0);
630 kumaneko 1726 show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)),
631     0);
632     if (fd != EOF)
633     close(fd);
634 kumaneko 1066 }
635 kumaneko 1067
636     filename = "/tmp/rewrite_test";
637     create2(filename);
638     policy = "allow_read/write /tmp/rewrite_test";
639     if (write_policy()) {
640     char *cp = "deny_rewrite /tmp/rewrite_test\n";
641     write(exception_fd, cp, strlen(cp));
642     policy = "allow_truncate /tmp/rewrite_test";
643     if (write_policy()) {
644     int fd;
645    
646     fd = open(filename, O_RDONLY);
647     show_result(fd, 1);
648 kumaneko 1726 if (fd != EOF)
649     close(fd);
650    
651 kumaneko 1067 fd = open(filename, O_WRONLY | O_APPEND);
652     show_result(fd, 1);
653 kumaneko 1726 if (fd != EOF)
654     close(fd);
655    
656 kumaneko 1067 fd = open(filename, O_WRONLY);
657     show_result(fd, 0);
658 kumaneko 1726 if (fd != EOF)
659     close(fd);
660    
661 kumaneko 1067 fd = open(filename, O_WRONLY | O_TRUNC);
662     show_result(fd, 0);
663 kumaneko 1726 if (fd != EOF)
664     close(fd);
665    
666 kumaneko 1067 fd = open(filename, O_WRONLY | O_TRUNC | O_APPEND);
667     show_result(fd, 0);
668 kumaneko 1726 if (fd != EOF)
669     close(fd);
670    
671 kumaneko 1067 show_result(truncate(filename, 0), 0);
672 kumaneko 1726
673 kumaneko 1067 cp = "255-MAC_FOR_FILE=disabled\n";
674     write(profile_fd, cp, strlen(cp));
675     fd = open(filename, O_WRONLY | O_APPEND);
676     cp = "255-MAC_FOR_FILE=enforcing\n";
677     write(profile_fd, cp, strlen(cp));
678     show_result(ftruncate(fd, 0), 0);
679    
680 kumaneko 1726 show_result(fcntl(fd, F_SETFL,
681     fcntl(fd, F_GETFL) & ~O_APPEND), 0);
682     if (fd != EOF)
683     close(fd);
684    
685 kumaneko 1067 delete_policy();
686     }
687     policy = "allow_read/write /tmp/rewrite_test";
688     delete_policy();
689     cp = "delete deny_rewrite /tmp/rewrite_test\n";
690     write(exception_fd, cp, strlen(cp));
691     }
692     unlink2(filename);
693 kumaneko 1066 }
694    
695 kumaneko 1726 int main(int argc, char *argv[])
696     {
697 kumaneko 1066 char *cp;
698 kumaneko 1744 ccs_test_init();
699 kumaneko 1066 domain_fd = open(proc_policy_domain_policy, O_WRONLY);
700 kumaneko 1067 exception_fd = open(proc_policy_exception_policy, O_WRONLY);
701 kumaneko 1066 {
702     int self_fd = open(proc_policy_self_domain, O_RDONLY);
703     memset(self_domain, 0, sizeof(self_domain));
704     read(self_fd, self_domain, sizeof(self_domain) - 1);
705     close(self_fd);
706     write(domain_fd, self_domain, strlen(self_domain));
707     cp = " /bin/true\n";
708     write(domain_fd, cp, strlen(cp));
709     write(domain_fd, self_domain, strlen(self_domain));
710     write(domain_fd, "\n", 1);
711     cp = "use_profile 255\n";
712     write(domain_fd, cp, strlen(cp));
713     }
714 kumaneko 2194 has_cond = !access("/proc/ccs/version", F_OK);
715 kumaneko 1066 cp = "255-MAX_REJECT_LOG=1024\n";
716     write(profile_fd, cp, strlen(cp));
717 kumaneko 1744 stage_file_test();
718 kumaneko 1066 cp = "use_profile 0\n";
719     write(domain_fd, cp, strlen(cp));
720 kumaneko 1744 clear_status();
721 kumaneko 1066 return 0;
722     }

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