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

Subversion リポジトリの参照

Diff of /trunk/2.4.x/tomoyo-tools/kernel_test/tomoyo_new_file_test.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/ccs-tools/ccstools/kernel_test/ccs_new_file_test.c revision 3751 by kumaneko, Fri Jun 11 02:26:44 2010 UTC trunk/1.8.x/ccs-tools/ccstools/kernel_test/ccs_new_file_test.c revision 4627 by kumaneko, Mon Feb 14 06:57:32 2011 UTC
# Line 1  Line 1 
1  /*  /*
2   * ccs_new_file_test.c   * ccs_new_file_test.c
3   *   *
4   * Copyright (C) 2005-2009  NTT DATA CORPORATION   * Copyright (C) 2005-2011  NTT DATA CORPORATION
5   *   *
6   * Version: 1.7.1   2009/11/11   * Version: 1.8.0+   2011/02/14
7   *   *
8     * 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   */   */
21  #include "include.h"  #include "include.h"
22    
23  static const char *policy = "";  static const char *policy = "";
24    
 #if 0  
 static int write_policy(void)  
 {  
         FILE *fp;  
         char buffer[8192];  
         int domain_found = 0;  
         int policy_found = 0;  
         memset(buffer, 0, sizeof(buffer));  
         set_profile(0, "file::open");  
         fp = fopen(proc_policy_domain_policy, "r");  
         set_profile(3, "file::open");  
         fprintf(domain_fp, "%s\n", policy);  
         if (!fp) {  
                 printf("%s : BUG: policy read failed\n", policy);  
                 return 0;  
         }  
         while (fgets(buffer, sizeof(buffer) - 1, fp)) {  
                 char *cp = strchr(buffer, '\n');  
                 if (cp)  
                         *cp = '\0';  
                 if (!strncmp(buffer, "<kernel>", 8))  
                         domain_found = !strcmp(self_domain, buffer);  
                 if (!domain_found)  
                         continue;  
                 /* printf("<%s>\n", buffer); */  
                 if (!strcmp(buffer, policy)) {  
                         policy_found = 1;  
                         break;  
                 }  
         }  
         fclose(fp);  
         if (!policy_found) {  
                 printf("%s : BUG: policy write failed\n", policy);  
                 return 0;  
         }  
         errno = 0;  
         return 1;  
 }  
 #endif  
   
