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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4792 - (hide annotations) (download) (as text)
Fri Apr 1 03:12:59 2011 UTC (13 years, 1 month ago) by kumaneko
File MIME type: text/x-csrc
File size: 2080 byte(s)


1 kumaneko 821 /*
2     * tomoyo_env_test.c
3     *
4     * Testing program for fs/tomoyo_env.c
5     *
6 kumaneko 4792 * Copyright (C) 2005-2011 NTT DATA CORPORATION
7 kumaneko 821 *
8 kumaneko 4792 * Version: 1.6.9 2011/04/01
9 kumaneko 821 *
10     */
11     #include "include.h"
12    
13     static int is_enforce = 0;
14    
15 kumaneko 1744 static void show_prompt(const char *str)
16 kumaneko 1726 {
17     printf("Testing %40s: (%s) ", str,
18     is_enforce ? "must fail" : "should success");
19 kumaneko 821 errno = 0;
20     }
21    
22 kumaneko 1744 static void show_result(int result)
23 kumaneko 1726 {
24 kumaneko 821 if (is_enforce) {
25     if (result == EOF) {
26 kumaneko 1726 if (errno == EPERM)
27     printf("OK: Permission denied.\n");
28     else
29     printf("FAILED: %s\n", strerror(errno));
30 kumaneko 821 } else {
31     printf("BUG!\n");
32     }
33     } else {
34 kumaneko 1726 if (result != EOF)
35     printf("OK\n");
36     else
37     printf("%s\n", strerror(errno));
38 kumaneko 821 }
39     }
40    
41 kumaneko 1744 static void stage_env_test(void)
42 kumaneko 1726 {
43 kumaneko 821 static char buffer[1024];
44     char *argv[2] = { "true", NULL };
45     char *envp[2] = { "env-test", NULL };
46     int status = 0;
47     memset(buffer, 0, sizeof(buffer));
48     {
49 kumaneko 1726 is_enforce = 0;
50 kumaneko 2403 write_status("MAC_FOR_ENV=permissive\n");
51 kumaneko 821 if (fork() == 0) {
52     execve("/bin/true", argv, envp);
53     _exit(errno);
54     }
55 kumaneko 1726 snprintf(buffer, sizeof(buffer) - 1,
56     "Executing /bin/true in permissive mode");
57 kumaneko 1744 show_prompt(buffer);
58 kumaneko 821 wait(&status);
59     errno = WEXITSTATUS(status);
60 kumaneko 1744 show_result(errno ? EOF : 0);
61 kumaneko 821
62 kumaneko 1726 is_enforce = 1;
63 kumaneko 2403 write_status("MAC_FOR_ENV=enforcing\n");
64 kumaneko 821 if (fork() == 0) {
65     execve("/bin/true", argv, envp);
66     _exit(errno);
67     }
68 kumaneko 1726 snprintf(buffer, sizeof(buffer) - 1,
69     "Executing /bin/true in enforce mode");
70 kumaneko 1744 show_prompt(buffer);
71 kumaneko 821 wait(&status);
72     errno = WEXITSTATUS(status);
73 kumaneko 1744 show_result(errno ? EOF : 0);
74 kumaneko 821
75 kumaneko 1726 is_enforce = 0;
76 kumaneko 821 if (fork() == 0) {
77     envp[0] = "";
78     execve("/bin/true", argv, envp);
79     _exit(errno);
80     }
81 kumaneko 1726 snprintf(buffer, sizeof(buffer) - 1,
82     "Executing /bin/true in enforce mode");
83 kumaneko 1744 show_prompt(buffer);
84 kumaneko 821 wait(&status);
85     errno = WEXITSTATUS(status);
86 kumaneko 1744 show_result(errno ? EOF : 0);
87 kumaneko 1726 }
88 kumaneko 821 }
89    
90 kumaneko 1726 int main(int argc, char *argv[])
91     {
92 kumaneko 1744 ccs_test_init();
93 kumaneko 2314 if (access(proc_policy_domain_policy, F_OK)) {
94     fprintf(stderr, "You can't use this program for this kernel."
95     "\n");
96 kumaneko 2313 return 1;
97 kumaneko 2314 }
98 kumaneko 1744 stage_env_test();
99     clear_status();
100 kumaneko 821 return 0;
101     }

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