221 |
return value ? "yes" : "no"; |
return value ? "yes" : "no"; |
222 |
} |
} |
223 |
|
|
224 |
|
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
225 |
|
{ |
226 |
|
va_list args; |
227 |
|
const int pos = strlen(buffer); |
228 |
|
va_start(args, fmt); |
229 |
|
vsnprintf(buffer + pos, len - pos - 1, fmt, args); |
230 |
|
va_end(args); |
231 |
|
} |
232 |
|
|
233 |
/** |
/** |
234 |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
* ccs_flush - Flush queued string to userspace's buffer. |
235 |
* |
* |
236 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* @fmt: The printf()'s format string, followed by parameters. |
|
237 |
* |
* |
238 |
* Returns true on success, false otherwise. |
* Returns true if all data was flushed, false otherwise. |
239 |
|
*/ |
240 |
|
static bool ccs_flush(struct ccs_io_buffer *head) |
241 |
|
{ |
242 |
|
while (head->r.w_pos) { |
243 |
|
const char *w = head->r.w[0]; |
244 |
|
int len = strlen(w); |
245 |
|
if (len) { |
246 |
|
if (len > head->read_user_buf_avail) |
247 |
|
len = head->read_user_buf_avail; |
248 |
|
if (!len) |
249 |
|
return false; |
250 |
|
if (copy_to_user(head->read_user_buf, w, len)) |
251 |
|
return false; |
252 |
|
head->read_user_buf_avail -= len; |
253 |
|
head->read_user_buf += len; |
254 |
|
w += len; |
255 |
|
} |
256 |
|
if (*w) { |
257 |
|
head->r.w[0] = w; |
258 |
|
return false; |
259 |
|
} |
260 |
|
/* Add '\0' for audit logs and query. */ |
261 |
|
if (head->poll) { |
262 |
|
if (!head->read_user_buf_avail || |
263 |
|
copy_to_user(head->read_user_buf, "", 1)) |
264 |
|
return false; |
265 |
|
head->read_user_buf_avail--; |
266 |
|
head->read_user_buf++; |
267 |
|
} |
268 |
|
head->r.w_pos--; |
269 |
|
for (len = 0; len < head->r.w_pos; len++) |
270 |
|
head->r.w[len] = head->r.w[len + 1]; |
271 |
|
} |
272 |
|
head->r.avail = 0; |
273 |
|
return true; |
274 |
|
} |
275 |
|
|
276 |
|
/** |
277 |
|
* ccs_set_string - Queue string to "struct ccs_io_buffer" structure. |
278 |
* |
* |
279 |
* The snprintf() will truncate, but ccs_io_printf() won't. |
* @head: Pointer to "struct ccs_io_buffer". |
280 |
|
* @string: String to print. |
281 |
|
* |
282 |
|
* Note that @string has to be kept valid until @head is kfree()d. |
283 |
|
* This means that char[] allocated on stack memory cannot be passed to |
284 |
|
* this function. Use ccs_io_printf() for char[] allocated on stack memory. |
285 |
*/ |
*/ |
286 |
bool ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
static void ccs_set_string(struct ccs_io_buffer *head, const char *string) |
287 |
|
{ |
288 |
|
if (head->r.w_pos < CCS_MAX_IO_READ_QUEUE) { |
289 |
|
head->r.w[head->r.w_pos++] = string; |
290 |
|
ccs_flush(head); |
291 |
|
} else |
292 |
|
WARN_ON(1); |
293 |
|
} |
294 |
|
|
295 |
|
/** |
296 |
|
* ccs_io_printf - printf() to "struct ccs_io_buffer" structure. |
297 |
|
* |
298 |
|
* @head: Pointer to "struct ccs_io_buffer". |
299 |
|
* @fmt: The printf()'s format string, followed by parameters. |
300 |
|
*/ |
301 |
|
void ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
302 |
{ |
{ |
303 |
va_list args; |
va_list args; |
304 |
int len; |
int len; |
305 |
int pos = head->read_avail; |
int pos = head->r.avail; |
306 |
int size = head->readbuf_size - pos; |
int size = head->readbuf_size - pos; |
307 |
if (size <= 0) |
if (size <= 0) |
308 |
return false; |
return; |
309 |
va_start(args, fmt); |
va_start(args, fmt); |
310 |
len = vsnprintf(head->read_buf + pos, size, fmt, args); |
len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1; |
311 |
va_end(args); |
va_end(args); |
312 |
if (pos + len >= head->readbuf_size) |
if (pos + len >= head->readbuf_size) { |
313 |
return false; |
WARN_ON(1); |
314 |
head->read_avail += len; |
return; |
315 |
return true; |
} |
316 |
|
head->r.avail += len; |
317 |
|
ccs_set_string(head, head->read_buf + pos); |
318 |
|
} |
319 |
|
|
320 |
|
static void ccs_set_space(struct ccs_io_buffer *head) |
321 |
|
{ |
322 |
|
ccs_set_string(head, " "); |
323 |
|
} |
324 |
|
|
325 |
|
static bool ccs_set_lf(struct ccs_io_buffer *head) |
326 |
|
{ |
327 |
|
ccs_set_string(head, "\n"); |
328 |
|
return !head->r.w_pos; |
329 |
} |
} |
330 |
|
|
331 |
/** |
/** |
619 |
return ccs_set_mode(data, cp, use_default, profile); |
return ccs_set_mode(data, cp, use_default, profile); |
620 |
} |
} |
621 |
|
|
622 |
static bool ccs_print_preference(struct ccs_io_buffer *head, const int idx) |
static void ccs_print_preference(struct ccs_io_buffer *head, const int idx) |
623 |
{ |
{ |
624 |
struct ccs_preference *pref = &ccs_default_profile.preference; |
struct ccs_preference *pref = &ccs_default_profile.preference; |
625 |
const struct ccs_profile *profile = idx >= 0 ? |
const struct ccs_profile *profile = idx >= 0 ? |
632 |
if (profile) { |
if (profile) { |
633 |
pref = profile->audit; |
pref = profile->audit; |
634 |
if (pref == &ccs_default_profile.preference) |
if (pref == &ccs_default_profile.preference) |
635 |
pref = NULL; |
goto skip0; |
636 |
} |
} |
637 |
if (pref && !ccs_io_printf(head, "%sPREFERENCE::%s={ " |
ccs_io_printf(head, "%sPREFERENCE::%s={ " |
638 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
639 |
"max_grant_log=%u max_reject_log=%u " |
"max_grant_log=%u max_reject_log=%u " |
640 |
#endif |
#endif |
641 |
"task_info=%s path_info=%s }\n", buffer, |
"task_info=%s path_info=%s }\n", buffer, |
642 |
"audit", |
"audit", |
643 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
644 |
pref->audit_max_grant_log, |
pref->audit_max_grant_log, |
645 |
pref->audit_max_reject_log, |
pref->audit_max_reject_log, |
646 |
#endif |
#endif |
647 |
ccs_yesno(pref->audit_task_info), |
ccs_yesno(pref->audit_task_info), |
648 |
ccs_yesno(pref->audit_path_info))) |
ccs_yesno(pref->audit_path_info)); |
649 |
return false; |
skip0: |
650 |
if (profile) { |
if (profile) { |
651 |
pref = profile->learning; |
pref = profile->learning; |
652 |
if (pref == &ccs_default_profile.preference) |
if (pref == &ccs_default_profile.preference) |
653 |
pref = NULL; |
goto skip1; |
654 |
} |
} |
655 |
if (pref && !ccs_io_printf(head, "%sPREFERENCE::%s={ " |
ccs_io_printf(head, "%sPREFERENCE::%s={ " |
656 |
"verbose=%s max_entry=%u exec.realpath=%s " |
"verbose=%s max_entry=%u exec.realpath=%s " |
657 |
"exec.argv0=%s symlink.target=%s }\n", |
"exec.argv0=%s symlink.target=%s }\n", |
658 |
buffer, "learning", |
buffer, "learning", |
659 |
ccs_yesno(pref->learning_verbose), |
ccs_yesno(pref->learning_verbose), |
660 |
pref->learning_max_entry, |
pref->learning_max_entry, |
661 |
ccs_yesno(pref->learning_exec_realpath), |
ccs_yesno(pref->learning_exec_realpath), |
662 |
ccs_yesno(pref->learning_exec_argv0), |
ccs_yesno(pref->learning_exec_argv0), |
663 |
ccs_yesno(pref->learning_symlink_target))) |
ccs_yesno(pref->learning_symlink_target)); |
664 |
return false; |
skip1: |
665 |
if (profile) { |
if (profile) { |
666 |
pref = profile->permissive; |
pref = profile->permissive; |
667 |
if (pref == &ccs_default_profile.preference) |
if (pref == &ccs_default_profile.preference) |
668 |
pref = NULL; |
goto skip2; |
669 |
} |
} |
670 |
if (pref && !ccs_io_printf(head, "%sPREFERENCE::%s={ verbose=%s }\n", |
ccs_io_printf(head, "%sPREFERENCE::%s={ verbose=%s }\n", |
671 |
buffer, "permissive", |
buffer, "permissive", |
672 |
ccs_yesno(pref->permissive_verbose))) |
ccs_yesno(pref->permissive_verbose)); |
673 |
return false; |
skip2: |
674 |
if (profile) { |
if (profile) { |
675 |
pref = profile->enforcing; |
pref = profile->enforcing; |
676 |
if (pref == &ccs_default_profile.preference) |
if (pref == &ccs_default_profile.preference) |
677 |
pref = NULL; |
return; |
678 |
} |
} |
679 |
return !pref || ccs_io_printf(head, "%sPREFERENCE::%s={ verbose=%s " |
ccs_io_printf(head, "%sPREFERENCE::%s={ verbose=%s " |
680 |
"penalty=%u }\n", buffer, "enforcing", |
"penalty=%u }\n", buffer, "enforcing", |
681 |
ccs_yesno(pref->enforcing_verbose), |
ccs_yesno(pref->enforcing_verbose), |
682 |
pref->enforcing_penalty); |
pref->enforcing_penalty); |
683 |
|
} |
684 |
|
|
685 |
|
static void ccs_print_config(struct ccs_io_buffer *head, const u8 config) |
686 |
|
{ |
687 |
|
ccs_io_printf(head, "={ mode=%s", ccs_mode[config & 3]); |
688 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
689 |
|
ccs_io_printf(head, " grant_log=%s reject_log=%s", |
690 |
|
ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG), |
691 |
|
ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG)); |
692 |
|
#endif |
693 |
|
ccs_set_string(head, " }\n"); |
694 |
} |
} |
695 |
|
|
696 |
/** |
/** |
700 |
*/ |
*/ |
701 |
static void ccs_read_profile(struct ccs_io_buffer *head) |
static void ccs_read_profile(struct ccs_io_buffer *head) |
702 |
{ |
{ |
703 |
int index; |
u8 index; |
704 |
if (head->read_eof) |
const struct ccs_profile *profile; |
705 |
return; |
next: |
706 |
if (head->read_bit) |
index = head->r.index; |
707 |
goto body; |
profile = ccs_profile_ptr[index]; |
708 |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
switch (head->r.step) { |
709 |
ccs_print_preference(head, -1); |
case 0: |
710 |
head->read_bit = 1; |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
711 |
body: |
ccs_print_preference(head, -1); |
712 |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
head->r.step++; |
713 |
bool done; |
break; |
714 |
u8 config; |
case 1: |
715 |
int i; |
for ( ; head->r.index < CCS_MAX_PROFILES; |
716 |
int pos; |
head->r.index++) |
717 |
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
if (ccs_profile_ptr[head->r.index]) |
718 |
const struct ccs_path_info *comment; |
break; |
719 |
head->read_step = index; |
if (head->r.index == CCS_MAX_PROFILES) |
720 |
if (!profile) |
return; |
721 |
continue; |
head->r.step++; |
722 |
pos = head->read_avail; |
break; |
723 |
comment = profile->comment; |
case 2: |
724 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
{ |
725 |
comment ? comment->name : ""); |
const struct ccs_path_info *comment = profile->comment; |
726 |
if (!done) |
ccs_io_printf(head, "%u-COMMENT=", index); |
727 |
goto out; |
ccs_set_string(head, comment ? comment->name : ""); |
728 |
config = profile->default_config; |
ccs_set_lf(head); |
729 |
#ifdef CONFIG_CCSECURITY_AUDIT |
head->r.step++; |
730 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
} |
731 |
"grant_log=%s reject_log=%s }\n", index, |
break; |
732 |
"CONFIG", "", ccs_mode[config & 3], |
case 3: |
733 |
ccs_yesno(config & |
{ |
734 |
CCS_CONFIG_WANT_GRANT_LOG), |
ccs_io_printf(head, "%u-%s", index, "CONFIG"); |
735 |
ccs_yesno(config & |
ccs_print_config(head, profile->default_config); |
736 |
CCS_CONFIG_WANT_REJECT_LOG))) |
head->r.bit = 0; |
737 |
goto out; |
head->r.step++; |
738 |
#else |
} |
739 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", index, |
break; |
740 |
"CONFIG", "", ccs_mode[config & 3])) |
case 4: |
741 |
goto out; |
for ( ; head->r.bit < CCS_MAX_MAC_INDEX |
742 |
#endif |
+ CCS_MAX_CAPABILITY_INDEX |
743 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
+ CCS_MAX_MAC_CATEGORY_INDEX; head->r.bit++) { |
744 |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
const u8 i = head->r.bit; |
745 |
#ifdef CONFIG_CCSECURITY_AUDIT |
const u8 config = profile->config[i]; |
|
const char *g; |
|
|
const char *r; |
|
|
#endif |
|
|
config = profile->config[i]; |
|
746 |
if (config == CCS_CONFIG_USE_DEFAULT) |
if (config == CCS_CONFIG_USE_DEFAULT) |
747 |
continue; |
continue; |
748 |
#ifdef CONFIG_CCSECURITY_AUDIT |
ccs_io_printf(head, "%u-%s%s", index, "CONFIG::", |
749 |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
ccs_mac_keywords[i]); |
750 |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
ccs_print_config(head, config); |
751 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
head->r.bit++; |
752 |
"grant_log=%s reject_log=%s }\n", |
break; |
753 |
index, "CONFIG::", |
} |
754 |
ccs_mac_keywords[i], |
if (head->r.bit == CCS_MAX_MAC_INDEX |
755 |
ccs_mode[config & 3], g, r)) |
+ CCS_MAX_CAPABILITY_INDEX |
756 |
goto out; |
+ CCS_MAX_MAC_CATEGORY_INDEX) { |
757 |
#else |
ccs_print_preference(head, index); |
758 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", |
head->r.index++; |
759 |
index, "CONFIG::", |
head->r.step = 1; |
|
ccs_mac_keywords[i], |
|
|
ccs_mode[config & 3])) |
|
|
goto out; |
|
|
#endif |
|
760 |
} |
} |
|
if (!ccs_print_preference(head, index)) |
|
|
goto out; |
|
|
continue; |
|
|
out: |
|
|
head->read_avail = pos; |
|
761 |
break; |
break; |
762 |
} |
} |
763 |
if (index == CCS_MAX_PROFILES) |
if (ccs_flush(head)) |
764 |
head->read_eof = true; |
goto next; |
765 |
} |
} |
766 |
|
|
767 |
static bool ccs_same_manager_entry(const struct ccs_acl_head *a, |
static bool ccs_same_manager_entry(const struct ccs_acl_head *a, |
828 |
*/ |
*/ |
829 |
static void ccs_read_manager(struct ccs_io_buffer *head) |
static void ccs_read_manager(struct ccs_io_buffer *head) |
830 |
{ |
{ |
831 |
struct list_head *pos; |
if (head->r.eof) |
|
if (head->read_eof) |
|
832 |
return; |
return; |
833 |
list_for_each_cookie(pos, head->read_var2, |
list_for_each_cookie(head->r.acl, &ccs_policy_list[CCS_ID_MANAGER]) { |
834 |
&ccs_policy_list[CCS_ID_MANAGER]) { |
struct ccs_manager *ptr = |
835 |
struct ccs_manager *ptr |
list_entry(head->r.acl, typeof(*ptr), head.list); |
|
= list_entry(pos, typeof(*ptr), head.list); |
|
836 |
if (ptr->head.is_deleted) |
if (ptr->head.is_deleted) |
837 |
continue; |
continue; |
838 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_flush(head)) |
839 |
return; |
return; |
840 |
|
ccs_set_string(head, ptr->manager->name); |
841 |
|
ccs_set_lf(head); |
842 |
} |
} |
843 |
head->read_eof = true; |
head->r.eof = true; |
844 |
} |
} |
845 |
|
|
846 |
/** |
/** |
929 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
930 |
bool global_pid = false; |
bool global_pid = false; |
931 |
if (!strcmp(data, "allow_execute")) { |
if (!strcmp(data, "allow_execute")) { |
932 |
head->read_execute_only = true; |
head->r.print_execute_only = true; |
933 |
return true; |
return true; |
934 |
} |
} |
935 |
if (sscanf(data, "pid=%u", &pid) == 1 || |
if (sscanf(data, "pid=%u", &pid) == 1 || |
953 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
954 |
} else |
} else |
955 |
return false; |
return false; |
956 |
head->write_var1 = domain; |
head->w.domain = domain; |
957 |
/* Accessing read_buf is safe because head->io_sem is held. */ |
/* Accessing read_buf is safe because head->io_sem is held. */ |
958 |
if (!head->read_buf) |
if (!head->read_buf) |
959 |
return true; /* Do nothing if open(O_WRONLY). */ |
return true; /* Do nothing if open(O_WRONLY). */ |
960 |
head->read_avail = 0; |
memset(&head->r, 0, sizeof(head->r)); |
961 |
head->read_cond = false; |
head->r.print_this_domain_only = true; |
962 |
|
head->r.eof = !domain; |
963 |
|
head->r.domain = &domain->list; |
964 |
ccs_io_printf(head, "# select %s\n", data); |
ccs_io_printf(head, "# select %s\n", data); |
|
head->read_single_domain = true; |
|
|
head->read_eof = !domain; |
|
|
head->read_var1 = &domain->list; |
|
|
head->read_var2 = NULL; |
|
|
head->read_bit = 0; |
|
|
head->read_step = 0; |
|
965 |
if (domain && domain->is_deleted) |
if (domain && domain->is_deleted) |
966 |
ccs_io_printf(head, "# This is a deleted domain.\n"); |
ccs_set_string(head, "# This is a deleted domain.\n"); |
967 |
return true; |
return true; |
968 |
} |
} |
969 |
|
|
1024 |
static int ccs_write_domain(struct ccs_io_buffer *head) |
static int ccs_write_domain(struct ccs_io_buffer *head) |
1025 |
{ |
{ |
1026 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1027 |
struct ccs_domain_info *domain = head->write_var1; |
struct ccs_domain_info *domain = head->w.domain; |
1028 |
bool is_delete = false; |
bool is_delete = false; |
1029 |
bool is_select = false; |
bool is_select = false; |
1030 |
unsigned int profile; |
unsigned int profile; |
1045 |
domain = ccs_find_domain(data); |
domain = ccs_find_domain(data); |
1046 |
else |
else |
1047 |
domain = ccs_assign_domain(data, 0); |
domain = ccs_assign_domain(data, 0); |
1048 |
head->write_var1 = domain; |
head->w.domain = domain; |
1049 |
return 0; |
return 0; |
1050 |
} |
} |
1051 |
if (!domain) |
if (!domain) |
1072 |
* |
* |
1073 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1074 |
* @ptr: Pointer to "struct ccs_name_union". |
* @ptr: Pointer to "struct ccs_name_union". |
|
* |
|
|
* Returns true on success, false otherwise. |
|
1075 |
*/ |
*/ |
1076 |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
static void ccs_print_name_union(struct ccs_io_buffer *head, |
1077 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
1078 |
{ |
{ |
1079 |
int pos = head->read_avail; |
const bool cond = head->r.print_cond_part; |
1080 |
if (pos && head->read_buf[pos - 1] == ' ') |
if (!cond) |
1081 |
head->read_avail--; |
ccs_set_space(head); |
1082 |
if (ptr->is_group) |
if (ptr->is_group) { |
1083 |
return ccs_io_printf(head, " @%s", |
ccs_set_string(head, "@"); |
1084 |
ptr->group->group_name->name); |
ccs_set_string(head, ptr->group->group_name->name); |
1085 |
return ccs_io_printf(head, " %s", ptr->filename->name); |
} else { |
1086 |
} |
if (cond) |
1087 |
|
ccs_set_string(head, "\""); |
1088 |
/** |
ccs_set_string(head, ptr->filename->name); |
1089 |
* ccs_print_name_union_quoted - Print a ccs_name_union with double quotes. |
if (cond) |
1090 |
* |
ccs_set_string(head, "\""); |
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_name_union". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
|
|
const struct ccs_name_union *ptr) |
|
|
{ |
|
|
if (ptr->is_group) |
|
|
return ccs_io_printf(head, "@%s", |
|
|
ptr->group->group_name->name); |
|
|
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
|
|
} |
|
|
|
|
|
static void ccs_print_number(char *buffer, int buffer_len, |
|
|
const struct ccs_number_union *ptr) |
|
|
{ |
|
|
int i; |
|
|
unsigned long min = ptr->values[0]; |
|
|
const unsigned long max = ptr->values[1]; |
|
|
u8 min_type = ptr->value_type[0]; |
|
|
const u8 max_type = ptr->value_type[1]; |
|
|
memset(buffer, 0, buffer_len); |
|
|
buffer_len -= 2; |
|
|
for (i = 0; i < 2; i++) { |
|
|
int len; |
|
|
switch (min_type) { |
|
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
|
|
snprintf(buffer, buffer_len, "0x%lX", min); |
|
|
break; |
|
|
case CCS_VALUE_TYPE_OCTAL: |
|
|
snprintf(buffer, buffer_len, "0%lo", min); |
|
|
break; |
|
|
default: |
|
|
snprintf(buffer, buffer_len, "%lu", min); |
|
|
break; |
|
|
} |
|
|
if (min == max && min_type == max_type) |
|
|
break; |
|
|
len = strlen(buffer); |
|
|
buffer[len++] = '-'; |
|
|
buffer += len; |
|
|
buffer_len -= len; |
|
|
min_type = max_type; |
|
|
min = max; |
|
1091 |
} |
} |
1092 |
} |
} |
1093 |
|
|
1094 |
/** |
/** |
|
* ccs_print_number_union_common - Print a ccs_number_union. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_number_union". |
|
|
* @need_space: True if a space character is needed. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
|
|
const struct ccs_number_union *ptr, |
|
|
const bool need_space) |
|
|
{ |
|
|
char buffer[128]; |
|
|
if (need_space && !ccs_io_printf(head, " ")) |
|
|
return false; |
|
|
if (ptr->is_group) |
|
|
return ccs_io_printf(head, "@%s", |
|
|
ptr->group->group_name->name); |
|
|
ccs_print_number(buffer, sizeof(buffer), ptr); |
|
|
return ccs_io_printf(head, "%s", buffer); |
|
|
} |
|
|
|
|
|
/** |
|
1095 |
* ccs_print_number_union - Print a ccs_number_union. |
* ccs_print_number_union - Print a ccs_number_union. |
1096 |
* |
* |
1097 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1098 |
* @ptr: Pointer to "struct ccs_number_union". |
* @ptr: Pointer to "struct ccs_number_union". |
|
* |
|
|
* Returns true on success, false otherwise. |
|
1099 |
*/ |
*/ |
1100 |
static bool ccs_print_number_union(struct ccs_io_buffer *head, |
static void ccs_print_number_union(struct ccs_io_buffer *head, |
1101 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1102 |
{ |
{ |
1103 |
return ccs_print_number_union_common(head, ptr, true); |
if (!head->r.print_cond_part) |
1104 |
} |
ccs_set_space(head); |
1105 |
|
if (ptr->is_group) { |
1106 |
/** |
ccs_set_string(head, "@"); |
1107 |
* ccs_print_number_union_nospace - Print a ccs_number_union without a space character. |
ccs_set_string(head, ptr->group->group_name->name); |
1108 |
* |
} else { |
1109 |
* @head: Pointer to "struct ccs_io_buffer". |
int i; |
1110 |
* @ptr: Pointer to "struct ccs_number_union". |
unsigned long min = ptr->values[0]; |
1111 |
* |
const unsigned long max = ptr->values[1]; |
1112 |
* Returns true on success, false otherwise. |
u8 min_type = ptr->value_type[0]; |
1113 |
*/ |
const u8 max_type = ptr->value_type[1]; |
1114 |
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
char buffer[128]; |
1115 |
const struct ccs_number_union *ptr) |
buffer[0] = '\0'; |
1116 |
{ |
for (i = 0; i < 2; i++) { |
1117 |
return ccs_print_number_union_common(head, ptr, false); |
switch (min_type) { |
1118 |
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
1119 |
|
ccs_addprintf(buffer, sizeof(buffer), "0x%lX", |
1120 |
|
min); |
1121 |
|
break; |
1122 |
|
case CCS_VALUE_TYPE_OCTAL: |
1123 |
|
ccs_addprintf(buffer, sizeof(buffer), "0%lo", |
1124 |
|
min); |
1125 |
|
break; |
1126 |
|
default: |
1127 |
|
ccs_addprintf(buffer, sizeof(buffer), "%lu", |
1128 |
|
min); |
1129 |
|
break; |
1130 |
|
} |
1131 |
|
if (min == max && min_type == max_type) |
1132 |
|
break; |
1133 |
|
ccs_addprintf(buffer, sizeof(buffer), "-"); |
1134 |
|
min_type = max_type; |
1135 |
|
min = max; |
1136 |
|
} |
1137 |
|
ccs_io_printf(head, "%s", buffer); |
1138 |
|
} |
1139 |
} |
} |
1140 |
|
|
1141 |
/** |
/** |
1142 |
* ccs_print_condition - Print condition part. |
* ccs_print_condition - Print condition part. |
1143 |
* |
* |
1144 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1145 |
* @cond: Pointer to "struct ccs_condition". Maybe NULL. |
* @cond: Pointer to "struct ccs_condition". |
1146 |
* |
* |
1147 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1148 |
*/ |
*/ |
1149 |
static bool ccs_print_condition(struct ccs_io_buffer *head, |
static bool ccs_print_condition(struct ccs_io_buffer *head, |
1150 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1151 |
{ |
{ |
1152 |
const struct ccs_condition_element *condp; |
switch (head->r.cond_step) { |
1153 |
const struct ccs_number_union *numbers_p; |
case 0: |
1154 |
const struct ccs_name_union *names_p; |
{ |
1155 |
const struct ccs_argv *argv; |
if (cond->condc) |
1156 |
const struct ccs_envp *envp; |
ccs_set_string(head, " if"); |
1157 |
u16 condc; |
head->r.cond_index = 0; |
1158 |
u16 i; |
head->r.cond_step++; |
1159 |
u16 j; |
} |
1160 |
char buffer[32]; |
/* fall through */ |
1161 |
if (!cond) |
case 1: |
1162 |
goto no_condition; |
{ |
1163 |
condc = cond->condc; |
const u16 condc = cond->condc; |
1164 |
condp = (const struct ccs_condition_element *) (cond + 1); |
const struct ccs_condition_element *condp = |
1165 |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
(typeof(condp)) (cond + 1); |
1166 |
names_p = (const struct ccs_name_union *) |
const struct ccs_number_union *numbers_p = |
1167 |
(numbers_p + cond->numbers_count); |
(typeof(numbers_p)) (condp + condc); |
1168 |
argv = (const struct ccs_argv *) (names_p + cond->names_count); |
const struct ccs_name_union *names_p = |
1169 |
envp = (const struct ccs_envp *) (argv + cond->argc); |
(typeof(names_p)) |
1170 |
memset(buffer, 0, sizeof(buffer)); |
(numbers_p + cond->numbers_count); |
1171 |
if (condc && !ccs_io_printf(head, "%s", " if")) |
const struct ccs_argv *argv = |
1172 |
goto out; |
(typeof(argv)) (names_p + cond->names_count); |
1173 |
for (i = 0; i < condc; i++) { |
const struct ccs_envp *envp = |
1174 |
const u8 match = condp->equals; |
(typeof(envp)) (argv + cond->argc); |
1175 |
const u8 left = condp->left; |
u16 skip; |
1176 |
const u8 right = condp->right; |
for (skip = 0; skip < head->r.cond_index; skip++) { |
1177 |
condp++; |
const u8 left = condp->left; |
1178 |
switch (left) { |
const u8 right = condp->right; |
1179 |
case CCS_ARGV_ENTRY: |
condp++; |
1180 |
if (!ccs_io_printf(head, " exec.argv[%u]%s\"%s\"", |
switch (left) { |
1181 |
argv->index, argv->is_not ? |
case CCS_ARGV_ENTRY: |
1182 |
"!=" : "=", argv->value->name)) |
argv++; |
1183 |
goto out; |
continue; |
1184 |
argv++; |
case CCS_ENVP_ENTRY: |
1185 |
continue; |
envp++; |
1186 |
case CCS_ENVP_ENTRY: |
continue; |
1187 |
if (!ccs_io_printf(head, " exec.envp[\"%s\"]%s", |
case CCS_NUMBER_UNION: |
1188 |
envp->name->name, envp->is_not ? |
numbers_p++; |
1189 |
"!=" : "=")) |
break; |
1190 |
goto out; |
} |
1191 |
if (envp->value) { |
switch (right) { |
1192 |
if (!ccs_io_printf(head, "\"%s\"", |
case CCS_NAME_UNION: |
1193 |
envp->value->name)) |
names_p++; |
1194 |
goto out; |
break; |
1195 |
} else { |
case CCS_NUMBER_UNION: |
1196 |
if (!ccs_io_printf(head, "NULL")) |
numbers_p++; |
1197 |
goto out; |
break; |
1198 |
|
} |
1199 |
|
} |
1200 |
|
while (head->r.cond_index < condc) { |
1201 |
|
const u8 match = condp->equals; |
1202 |
|
const u8 left = condp->left; |
1203 |
|
const u8 right = condp->right; |
1204 |
|
if (!ccs_flush(head)) |
1205 |
|
return false; |
1206 |
|
condp++; |
1207 |
|
head->r.cond_index++; |
1208 |
|
ccs_set_space(head); |
1209 |
|
switch (left) { |
1210 |
|
case CCS_ARGV_ENTRY: |
1211 |
|
ccs_io_printf(head, |
1212 |
|
"exec.argv[%u]%s\"%s\"", |
1213 |
|
argv->index, |
1214 |
|
argv->is_not ? |
1215 |
|
"!=" : "=", |
1216 |
|
argv->value->name); |
1217 |
|
argv++; |
1218 |
|
continue; |
1219 |
|
case CCS_ENVP_ENTRY: |
1220 |
|
ccs_io_printf(head, |
1221 |
|
"exec.envp[\"%s\"]%s", |
1222 |
|
envp->name->name, |
1223 |
|
envp->is_not ? |
1224 |
|
"!=" : "="); |
1225 |
|
if (envp->value) { |
1226 |
|
ccs_set_string(head, "\""); |
1227 |
|
ccs_set_string(head, envp-> |
1228 |
|
value->name); |
1229 |
|
ccs_set_string(head, "\""); |
1230 |
|
} else { |
1231 |
|
ccs_set_string(head, "NULL"); |
1232 |
|
} |
1233 |
|
envp++; |
1234 |
|
continue; |
1235 |
|
case CCS_NUMBER_UNION: |
1236 |
|
ccs_print_number_union(head, |
1237 |
|
numbers_p++); |
1238 |
|
break; |
1239 |
|
default: |
1240 |
|
ccs_set_string(head, |
1241 |
|
ccs_condition_keyword[left]); |
1242 |
|
break; |
1243 |
|
} |
1244 |
|
ccs_set_string(head, match ? "=" : "!="); |
1245 |
|
switch (right) { |
1246 |
|
case CCS_NAME_UNION: |
1247 |
|
ccs_print_name_union(head, names_p++); |
1248 |
|
break; |
1249 |
|
case CCS_NUMBER_UNION: |
1250 |
|
ccs_print_number_union(head, |
1251 |
|
numbers_p++); |
1252 |
|
break; |
1253 |
|
default: |
1254 |
|
ccs_set_string(head, |
1255 |
|
ccs_condition_keyword[right]); |
1256 |
|
break; |
1257 |
|
} |
1258 |
} |
} |
|
envp++; |
|
|
continue; |
|
|
case CCS_NUMBER_UNION: |
|
|
if (!ccs_print_number_union(head, numbers_p++)) |
|
|
goto out; |
|
|
break; |
|
|
default: |
|
|
if (left >= CCS_MAX_CONDITION_KEYWORD) |
|
|
goto out; |
|
|
if (!ccs_io_printf(head, " %s", |
|
|
ccs_condition_keyword[left])) |
|
|
goto out; |
|
|
break; |
|
1259 |
} |
} |
1260 |
if (!ccs_io_printf(head, "%s", match ? "=" : "!=")) |
head->r.cond_step++; |
1261 |
goto out; |
/* fall through */ |
1262 |
switch (right) { |
case 2: |
1263 |
case CCS_NAME_UNION: |
if (!ccs_flush(head)) |
|
if (!ccs_print_name_union_quoted(head, names_p++)) |
|
|
goto out; |
|
|
break; |
|
|
case CCS_NUMBER_UNION: |
|
|
if (!ccs_print_number_union_nospace(head, numbers_p++)) |
|
|
goto out; |
|
|
break; |
|
|
default: |
|
|
if (right >= CCS_MAX_CONDITION_KEYWORD) |
|
|
goto out; |
|
|
if (!ccs_io_printf(head, "%s", |
|
|
ccs_condition_keyword[right])) |
|
|
goto out; |
|
1264 |
break; |
break; |
1265 |
|
head->r.cond_step++; |
1266 |
|
/* fall through */ |
1267 |
|
case 3: |
1268 |
|
{ |
1269 |
|
u8 j; |
1270 |
|
const u8 i = cond->post_state[3]; |
1271 |
|
if (i) |
1272 |
|
ccs_set_string(head, " ; set"); |
1273 |
|
for (j = 0; j < 3; j++) |
1274 |
|
if ((i & (1 << j))) |
1275 |
|
ccs_io_printf(head, |
1276 |
|
" task.state[%u]=%u", j, |
1277 |
|
cond->post_state[j]); |
1278 |
|
if (i & (1 << 4)) |
1279 |
|
ccs_io_printf(head, " audit=%s", |
1280 |
|
ccs_yesno(cond->post_state[4])); |
1281 |
} |
} |
1282 |
} |
ccs_set_lf(head); |
|
i = cond->post_state[3]; |
|
|
if (!i) |
|
|
goto no_condition; |
|
|
if (!ccs_io_printf(head, " ; set")) |
|
|
goto out; |
|
|
for (j = 0; j < 3; j++) { |
|
|
if (!(i & (1 << j))) |
|
|
continue; |
|
|
if (!ccs_io_printf(head, " task.state[%u]=%u", j, |
|
|
cond->post_state[j])) |
|
|
goto out; |
|
|
} |
|
|
if (i & (1 << 4)) { |
|
|
if (!ccs_io_printf(head, " audit=%s", |
|
|
ccs_yesno(cond->post_state[4]))) |
|
|
goto out; |
|
|
} |
|
|
no_condition: |
|
|
if (ccs_io_printf(head, "\n")) |
|
1283 |
return true; |
return true; |
1284 |
out: |
} |
1285 |
return false; |
return false; |
1286 |
} |
} |
1287 |
|
|
1288 |
/** |
/** |
1289 |
|
* ccs_fns - Find next set bit. |
1290 |
|
* |
1291 |
|
* @perm: 8 bits value. |
1292 |
|
* @bit: First bit to find. |
1293 |
|
* |
1294 |
|
* Returns next set bit on success, 8 otherwise. |
1295 |
|
*/ |
1296 |
|
static u8 ccs_fns(const u8 perm, u8 bit) |
1297 |
|
{ |
1298 |
|
for ( ; bit < 8; bit++) |
1299 |
|
if (perm & (1 << bit)) |
1300 |
|
break; |
1301 |
|
return bit; |
1302 |
|
} |
1303 |
|
|
1304 |
|
/** |
1305 |
* ccs_print_entry - Print an ACL entry. |
* ccs_print_entry - Print an ACL entry. |
1306 |
* |
* |
1307 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1308 |
* @ptr: Pointer to an ACL entry. |
* @acl: Pointer to an ACL entry. |
1309 |
* |
* |
1310 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1311 |
*/ |
*/ |
1312 |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
1313 |
const struct ccs_acl_info *acl) |
const struct ccs_acl_info *acl) |
1314 |
{ |
{ |
|
int pos; |
|
1315 |
const u8 acl_type = acl->type; |
const u8 acl_type = acl->type; |
1316 |
u8 bit = head->read_bit; |
u8 bit; |
1317 |
if (head->read_cond) |
if (head->r.print_cond_part) |
1318 |
goto print_cond; |
goto print_cond_part; |
1319 |
if (acl->is_deleted) |
if (acl->is_deleted) |
1320 |
return true; |
return true; |
1321 |
next: |
next: |
1322 |
pos = head->read_avail; |
bit = head->r.bit; |
1323 |
if (acl_type == CCS_TYPE_PATH_ACL) { |
if (!ccs_flush(head)) |
1324 |
|
return false; |
1325 |
|
else if (acl_type == CCS_TYPE_PATH_ACL) { |
1326 |
struct ccs_path_acl *ptr |
struct ccs_path_acl *ptr |
1327 |
= container_of(acl, typeof(*ptr), head); |
= container_of(acl, typeof(*ptr), head); |
1328 |
const u16 perm = ptr->perm; |
const u16 perm = ptr->perm; |
1329 |
for ( ; bit < CCS_MAX_PATH_OPERATION; bit++) { |
for ( ; bit < CCS_MAX_PATH_OPERATION; bit++) { |
1330 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1331 |
continue; |
continue; |
1332 |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE |
if (head->r.print_execute_only && |
1333 |
&& bit != CCS_TYPE_TRANSIT) |
bit != CCS_TYPE_EXECUTE && bit != CCS_TYPE_TRANSIT) |
1334 |
continue; |
continue; |
1335 |
/* Print "read/write" instead of "read" and "write". */ |
/* Print "read/write" instead of "read" and "write". */ |
1336 |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
1338 |
continue; |
continue; |
1339 |
break; |
break; |
1340 |
} |
} |
1341 |
if (bit == CCS_MAX_PATH_OPERATION) |
if (bit >= CCS_MAX_PATH_OPERATION) |
1342 |
goto done; |
goto done; |
1343 |
if (!ccs_io_printf(head, "allow_%s", ccs_path_keyword[bit]) || |
ccs_io_printf(head, "allow_%s", ccs_path_keyword[bit]); |
1344 |
!ccs_print_name_union(head, &ptr->name)) |
ccs_print_name_union(head, &ptr->name); |
|
goto fail; |
|
1345 |
} else if (acl_type == CCS_TYPE_EXECUTE_HANDLER || |
} else if (acl_type == CCS_TYPE_EXECUTE_HANDLER || |
1346 |
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
1347 |
struct ccs_execute_handler *ptr |
struct ccs_execute_handler *ptr |
1348 |
= container_of(acl, typeof(*ptr), head); |
= container_of(acl, typeof(*ptr), head); |
1349 |
if (!ccs_io_printf(head, "%s %s", |
ccs_io_printf(head, "%s ", |
1350 |
acl_type == CCS_TYPE_EXECUTE_HANDLER ? |
acl_type == CCS_TYPE_EXECUTE_HANDLER ? |
1351 |
CCS_KEYWORD_EXECUTE_HANDLER : |
CCS_KEYWORD_EXECUTE_HANDLER : |
1352 |
CCS_KEYWORD_DENIED_EXECUTE_HANDLER, |
CCS_KEYWORD_DENIED_EXECUTE_HANDLER); |
1353 |
ptr->handler->name)) |
ccs_set_string(head, ptr->handler->name); |
1354 |
goto fail; |
} else if (head->r.print_execute_only) { |
|
} if (head->read_execute_only) { |
|
1355 |
return true; |
return true; |
1356 |
} else if (acl_type == CCS_TYPE_MKDEV_ACL) { |
} else if (acl_type == CCS_TYPE_MKDEV_ACL) { |
1357 |
struct ccs_mkdev_acl *ptr |
struct ccs_mkdev_acl *ptr = |
1358 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1359 |
const u8 perm = ptr->perm; |
bit = ccs_fns(ptr->perm, bit); |
1360 |
for ( ; bit < CCS_MAX_MKDEV_OPERATION; bit++) { |
if (bit >= CCS_MAX_MKDEV_OPERATION) |
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
break; |
|
|
} |
|
|
if (bit == CCS_MAX_MKDEV_OPERATION) |
|
1361 |
goto done; |
goto done; |
1362 |
if (!ccs_io_printf(head, "allow_%s", ccs_mkdev_keyword[bit]) || |
ccs_io_printf(head, "allow_%s", ccs_mkdev_keyword[bit]); |
1363 |
!ccs_print_name_union(head, &ptr->name) || |
ccs_print_name_union(head, &ptr->name); |
1364 |
!ccs_print_number_union(head, &ptr->mode) || |
ccs_print_number_union(head, &ptr->mode); |
1365 |
!ccs_print_number_union(head, &ptr->major) || |
ccs_print_number_union(head, &ptr->major); |
1366 |
!ccs_print_number_union(head, &ptr->minor)) |
ccs_print_number_union(head, &ptr->minor); |
|
goto fail; |
|
1367 |
} else if (acl_type == CCS_TYPE_PATH2_ACL) { |
} else if (acl_type == CCS_TYPE_PATH2_ACL) { |
1368 |
struct ccs_path2_acl *ptr |
struct ccs_path2_acl *ptr = |
1369 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1370 |
const u8 perm = ptr->perm; |
bit = ccs_fns(ptr->perm, bit); |
1371 |
for ( ; bit < CCS_MAX_PATH2_OPERATION; bit++) { |
if (bit >= CCS_MAX_PATH2_OPERATION) |
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
break; |
|
|
} |
|
|
if (bit == CCS_MAX_PATH2_OPERATION) |
|
1372 |
goto done; |
goto done; |
1373 |
if (!ccs_io_printf(head, "allow_%s", ccs_path2_keyword[bit]) || |
ccs_io_printf(head, "allow_%s", ccs_path2_keyword[bit]); |
1374 |
!ccs_print_name_union(head, &ptr->name1) || |
ccs_print_name_union(head, &ptr->name1); |
1375 |
!ccs_print_name_union(head, &ptr->name2)) |
ccs_print_name_union(head, &ptr->name2); |
|
goto fail; |
|
1376 |
} else if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
} else if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1377 |
struct ccs_path_number_acl *ptr |
struct ccs_path_number_acl *ptr = |
1378 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1379 |
const u8 perm = ptr->perm; |
bit = ccs_fns(ptr->perm, bit); |
1380 |
for ( ; bit < CCS_MAX_PATH_NUMBER_OPERATION; bit++) { |
if (bit >= CCS_MAX_PATH_NUMBER_OPERATION) |
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
break; |
|
|
} |
|
|
if (bit == CCS_MAX_PATH_NUMBER_OPERATION) |
|
1381 |
goto done; |
goto done; |
1382 |
if (!ccs_io_printf(head, "allow_%s", |
ccs_io_printf(head, "allow_%s", |
1383 |
ccs_path_number_keyword[bit]) || |
ccs_path_number_keyword[bit]); |
1384 |
!ccs_print_name_union(head, &ptr->name) || |
ccs_print_name_union(head, &ptr->name); |
1385 |
!ccs_print_number_union(head, &ptr->number)) |
ccs_print_number_union(head, &ptr->number); |
|
goto fail; |
|
1386 |
} else if (acl_type == CCS_TYPE_ENV_ACL) { |
} else if (acl_type == CCS_TYPE_ENV_ACL) { |
1387 |
struct ccs_env_acl *ptr |
struct ccs_env_acl *ptr = |
1388 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1389 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_ENV "%s", |
ccs_set_string(head, CCS_KEYWORD_ALLOW_ENV); |
1390 |
ptr->env->name)) |
ccs_set_string(head, ptr->env->name); |
|
goto fail; |
|
1391 |
} else if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
} else if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
1392 |
struct ccs_capability_acl *ptr |
struct ccs_capability_acl *ptr = |
1393 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1394 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CAPABILITY "%s", |
ccs_set_string(head, CCS_KEYWORD_ALLOW_CAPABILITY); |
1395 |
ccs_cap2keyword(ptr->operation))) |
ccs_set_string(head, ccs_cap2keyword(ptr->operation)); |
|
goto fail; |
|
1396 |
} else if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
} else if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
1397 |
struct ccs_ip_network_acl *ptr |
struct ccs_ip_network_acl *ptr = |
1398 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1399 |
char buf[128]; |
bit = ccs_fns(ptr->perm, bit); |
1400 |
const char *w[2] = { buf, "" }; |
if (bit >= CCS_MAX_NETWORK_OPERATION) |
|
const u8 perm = ptr->perm; |
|
|
for ( ; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
|
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
break; |
|
|
} |
|
|
if (bit == CCS_MAX_NETWORK_OPERATION) |
|
1401 |
goto done; |
goto done; |
1402 |
|
ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s ", |
1403 |
|
ccs_net_keyword[bit]); |
1404 |
switch (ptr->address_type) { |
switch (ptr->address_type) { |
1405 |
|
char buf[128]; |
1406 |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
1407 |
w[0] = "@"; |
ccs_set_string(head, "@"); |
1408 |
w[1] = ptr->address.group->group_name->name; |
ccs_set_string(head, |
1409 |
|
ptr->address.group->group_name->name); |
1410 |
break; |
break; |
1411 |
case CCS_IP_ADDRESS_TYPE_IPv4: |
case CCS_IP_ADDRESS_TYPE_IPv4: |
1412 |
ccs_print_ipv4(buf, sizeof(buf), ptr->address.ipv4.min, |
ccs_print_ipv4(buf, sizeof(buf), ptr->address.ipv4.min, |
1413 |
ptr->address.ipv4.max); |
ptr->address.ipv4.max); |
1414 |
|
ccs_io_printf(head, "%s", buf); |
1415 |
break; |
break; |
1416 |
case CCS_IP_ADDRESS_TYPE_IPv6: |
case CCS_IP_ADDRESS_TYPE_IPv6: |
1417 |
ccs_print_ipv6(buf, sizeof(buf), ptr->address.ipv6.min, |
ccs_print_ipv6(buf, sizeof(buf), ptr->address.ipv6.min, |
1418 |
ptr->address.ipv6.max); |
ptr->address.ipv6.max); |
1419 |
|
ccs_io_printf(head, "%s", buf); |
1420 |
break; |
break; |
1421 |
} |
} |
1422 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s %s%s", |
ccs_print_number_union(head, &ptr->port); |
|
ccs_net_keyword[bit], w[0], w[1]) || |
|
|
!ccs_print_number_union(head, &ptr->port)) |
|
|
goto fail; |
|
1423 |
} else if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
} else if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1424 |
struct ccs_signal_acl *ptr |
struct ccs_signal_acl *ptr = |
1425 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1426 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_SIGNAL "%u %s", |
ccs_io_printf(head, CCS_KEYWORD_ALLOW_SIGNAL "%u ", ptr->sig); |
1427 |
ptr->sig, ptr->domainname->name)) |
ccs_set_string(head, ptr->domainname->name); |
|
goto fail; |
|
1428 |
} else if (acl_type == CCS_TYPE_MOUNT_ACL) { |
} else if (acl_type == CCS_TYPE_MOUNT_ACL) { |
1429 |
struct ccs_mount_acl *ptr |
struct ccs_mount_acl *ptr = |
1430 |
= container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1431 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_MOUNT) || |
ccs_io_printf(head, "allow_mount"); |
1432 |
!ccs_print_name_union(head, &ptr->dev_name) || |
ccs_print_name_union(head, &ptr->dev_name); |
1433 |
!ccs_print_name_union(head, &ptr->dir_name) || |
ccs_print_name_union(head, &ptr->dir_name); |
1434 |
!ccs_print_name_union(head, &ptr->fs_type) || |
ccs_print_name_union(head, &ptr->fs_type); |
1435 |
!ccs_print_number_union(head, &ptr->flags)) |
ccs_print_number_union(head, &ptr->flags); |
1436 |
goto fail; |
} |
1437 |
} |
head->r.bit = bit + 1; |
1438 |
head->read_bit = bit; |
if (acl->cond) { |
1439 |
head->read_cond = true; |
head->r.print_cond_part = true; |
1440 |
print_cond: |
head->r.cond_step = 0; |
1441 |
pos = head->read_avail; |
if (!ccs_flush(head)) |
1442 |
if (!ccs_print_condition(head, acl->cond)) { |
return false; |
1443 |
head->read_avail = pos; |
print_cond_part: |
1444 |
return false; |
if (!ccs_print_condition(head, acl->cond)) |
1445 |
|
return false; |
1446 |
|
head->r.print_cond_part = false; |
1447 |
|
} else { |
1448 |
|
ccs_set_lf(head); |
1449 |
} |
} |
|
head->read_cond = false; |
|
1450 |
switch (acl_type) { |
switch (acl_type) { |
1451 |
case CCS_TYPE_PATH_ACL: |
case CCS_TYPE_PATH_ACL: |
1452 |
case CCS_TYPE_MKDEV_ACL: |
case CCS_TYPE_MKDEV_ACL: |
1453 |
case CCS_TYPE_PATH2_ACL: |
case CCS_TYPE_PATH2_ACL: |
1454 |
case CCS_TYPE_PATH_NUMBER_ACL: |
case CCS_TYPE_PATH_NUMBER_ACL: |
1455 |
case CCS_TYPE_IP_NETWORK_ACL: |
case CCS_TYPE_IP_NETWORK_ACL: |
|
bit++; |
|
1456 |
goto next; |
goto next; |
1457 |
} |
} |
1458 |
done: |
done: |
1459 |
head->read_bit = 0; |
head->r.bit = 0; |
1460 |
return true; |
return true; |
|
fail: |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
1461 |
} |
} |
1462 |
|
|
1463 |
/** |
/** |
1473 |
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
1474 |
struct ccs_domain_info *domain) |
struct ccs_domain_info *domain) |
1475 |
{ |
{ |
1476 |
struct list_head *pos; |
list_for_each_cookie(head->r.acl, &domain->acl_info_list) { |
1477 |
/* Print ACL entries in the domain. */ |
struct ccs_acl_info *ptr = |
1478 |
list_for_each_cookie(pos, head->read_var2, &domain->acl_info_list) { |
list_entry(head->r.acl, typeof(*ptr), list); |
|
struct ccs_acl_info *ptr |
|
|
= list_entry(pos, struct ccs_acl_info, list); |
|
1479 |
if (!ccs_print_entry(head, ptr)) |
if (!ccs_print_entry(head, ptr)) |
1480 |
return false; |
return false; |
1481 |
} |
} |
1482 |
|
head->r.acl = NULL; |
1483 |
return true; |
return true; |
1484 |
} |
} |
1485 |
|
|
1492 |
*/ |
*/ |
1493 |
static void ccs_read_domain(struct ccs_io_buffer *head) |
static void ccs_read_domain(struct ccs_io_buffer *head) |
1494 |
{ |
{ |
1495 |
struct list_head *pos; |
if (head->r.eof) |
|
if (head->read_eof) |
|
1496 |
return; |
return; |
1497 |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(head->r.domain, &ccs_domain_list) { |
1498 |
struct ccs_domain_info *domain = |
struct ccs_domain_info *domain = |
1499 |
list_entry(pos, struct ccs_domain_info, list); |
list_entry(head->r.domain, typeof(*domain), list); |
1500 |
switch (head->read_step) { |
switch (head->r.step) { |
1501 |
u8 i; |
u8 i; |
|
const char *w[CCS_MAX_DOMAIN_INFO_FLAGS]; |
|
1502 |
case 0: |
case 0: |
1503 |
if (domain->is_deleted && !head->read_single_domain) |
if (domain->is_deleted && |
1504 |
|
!head->r.print_this_domain_only) |
1505 |
continue; |
continue; |
1506 |
/* Print domainname and flags. */ |
/* Print domainname and flags. */ |
1507 |
|
ccs_set_string(head, domain->domainname->name); |
1508 |
|
ccs_set_lf(head); |
1509 |
|
ccs_io_printf(head, CCS_KEYWORD_USE_PROFILE "%u\n", |
1510 |
|
domain->profile); |
1511 |
for (i = 0; i < CCS_MAX_DOMAIN_INFO_FLAGS; i++) |
for (i = 0; i < CCS_MAX_DOMAIN_INFO_FLAGS; i++) |
1512 |
w[i] = domain->flags[i] ? ccs_dif[i] : ""; |
if (domain->flags[i]) |
1513 |
if (!ccs_io_printf(head, "%s\n" CCS_KEYWORD_USE_PROFILE |
ccs_set_string(head, ccs_dif[i]); |
1514 |
"%u\n%s%s%s%s%s\n", |
head->r.step++; |
1515 |
domain->domainname->name, |
ccs_set_lf(head); |
|
domain->profile, |
|
|
w[CCS_DIF_QUOTA_WARNED], |
|
|
w[CCS_DIF_IGNORE_GLOBAL], |
|
|
w[CCS_DIF_IGNORE_GLOBAL_ALLOW_READ], |
|
|
w[CCS_DIF_IGNORE_GLOBAL_ALLOW_ENV], |
|
|
w[CCS_DIF_TRANSITION_FAILED])) |
|
|
return; |
|
|
head->read_step++; |
|
1516 |
/* fall through */ |
/* fall through */ |
1517 |
case 1: |
case 1: |
1518 |
if (!ccs_read_domain2(head, domain)) |
if (!ccs_read_domain2(head, domain)) |
1519 |
return; |
return; |
1520 |
head->read_step++; |
head->r.step++; |
1521 |
|
if (!ccs_set_lf(head)) |
1522 |
|
return; |
1523 |
/* fall through */ |
/* fall through */ |
1524 |
case 2: |
case 2: |
1525 |
if (!ccs_io_printf(head, "\n")) |
head->r.step = 0; |
1526 |
return; |
if (head->r.print_this_domain_only) |
1527 |
head->read_step = 0; |
goto done; |
|
if (head->read_single_domain) |
|
|
goto out; |
|
1528 |
} |
} |
1529 |
} |
} |
1530 |
out: |
done: |
1531 |
head->read_eof = true; |
head->r.eof = true; |
1532 |
} |
} |
1533 |
|
|
1534 |
/** |
/** |
1579 |
*/ |
*/ |
1580 |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
1581 |
{ |
{ |
1582 |
struct list_head *pos; |
if (head->r.eof) |
|
if (head->read_eof) |
|
1583 |
return; |
return; |
1584 |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(head->r.domain, &ccs_domain_list) { |
1585 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain = |
1586 |
domain = list_entry(pos, struct ccs_domain_info, list); |
list_entry(head->r.domain, typeof(*domain), list); |
1587 |
if (domain->is_deleted) |
if (domain->is_deleted) |
1588 |
continue; |
continue; |
1589 |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
if (!ccs_flush(head)) |
|
domain->domainname->name)) |
|
1590 |
return; |
return; |
1591 |
|
ccs_io_printf(head, "%u ", domain->profile); |
1592 |
|
ccs_set_string(head, domain->domainname->name); |
1593 |
|
ccs_set_lf(head); |
1594 |
} |
} |
1595 |
head->read_eof = true; |
head->r.eof = true; |
1596 |
} |
} |
1597 |
|
|
1598 |
/** |
/** |
1604 |
*/ |
*/ |
1605 |
static int ccs_write_pid(struct ccs_io_buffer *head) |
static int ccs_write_pid(struct ccs_io_buffer *head) |
1606 |
{ |
{ |
1607 |
head->read_eof = false; |
head->r.eof = false; |
1608 |
return 0; |
return 0; |
1609 |
} |
} |
1610 |
|
|
1630 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
1631 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1632 |
if (!buf) { |
if (!buf) { |
1633 |
head->read_eof = true; |
head->r.eof = true; |
1634 |
return; /* Do nothing if open(O_RDONLY). */ |
return; /* Do nothing if open(O_RDONLY). */ |
1635 |
} |
} |
1636 |
if (head->read_avail || head->read_eof) |
if (head->r.w_pos || head->r.eof) |
1637 |
return; |
return; |
1638 |
head->read_eof = true; |
head->r.eof = true; |
1639 |
if (ccs_str_starts(&buf, "info ")) |
if (ccs_str_starts(&buf, "info ")) |
1640 |
task_info = true; |
task_info = true; |
1641 |
if (ccs_str_starts(&buf, "global-pid ")) |
if (ccs_str_starts(&buf, "global-pid ")) |
1657 |
ccs_tasklist_unlock(); |
ccs_tasklist_unlock(); |
1658 |
if (!domain) |
if (!domain) |
1659 |
return; |
return; |
1660 |
if (!task_info) |
if (!task_info) { |
1661 |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
ccs_io_printf(head, "%u %u ", pid, domain->profile); |
1662 |
domain->domainname->name); |
ccs_set_string(head, domain->domainname->name); |
1663 |
else |
} else { |
1664 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1665 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1666 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1670 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1671 |
(u8) (ccs_flags >> 16), |
(u8) (ccs_flags >> 16), |
1672 |
(u8) (ccs_flags >> 8)); |
(u8) (ccs_flags >> 8)); |
1673 |
|
} |
1674 |
} |
} |
1675 |
|
|
1676 |
static const char *ccs_transition_type[CCS_MAX_TRANSITION_TYPE] = { |
static const char *ccs_transition_type[CCS_MAX_TRANSITION_TYPE] = { |
1736 |
*/ |
*/ |
1737 |
static bool ccs_read_group(struct ccs_io_buffer *head, const int idx) |
static bool ccs_read_group(struct ccs_io_buffer *head, const int idx) |
1738 |
{ |
{ |
1739 |
struct list_head *gpos; |
list_for_each_cookie(head->r.group, &ccs_group_list[idx]) { |
|
struct list_head *mpos; |
|
|
const char *w[3] = { "", "", "" }; |
|
|
w[0] = ccs_group_name[idx]; |
|
|
list_for_each_cookie(gpos, head->read_var1, &ccs_group_list[idx]) { |
|
1740 |
struct ccs_group *group = |
struct ccs_group *group = |
1741 |
list_entry(gpos, struct ccs_group, head.list); |
list_entry(head->r.group, typeof(*group), head.list); |
1742 |
w[1] = group->group_name->name; |
list_for_each_cookie(head->r.acl, &group->member_list) { |
|
list_for_each_cookie(mpos, head->read_var2, |
|
|
&group->member_list) { |
|
|
char buffer[128]; |
|
1743 |
struct ccs_acl_head *ptr = |
struct ccs_acl_head *ptr = |
1744 |
list_entry(mpos, struct ccs_acl_head, list); |
list_entry(head->r.acl, typeof(*ptr), list); |
1745 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
1746 |
continue; |
continue; |
1747 |
w[2] = buffer; |
if (!ccs_flush(head)) |
1748 |
|
return false; |
1749 |
|
ccs_set_string(head, ccs_group_name[idx]); |
1750 |
|
ccs_set_string(head, group->group_name->name); |
1751 |
if (idx == CCS_PATH_GROUP) { |
if (idx == CCS_PATH_GROUP) { |
1752 |
w[2] = container_of(ptr, struct ccs_path_group, |
ccs_set_space(head); |
1753 |
head)->member_name->name; |
ccs_set_string(head, container_of |
1754 |
|
(ptr, struct ccs_path_group, |
1755 |
|
head)->member_name->name); |
1756 |
} else if (idx == CCS_NUMBER_GROUP) { |
} else if (idx == CCS_NUMBER_GROUP) { |
1757 |
ccs_print_number(buffer, sizeof(buffer), |
ccs_print_number_union(head, &container_of |
1758 |
&container_of |
(ptr, struct ccs_number_group, |
1759 |
(ptr, struct ccs_number_group, |
head)->number); |
|
head)->number); |
|
1760 |
} else if (idx == CCS_ADDRESS_GROUP) { |
} else if (idx == CCS_ADDRESS_GROUP) { |
1761 |
|
char buffer[128]; |
1762 |
struct ccs_address_group *member = |
struct ccs_address_group *member = |
1763 |
container_of(ptr, typeof(*member), |
container_of(ptr, typeof(*member), |
1764 |
head); |
head); |
1770 |
ccs_print_ipv4(buffer, sizeof(buffer), |
ccs_print_ipv4(buffer, sizeof(buffer), |
1771 |
member->min.ipv4, |
member->min.ipv4, |
1772 |
member->max.ipv4); |
member->max.ipv4); |
1773 |
|
ccs_io_printf(head, " %s", buffer); |
1774 |
} |
} |
1775 |
if (!ccs_io_printf(head, "%s%s %s\n", w[0], w[1], |
ccs_set_lf(head); |
|
w[2])) |
|
|
return false; |
|
1776 |
} |
} |
1777 |
|
head->r.acl = NULL; |
1778 |
} |
} |
1779 |
|
head->r.group = NULL; |
1780 |
return true; |
return true; |
1781 |
} |
} |
1782 |
|
|
1792 |
*/ |
*/ |
1793 |
static bool ccs_read_policy(struct ccs_io_buffer *head, const int idx) |
static bool ccs_read_policy(struct ccs_io_buffer *head, const int idx) |
1794 |
{ |
{ |
1795 |
struct list_head *pos; |
list_for_each_cookie(head->r.acl, &ccs_policy_list[idx]) { |
1796 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_list[idx]) { |
struct ccs_acl_head *acl = |
1797 |
const char *w[4] = { "", "", "", "" }; |
container_of(head->r.acl, typeof(*acl), list); |
|
char buffer[16]; |
|
|
struct ccs_acl_head *acl = container_of(pos, typeof(*acl), |
|
|
list); |
|
1798 |
if (acl->is_deleted) |
if (acl->is_deleted) |
1799 |
continue; |
continue; |
1800 |
|
if (!ccs_flush(head)) |
1801 |
|
return false; |
1802 |
switch (idx) { |
switch (idx) { |
1803 |
case CCS_ID_TRANSITION_CONTROL: |
case CCS_ID_TRANSITION_CONTROL: |
1804 |
{ |
{ |
1805 |
struct ccs_transition_control *ptr = |
struct ccs_transition_control *ptr = |
1806 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1807 |
w[0] = ccs_transition_type[ptr->type]; |
ccs_set_string(head, |
1808 |
w[1] = ptr->program ? ptr->program->name |
ccs_transition_type[ptr->type]); |
1809 |
: "any"; |
ccs_set_string(head, ptr->program ? |
1810 |
w[2] = " from "; |
ptr->program->name : "any"); |
1811 |
w[3] = ptr->domainname ? ptr->domainname->name |
ccs_set_string(head, " from "); |
1812 |
: "any"; |
ccs_set_string(head, ptr->domainname ? |
1813 |
|
ptr->domainname->name : "any"); |
1814 |
} |
} |
1815 |
break; |
break; |
1816 |
case CCS_ID_AGGREGATOR: |
case CCS_ID_AGGREGATOR: |
1817 |
{ |
{ |
1818 |
struct ccs_aggregator *ptr = |
struct ccs_aggregator *ptr = |
1819 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1820 |
w[0] = CCS_KEYWORD_AGGREGATOR; |
ccs_set_string(head, CCS_KEYWORD_AGGREGATOR); |
1821 |
w[1] = ptr->original_name->name; |
ccs_set_string(head, ptr->original_name->name); |
1822 |
w[2] = " "; |
ccs_set_space(head); |
1823 |
w[3] = ptr->aggregated_name->name; |
ccs_set_string(head, |
1824 |
|
ptr->aggregated_name->name); |
1825 |
} |
} |
1826 |
break; |
break; |
1827 |
case CCS_ID_PATTERN: |
case CCS_ID_PATTERN: |
1828 |
{ |
{ |
1829 |
struct ccs_pattern *ptr = |
struct ccs_pattern *ptr = |
1830 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1831 |
w[0] = CCS_KEYWORD_FILE_PATTERN; |
ccs_set_string(head, CCS_KEYWORD_FILE_PATTERN); |
1832 |
w[1] = ptr->pattern->name; |
ccs_set_string(head, ptr->pattern->name); |
1833 |
} |
} |
1834 |
break; |
break; |
1835 |
case CCS_ID_NO_REWRITE: |
case CCS_ID_NO_REWRITE: |
1836 |
{ |
{ |
1837 |
struct ccs_no_rewrite *ptr = |
struct ccs_no_rewrite *ptr = |
1838 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1839 |
w[0] = CCS_KEYWORD_DENY_REWRITE; |
ccs_set_string(head, CCS_KEYWORD_DENY_REWRITE); |
1840 |
w[1] = ptr->pattern->name; |
ccs_set_string(head, ptr->pattern->name); |
1841 |
} |
} |
1842 |
break; |
break; |
1843 |
case CCS_ID_RESERVEDPORT: |
case CCS_ID_RESERVEDPORT: |
1846 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1847 |
const u16 min_port = ptr->min_port; |
const u16 min_port = ptr->min_port; |
1848 |
const u16 max_port = ptr->max_port; |
const u16 max_port = ptr->max_port; |
1849 |
w[0] = CCS_KEYWORD_DENY_AUTOBIND; |
ccs_set_string(head, |
1850 |
snprintf(buffer, sizeof(buffer) - 1, "%u%c%u", |
CCS_KEYWORD_DENY_AUTOBIND); |
1851 |
min_port, min_port != max_port ? |
ccs_io_printf(head, "%u", min_port); |
1852 |
'-' : '\0', max_port); |
if (min_port != max_port) |
1853 |
buffer[sizeof(buffer) - 1] = '\0'; |
ccs_io_printf(head, "-%u", max_port); |
|
w[1] = buffer; |
|
1854 |
} |
} |
1855 |
break; |
break; |
1856 |
default: |
default: |
1857 |
continue; |
continue; |
1858 |
} |
} |
1859 |
if (!ccs_io_printf(head, "%s%s%s%s\n", w[0], w[1], w[2], w[3])) |
ccs_set_lf(head); |
|
return false; |
|
1860 |
} |
} |
1861 |
|
head->r.acl = NULL; |
1862 |
return true; |
return true; |
1863 |
} |
} |
1864 |
|
|
|
static void ccs_read_global_domain(struct ccs_io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) |
|
|
head->read_eof = ccs_read_domain2(head, &ccs_global_domain); |
|
|
} |
|
|
|
|
1865 |
/** |
/** |
1866 |
* ccs_read_exception - Read exception policy. |
* ccs_read_exception - Read exception policy. |
1867 |
* |
* |
1871 |
*/ |
*/ |
1872 |
static void ccs_read_exception(struct ccs_io_buffer *head) |
static void ccs_read_exception(struct ccs_io_buffer *head) |
1873 |
{ |
{ |
1874 |
if (head->read_eof) |
if (head->r.eof) |
1875 |
return; |
return; |
1876 |
while (head->read_step < CCS_MAX_POLICY && |
while (head->r.step < CCS_MAX_POLICY && |
1877 |
ccs_read_policy(head, head->read_step)) |
ccs_read_policy(head, head->r.step)) |
1878 |
head->read_step++; |
head->r.step++; |
1879 |
if (head->read_step < CCS_MAX_POLICY) |
if (head->r.step < CCS_MAX_POLICY) |
1880 |
return; |
return; |
1881 |
while (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP && |
while (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP && |
1882 |
ccs_read_group(head, head->read_step - CCS_MAX_POLICY)) |
ccs_read_group(head, head->r.step - CCS_MAX_POLICY)) |
1883 |
head->read_step++; |
head->r.step++; |
1884 |
if (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP) |
if (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP) |
1885 |
return; |
return; |
1886 |
head->read = ccs_read_global_domain; |
head->r.eof = ccs_read_domain2(head, &ccs_global_domain); |
1887 |
} |
} |
1888 |
|
|
1889 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for ccs_query_list. */ |
1908 |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
1909 |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
1910 |
|
|
|
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
|
|
{ |
|
|
va_list args; |
|
|
const int pos = strlen(buffer); |
|
|
va_start(args, fmt); |
|
|
vsnprintf(buffer + pos, len - pos - 1, fmt, args); |
|
|
va_end(args); |
|
|
} |
|
|
|
|
1911 |
static void ccs_truncate(char *str) |
static void ccs_truncate(char *str) |
1912 |
{ |
{ |
1913 |
while (* (unsigned char *) str > (unsigned char) ' ') |
while (* (unsigned char *) str > (unsigned char) ' ') |
2044 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2045 |
if (quota_exceeded) |
if (quota_exceeded) |
2046 |
goto out; |
goto out; |
2047 |
snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
pos = snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
2048 |
ccs_query_entry->serial, r->retry, header); |
ccs_query_entry->serial, r->retry, header); |
2049 |
kfree(header); |
kfree(header); |
2050 |
header = NULL; |
header = NULL; |
2051 |
ccs_addprintf(ccs_query_entry->query, len, fmt, args); |
va_start(args, fmt); |
2052 |
|
vsnprintf(ccs_query_entry->query + pos, len - 1 - pos, fmt, args); |
2053 |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
2054 |
|
va_end(args); |
2055 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2056 |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
2057 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2139 |
int pos = 0; |
int pos = 0; |
2140 |
int len = 0; |
int len = 0; |
2141 |
char *buf; |
char *buf; |
2142 |
if (head->read_avail) |
if (head->r.w_pos) |
2143 |
return; |
return; |
2144 |
if (head->read_buf) { |
if (head->read_buf) { |
2145 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2146 |
head->read_buf = NULL; |
head->read_buf = NULL; |
|
head->readbuf_size = 0; |
|
2147 |
} |
} |
2148 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2149 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2151 |
= list_entry(tmp, struct ccs_query_entry, list); |
= list_entry(tmp, struct ccs_query_entry, list); |
2152 |
if (ptr->answer) |
if (ptr->answer) |
2153 |
continue; |
continue; |
2154 |
if (pos++ != head->read_step) |
if (pos++ != head->r.query_index) |
2155 |
continue; |
continue; |
2156 |
len = ptr->query_len; |
len = ptr->query_len; |
2157 |
break; |
break; |
2158 |
} |
} |
2159 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2160 |
if (!len) { |
if (!len) { |
2161 |
head->read_step = 0; |
head->r.query_index = 0; |
2162 |
return; |
return; |
2163 |
} |
} |
2164 |
buf = kzalloc(len, CCS_GFP_FLAGS); |
buf = kzalloc(len, CCS_GFP_FLAGS); |
2171 |
= list_entry(tmp, struct ccs_query_entry, list); |
= list_entry(tmp, struct ccs_query_entry, list); |
2172 |
if (ptr->answer) |
if (ptr->answer) |
2173 |
continue; |
continue; |
2174 |
if (pos++ != head->read_step) |
if (pos++ != head->r.query_index) |
2175 |
continue; |
continue; |
2176 |
/* |
/* |
2177 |
* Some query can be skipped because ccs_query_list |
* Some query can be skipped because ccs_query_list |
2183 |
} |
} |
2184 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2185 |
if (buf[0]) { |
if (buf[0]) { |
|
head->read_avail = len; |
|
|
head->readbuf_size = head->read_avail; |
|
2186 |
head->read_buf = buf; |
head->read_buf = buf; |
2187 |
head->read_step++; |
head->r.w[head->r.w_pos++] = buf; |
2188 |
|
head->r.query_index++; |
2189 |
} else { |
} else { |
2190 |
kfree(buf); |
kfree(buf); |
2191 |
} |
} |
2234 |
*/ |
*/ |
2235 |
static void ccs_read_version(struct ccs_io_buffer *head) |
static void ccs_read_version(struct ccs_io_buffer *head) |
2236 |
{ |
{ |
2237 |
if (head->read_eof) |
if (head->r.eof) |
2238 |
return; |
return; |
2239 |
ccs_io_printf(head, "1.7.2"); |
ccs_set_string(head, "1.7.2"); |
2240 |
head->read_eof = true; |
head->r.eof = true; |
2241 |
} |
} |
2242 |
|
|
2243 |
/** |
/** |
2247 |
*/ |
*/ |
2248 |
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
2249 |
{ |
{ |
2250 |
if (head->read_eof) |
if (head->r.eof) |
2251 |
return; |
return; |
2252 |
/* |
/* |
2253 |
* ccs_current_domain()->domainname != NULL because every process |
* ccs_current_domain()->domainname != NULL because every process |
2254 |
* belongs to a domain and the domain's name cannot be NULL. |
* belongs to a domain and the domain's name cannot be NULL. |
2255 |
*/ |
*/ |
2256 |
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
2257 |
head->read_eof = true; |
head->r.eof = true; |
2258 |
} |
} |
2259 |
|
|
2260 |
/** |
/** |
2413 |
int ccs_read_control(struct file *file, char __user *buffer, |
int ccs_read_control(struct file *file, char __user *buffer, |
2414 |
const int buffer_len) |
const int buffer_len) |
2415 |
{ |
{ |
2416 |
int len = 0; |
int len; |
2417 |
struct ccs_io_buffer *head = file->private_data; |
struct ccs_io_buffer *head = file->private_data; |
|
char *cp; |
|
2418 |
int idx; |
int idx; |
2419 |
if (!head->read) |
if (!head->read) |
2420 |
return -ENOSYS; |
return -ENOSYS; |
2422 |
return -EFAULT; |
return -EFAULT; |
2423 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2424 |
return -EINTR; |
return -EINTR; |
2425 |
|
head->read_user_buf = buffer; |
2426 |
|
head->read_user_buf_avail = buffer_len; |
2427 |
idx = ccs_read_lock(); |
idx = ccs_read_lock(); |
2428 |
while (1) { |
if (ccs_flush(head)) |
2429 |
/* Call the policy handler. */ |
/* Call the policy handler. */ |
2430 |
head->read(head); |
head->read(head); |
2431 |
/* Write to buffer. */ |
ccs_flush(head); |
|
len = head->read_avail; |
|
|
if (len || head->poll || head->read_eof) |
|
|
break; |
|
|
len = head->readbuf_size * 2; |
|
|
cp = kzalloc(len, CCS_GFP_FLAGS); |
|
|
if (!cp) { |
|
|
len = -ENOMEM; |
|
|
goto out; |
|
|
} |
|
|
kfree(head->read_buf); |
|
|
head->read_buf = cp; |
|
|
head->readbuf_size = len; |
|
|
} |
|
|
if (len > buffer_len) |
|
|
len = buffer_len; |
|
|
if (!len) |
|
|
goto out; |
|
|
/* head->read_buf changes by some functions. */ |
|
|
cp = head->read_buf; |
|
|
if (copy_to_user(buffer, cp, len)) { |
|
|
len = -EFAULT; |
|
|
goto out; |
|
|
} |
|
|
head->read_avail -= len; |
|
|
memmove(cp, cp + len, head->read_avail); |
|
|
out: |
|
2432 |
ccs_read_unlock(idx); |
ccs_read_unlock(idx); |
2433 |
|
len = head->read_user_buf - buffer; |
2434 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2435 |
return len; |
return len; |
2436 |
} |
} |
2469 |
/* Read a line and dispatch it to the policy handler. */ |
/* Read a line and dispatch it to the policy handler. */ |
2470 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2471 |
char c; |
char c; |
2472 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->w.avail >= head->writebuf_size - 1) { |
2473 |
const int len = head->writebuf_size * 2; |
const int len = head->writebuf_size * 2; |
2474 |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
2475 |
if (!cp) { |
if (!cp) { |
2476 |
error = -ENOMEM; |
error = -ENOMEM; |
2477 |
break; |
break; |
2478 |
} |
} |
2479 |
memmove(cp, cp0, head->write_avail); |
memmove(cp, cp0, head->w.avail); |
2480 |
kfree(cp0); |
kfree(cp0); |
2481 |
head->write_buf = cp; |
head->write_buf = cp; |
2482 |
cp0 = cp; |
cp0 = cp; |
2488 |
} |
} |
2489 |
buffer++; |
buffer++; |
2490 |
avail_len--; |
avail_len--; |
2491 |
cp0[head->write_avail++] = c; |
cp0[head->w.avail++] = c; |
2492 |
if (c != '\n') |
if (c != '\n') |
2493 |
continue; |
continue; |
2494 |
cp0[head->write_avail - 1] = '\0'; |
cp0[head->w.avail - 1] = '\0'; |
2495 |
head->write_avail = 0; |
head->w.avail = 0; |
2496 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2497 |
head->write(head); |
head->write(head); |
2498 |
} |
} |