4 * TOMOYO Linux's utilities.
6 * Copyright (C) 2005-2011 NTT DATA CORPORATION
8 * Version: 1.8.2+ 2011/07/07
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License v2 as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #define _FILE_OFFSET_BITS 64
24 #define _LARGEFILE_SOURCE
25 #define _LARGEFILE64_SOURCE
27 #include <arpa/inet.h>
28 #include <asm/types.h>
37 #include <sys/socket.h>
39 #include <sys/types.h>
52 /***** CONSTANTS DEFINITION START *****/
56 #define TOMOYO_PROC_POLICY_DIR "/sys/kernel/security/tomoyo/"
58 #define CCS_PROC_POLICY_DIR \
59 is_ccs() ? "/proc/ccs/" : "/sys/kernel/security/tomoyo/"
60 #define CCS_PROC_POLICY_DOMAIN_POLICY \
61 is_ccs() ? "/proc/ccs/domain_policy" : \
62 "/sys/kernel/security/tomoyo/domain_policy"
63 #define CCS_PROC_POLICY_EXCEPTION_POLICY \
64 is_ccs() ? "/proc/ccs/exception_policy" : \
65 "/sys/kernel/security/tomoyo/exception_policy"
66 #define CCS_PROC_POLICY_AUDIT \
67 is_ccs() ? "/proc/ccs/audit" : \
68 "/sys/kernel/security/tomoyo/audit"
69 #define CCS_PROC_POLICY_MANAGER \
70 is_ccs() ? "/proc/ccs/manager" : \
71 "/sys/kernel/security/tomoyo/manager"
72 #define CCS_PROC_POLICY_STAT \
73 is_ccs() ? "/proc/ccs/stat" : \
74 "/sys/kernel/security/tomoyo/stat"
75 #define CCS_PROC_POLICY_PROCESS_STATUS \
76 is_ccs() ? "/proc/ccs/.process_status" : \
77 "/sys/kernel/security/tomoyo/.process_status"
78 #define CCS_PROC_POLICY_PROFILE \
79 is_ccs() ? "/proc/ccs/profile" : \
80 "/sys/kernel/security/tomoyo/profile"
81 #define CCS_PROC_POLICY_QUERY \
82 is_ccs() ? "/proc/ccs/query" : \
83 "/sys/kernel/security/tomoyo/query"
85 #define CCS_PROC_POLICY_DIR "/proc/ccs/"
86 #define CCS_PROC_POLICY_DOMAIN_POLICY "/proc/ccs/domain_policy"
87 #define CCS_PROC_POLICY_EXCEPTION_POLICY "/proc/ccs/exception_policy"
88 #define CCS_PROC_POLICY_AUDIT "/proc/ccs/audit"
89 #define CCS_PROC_POLICY_MANAGER "/proc/ccs/manager"
90 #define CCS_PROC_POLICY_STAT "/proc/ccs/stat"
91 #define CCS_PROC_POLICY_PROCESS_STATUS "/proc/ccs/.process_status"
92 #define CCS_PROC_POLICY_PROFILE "/proc/ccs/profile"
93 #define CCS_PROC_POLICY_QUERY "/proc/ccs/query"
96 /***** CONSTANTS DEFINITION END *****/
98 /***** STRUCTURES DEFINITION START *****/
100 struct ccs_path_info {
102 u32 hash; /* = ccs_full_name_hash(name, total_len) */
103 u16 total_len; /* = strlen(name) */
104 u16 const_len; /* = ccs_const_part_length(name) */
105 _Bool is_dir; /* = ccs_strendswith(name, "/") */
106 _Bool is_patterned; /* = const_len < total_len */
109 struct ccs_ip_address_entry {
115 struct ccs_number_entry {
120 struct ccs_domain_info {
121 const struct ccs_path_info *domainname;
122 const char *target_domainname; /* This may be NULL */
123 const struct ccs_transition_control_entry *d_t; /* This may be NULL */
124 const struct ccs_path_info **string_ptr;
126 int number; /* domain number (-1 if is_dis or is_dd) */
128 _Bool is_dis; /* domain initializer source */
129 _Bool is_dit; /* domain initializer target */
130 _Bool is_dk; /* domain keeper */
131 _Bool is_du; /* unreachable domain */
132 _Bool is_dd; /* deleted domain */
133 _Bool profile_assigned;
137 struct ccs_domain_policy {
138 struct ccs_domain_info *list;
140 unsigned char *list_selected;
143 struct ccs_task_entry {
154 /***** STRUCTURES DEFINITION END *****/
156 /***** PROTOTYPES DEFINITION START *****/
158 FILE *ccs_open_read(const char *filename);
159 FILE *ccs_open_write(const char *filename);
160 _Bool ccs_check_remote_host(void);
161 _Bool ccs_close_write(FILE *fp);
162 _Bool ccs_correct_domain(const char *domainname);
163 _Bool ccs_correct_path(const char *filename);
164 _Bool ccs_correct_word(const char *string);
165 _Bool ccs_decode(const char *ascii, char *bin);
166 _Bool ccs_domain_def(const char *domainname);
167 _Bool ccs_move_proc_to_file(const char *src, const char *dest);
168 _Bool ccs_path_matches_pattern(const struct ccs_path_info *pathname0,
169 const struct ccs_path_info *pattern0);
170 _Bool ccs_pathcmp(const struct ccs_path_info *a,
171 const struct ccs_path_info *b);
172 _Bool ccs_str_starts(char *str, const char *begin);
173 char *ccs_freadline(FILE *fp);
174 char *ccs_freadline_unpack(FILE *fp);
175 char *ccs_shprintf(const char *fmt, ...)
176 __attribute__ ((format(printf, 1, 2)));
177 char *ccs_strdup(const char *string);
178 const char *ccs_domain_name(const struct ccs_domain_policy *dp,
180 const struct ccs_path_info *ccs_savename(const char *name);
181 int ccs_add_string_entry(struct ccs_domain_policy *dp, const char *entry,
183 int ccs_assign_domain(struct ccs_domain_policy *dp, const char *domainname,
184 const _Bool is_dis, const _Bool is_dd);
185 int ccs_del_string_entry(struct ccs_domain_policy *dp, const char *entry,
187 int ccs_find_domain(const struct ccs_domain_policy *dp,
188 const char *domainname0, const _Bool is_dis,
190 int ccs_find_domain_by_ptr(struct ccs_domain_policy *dp,
191 const struct ccs_path_info *domainname);
192 int ccs_open_stream(const char *filename);
193 int ccs_parse_ip(const char *address, struct ccs_ip_address_entry *entry);
194 int ccs_parse_number(const char *number, struct ccs_number_entry *entry);
195 int ccs_string_compare(const void *a, const void *b);
196 int ccs_write_domain_policy(struct ccs_domain_policy *dp, const int fd);
197 struct ccs_path_group_entry *ccs_find_path_group(const char *group_name);
198 void *ccs_malloc(const size_t size);
199 void *ccs_realloc(void *ptr, const size_t size);
200 void *ccs_realloc2(void *ptr, const size_t size);
201 void ccs_clear_domain_policy(struct ccs_domain_policy *dp);
202 void ccs_delete_domain(struct ccs_domain_policy *dp, const int index);
203 void ccs_fill_path_info(struct ccs_path_info *ptr);
204 void ccs_fprintf_encoded(FILE *fp, const char *ccs_pathname);
206 void ccs_handle_domain_policy(struct ccs_domain_policy *dp, FILE *fp,
208 void ccs_normalize_line(char *buffer);
210 void ccs_read_domain_policy(struct ccs_domain_policy *dp,
211 const char *filename);
212 void ccs_read_process_list(_Bool show_all);
214 extern _Bool ccs_freadline_raw;
215 extern _Bool ccs_network_mode;
216 extern int ccs_task_list_len;
217 extern struct ccs_task_entry *ccs_task_list;
218 extern u16 ccs_network_port;
219 extern u32 ccs_network_ip;
221 /***** PROTOTYPES DEFINITION END *****/