25  static void show_result(int result, char should_success)  static void show_result(int result, char should_success)
26  {  {
27          int err = errno;          int err = errno;
# Line 126  static void stage_file_test(void) Line 98  static void stage_file_test(void)
98          struct sockaddr_un addr;          struct sockaddr_un addr;
99          struct ifreq ifreq;          struct ifreq ifreq;
100          char *filename = "";          char *filename = "";
101            int ret_ignored;
102          set_profile(3, "file::execute");          set_profile(3, "file::execute");
103          set_profile(3, "file::open");          set_profile(3, "file::open");
104          set_profile(3, "file::create");          set_profile(3, "file::create");
# Line 136  static void stage_file_test(void) Line 109  static void stage_file_test(void)
109          set_profile(3, "file::mksock");          set_profile(3, "file::mksock");
110          set_profile(3, "file::truncate");          set_profile(3, "file::truncate");
111          set_profile(3, "file::symlink");          set_profile(3, "file::symlink");
         set_profile(3, "file::rewrite");  
112          set_profile(3, "file::mkblock");          set_profile(3, "file::mkblock");
113          set_profile(3, "file::mkchar");          set_profile(3, "file::mkchar");
114          set_profile(3, "file::link");          set_profile(3, "file::link");
# Line 147  static void stage_file_test(void) Line 119  static void stage_file_test(void)
119          set_profile(3, "file::ioctl");          set_profile(3, "file::ioctl");
120          set_profile(3, "file::chroot");          set_profile(3, "file::chroot");
121          set_profile(3, "file::mount");          set_profile(3, "file::mount");
122          set_profile(3, "file::umount");          set_profile(3, "file::unmount");
123          set_profile(3, "file::pivot_root");          set_profile(3, "file::pivot_root");
124    
125          policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range "          policy = "file read proc:/sys/net/ipv4/ip_local_port_range "
126                  "if task.uid=0 task.gid=0";                  "task.uid=0 task.gid=0";
127          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
128          show_result(sysctl(name, 3, buffer, &size, 0, 0), 1);          show_result(sysctl(name, 3, buffer, &size, 0, 0), 1);
129          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
130          show_result(sysctl(name, 3, buffer, &size, 0, 0), 0);          show_result(sysctl(name, 3, buffer, &size, 0, 0), 0);
131    
132          policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range "          policy = "file write proc:/sys/net/ipv4/ip_local_port_range "
133                  "if task.euid=0 0=0 1-100=10-1000";                  "task.euid=0 0=0 1-100=10-1000";
134          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
135          show_result(sysctl(name, 3, 0, 0, buffer, size), 1);          show_result(sysctl(name, 3, 0, 0, buffer, size), 1);
136          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
137          show_result(sysctl(name, 3, 0, 0, buffer, size), 0);          show_result(sysctl(name, 3, 0, 0, buffer, size), 0);
138    
139          policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range "          policy = "file read proc:/sys/net/ipv4/ip_local_port_range "
140                  "if 1!=10-100";                  "1!=10-100";
141            write_domain_policy(policy, 0);
142            policy = "file write proc:/sys/net/ipv4/ip_local_port_range "
143                    "1!=10-100";
144          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
145          show_result(sysctl(name, 3, buffer, &size, buffer, size), 1);          show_result(sysctl(name, 3, buffer, &size, buffer, size), 1);
146            policy = "file read proc:/sys/net/ipv4/ip_local_port_range "
147                    "1!=10-100";
148            write_domain_policy(policy, 1);
149            policy = "file write proc:/sys/net/ipv4/ip_local_port_range "
150                    "1!=10-100";
151          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
152          show_result(sysctl(name, 3, buffer, &size, buffer, size), 0);          show_result(sysctl(name, 3, buffer, &size, buffer, size), 0);
153    
154          policy = "allow_read /bin/true "          policy = "file read /bin/true "
155                  "if path1.uid=0 path1.parent.uid=0 10=10-100";                  "path1.uid=0 path1.parent.uid=0 10=10-100";
156          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
157          show_result(uselib("/bin/true"), 1);          show_result(uselib("/bin/true"), 1);
158          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
159          show_result(uselib("/bin/true"), 0);          show_result(uselib("/bin/true"), 0);
160    
161          policy = "allow_execute /bin/true if task.uid!=10 path1.parent.uid=0";          policy = "file execute /bin/true task.uid!=10 path1.parent.uid=0";
162          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
163          fflush(stdout);          fflush(stdout);
164          fflush(stderr);          fflush(stderr);
165          pipe(pipe_fd);          ret_ignored = pipe(pipe_fd);
166          if (fork() == 0) {          if (fork() == 0) {
167                  execl("/bin/true", "/bin/true", NULL);                  execl("/bin/true", "/bin/true", NULL);
168                  err = errno;                  err = errno;
169                  write(pipe_fd[1], &err, sizeof(err));                  ret_ignored = write(pipe_fd[1], &err, sizeof(err));
170                  _exit(0);                  _exit(0);
171          }          }
172          close(pipe_fd[1]);          close(pipe_fd[1]);
173          read(pipe_fd[0], &err, sizeof(err));          ret_ignored = read(pipe_fd[0], &err, sizeof(err));
174          close(pipe_fd[0]);          close(pipe_fd[0]);
175          wait(NULL);          wait(NULL);
176          errno = err;          errno = err;
# Line 198  static void stage_file_test(void) Line 178  static void stage_file_test(void)
178          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
179          fflush(stdout);          fflush(stdout);
180          fflush(stderr);          fflush(stderr);
181          pipe(pipe_fd);          ret_ignored = pipe(pipe_fd);
182          if (fork() == 0) {          if (fork() == 0) {
183                  execl("/bin/true", "/bin/true", NULL);                  execl("/bin/true", "/bin/true", NULL);
184                  err = errno;                  err = errno;
185                  write(pipe_fd[1], &err, sizeof(err));                  ret_ignored = write(pipe_fd[1], &err, sizeof(err));
186                  _exit(0);                  _exit(0);
187          }          }
188          close(pipe_fd[1]);          close(pipe_fd[1]);
189          read(pipe_fd[0], &err, sizeof(err));          ret_ignored = read(pipe_fd[0], &err, sizeof(err));
190          close(pipe_fd[0]);          close(pipe_fd[0]);
191          wait(NULL);          wait(NULL);
192          errno = err;          errno = err;
193          show_result(err ? EOF : 0, 0);          show_result(err ? EOF : 0, 0);
194    
195          policy = "allow_read /dev/null if path1.type=char path1.dev_major=1 "          policy = "file read /dev/null path1.type=char path1.dev_major=1 "
196                  "path1.dev_minor=3";                  "path1.dev_minor=3";
197          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
198          fd = open("/dev/null", O_RDONLY);          fd = open("/dev/null", O_RDONLY);
# Line 225  static void stage_file_test(void) Line 205  static void stage_file_test(void)
205          if (fd != EOF)          if (fd != EOF)
206                  close(fd);                  close(fd);
207    
208          policy = "allow_read /dev/null if path1.perm=0666";          policy = "file read /dev/null path1.perm=0666";
209          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
210          fd = open("/dev/null", O_RDONLY);          fd = open("/dev/null", O_RDONLY);
211          show_result(fd, 1);          show_result(fd, 1);
# Line 237  static void stage_file_test(void) Line 217  static void stage_file_test(void)
217          if (fd != EOF)          if (fd != EOF)
218                  close(fd);                  close(fd);
219    
220          policy = "allow_read /dev/null if path1.perm!=0777";          policy = "file read /dev/null path1.perm!=0777";
221          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
222          fd = open("/dev/null", O_RDONLY);          fd = open("/dev/null", O_RDONLY);
223          show_result(fd, 1);          show_result(fd, 1);
# Line 249  static void stage_file_test(void) Line 229  static void stage_file_test(void)
229          if (fd != EOF)          if (fd != EOF)
230                  close(fd);                  close(fd);
231    
232          policy = "allow_read /dev/null if path1.perm=owner_read "          policy = "file read /dev/null path1.perm=owner_read "
233                  "path1.perm=owner_write path1.perm!=owner_execute "                  "path1.perm=owner_write path1.perm!=owner_execute "
234                  "path1.perm=group_read path1.perm=group_write "                  "path1.perm=group_read path1.perm=group_write "
235                  "path1.perm!=group_execute path1.perm=others_read "                  "path1.perm!=group_execute path1.perm=others_read "
# Line 267  static void stage_file_test(void) Line 247  static void stage_file_test(void)
247                  close(fd);                  close(fd);
248    
249          set_profile(3, "file::mkfifo");          set_profile(3, "file::mkfifo");
250          policy = "allow_mkfifo /tmp/mknod_fifo_test 0644 "          policy = "file mkfifo /tmp/mknod_fifo_test 0644 "
251                  "if path1.parent.perm=01777 path1.parent.perm=sticky "                  "path1.parent.perm=01777 path1.parent.perm=sticky "
252                  "path1.parent.uid=0 path1.parent.gid=0";                  "path1.parent.uid=0 path1.parent.gid=0";
253          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
254          filename = "/tmp/mknod_fifo_test";          filename = "/tmp/mknod_fifo_test";
# Line 282  static void stage_file_test(void) Line 262  static void stage_file_test(void)
262          filename = "/dev/null";          filename = "/dev/null";
263          stat(filename, &sbuf);          stat(filename, &sbuf);
264          snprintf(pbuffer, sizeof(pbuffer) - 1,          snprintf(pbuffer, sizeof(pbuffer) - 1,
265                   "allow_write %s if path1.major=%u path1.minor=%u",                   "file write %s path1.major=%u path1.minor=%u",
266                   filename, (unsigned int) MAJOR(sbuf.st_dev),                   filename, (unsigned int) MAJOR(sbuf.st_dev),
267                   (unsigned int) MINOR(sbuf.st_dev));                   (unsigned int) MINOR(sbuf.st_dev));
268          policy = pbuffer;          policy = pbuffer;
# Line 297  static void stage_file_test(void) Line 277  static void stage_file_test(void)
277          if (fd != EOF)          if (fd != EOF)
278                  close(fd);                  close(fd);
279    
280          policy = "allow_read/write /tmp/fifo if path1.type=fifo";          policy = "file read/write /tmp/fifo path1.type=fifo";
281          mkfifo2("/tmp/fifo");          mkfifo2("/tmp/fifo");
282          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
283          fd = open("/tmp/fifo", O_RDWR);          fd = open("/tmp/fifo", O_RDWR);
# Line 310  static void stage_file_test(void) Line 290  static void stage_file_test(void)
290          if (fd != EOF)          if (fd != EOF)
291                  close(fd);                  close(fd);
292    
293          policy = "allow_read /dev/null if path1.parent.ino=path1.parent.ino";          policy = "file read /dev/null path1.parent.ino=path1.parent.ino";
294          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
295          fd = open("/dev/null", O_RDONLY);          fd = open("/dev/null", O_RDONLY);
296          show_result(fd, 1);          show_result(fd, 1);
# Line 322  static void stage_file_test(void) Line 302  static void stage_file_test(void)
302          if (fd != EOF)          if (fd != EOF)
303                  close(fd);                  close(fd);
304    
305          policy = "allow_write /dev/null if path1.uid=path1.gid";          policy = "file write /dev/null path1.uid=path1.gid";
306          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
307          fd = open("/dev/null", O_WRONLY);          fd = open("/dev/null", O_WRONLY);
308          show_result(fd, 1);          show_result(fd, 1);
# Line 334  static void stage_file_test(void) Line 314  static void stage_file_test(void)
314          if (fd != EOF)          if (fd != EOF)
315                  close(fd);                  close(fd);
316    
317          policy = "allow_read/write /dev/null if task.uid=path1.parent.uid";          policy = "file read/write /dev/null task.uid=path1.parent.uid";
318          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
319          fd = open("/dev/null", O_RDWR);          fd = open("/dev/null", O_RDWR);
320          show_result(fd, 1);          show_result(fd, 1);
# Line 346  static void stage_file_test(void) Line 326  static void stage_file_test(void)
326          if (fd != EOF)          if (fd != EOF)
327                  close(fd);                  close(fd);
328    
329          policy = "allow_create /tmp/open_test 0644 "          policy = "file create /tmp/open_test 0644 "
330                  "if path1.parent.uid=task.uid";                  "path1.parent.uid=task.uid";
331          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
332          policy = "allow_write /tmp/open_test if path1.parent.uid=0";          policy = "file write /tmp/open_test path1.parent.uid=0";
333          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
334          fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644);          fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644);
335          show_result(fd, 1);          show_result(fd, 1);
# Line 363  static void stage_file_test(void) Line 343  static void stage_file_test(void)
343                  close(fd);                  close(fd);
344          unlink2("/tmp/open_test");          unlink2("/tmp/open_test");
345    
346          policy = "allow_create /tmp/open_test 0644 "          policy = "file create /tmp/open_test 0644 "
347                  "if path1.parent.uid=task.uid";                  "path1.parent.uid=task.uid";
348          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
349    
350          policy = "allow_write /tmp/open_test if task.uid=0 path1.ino!=0";          policy = "file write /tmp/open_test task.uid=0 path1.ino!=0";
351          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
352          policy = "allow_create /tmp/open_test 0644 if 0=0";          policy = "file create /tmp/open_test 0644 0=0";
353          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
354          fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644);          fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0644);
355          show_result(fd, 1);          show_result(fd, 1);
# Line 382  static void stage_file_test(void) Line 362  static void stage_file_test(void)
362          if (fd != EOF)          if (fd != EOF)
363                  close(fd);                  close(fd);
364          unlink2("/tmp/open_test");          unlink2("/tmp/open_test");
365          policy = "allow_write /tmp/open_test if task.uid=0 path1.ino!=0";          policy = "file write /tmp/open_test task.uid=0 path1.ino!=0";
366          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
367    
368          filename = "/tmp/truncate_test";          filename = "/tmp/truncate_test";
369          create2(filename);          create2(filename);
370    
371          policy = "allow_truncate /tmp/truncate_test if task.uid=path1.uid";          policy = "file truncate /tmp/truncate_test task.uid=path1.uid";
372          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
373          policy = "allow_write /tmp/truncate_test if 1!=100-1000000";          policy = "file write /tmp/truncate_test 1!=100-1000000";
374          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
375          fd = open(filename, O_WRONLY | O_TRUNC);          fd = open(filename, O_WRONLY | O_TRUNC);
376          show_result(fd, 1);          show_result(fd, 1);
# Line 401  static void stage_file_test(void) Line 381  static void stage_file_test(void)
381          show_result(fd, 0);          show_result(fd, 0);
382          if (fd != EOF)          if (fd != EOF)
383                  close(fd);                  close(fd);
384          policy = "allow_truncate /tmp/truncate_test "          policy = "file truncate /tmp/truncate_test "
385                  "if task.uid=path1.uid";                  "task.uid=path1.uid";
386          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
387    
388          policy = "allow_write /tmp/truncate_test";          policy = "file write /tmp/truncate_test";
389          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
390          policy = "allow_truncate /tmp/truncate_test";          policy = "file truncate /tmp/truncate_test";
391          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
392          fd = open(filename, O_WRONLY | O_TRUNC);          fd = open(filename, O_WRONLY | O_TRUNC);
393          show_result(fd, 1);          show_result(fd, 1);
# Line 418  static void stage_file_test(void) Line 398  static void stage_file_test(void)
398          show_result(fd, 0);          show_result(fd, 0);
399          if (fd != EOF)          if (fd != EOF)
400                  close(fd);                  close(fd);
401          policy = "allow_write /tmp/truncate_test";          policy = "file write /tmp/truncate_test";
402          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
403    
404          policy = "allow_truncate /tmp/truncate_test";          policy = "file truncate /tmp/truncate_test";
405          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
406          show_result(truncate(filename, 0), 1);          show_result(truncate(filename, 0), 1);
407          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
408          show_result(truncate(filename, 0), 0);          show_result(truncate(filename, 0), 0);
409    
410          policy = "allow_truncate /tmp/truncate_test";          policy = "file truncate /tmp/truncate_test";
411          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
412          set_profile(0, "file::open");          set_profile(0, "file::open");
413          fd = open(filename, O_WRONLY);          fd = open(filename, O_WRONLY);
# Line 440  static void stage_file_test(void) Line 420  static void stage_file_test(void)
420    
421          unlink2(filename);          unlink2(filename);
422    
423          policy = "allow_create /tmp/mknod_reg_test 0644";          policy = "file create /tmp/mknod_reg_test 0644";
424          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
425          filename = "/tmp/mknod_reg_test";          filename = "/tmp/mknod_reg_test";
426          show_result(mknod(filename, S_IFREG | 0644, 0), 1);          show_result(mknod(filename, S_IFREG | 0644, 0), 1);
# Line 448  static void stage_file_test(void) Line 428  static void stage_file_test(void)
428          unlink2(filename);          unlink2(filename);
429          show_result(mknod(filename, S_IFREG | 0644, 0), 0);          show_result(mknod(filename, S_IFREG | 0644, 0), 0);
430    
431          policy = "allow_mkchar /tmp/mknod_chr_test 0644 1 3";          policy = "file mkchar /tmp/mknod_chr_test 0644 1 3";
432          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
433          filename = "/tmp/mknod_chr_test";          filename = "/tmp/mknod_chr_test";
434          show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 1);          show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 1);
# Line 456  static void stage_file_test(void) Line 436  static void stage_file_test(void)
436          unlink2(filename);          unlink2(filename);
437          show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 0);          show_result(mknod(filename, S_IFCHR | 0644, MKDEV(1, 3)), 0);
438    
439          policy = "allow_mkblock /tmp/mknod_blk_test 0644 1 0";          policy = "file mkblock /tmp/mknod_blk_test 0644 1 0";
440          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
441          filename = "/tmp/mknod_blk_test";          filename = "/tmp/mknod_blk_test";
442          show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 1);          show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 1);
# Line 464  static void stage_file_test(void) Line 444  static void stage_file_test(void)
444          unlink2(filename);          unlink2(filename);
445          show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 0);          show_result(mknod(filename, S_IFBLK | 0644, MKDEV(1, 0)), 0);
446    
447          policy = "allow_mkfifo /tmp/mknod_fifo_test 0644";          policy = "file mkfifo /tmp/mknod_fifo_test 0644";
448          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
449          filename = "/tmp/mknod_fifo_test";          filename = "/tmp/mknod_fifo_test";
450          show_result(mknod(filename, S_IFIFO | 0644, 0), 1);          show_result(mknod(filename, S_IFIFO | 0644, 0), 1);
# Line 472  static void stage_file_test(void) Line 452  static void stage_file_test(void)
452          unlink2(filename);          unlink2(filename);
453          show_result(mknod(filename, S_IFIFO | 0644, 0), 0);          show_result(mknod(filename, S_IFIFO | 0644, 0), 0);
454    
455          policy = "allow_mksock /tmp/mknod_sock_test 0644";          policy = "file mksock /tmp/mknod_sock_test 0644";
456          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
457          filename = "/tmp/mknod_sock_test";          filename = "/tmp/mknod_sock_test";
458          show_result(mknod(filename, S_IFSOCK | 0644, 0), 1);          show_result(mknod(filename, S_IFSOCK | 0644, 0), 1);
# Line 480  static void stage_file_test(void) Line 460  static void stage_file_test(void)
460          unlink2(filename);          unlink2(filename);
461          show_result(mknod(filename, S_IFSOCK | 0644, 0), 0);          show_result(mknod(filename, S_IFSOCK | 0644, 0), 0);
462    
463          policy = "allow_mkdir /tmp/mkdir_test/ 0600";          policy = "file mkdir /tmp/mkdir_test/ 0600";
464          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
465          filename = "/tmp/mkdir_test";          filename = "/tmp/mkdir_test";
466          show_result(mkdir(filename, 0600), 1);          show_result(mkdir(filename, 0600), 1);
# Line 488  static void stage_file_test(void) Line 468  static void stage_file_test(void)
468          rmdir2(filename);          rmdir2(filename);
469          show_result(mkdir(filename, 0600), 0);          show_result(mkdir(filename, 0600), 0);
470    
471          policy = "allow_rmdir /tmp/rmdir_test/";          policy = "file rmdir /tmp/rmdir_test/";
472          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
473          filename = "/tmp/rmdir_test";          filename = "/tmp/rmdir_test";
474          mkdir2(filename);          mkdir2(filename);
# Line 498  static void stage_file_test(void) Line 478  static void stage_file_test(void)
478          show_result(rmdir(filename), 0);          show_result(rmdir(filename), 0);
479          rmdir2(filename);          rmdir2(filename);
480    
481          policy = "allow_unlink /tmp/unlink_test";          policy = "file unlink /tmp/unlink_test";
482          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
483          filename = "/tmp/unlink_test";          filename = "/tmp/unlink_test";
484          create2(filename);          create2(filename);
# Line 508  static void stage_file_test(void) Line 488  static void stage_file_test(void)
488          show_result(unlink(filename), 0);          show_result(unlink(filename), 0);
489          unlink2(filename);          unlink2(filename);
490    
491          policy = "allow_symlink /tmp/symlink_source_test";          policy = "file symlink /tmp/symlink_source_test";
492          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
493          filename = "/tmp/symlink_source_test";          filename = "/tmp/symlink_source_test";
494          show_result(symlink("/tmp/symlink_dest_test", filename), 1);          show_result(symlink("/tmp/symlink_dest_test", filename), 1);
# Line 516  static void stage_file_test(void) Line 496  static void stage_file_test(void)
496          unlink2(filename);          unlink2(filename);
497          show_result(symlink("/tmp/symlink_dest_test", filename), 0);          show_result(symlink("/tmp/symlink_dest_test", filename), 0);
498    
499          policy = "allow_symlink /tmp/symlink_source_test "          policy = "file symlink /tmp/symlink_source_test "
500                  "if symlink.target=\"/tmp/symlink_\\*_test\"";                  "symlink.target=\"/tmp/symlink_\\*_test\"";
501          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
502          filename = "/tmp/symlink_source_test";          filename = "/tmp/symlink_source_test";
503          show_result(symlink("/tmp/symlink_dest_test", filename), 1);          show_result(symlink("/tmp/symlink_dest_test", filename), 1);
# Line 525  static void stage_file_test(void) Line 505  static void stage_file_test(void)
505          unlink2(filename);          unlink2(filename);
506          show_result(symlink("/tmp/symlink_dest_test", filename), 0);          show_result(symlink("/tmp/symlink_dest_test", filename), 0);
507    
508          policy = "allow_symlink /tmp/symlink_source_test "          policy = "file symlink /tmp/symlink_source_test "
509                  "if task.uid=0 symlink.target=\"/tmp/symlink_\\*_test\"";                  "task.uid=0 symlink.target=\"/tmp/symlink_\\*_test\"";
510          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
511          filename = "/tmp/symlink_source_test";          filename = "/tmp/symlink_source_test";
512          show_result(symlink("/tmp/symlink_dest_test", filename), 1);          show_result(symlink("/tmp/symlink_dest_test", filename), 1);
# Line 534  static void stage_file_test(void) Line 514  static void stage_file_test(void)
514          unlink2(filename);          unlink2(filename);
515          show_result(symlink("/tmp/symlink_dest_test", filename), 0);          show_result(symlink("/tmp/symlink_dest_test", filename), 0);
516    
517          policy = "allow_symlink /tmp/symlink_source_test "          policy = "file symlink /tmp/symlink_source_test "
518                  "if symlink.target!=\"\\*\"";                  "symlink.target!=\"\\*\"";
519          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
520          filename = "/tmp/symlink_source_test";          filename = "/tmp/symlink_source_test";
521          show_result(symlink("/tmp/symlink_dest_test", filename), 1);          show_result(symlink("/tmp/symlink_dest_test", filename), 1);
# Line 543  static void stage_file_test(void) Line 523  static void stage_file_test(void)
523          unlink2(filename);          unlink2(filename);
524          show_result(symlink("/tmp/symlink_dest_test", filename), 0);          show_result(symlink("/tmp/symlink_dest_test", filename), 0);
525    
526          policy = "allow_symlink /tmp/symlink_source_test "          policy = "file symlink /tmp/symlink_source_test "
527                  "if symlink.target!=\"/tmp/symlink_\\*_test\"";                  "symlink.target!=\"/tmp/symlink_\\*_test\"";
528          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
529          filename = "/tmp/symlink_source_test";          filename = "/tmp/symlink_source_test";
530          show_result(symlink("/tmp/symlink_dest_test", filename), 0);          show_result(symlink("/tmp/symlink_dest_test", filename), 0);
# Line 552  static void stage_file_test(void) Line 532  static void stage_file_test(void)
532          unlink2(filename);          unlink2(filename);
533          show_result(symlink("/tmp/symlink_dest_test", filename), 0);          show_result(symlink("/tmp/symlink_dest_test", filename), 0);
534    
535          policy = "allow_link /tmp/link_source_test /tmp/link_dest_test";          policy = "file link /tmp/link_source_test /tmp/link_dest_test";
536          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
537          filename = "/tmp/link_source_test";          filename = "/tmp/link_source_test";
538          create2(filename);          create2(filename);
# Line 562  static void stage_file_test(void) Line 542  static void stage_file_test(void)
542          show_result(link(filename, "/tmp/link_dest_test"), 0);          show_result(link(filename, "/tmp/link_dest_test"), 0);
543          unlink2(filename);          unlink2(filename);
544    
545          policy = "allow_rename /tmp/rename_source_test /tmp/rename_dest_test";          policy = "file rename /tmp/rename_source_test /tmp/rename_dest_test";
546          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
547          filename = "/tmp/rename_source_test";          filename = "/tmp/rename_source_test";
548          create2(filename);          create2(filename);
# Line 573  static void stage_file_test(void) Line 553  static void stage_file_test(void)
553          show_result(rename(filename, "/tmp/rename_dest_test"), 0);          show_result(rename(filename, "/tmp/rename_dest_test"), 0);
554          unlink2(filename);          unlink2(filename);
555    
556          policy = "allow_mksock /tmp/socket_test 0755";          policy = "file mksock /tmp/socket_test 0755";
557          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
558          filename = "/tmp/socket_test";          filename = "/tmp/socket_test";
559          memset(&addr, 0, sizeof(addr));          memset(&addr, 0, sizeof(addr));
# Line 591  static void stage_file_test(void) Line 571  static void stage_file_test(void)
571                      0);                      0);
572          if (fd != EOF)          if (fd != EOF)
573                  close(fd);                  close(fd);
   
         filename = "/tmp/rewrite_test";  
         create2(filename);  
         policy = "allow_read/write /tmp/rewrite_test";  
         write_domain_policy(policy, 0);  
         write_exception_policy("deny_rewrite /tmp/rewrite_test", 0);  
         policy = "allow_truncate /tmp/rewrite_test";  
         write_domain_policy(policy, 0);  
   
         fd = open(filename, O_RDONLY);  
         show_result(fd, 1);  
         if (fd != EOF)  
                 close(fd);  
   
         fd = open(filename, O_WRONLY | O_APPEND);  
         show_result(fd, 1);  
         if (fd != EOF)  
                 close(fd);  
   
         fd = open(filename, O_WRONLY);  
         show_result(fd, 0);  
         if (fd != EOF)  
                 close(fd);  
   
         fd = open(filename, O_WRONLY | O_TRUNC);  
         show_result(fd, 0);  
         if (fd != EOF)  
                 close(fd);  
   
         fd = open(filename, O_WRONLY | O_TRUNC | O_APPEND);  
         show_result(fd, 0);  
         if (fd != EOF)  
                 close(fd);  
   
         show_result(truncate(filename, 0), 0);  
   
         set_profile(0, "file::open");  
         fd = open(filename, O_WRONLY | O_APPEND);  
         set_profile(3, "file::open");  
         show_result(ftruncate(fd, 0), 0);  
   
         show_result(fcntl(fd, F_SETFL,  
                           fcntl(fd, F_GETFL) & ~O_APPEND), 0);  
         if (fd != EOF)  
                 close(fd);  
   
         write_domain_policy(policy, 1);  
   
         policy = "allow_read/write /tmp/rewrite_test";  
         write_domain_policy(policy, 1);  
         write_exception_policy("deny_rewrite /tmp/rewrite_test", 1);  
   
