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

Subversion リポジトリの参照

Diff of /branches/kernel_test/ccs_new_file_test.c

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

revision 1721 by kumaneko, Mon Oct 20 05:56:25 2008 UTC revision 1726 by kumaneko, Mon Oct 20 14:21:31 2008 UTC
# Line 5  Line 5 
5   *   *
6   * Copyright (C) 2005-2008  NTT DATA CORPORATION   * Copyright (C) 2005-2008  NTT DATA CORPORATION
7   *   *
8   * Version: 1.6.5-pre   2008/10/07   * Version: 1.6.5-pre   2008/10/20
9   *   *
10   */   */
11  #include "include.h"  #include "include.h"
# Line 15  static int exception_fd = EOF; Line 15  static int exception_fd = EOF;
15  static const char *policy = "";  static const char *policy = "";
16  static char self_domain[4096] = "";  static char self_domain[4096] = "";
17    
18  static int write_policy(void) {  static int write_policy(void)
19    {
20          FILE *fp;          FILE *fp;
21          char buffer[8192];          char buffer[8192];
22          char *cp;          char *cp;
# Line 35  static int write_policy(void) { Line 36  static int write_policy(void) {
36          }          }
37          while (fgets(buffer, sizeof(buffer) - 1, fp)) {          while (fgets(buffer, sizeof(buffer) - 1, fp)) {
38                  cp = strchr(buffer, '\n');                  cp = strchr(buffer, '\n');
39                  if (cp) *cp = '\0';                  if (cp)
40                  if (!strncmp(buffer, "<kernel>", 8)) domain_found = !strcmp(self_domain, buffer);                          *cp = '\0';
41                    if (!strncmp(buffer, "<kernel>", 8))
42                            domain_found = !strcmp(self_domain, buffer);
43                  if (domain_found) {                  if (domain_found) {
44                          //printf("<%s>\n", buffer);                          /* printf("<%s>\n", buffer); */
45                          if (!strcmp(buffer, policy)) {                          if (!strcmp(buffer, policy)) {
46                                  policy_found = 1;                                  policy_found = 1;
47                                  break;                                  break;
# Line 54  static int write_policy(void) { Line 57  static int write_policy(void) {
57          return 1;          return 1;
58  }  }
59    
60  static void delete_policy(void) {  static void delete_policy(void)
61    {
62          write(domain_fd, "delete ", 7);          write(domain_fd, "delete ", 7);
63          write(domain_fd, policy, strlen(policy));          write(domain_fd, policy, strlen(policy));
64          write(domain_fd, "\n", 1);          write(domain_fd, "\n", 1);
65  }  }
66    
67  static void show_result(int result, char should_success) {  static void show_result(int result, char should_success)
68    {
69          int err = errno;          int err = errno;
70          printf("%s : ", policy);          printf("%s : ", policy);
71          if (should_success) {          if (should_success) {
72                  if (result != EOF) printf("OK\n");                  if (result != EOF)
73                  else printf("FAILED: %s\n", strerror(err));                          printf("OK\n");
74                    else
75                            printf("FAILED: %s\n", strerror(err));
76          } else {          } else {
77                  if (result == EOF) {                  if (result == EOF) {
78                          if (err == EPERM) printf("OK: Permission denied.\n");                          if (err == EPERM)
79                          else printf("FAILED: %s\n", strerror(err));                                  printf("OK: Permission denied.\n");
80                            else
81                                    printf("FAILED: %s\n", strerror(err));
82                  } else {                  } else {
83                          printf("BUG: didn't fail.\n");                          printf("BUG: didn't fail.\n");
84                  }                  }
85          }          }
86  }  }
87    
88  static void create2(const char *pathname) {  static void create2(const char *pathname)
89    {
90          const char *cp = "255-MAC_FOR_FILE=disabled\n";          const char *cp = "255-MAC_FOR_FILE=disabled\n";
91          write(profile_fd, cp, strlen(cp));          write(profile_fd, cp, strlen(cp));
92          close(creat(pathname, 0600));          close(creat(pathname, 0600));
# Line 85  static void create2(const char *pathname Line 95  static void create2(const char *pathname
95          errno = 0;          errno = 0;
96  }  }
97    
98  static void mkdir2(const char *pathname) {  static void mkdir2(const char *pathname)
99    {
100          const char *cp = "255-MAC_FOR_FILE=disabled\n";          const char *cp = "255-MAC_FOR_FILE=disabled\n";
101          write(profile_fd, cp, strlen(cp));          write(profile_fd, cp, strlen(cp));
102          mkdir(pathname, 0600);          mkdir(pathname, 0600);
# Line 94  static void mkdir2(const char *pathname) Line 105  static void mkdir2(const char *pathname)
105          errno = 0;          errno = 0;
106  }  }
107    
108  static void unlink2(const char *pathname) {  static void unlink2(const char *pathname)
109    {
110          const char *cp = "255-MAC_FOR_FILE=disabled\n";          const char *cp = "255-MAC_FOR_FILE=disabled\n";
111          write(profile_fd, cp, strlen(cp));          write(profile_fd, cp, strlen(cp));
112          unlink(pathname);          unlink(pathname);
113          cp = "255-MAC_FOR_FILE=enforcing\n";          cp = "255-MAC_FOR_FILE=enforcing\n";
114          write(profile_fd, cp, strlen(cp));          write(profile_fd, cp, strlen(cp));
115          errno = 0;          errno = 0;
116  }                        }
117    
118  static void rmdir2(const char *pathname) {  static void rmdir2(const char *pathname)
119    {
120          const char *cp = "255-MAC_FOR_FILE=disabled\n";          const char *cp = "255-MAC_FOR_FILE=disabled\n";
121          write(profile_fd, cp, strlen(cp));          write(profile_fd, cp, strlen(cp));
122          rmdir(pathname);          rmdir(pathname);
# Line 112  static void rmdir2(const char *pathname) Line 125  static void rmdir2(const char *pathname)
125          errno = 0;          errno = 0;
126  }  }
127    
128  static void StageFileTest(void) {  static void StageFileTest(void)
129    {
130          char *filename = "";          char *filename = "";
131          policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range if task.uid=0 task.gid=0";          policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range "
132                    "if task.uid=0 task.gid=0";
133          if (write_policy()) {          if (write_policy()) {
134                  static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE };                  static int name[] = { CTL_NET, NET_IPV4,
135                                          NET_IPV4_LOCAL_PORT_RANGE };
136                  int buffer[2] = { 32768, 61000 };                  int buffer[2] = { 32768, 61000 };
137                  size_t size = sizeof(buffer);                  size_t size = sizeof(buffer);
138                  show_result(sysctl(name, 3, buffer, &size, 0, 0), 1);                  show_result(sysctl(name, 3, buffer, &size, 0, 0), 1);
139                  delete_policy();                  delete_policy();
140                  show_result(sysctl(name, 3, buffer, &size, 0, 0), 0);                  show_result(sysctl(name, 3, buffer, &size, 0, 0), 0);
141          }          }
142          policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range if task.euid=0 0=0 1-100=10-1000";          policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range "
143                    "if task.euid=0 0=0 1-100=10-1000";
144          if (write_policy()) {          if (write_policy()) {
145                  static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE };                  static int name[] = { CTL_NET, NET_IPV4,
146                                          NET_IPV4_LOCAL_PORT_RANGE };
147                  int buffer[2] = { 32768, 61000 };                  int buffer[2] = { 32768, 61000 };
148                  size_t size = sizeof(buffer);                  size_t size = sizeof(buffer);
149                  show_result(sysctl(name, 3, 0, 0, buffer, size), 1);                  show_result(sysctl(name, 3, 0, 0, buffer, size), 1);
150                  delete_policy();                  delete_policy();
151                  show_result(sysctl(name, 3, 0, 0, buffer, size), 0);                  show_result(sysctl(name, 3, 0, 0, buffer, size), 0);
152          }          }
153          policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range if 1!=10-100";          policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range "
154                    "if 1!=10-100";
155          if (write_policy()) {          if (write_policy()) {
156                  static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE };                  static int name[] = { CTL_NET, NET_IPV4,
157                                          NET_IPV4_LOCAL_PORT_RANGE };
158                  int buffer[2] = { 32768, 61000 };                  int buffer[2] = { 32768, 61000 };
159                  size_t size = sizeof(buffer);                  size_t size = sizeof(buffer);
160                  show_result(sysctl(name, 3, buffer, &size, buffer, size), 1);                  show_result(sysctl(name, 3, buffer, &size, buffer, size), 1);
# Line 142  static void StageFileTest(void) { Line 162  static void StageFileTest(void) {
162                  show_result(sysctl(name, 3, buffer, &size, buffer, size), 0);                  show_result(sysctl(name, 3, buffer, &size, buffer, size), 0);
163          }          }
164    
165          policy = "allow_read /bin/true if path1.uid=0 path1.parent.uid=0 10=10-100";          policy = "allow_read /bin/true "
166                    "if path1.uid=0 path1.parent.uid=0 10=10-100";
167          if (write_policy()) {          if (write_policy()) {
168                  show_result(uselib("/bin/true"), 1);                  show_result(uselib("/bin/true"), 1);
169                  delete_policy();                  delete_policy();
# Line 153  static void StageFileTest(void) { Line 174  static void StageFileTest(void) {
174          if (write_policy()) {          if (write_policy()) {
175                  int pipe_fd[2] = { EOF, EOF };                  int pipe_fd[2] = { EOF, EOF };
176                  int err = 0;                  int err = 0;
177                  fflush(stdout); fflush(stderr);                  fflush(stdout);
178                    fflush(stderr);
179                  pipe(pipe_fd);                  pipe(pipe_fd);
180                  if (fork() == 0) {                  if (fork() == 0) {
181                          execl("/bin/true", "/bin/true", NULL);                          execl("/bin/true", "/bin/true", NULL);
# Line 168  static void StageFileTest(void) { Line 190  static void StageFileTest(void) {
190                  errno = err;                  errno = err;
191                  show_result(err ? EOF : 0, 1);                  show_result(err ? EOF : 0, 1);
192                  delete_policy();                  delete_policy();
193                  fflush(stdout); fflush(stderr);                  fflush(stdout);
194                    fflush(stderr);
195                  pipe(pipe_fd);                  pipe(pipe_fd);
196                  if (fork() == 0) {                  if (fork() == 0) {
197                          execl("/bin/true", "/bin/true", NULL);                          execl("/bin/true", "/bin/true", NULL);
# Line 188  static void StageFileTest(void) { Line 211  static void StageFileTest(void) {
211          if (write_policy()) {          if (write_policy()) {
212                  int fd = open("/dev/null", O_RDONLY);                  int fd = open("/dev/null", O_RDONLY);
213                  show_result(fd, 1);                  show_result(fd, 1);
214                  if (fd != EOF) close(fd);                  if (fd != EOF)
215                            close(fd);
216                  delete_policy();                  delete_policy();
217                  fd = open("/dev/null", O_RDONLY);                  fd = open("/dev/null", O_RDONLY);
218                  show_result(fd, 0);                  show_result(fd, 0);
219                  if (fd != EOF) close(fd);                  if (fd != EOF)
220                            close(fd);
221          }          }
222    
223          policy = "allow_write /dev/null if path1.uid=path1.gid";          policy = "allow_write /dev/null if path1.uid=path1.gid";
224          if (write_policy()) {          if (write_policy()) {
225                  int fd = open("/dev/null", O_WRONLY);                  int fd = open("/dev/null", O_WRONLY);
226                  show_result(fd, 1);                  show_result(fd, 1);
227                  if (fd != EOF) close(fd);                  if (fd != EOF)
228                            close(fd);
229                  delete_policy();                  delete_policy();
230                  fd = open("/dev/null", O_WRONLY);                  fd = open("/dev/null", O_WRONLY);
231                  show_result(fd, 0);                  show_result(fd, 0);
232                  if (fd != EOF) close(fd);                  if (fd != EOF)
233                            close(fd);
234          }          }
235    
236          policy = "allow_read/write /dev/null if task.uid=path1.parent.uid";          policy = "allow_read/write /dev/null if task.uid=path1.parent.uid";
237          if (write_policy()) {          if (write_policy()) {
238                  int fd = open("/dev/null", O_RDWR);                  int fd = open("/dev/null", O_RDWR);
239                  show_result(fd, 1);                  show_result(fd, 1);
240                  if (fd != EOF) close(fd);                  if (fd != EOF)
241                            close(fd);
242                  delete_policy();                  delete_policy();
243                  fd = open("/dev/null", O_RDWR);                  fd = open("/dev/null", O_RDWR);
244                  show_result(fd, 0);                  show_result(fd, 0);
245                  if (fd != EOF) close(fd);                  if (fd != EOF)
246                            close(fd);
247          }          }
248    
249          policy = "allow_create /tmp/open_test if path1.parent.uid=task.uid";          policy = "allow_create /tmp/open_test if path1.parent.uid=task.uid";
250          if (write_policy()) {          if (write_policy()) {
251                  policy = "allow_write /tmp/open_test if path1.parent.uid=0";                  policy = "allow_write /tmp/open_test if path1.parent.uid=0";
252                  if (write_policy()) {                  if (write_policy()) {
253                          int fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0666);                          int fd = open("/tmp/open_test",
254                                          O_WRONLY | O_CREAT | O_EXCL, 0666);
255                          show_result(fd, 1);                          show_result(fd, 1);
256                          if (fd != EOF) close(fd);                          if (fd != EOF)
257                                    close(fd);
258                          unlink2("/tmp/open_test");                          unlink2("/tmp/open_test");
259                          delete_policy();                          delete_policy();
260                          fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0666);                          fd = open("/tmp/open_test",
261                                      O_WRONLY | O_CREAT | O_EXCL, 0666);
262                          show_result(fd, 0);                          show_result(fd, 0);
263                          if (fd != EOF) close(fd);                          if (fd != EOF)
264                                    close(fd);
265                          unlink2("/tmp/open_test");                          unlink2("/tmp/open_test");
266                  }                  }
267                  policy = "allow_create /tmp/open_test if path1.parent.uid=task.uid\n";                  policy = "allow_create /tmp/open_test "
268                            "if path1.parent.uid=task.uid\n";
269                  delete_policy();                  delete_policy();
270          }          }
271    
# Line 239  static void StageFileTest(void) { Line 273  static void StageFileTest(void) {
273          if (write_policy()) {          if (write_policy()) {
274                  policy = "allow_create /tmp/open_test if 0=0";                  policy = "allow_create /tmp/open_test if 0=0";
275                  if (write_policy()) {                  if (write_policy()) {
276                          int fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0666);                          int fd = open("/tmp/open_test",
277                                          O_WRONLY | O_CREAT | O_EXCL, 0666);
278                          show_result(fd, 1);                          show_result(fd, 1);
279                          if (fd != EOF) close(fd);                          if (fd != EOF)
280                                    close(fd);
281                          unlink2("/tmp/open_test");                          unlink2("/tmp/open_test");
282                          delete_policy();                          delete_policy();
283                          fd = open("/tmp/open_test", O_WRONLY | O_CREAT | O_EXCL, 0666);                          fd = open("/tmp/open_test",
284                                      O_WRONLY | O_CREAT | O_EXCL, 0666);
285                          show_result(fd, 0);                          show_result(fd, 0);
286                          if (fd != EOF) close(fd);                          if (fd != EOF)
287                                    close(fd);
288                          unlink2("/tmp/open_test");                          unlink2("/tmp/open_test");
289                  }                  }
290                  policy = "allow_write /tmp/open_test if task.uid=0 path1.ino!=0\n";                  policy = "allow_write /tmp/open_test "
291                            "if task.uid=0 path1.ino!=0\n";
292                  delete_policy();                  delete_policy();
293          }          }
294    
# Line 262  static void StageFileTest(void) { Line 301  static void StageFileTest(void) {
301                  if (write_policy()) {                  if (write_policy()) {
302                          int fd = open(filename, O_WRONLY | O_TRUNC);                          int fd = open(filename, O_WRONLY | O_TRUNC);
303                          show_result(fd, 1);                          show_result(fd, 1);
304                          if (fd != EOF) close(fd);                          if (fd != EOF)
305                                    close(fd);
306                          delete_policy();                          delete_policy();
307                          fd = open(filename, O_WRONLY | O_TRUNC);                          fd = open(filename, O_WRONLY | O_TRUNC);
308                          show_result(fd, 0);                          show_result(fd, 0);
309                          if (fd != EOF) close(fd);                          if (fd != EOF)
310                                    close(fd);
311                  }                  }
312                  policy = "allow_truncate /tmp/truncate_test if task.uid=path1.uid";                  policy = "allow_truncate /tmp/truncate_test "
313                            "if task.uid=path1.uid";
314                  delete_policy();                  delete_policy();
315          }          }
316    
# Line 278  static void StageFileTest(void) { Line 320  static void StageFileTest(void) {
320                  if (write_policy()) {                  if (write_policy()) {
321                          int fd = open(filename, O_WRONLY | O_TRUNC);                          int fd = open(filename, O_WRONLY | O_TRUNC);
322                          show_result(fd, 1);                          show_result(fd, 1);
323                          if (fd != EOF) close(fd);                          if (fd != EOF)
324                                    close(fd);
325                          delete_policy();                          delete_policy();
326                          fd = open(filename, O_WRONLY | O_TRUNC);                          fd = open(filename, O_WRONLY | O_TRUNC);
327                          show_result(fd, 0);                          show_result(fd, 0);
328                          if (fd != EOF) close(fd);                          if (fd != EOF)
329                                    close(fd);
330                  }                  }
331                  policy = "allow_write /tmp/truncate_test\n";                  policy = "allow_write /tmp/truncate_test\n";
332                  delete_policy();                  delete_policy();
333          }          }
334            
335          policy = "allow_truncate /tmp/truncate_test";          policy = "allow_truncate /tmp/truncate_test";
336          if (write_policy()) {          if (write_policy()) {
337                  show_result(truncate(filename, 0), 1);                  show_result(truncate(filename, 0), 1);
# Line 306  static void StageFileTest(void) { Line 350  static void StageFileTest(void) {
350                  show_result(ftruncate(fd, 0), 1);                  show_result(ftruncate(fd, 0), 1);
351                  delete_policy();                  delete_policy();
352                  show_result(ftruncate(fd, 0), 0);                  show_result(ftruncate(fd, 0), 0);
353                  if (fd != EOF) close(fd);                  if (fd != EOF)
354                            close(fd);
355          }          }
356            
357          unlink2(filename);          unlink2(filename);
358            
359          policy = "allow_create /tmp/mknod_reg_test";          policy = "allow_create /tmp/mknod_reg_test";
360          if (write_policy()) {          if (write_policy()) {
361                  filename = "/tmp/mknod_reg_test";                  filename = "/tmp/mknod_reg_test";
# Line 355  static void StageFileTest(void) { Line 400  static void StageFileTest(void) {
400                  unlink2(filename);                  unlink2(filename);
401                  show_result(mknod(filename, S_IFSOCK, 0), 0);                  show_result(mknod(filename, S_IFSOCK, 0), 0);
402          }          }
403            
404          policy = "allow_mkdir /tmp/mkdir_test/";          policy = "allow_mkdir /tmp/mkdir_test/";
405          if (write_policy()) {          if (write_policy()) {
406                  filename = "/tmp/mkdir_test";                  filename = "/tmp/mkdir_test";
# Line 364  static void StageFileTest(void) { Line 409  static void StageFileTest(void) {
409                  rmdir2(filename);                  rmdir2(filename);
410                  show_result(mkdir(filename, 0600), 0);                  show_result(mkdir(filename, 0600), 0);
411          }          }
412            
413          policy = "allow_rmdir /tmp/rmdir_test/";          policy = "allow_rmdir /tmp/rmdir_test/";
414          if (write_policy()) {          if (write_policy()) {
415                  filename = "/tmp/rmdir_test";                  filename = "/tmp/rmdir_test";
# Line 375  static void StageFileTest(void) { Line 420  static void StageFileTest(void) {
420                  show_result(rmdir(filename), 0);                  show_result(rmdir(filename), 0);
421                  rmdir2(filename);                  rmdir2(filename);
422          }          }
423            
424          policy = "allow_unlink /tmp/unlink_test";          policy = "allow_unlink /tmp/unlink_test";
425          if (write_policy()) {          if (write_policy()) {
426                  filename = "/tmp/unlink_test";                  filename = "/tmp/unlink_test";
# Line 386  static void StageFileTest(void) { Line 431  static void StageFileTest(void) {
431                  show_result(unlink(filename), 0);                  show_result(unlink(filename), 0);
432                  unlink2(filename);                  unlink2(filename);
433          }          }
434            
435          policy = "allow_symlink /tmp/symlink_source_test";          policy = "allow_symlink /tmp/symlink_source_test";
436          if (write_policy()) {          if (write_policy()) {
437                  filename = "/tmp/symlink_source_test";                  filename = "/tmp/symlink_source_test";
# Line 395  static void StageFileTest(void) { Line 440  static void StageFileTest(void) {
440                  unlink2(filename);                  unlink2(filename);
441                  show_result(symlink("/tmp/symlink_dest_test", filename), 0);                  show_result(symlink("/tmp/symlink_dest_test", filename), 0);
442          }          }
443            
444          policy = "allow_link /tmp/link_source_test /tmp/link_dest_test";          policy = "allow_link /tmp/link_source_test /tmp/link_dest_test";
445          if (write_policy()) {          if (write_policy()) {
446                  filename = "/tmp/link_source_test";                  filename = "/tmp/link_source_test";
# Line 428  static void StageFileTest(void) { Line 473  static void StageFileTest(void) {
473                  addr.sun_family = AF_UNIX;                  addr.sun_family = AF_UNIX;
474                  strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1);                  strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1);
475                  fd = socket(AF_UNIX, SOCK_STREAM, 0);                  fd = socket(AF_UNIX, SOCK_STREAM, 0);
476                  show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)), 1);                  show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)),
477                  if (fd != EOF) close(fd);                              1);
478                    if (fd != EOF)
479                            close(fd);
480                  delete_policy();                  delete_policy();
481                  unlink2(filename);                  unlink2(filename);
482                  fd = socket(AF_UNIX, SOCK_STREAM, 0);                  fd = socket(AF_UNIX, SOCK_STREAM, 0);
483                  show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)), 0);                  show_result(bind(fd, (struct sockaddr *) &addr, sizeof(addr)),
484                  if (fd != EOF) close(fd);                              0);
485                    if (fd != EOF)
486                            close(fd);
487          }          }
488    
489          filename = "/tmp/rewrite_test";          filename = "/tmp/rewrite_test";
# Line 449  static void StageFileTest(void) { Line 498  static void StageFileTest(void) {
498    
499                          fd = open(filename, O_RDONLY);                          fd = open(filename, O_RDONLY);
500                          show_result(fd, 1);                          show_result(fd, 1);
501                          if (fd != EOF) close(fd);                          if (fd != EOF)
502                                                            close(fd);
503    
504                          fd = open(filename, O_WRONLY | O_APPEND);                          fd = open(filename, O_WRONLY | O_APPEND);
505                          show_result(fd, 1);                          show_result(fd, 1);
506                          if (fd != EOF) close(fd);                          if (fd != EOF)
507                                                            close(fd);
508    
509                          fd = open(filename, O_WRONLY);                          fd = open(filename, O_WRONLY);
510                          show_result(fd, 0);                          show_result(fd, 0);
511                          if (fd != EOF) close(fd);                          if (fd != EOF)
512                                                            close(fd);
513    
514                          fd = open(filename, O_WRONLY | O_TRUNC);                          fd = open(filename, O_WRONLY | O_TRUNC);
515                          show_result(fd, 0);                          show_result(fd, 0);
516                          if (fd != EOF) close(fd);                          if (fd != EOF)
517                                                            close(fd);
518    
519                          fd = open(filename, O_WRONLY | O_TRUNC | O_APPEND);                          fd = open(filename, O_WRONLY | O_TRUNC | O_APPEND);
520                          show_result(fd, 0);                          show_result(fd, 0);
521                          if (fd != EOF) close(fd);                          if (fd != EOF)
522                                                            close(fd);
523    
524                          show_result(truncate(filename, 0), 0);                          show_result(truncate(filename, 0), 0);
525                            
526                          cp = "255-MAC_FOR_FILE=disabled\n";                          cp = "255-MAC_FOR_FILE=disabled\n";
527                          write(profile_fd, cp, strlen(cp));                          write(profile_fd, cp, strlen(cp));
528                          fd = open(filename, O_WRONLY | O_APPEND);                          fd = open(filename, O_WRONLY | O_APPEND);
529                          cp = "255-MAC_FOR_FILE=enforcing\n";                          cp = "255-MAC_FOR_FILE=enforcing\n";
530                          write(profile_fd, cp, strlen(cp));                          write(profile_fd, cp, strlen(cp));
531                          show_result(ftruncate(fd, 0), 0);                          show_result(ftruncate(fd, 0), 0);
532                            
533                          show_result(fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_APPEND), 0);                          show_result(fcntl(fd, F_SETFL,
534                          if (fd != EOF) close(fd);                                            fcntl(fd, F_GETFL) & ~O_APPEND), 0);
535                            if (fd != EOF)
536                                    close(fd);
537    
538                          delete_policy();                          delete_policy();
539                  }                  }
# Line 489  static void StageFileTest(void) { Line 545  static void StageFileTest(void) {
545          unlink2(filename);          unlink2(filename);
546  }  }
547    
548  int main(int argc, char *argv[]) {  int main(int argc, char *argv[])
549    {
550          char *cp;          char *cp;
551          Init();          Init();
552          domain_fd = open(proc_policy_domain_policy, O_WRONLY);          domain_fd = open(proc_policy_domain_policy, O_WRONLY);

Legend:
Removed from v.1721  
changed lines
  Added in v.1726

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