7 #include <linux/slab.h>
92 static const u16 tomoyo_eom[2][12] = {
93 { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
94 { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
99 stamp->
sec = time % 60;
101 stamp->
min = time % 60;
103 stamp->
hour = time % 24;
105 for (y = 1970; ; y++) {
106 const unsigned short days = (y & 3) ? 365 : 366;
112 for (m = 0; m < 11 && time >= tomoyo_eom[
r][
m]; m++)
115 time -= tomoyo_eom[
r][m - 1];
133 const char *
cp =
strstr(
string, keyword);
135 return cp ==
string || *(cp - 1) ==
'/';
152 char *del =
strchr(pos,
' ');
174 if (*pos++ !=
' ' || *pos++ ==
'/')
199 const char *
cp = *
str;
204 if (c ==
'x' || c ==
'X') {
207 }
else if (c >=
'0' && c <=
'7') {
240 snprintf(buffer, buffer_len,
"%lu", value);
242 snprintf(buffer, buffer_len,
"0%lo", value);
244 snprintf(buffer, buffer_len,
"0x%lX", value);
246 snprintf(buffer, buffer_len,
"type(%u)", type);
261 if (param->
data[0] ==
'@') {
287 memset(ptr, 0,
sizeof(*ptr));
288 if (param->
data[0] ==
'@') {
324 static inline bool tomoyo_byte_range(
const char *
str)
326 return *str >=
'0' && *str++ <=
'3' &&
327 *str >=
'0' && *str++ <=
'7' &&
328 *str >=
'0' && *str <=
'7';
338 static inline bool tomoyo_alphabet_char(
const char c)
340 return (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z');
352 static inline u8 tomoyo_make_byte(
const u8 c1,
const u8 c2,
const u8 c3)
354 return ((c1 -
'0') << 6) + ((c2 -
'0') << 3) + (c3 -
'0');
364 static inline bool tomoyo_valid(
const unsigned char c)
366 return c >
' ' && c < 127;
376 static inline bool tomoyo_invalid(
const unsigned char c)
378 return c && (c <= ' ' || c >= 127);
420 while (tomoyo_invalid(*sp))
426 while (tomoyo_valid(*sp))
428 while (tomoyo_invalid(*sp))
443 static bool tomoyo_correct_word2(
const char *
string,
size_t len)
446 bool in_repetition =
false;
473 if (
string - 3 < start || *(
string - 3) !=
'/')
475 in_repetition =
true;
482 in_repetition =
false;
488 if (!len-- || !len--)
492 if (d < '0' || d >
'7' || e < '0' || e >
'7')
494 c = tomoyo_make_byte(c, d, e);
495 if (c <= ' ' || c >= 127)
499 }
else if (in_repetition && c ==
'/') {
501 }
else if (c <= ' ' || c >= 127) {
522 return tomoyo_correct_word2(
string,
strlen(
string));
549 domainname =
strchr(domainname,
' ');
553 const unsigned char *
cp =
strchr(domainname,
' ');
556 if (*domainname !=
'/' ||
557 !tomoyo_correct_word2(domainname, cp - domainname))
573 const unsigned char *
cp;
582 if (buffer[len - 1] !=
'>' ||
583 !tomoyo_correct_word2(buffer + 1, len - 2))
602 name.
name = domainname;
619 static int tomoyo_const_part_length(
const char *
filename)
626 while ((c = *filename++) !=
'\0') {
641 if (c < '0' || c >
'7')
644 if (c < '0' || c >
'7')
664 const int len =
strlen(name);
666 ptr->
const_len = tomoyo_const_part_length(name);
667 ptr->
is_dir = len && (name[len - 1] ==
'/');
682 static bool tomoyo_file_matches_pattern2(
const char *filename,
683 const char *filename_end,
685 const char *pattern_end)
687 while (filename < filename_end && pattern < pattern_end) {
689 if (*pattern !=
'\\') {
690 if (*filename++ != *pattern++)
702 }
else if (c ==
'\\') {
703 if (filename[1] ==
'\\')
705 else if (tomoyo_byte_range(filename + 1))
714 if (*++filename !=
'\\')
726 if (!tomoyo_alphabet_char(c))
733 if (c ==
'\\' && tomoyo_byte_range(filename + 1)
734 &&
strncmp(filename + 1, pattern, 3) == 0) {
742 for (i = 0; i <= filename_end -
filename; i++) {
743 if (tomoyo_file_matches_pattern2(
744 filename + i, filename_end,
745 pattern + 1, pattern_end))
748 if (c ==
'.' && *pattern ==
'@')
752 if (filename[i + 1] ==
'\\')
754 else if (tomoyo_byte_range(filename + i + 1))
766 }
else if (c ==
'X') {
769 }
else if (c ==
'A') {
770 while (tomoyo_alphabet_char(filename[j]))
773 for (i = 1; i <=
j; i++) {
774 if (tomoyo_file_matches_pattern2(
775 filename + i, filename_end,
776 pattern + 1, pattern_end))
784 while (*pattern ==
'\\' &&
785 (*(pattern + 1) ==
'*' || *(pattern + 1) ==
'@'))
787 return filename == filename_end && pattern == pattern_end;
800 static bool tomoyo_file_matches_pattern(
const char *filename,
801 const char *filename_end,
803 const char *pattern_end)
805 const char *pattern_start =
pattern;
809 while (pattern < pattern_end - 1) {
811 if (*pattern++ !=
'\\' || *pattern++ !=
'-')
813 result = tomoyo_file_matches_pattern2(filename,
824 result = tomoyo_file_matches_pattern2(filename, filename_end,
825 pattern_start, pattern_end);
826 return first ? result : !
result;
837 static bool tomoyo_path_matches_pattern2(
const char *
f,
const char *
p)
839 const char *f_delimiter;
840 const char *p_delimiter;
843 f_delimiter =
strchr(f,
'/');
845 f_delimiter = f +
strlen(f);
846 p_delimiter =
strchr(p,
'/');
848 p_delimiter = p +
strlen(p);
849 if (*p ==
'\\' && *(p + 1) ==
'{')
851 if (!tomoyo_file_matches_pattern(f, f_delimiter, p,
863 (*(p + 1) ==
'*' || *(p + 1) ==
'@'))
873 if (*(p - 1) !=
'/' || p_delimiter <= p + 3 || *p_delimiter !=
'/' ||
874 *(p_delimiter - 1) !=
'}' || *(p_delimiter - 2) !=
'\\')
878 if (!tomoyo_file_matches_pattern(f, f_delimiter, p + 2,
887 if (tomoyo_path_matches_pattern2(f, p_delimiter + 1))
889 f_delimiter =
strchr(f,
'/');
890 }
while (f_delimiter);
923 const char *f = filename->
name;
924 const char *p = pattern->
name;
929 return !tomoyo_pathcmp(filename, pattern);
938 return tomoyo_path_matches_pattern2(f, p);
1003 memset(r, 0,
sizeof(*r));
1005 domain = tomoyo_domain();
1025 unsigned int count = 0;
1038 switch (ptr->
type) {
1069 for (i = 0; i < 16; i++)
1070 if (perm & (1 << i))
1081 "Domain '%s' has too many ACLs to hold. "
1082 "Stopped learning mode.\n", domain->
domainname->name);