574          unlink2(filename);          unlink2(filename);
575    
576          policy = "allow_ioctl socket:[family=2:type=2:protocol=17] "          policy = "file ioctl socket:[family=2:type=2:protocol=17] "
577                  "35122-35124 if task.uid=0";                  "35122-35124 task.uid=0";
578          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
579          fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);          fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
580          memset(&ifreq, 0, sizeof(ifreq));          memset(&ifreq, 0, sizeof(ifreq));
# Line 654  static void stage_file_test(void) Line 582  static void stage_file_test(void)
582                   "lo");                   "lo");
583          show_result(ioctl(fd, 35123, &ifreq), 1);          show_result(ioctl(fd, 35123, &ifreq), 1);
584          write_domain_policy(policy, 1);          write_domain_policy(policy, 1);
585          policy = "allow_ioctl "          policy = "file ioctl "
586                  "socket:[family=2:type=2:protocol=17] 0-35122";                  "socket:[family=2:type=2:protocol=17] 0-35122";
587          write_domain_policy(policy, 0);          write_domain_policy(policy, 0);
588          show_result(ioctl(fd, 35123, &ifreq), 0);          show_result(ioctl(fd, 35123, &ifreq), 0);
# Line 669  int main(int argc, char *argv[]) Line 597  int main(int argc, char *argv[])
597          fprintf(domain_fp, "%s /bin/true\n", self_domain);          fprintf(domain_fp, "%s /bin/true\n", self_domain);
598          fprintf(domain_fp, "use_profile 255\n");          fprintf(domain_fp, "use_profile 255\n");
599          fprintf(domain_fp, "select pid=%u\n", pid);          fprintf(domain_fp, "select pid=%u\n", pid);
600          fprintf(profile_fp, "255-PREFERENCE::audit={ max_reject_log=1024 }\n");          fprintf(profile_fp, "255-PREFERENCE={ max_reject_log=1024 }\n");
601          stage_file_test();          stage_file_test();
602          fprintf(domain_fp, "use_profile 0\n");          fprintf(domain_fp, "use_profile 0\n");
603          clear_status();          clear_status();
604            if (0) /* To suppress "defined but not used" warnings. */
605                    write_exception_policy("", 0);
606          return 0;          return 0;
607  }  }

Legend:
Removed from v.3751  
changed lines
  Added in v.4627

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