4 * TOMOYO Linux's utilities.
6 * Copyright (C) 2005-2011 NTT DATA CORPORATION
8 * Version: 1.8.1 2011/04/01
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 *****/
54 #define CCS_ROOT_NAME "<kernel>"
55 #define CCS_ROOT_NAME_LEN (sizeof(CCS_ROOT_NAME) - 1)
57 #define CCS_PROC_POLICY_DIR "/proc/ccs/"
58 #define CCS_PROC_POLICY_DOMAIN_POLICY "/proc/ccs/domain_policy"
59 #define CCS_PROC_POLICY_DOMAIN_STATUS "/proc/ccs/.domain_status"
60 #define CCS_PROC_POLICY_EXCEPTION_POLICY "/proc/ccs/exception_policy"
61 #define CCS_PROC_POLICY_AUDIT "/proc/ccs/audit"
62 #define CCS_PROC_POLICY_MANAGER "/proc/ccs/manager"
63 #define CCS_PROC_POLICY_STAT "/proc/ccs/stat"
64 #define CCS_PROC_POLICY_PROCESS_STATUS "/proc/ccs/.process_status"
65 #define CCS_PROC_POLICY_PROFILE "/proc/ccs/profile"
66 #define CCS_PROC_POLICY_QUERY "/proc/ccs/query"
68 /***** CONSTANTS DEFINITION END *****/
70 /***** STRUCTURES DEFINITION START *****/
72 struct ccs_path_info {
74 u32 hash; /* = ccs_full_name_hash(name, total_len) */
75 u16 total_len; /* = strlen(name) */
76 u16 const_len; /* = ccs_const_part_length(name) */
77 _Bool is_dir; /* = ccs_strendswith(name, "/") */
78 _Bool is_patterned; /* = const_len < total_len */
81 struct ccs_ip_address_entry {
87 struct ccs_number_entry {
92 struct ccs_domain_info {
93 const struct ccs_path_info *domainname;
94 const char *target_domainname; /* This may be NULL */
95 const struct ccs_transition_control_entry *d_t; /* This may be NULL */
96 const struct ccs_path_info **string_ptr;
98 int number; /* domain number (-1 if is_dis or is_dd) */
100 _Bool is_dis; /* domain initializer source */
101 _Bool is_dit; /* domain initializer target */
102 _Bool is_dk; /* domain keeper */
103 _Bool is_du; /* unreachable domain */
104 _Bool is_dd; /* deleted domain */
105 _Bool profile_assigned;
109 struct ccs_domain_policy {
110 struct ccs_domain_info *list;
112 unsigned char *list_selected;
115 struct ccs_task_entry {
126 /***** STRUCTURES DEFINITION END *****/
128 /***** PROTOTYPES DEFINITION START *****/
130 FILE *ccs_open_read(const char *filename);
131 FILE *ccs_open_write(const char *filename);
132 _Bool ccs_check_remote_host(void);
133 _Bool ccs_close_write(FILE *fp);
134 _Bool ccs_correct_domain(const char *domainname);
135 _Bool ccs_correct_path(const char *filename);
136 _Bool ccs_correct_word(const char *string);
137 _Bool ccs_decode(const char *ascii, char *bin);
138 _Bool ccs_domain_def(const char *domainname);
139 _Bool ccs_identical_file(const char *file1, const char *file2);
140 _Bool ccs_move_proc_to_file(const char *src, const char *dest);
141 _Bool ccs_path_matches_pattern(const struct ccs_path_info *pathname0,
142 const struct ccs_path_info *pattern0);
143 _Bool ccs_pathcmp(const struct ccs_path_info *a, const struct ccs_path_info *b);
144 _Bool ccs_str_starts(char *str, const char *begin);
145 char *ccs_freadline(FILE *fp);
146 char *ccs_freadline_unpack(FILE *fp);
147 char *ccs_make_filename(const char *prefix, const time_t time);
148 char *ccs_shprintf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
149 const char *ccs_domain_name(const struct ccs_domain_policy *dp,
151 const struct ccs_path_info *ccs_savename(const char *name);
152 int ccs_add_string_entry(struct ccs_domain_policy *dp, const char *entry,
154 int ccs_assign_domain(struct ccs_domain_policy *dp, const char *domainname,
155 const _Bool is_dis, const _Bool is_dd);
156 int ccs_del_string_entry(struct ccs_domain_policy *dp, const char *entry,
158 int ccs_find_domain(const struct ccs_domain_policy *dp, const char *domainname0,
159 const _Bool is_dis, const _Bool is_dd);
160 int ccs_find_domain_by_ptr(struct ccs_domain_policy *dp,
161 const struct ccs_path_info *domainname);
162 int ccs_open_stream(const char *filename);
163 int ccs_parse_ip(const char *address, struct ccs_ip_address_entry *entry);
164 int ccs_parse_number(const char *number, struct ccs_number_entry *entry);
165 int ccs_string_compare(const void *a, const void *b);
166 int ccs_write_domain_policy(struct ccs_domain_policy *dp, const int fd);
167 struct ccs_path_group_entry *ccs_find_path_group(const char *group_name);
168 void ccs_clear_domain_policy(struct ccs_domain_policy *dp);
169 void ccs_delete_domain(struct ccs_domain_policy *dp, const int index);
170 void ccs_fill_path_info(struct ccs_path_info *ptr);
171 void ccs_fprintf_encoded(FILE *fp, const char *ccs_pathname);
173 void ccs_handle_domain_policy(struct ccs_domain_policy *dp, FILE *fp,
175 void ccs_normalize_line(char *buffer);
176 void ccs_out_of_memory(void);
178 void ccs_read_domain_policy(struct ccs_domain_policy *dp, const char *filename);
179 void ccs_read_process_list(_Bool show_all);
181 extern _Bool ccs_freadline_raw;
182 extern _Bool ccs_network_mode;
183 extern int ccs_task_list_len;
184 extern struct ccs_task_entry *ccs_task_list;
185 extern u16 ccs_network_port;
186 extern u32 ccs_network_ip;
188 /***** PROTOTYPES DEFINITION END *****/