1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 * Gui Policy Editor for TOMOYO Linux
6 * Copyright (C) Yoshihiro Kusuno 2010,2011 <yocto@users.sourceforge.jp>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Library General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
23 int get_domain_policy(struct ccs_domain_policy *dp, int *count)
27 ccs_domain_sort_type = 0;
28 ccs_current_screen = CCS_SCREEN_DOMAIN_LIST;
30 result = ccs_generic_list_loop();
32 *count = dp->list_len - ccs_unnumbered_domain_count;
36 int add_domain(char *input, char **err_buff)
40 ccs_current_screen = CCS_SCREEN_DOMAIN_LIST;
46 (*err_buff) = strdup(ccs_last_error);
48 ccs_last_error = NULL;
55 int set_profile(struct ccs_domain_policy *dp,
56 char *profile, char **err_buff)
58 int dummy = 0, result = 0;
60 ccs_current_screen = CCS_SCREEN_DOMAIN_LIST;
63 ccs_set_profile(dummy);
68 (*err_buff) = strdup(ccs_last_error);
70 ccs_last_error = NULL;
77 int get_task_list(struct ccs_task_entry **tsk, int *count)
81 ccs_domain_sort_type = 1;
82 ccs_current_screen = CCS_SCREEN_DOMAIN_LIST;
83 result = ccs_generic_list_loop();
85 *count = ccs_task_list_len;
89 static void generic_acl_copy(struct ccs_generic_acl **src, int src_cnt,
90 struct ccs_generic_acl **dst, int dst_cnt)
95 free((void *)((*dst)[--dst_cnt].operand));
97 *dst = realloc(*dst, src_cnt * sizeof(struct ccs_generic_acl));
101 memcpy(*dst, ccs_gacl_list,
102 src_cnt * sizeof(struct ccs_generic_acl));
103 for (i = 0; i < src_cnt; i++) {
104 (*dst)[i].directive = (*src)[i].directive;
105 (*dst)[i].selected = (*src)[i].selected;
106 (*dst)[i].operand = strdup((*src)[i].operand);
107 if (!((*dst)[i].operand))
112 int get_acl_list(struct ccs_domain_policy *dp, int current,
113 struct ccs_generic_acl **ga, int *count)
118 if (ccs_initializer_source(current)) {
120 } else if (ccs_deleted_domain(current)) {
123 free(ccs_current_domain);
124 ccs_current_domain = strdup(ccs_domain_name(dp, current));
125 if (!ccs_current_domain)
128 ccs_domain_sort_type = 0;
129 ccs_current_screen = CCS_SCREEN_ACL_LIST;
130 result = ccs_generic_list_loop();
131 generic_acl_copy(&ccs_gacl_list,
134 *count = ccs_gacl_list_count;
141 int get_process_acl_list(int current,
142 struct ccs_generic_acl **ga, int *count)
146 free(ccs_current_domain);
147 ccs_current_pid = ccs_task_list[current].pid;
148 ccs_current_domain = strdup(ccs_task_list[current].domain);
149 if (!ccs_current_domain)
152 ccs_domain_sort_type = 1;
153 ccs_current_screen = CCS_SCREEN_ACL_LIST;
154 result = ccs_generic_list_loop();
155 generic_acl_copy(&ccs_gacl_list,
158 *count = ccs_gacl_list_count;
163 int get_optimize_acl_list(int current, struct ccs_generic_acl **ga, int count)
165 ccs_current_screen = CCS_SCREEN_ACL_LIST;
166 ccs_policy_file = CCS_PROC_POLICY_DOMAIN_POLICY;
168 generic_acl_copy(ga, count, &ccs_gacl_list, ccs_gacl_list_count);
170 ccs_list_item_count = ccs_gacl_list_count = count;
171 ccs_editpolicy_optimize(current);
173 generic_acl_copy(&ccs_gacl_list, ccs_gacl_list_count, ga, count);
178 int add_acl_list(struct ccs_domain_policy *dp, int current,
179 char *input, char **err_buff)
184 if (ccs_initializer_source(current) ||
185 ccs_deleted_domain(current)) {
190 ccs_current_screen = CCS_SCREEN_ACL_LIST;
196 if (ccs_last_error) {
197 (*err_buff) = strdup(ccs_last_error);
198 free(ccs_last_error);
199 ccs_last_error = NULL;
206 const char *get_transition_name(enum ccs_transition_type type)
208 return ccs_transition_type[type];
211 int get_exception_policy(struct ccs_generic_acl **ga, int *count)
215 ccs_current_screen = CCS_SCREEN_EXCEPTION_LIST;
216 result = ccs_generic_list_loop();
218 *count = ccs_gacl_list_count;
222 int add_exception_policy(char *input, char **err_buff)
226 ccs_current_screen = CCS_SCREEN_EXCEPTION_LIST;
231 if (ccs_last_error) {
232 (*err_buff) = strdup(ccs_last_error);
233 free(ccs_last_error);
234 ccs_last_error = NULL;
241 int get_profile(struct ccs_generic_acl **ga, int *count)
246 free((void *)((*ga)[--(*count)].operand));
248 ccs_current_screen = CCS_SCREEN_PROFILE_LIST;
249 result = ccs_generic_list_loop();
251 generic_acl_copy(&ccs_gacl_list,
254 *count = ccs_gacl_list_count;
259 int add_profile(char *input, char **err_buff)
263 ccs_current_screen = CCS_SCREEN_PROFILE_LIST;
268 if (ccs_last_error) {
269 (*err_buff) = strdup(ccs_last_error);
270 free(ccs_last_error);
271 ccs_last_error = NULL;
278 int set_profile_level(int index, const char *input, char **err_buff)
282 ccs_current_screen = CCS_SCREEN_PROFILE_LIST;
283 ccs_gacl_list[index].selected = 1;
284 gpet_line = (char *)input;
288 if (ccs_last_error) {
289 (*err_buff) = strdup(ccs_last_error);
290 free(ccs_last_error);
291 ccs_last_error = NULL;
298 int get_manager(struct ccs_generic_acl **ga, int *count)
300 struct ccs_generic_acl *orig_generic_acl_list = NULL;
301 int orig_generic_acl_list_count = 0;
304 generic_acl_copy(&ccs_gacl_list,
306 &orig_generic_acl_list,
307 orig_generic_acl_list_count);
308 orig_generic_acl_list_count = ccs_gacl_list_count;
310 ccs_current_screen = CCS_SCREEN_MANAGER_LIST;
311 result = ccs_generic_list_loop();
313 generic_acl_copy(&ccs_gacl_list,
316 *count = ccs_gacl_list_count;
318 generic_acl_copy(&orig_generic_acl_list,
319 orig_generic_acl_list_count,
321 ccs_gacl_list_count);
322 ccs_gacl_list_count = orig_generic_acl_list_count;
327 int add_manager(char *input, char **err_buff)
331 ccs_current_screen = CCS_SCREEN_MANAGER_LIST;
336 if (ccs_last_error) {
337 (*err_buff) = strdup(ccs_last_error);
338 free(ccs_last_error);
339 ccs_last_error = NULL;
346 int get_memory(struct ccs_generic_acl **ga, int *count)
348 struct ccs_generic_acl *orig_generic_acl_list = NULL;
349 int orig_generic_acl_list_count = 0;
352 generic_acl_copy(&ccs_gacl_list,
354 &orig_generic_acl_list,
355 orig_generic_acl_list_count);
356 orig_generic_acl_list_count = ccs_gacl_list_count;
358 ccs_current_screen = CCS_SCREEN_STAT_LIST;
359 result = ccs_generic_list_loop();
361 generic_acl_copy(&ccs_gacl_list,
364 *count = ccs_gacl_list_count;
366 generic_acl_copy(&orig_generic_acl_list,
367 orig_generic_acl_list_count,
369 ccs_gacl_list_count);
370 ccs_gacl_list_count = orig_generic_acl_list_count;
375 int set_memory(struct ccs_generic_acl *ga, int count, char **err_buff)
379 ccs_current_screen = CCS_SCREEN_STAT_LIST;
380 ccs_policy_file = CCS_PROC_POLICY_STAT;
381 generic_acl_copy(&ga, count,
382 &ccs_gacl_list, ccs_gacl_list_count);
383 ccs_gacl_list_count = count;
385 for (i = 0; i < count; i++) {
386 ccs_gacl_list[i].selected = 0;
389 for (i = 0; i < count; i++) {
391 cp = strrchr(ccs_gacl_list[i].operand, ':');
392 if (cp && ga[i].selected) {
393 gpet_line = strdup(++cp);
394 // fprintf(stderr, "mem:%2d[%s][%s]\n", i, ccs_gacl_list[i].operand, cp);
395 ccs_gacl_list[i].selected = 1;
397 ccs_gacl_list[i].selected = 0;
401 if (ccs_last_error) {
402 (*err_buff) = strdup(ccs_last_error);
403 free(ccs_last_error);
404 ccs_last_error = NULL;
411 int delete_domain_policy(struct ccs_domain_policy *dp, char **err_buff)
415 ccs_current_screen = CCS_SCREEN_DOMAIN_LIST;
416 ccs_policy_file = CCS_PROC_POLICY_DOMAIN_POLICY;
418 ccs_delete_entry(-1);
421 if (ccs_last_error) {
422 (*err_buff) = strdup(ccs_last_error);
423 free(ccs_last_error);
424 ccs_last_error = NULL;
431 int delete_acl_policy(struct ccs_domain_policy *dp, char **err_buff,
432 struct ccs_generic_acl *ga, int count)
436 ccs_current_screen = CCS_SCREEN_ACL_LIST;
437 ccs_policy_file = CCS_PROC_POLICY_DOMAIN_POLICY;
439 generic_acl_copy(&ga, count,
440 &ccs_gacl_list, ccs_gacl_list_count);
441 ccs_gacl_list_count = count;
443 ccs_delete_entry(-1);
446 if (ccs_last_error) {
447 (*err_buff) = strdup(ccs_last_error);
448 free(ccs_last_error);
449 ccs_last_error = NULL;
456 int delete_exp_policy(struct ccs_domain_policy *dp, char **err_buff,
457 struct ccs_generic_acl *ga, int count)
461 ccs_current_screen = CCS_SCREEN_EXCEPTION_LIST;
462 ccs_policy_file = CCS_PROC_POLICY_EXCEPTION_POLICY;
464 ccs_gacl_list_count = count;
466 ccs_delete_entry(-1);
469 if (ccs_last_error) {
470 (*err_buff) = strdup(ccs_last_error);
471 free(ccs_last_error);
472 ccs_last_error = NULL;
479 int delete_manager_policy(
480 struct ccs_generic_acl *ga, int count, char **err_buff)
484 ccs_current_screen = CCS_SCREEN_MANAGER_LIST;
485 ccs_policy_file = CCS_PROC_POLICY_MANAGER;
486 generic_acl_copy(&ga, count,
487 &ccs_gacl_list, ccs_gacl_list_count);
488 ccs_gacl_list_count = count;
489 ccs_delete_entry(-1);
491 if (ccs_last_error) {
492 (*err_buff) = strdup(ccs_last_error);
493 free(ccs_last_error);
494 ccs_last_error = NULL;
503 return ccs_offline_mode;
508 return ccs_network_mode;
511 char *get_remote_ip(char *str_ip)
513 const u32 ip = ntohl(ccs_network_ip);
514 sprintf(str_ip, "%u.%u.%u.%u:%u",
515 (u8) (ip >> 24), (u8) (ip >> 16),
516 (u8) (ip >> 8), (u8) ip, ntohs(ccs_network_port));
520 const char *get_policy_dir(void)
522 return ccs_policy_dir;
525 const char *get_domain_last_name(const int index)
527 return ccs_get_last_name(index);