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

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

Legend:
Removed from v.2706  
changed lines
  Added in v.3171

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