| 1 | /* |
| 2 | * AIDE (Advanced Intrusion Detection Environment) |
| 3 | * |
| 4 | * Copyright (C) 2016, 2020-2022,2024,2025 Hannes von Haugwitz |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h"cxx . . $ `<file>/include/config.h`/ |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | #include "file.h"cxx . . $ `<file>/include/file.h`/ |
| 25 | #include "rx_rule.h"cxx . . $ `<file>/include/rx_rule.h`/ |
| 26 | #include "util.h"cxx . . $ `<file>/include/util.h`/ |
| 27 | |
| 28 | static int generate_restriction_stringcxx . . $ generate_restriction_string(81aa035bf6389ef0).(rx_restriction_tcxx . . $ rx_restriction_t# r, char *str) { |
| 29 | int n = 0; |
| 30 | if (r.f_typecxx . . $ rx_restriction_t#f_type. == FT_NULLcxx . . $ `include/file.h:29:9`! |
| 31 | #ifdef HAVE_FSTYPEcxx . . $ `include/config.h:53:9`! |
| 32 | && r.fs_typecxx . . $ rx_restriction_t#fs_type. == 0 |
| 33 | #endif |
| 34 | ) { |
| 35 | const char *no_restriction_string = "(none)"; |
| 36 | size_t length = strlencxx . . $ strlen(751346f8406fd082).(no_restriction_string); |
| 37 | if (str) { sprintfcxx . . $ sprintf(26c8642d26409d6d).(&str[n], "%s", no_restriction_string); } |
| 38 | n = length+1; |
| 39 | } else { |
| 40 | FT_TYPEcxx . . $ `include/file.h:28:9`! f_types = r.f_typecxx . . $ rx_restriction_t#f_type.; |
| 41 | unsigned int i = 0; |
| 42 | while (f_types) { |
| 43 | FT_TYPEcxx . . $ `include/file.h:28:9`! t = (1U<<i); |
| 44 | if (f_types&t) { |
| 45 | if (n) { |
| 46 | if (str) { str[n] = ','; } |
| 47 | n++; |
| 48 | } |
| 49 | if (str) { str[n] = get_f_type_char_from_f_typecxx . . $ get_f_type_char_from_f_type(1cb8f0426fc6e5a2).(t); } |
| 50 | n++; |
| 51 | } |
| 52 | i++; |
| 53 | f_types &= ~t; |
| 54 | } |
| 55 | #ifdef HAVE_FSTYPEcxx . . $ `include/config.h:53:9`! |
| 56 | if (r.fs_typecxx . . $ rx_restriction_t#fs_type. != 0) { |
| 57 | if (str) { str[n] = '='; } |
| 58 | n++; |
| 59 | size_t length = generate_fs_type_stringcxx . . $ generate_fs_type_string(42a4fda062c6f95b).(r.fs_typecxx . . $ rx_restriction_t#fs_type., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 60 | if (str) { generate_fs_type_stringcxx . . $ generate_fs_type_string(42a4fda062c6f95b).(r.fs_typecxx . . $ rx_restriction_t#fs_type., &str[n]); } |
| 61 | n += length; |
| 62 | } |
| 63 | #endif |
| 64 | if (str) { str[n] = '\0'; } |
| 65 | n++; |
| 66 | } |
| 67 | return n; |
| 68 | } |
| 69 | |
| 70 | char *get_restriction_stringcxx . . $ get_restriction_string(7c1dd464d1a8aef8).(rx_restriction_tcxx . . $ rx_restriction_t# r) { |
| 71 | char *str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 72 | int n = generate_restriction_stringcxx . . $ generate_restriction_string(81aa035bf6389ef0).(r, str); |
| 73 | str = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(n); |
| 74 | generate_restriction_stringcxx . . $ generate_restriction_string(81aa035bf6389ef0).(r, str); |
| 75 | return str; |
| 76 | } |
| 77 | |
| 78 | char* get_rule_type_long_stringcxx . . $ get_rule_type_long_string(10604bca7de90ad2).(AIDE_RULE_TYPEcxx . . $ AIDE_RULE_TYPE# rule_type) { |
| 79 | switch (rule_type) { |
| 80 | case AIDE_SELECTIVE_RULEcxx . . $ AIDE_SELECTIVE_RULE.: return "selective rule"; |
| 81 | case AIDE_EQUAL_RULEcxx . . $ AIDE_EQUAL_RULE.: return "equal rule"; |
| 82 | case AIDE_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_RECURSIVE_NEGATIVE_RULE.: return "recursive negative rule"; |
| 83 | case AIDE_NON_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_NON_RECURSIVE_NEGATIVE_RULE.: return "non-recursive negative rule"; |
| 84 | } |
| 85 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 86 | } |
| 87 | |
| 88 | char* get_rule_type_charcxx . . $ get_rule_type_char(10604bca7de90ad2).(AIDE_RULE_TYPEcxx . . $ AIDE_RULE_TYPE# rule_type) { |
| 89 | switch (rule_type) { |
| 90 | case AIDE_SELECTIVE_RULEcxx . . $ AIDE_SELECTIVE_RULE.: return ""; |
| 91 | case AIDE_EQUAL_RULEcxx . . $ AIDE_EQUAL_RULE.: return "="; |
| 92 | case AIDE_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_RECURSIVE_NEGATIVE_RULE.: return "!"; |
| 93 | case AIDE_NON_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_NON_RECURSIVE_NEGATIVE_RULE.: return "-"; |
| 94 | } |
| 95 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 96 | } |
| 97 | |
| 98 | char *get_match_result_stringcxx . . $ get_match_result_string(20a00c1e59edb1b6).(match_resultcxx . . $ match_result# match) { |
| 99 | switch(match) { |
| 100 | case RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH.: |
| 101 | return "RESULT_NO_RULE_MATCH"; |
| 102 | case RESULT_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_RECURSIVE_NEGATIVE_MATCH.: |
| 103 | return "RESULT_RECURSIVE_NEGATIVE_MATCH"; |
| 104 | case RESULT_NON_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_NON_RECURSIVE_NEGATIVE_MATCH.: |
| 105 | return "RESULT_NON_RECURSIVE_NEGATIVE_MATCH"; |
| 106 | case RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH.: |
| 107 | return "RESULT_EQUAL_MATCH"; |
| 108 | case RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH.: |
| 109 | return "RESULT_SELECTIVE_MATCH"; |
| 110 | case RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.: |
| 111 | return "RESULT_PARTIAL_MATCH"; |
| 112 | case RESULT_NO_LIMIT_MATCHcxx . . $ RESULT_NO_LIMIT_MATCH.: |
| 113 | return "RESULT_NO_LIMIT_MATCH"; |
| 114 | case RESULT_PARTIAL_LIMIT_MATCHcxx . . $ RESULT_PARTIAL_LIMIT_MATCH.: |
| 115 | return "RESULT_PARTIAL_LIMIT_MATCH"; |
| 116 | case RESULT_PART_LIMIT_AND_NO_RECURSE_MATCHcxx . . $ RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH.: |
| 117 | return "RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH"; |
| 118 | case RESULT_NEGATIVE_PARENT_MATCHcxx . . $ RESULT_NEGATIVE_PARENT_MATCH.: |
| 119 | return "RESULT_NEGATIVE_PARENT_MATCH"; |
| 120 | } |
| 121 | return "unknown match result"; |
| 122 | } |
| 123 | |
| 124 | char *get_match_result_desccxx . . $ get_match_result_desc(20a00c1e59edb1b6).(match_resultcxx . . $ match_result# match) { |
| 125 | switch(match) { |
| 126 | case RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH.: |
| 127 | return "no rule match"; |
| 128 | case RESULT_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_RECURSIVE_NEGATIVE_MATCH.: |
| 129 | return "recursive negative match"; |
| 130 | case RESULT_NON_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_NON_RECURSIVE_NEGATIVE_MATCH.: |
| 131 | return "non-recursive negative match"; |
| 132 | case RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH.: |
| 133 | return "equal match"; |
| 134 | case RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH.: |
| 135 | return "selective match"; |
| 136 | case RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.: |
| 137 | return "partial match"; |
| 138 | case RESULT_NO_LIMIT_MATCHcxx . . $ RESULT_NO_LIMIT_MATCH.: |
| 139 | return "no limit match"; |
| 140 | case RESULT_PARTIAL_LIMIT_MATCHcxx . . $ RESULT_PARTIAL_LIMIT_MATCH.: |
| 141 | return "partial limit match"; |
| 142 | case RESULT_PART_LIMIT_AND_NO_RECURSE_MATCHcxx . . $ RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH.: |
| 143 | return "partial limit match but non-recursive negative match"; |
| 144 | case RESULT_NEGATIVE_PARENT_MATCHcxx . . $ RESULT_NEGATIVE_PARENT_MATCH.: |
| 145 | return "negative parent match"; |
| 146 | } |
| 147 | return "unknown match result"; |
| 148 | } |