| 1 | /* |
| 2 | * AIDE (Advanced Intrusion Detection Environment) |
| 3 | * |
| 4 | * Copyright (C) 2019-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 | #ifndef _CONF_AST_H_INCLUDED |
| 22 | #define _CONF_AST_H_INCLUDED |
| 23 | |
| 24 | #include <stdbool.h> |
| 25 | #include "rx_rule.h" |
| 26 | |
| 27 | typedef enum config_option { |
| 28 | ACL_NO_SYMLINK_FOLLOW_OPTION, |
| 29 | DATABASE_ADD_METADATA_OPTION, |
| 30 | DATABASE_ATTRIBUTES_OPTION, |
| 31 | DATABASE_GZIP_OPTION, |
| 32 | DATABASE_IN_OPTION, |
| 33 | DATABASE_OUT_OPTION, |
| 34 | DATABASE_NEW_OPTION, |
| 35 | LOG_LEVEL_OPTION, |
| 36 | REPORT_BASE16_OPTION, |
| 37 | REPORT_DETAILED_INIT_OPTION, |
| 38 | REPORT_FORCE_ATTRS_OPTION, |
| 39 | REPORT_GROUPED_OPTION, |
| 40 | REPORT_IGNORE_ADDED_ATTRS_OPTION, |
| 41 | REPORT_IGNORE_REMOVED_ATTRS_OPTION, |
| 42 | REPORT_IGNORE_CHANGED_ATTRS_OPTION, |
| 43 | REPORT_IGNORE_E2FSATTRS_OPTION, |
| 44 | REPORT_LEVEL_OPTION, |
| 45 | REPORT_QUIET_OPTION, |
| 46 | REPORT_APPEND_OPTION, |
| 47 | REPORT_SUMMARIZE_CHANGES_OPTION, |
| 48 | REPORT_URL_OPTION, |
| 49 | ROOT_PREFIX_OPTION, |
| 50 | WARN_DEAD_SYMLINKS_OPTION, |
| 51 | CONFIG_VERSION, |
| 52 | CONFIG_CHECK_WARN_UNRESTRICTED_RULES, |
| 53 | REPORT_FORMAT_OPTION, |
| 54 | LIMIT_CMDLINE_OPTION, |
| 55 | NUM_WORKERS, |
| 56 | } config_option; |
| 57 | |
| 58 | typedef struct { |
| 59 | config_option option; |
| 60 | char *config_name; |
| 61 | char *report_string; |
| 62 | } config_option_t; |
| 63 | |
| 64 | extern config_option_t config_options[]; |
| 65 | |
| 66 | typedef enum attribute_operator { |
| 67 | ATTR_OP_PLUS = 0, |
| 68 | ATTR_OP_MINUS, |
| 69 | ATTR_OP_GROUP, |
| 70 | } attribute_operator; |
| 71 | |
| 72 | typedef struct attribute_expression { |
| 73 | attribute_operator op; |
| 74 | |
| 75 | struct attribute_expression* left; |
| 76 | char* right; |
| 77 | } attribute_expression; |
| 78 | |
| 79 | typedef enum string_operator { |
| 80 | STR_OP_STR, |
| 81 | STR_OP_VARIABLE, |
| 82 | STR_OP_CONCAT, |
| 83 | } string_operator; |
| 84 | typedef struct string_expression { |
| 85 | string_operator op; |
| 86 | |
| 87 | char* str; |
| 88 | struct string_expression* left; |
| 89 | struct string_expression* right; |
| 90 | } string_expression; |
| 91 | |
| 92 | typedef struct config_option_statement { |
| 93 | config_option option; |
| 94 | attribute_expression *a; |
| 95 | string_expression* e; |
| 96 | } config_option_statement; |
| 97 | |
| 98 | typedef enum bool_operator { |
| 99 | BOOL_OP_NOT, |
| 100 | BOOL_OP_DEFINED, |
| 101 | BOOL_OP_HOSTNAME, |
| 102 | BOOL_OP_EXISTS, |
| 103 | BOOL_OP_VERSION_GE, |
| 104 | } bool_operator; |
| 105 | |
| 106 | typedef struct bool_expression { |
| 107 | bool_operator op; |
| 108 | |
| 109 | union { |
| 110 | string_expression* _str; |
| 111 | struct bool_expression* _bool; |
| 112 | } left; |
| 113 | union { |
| 114 | string_expression* _str; |
| 115 | struct bool_expression* _bool; |
| 116 | } right; |
| 117 | |
| 118 | } bool_expression; |
| 119 | |
| 120 | typedef struct if_condition { |
| 121 | bool_expression* expression; |
| 122 | |
| 123 | int linenumber; |
| 124 | char *filename; |
| 125 | char* linebuf; |
| 126 | } if_condition; |
| 127 | |
| 128 | typedef struct if_statement { |
| 129 | struct if_condition* condition; |
| 130 | |
| 131 | struct ast* if_branch; |
| 132 | struct ast* else_branch; |
| 133 | } if_statement; |
| 134 | |
| 135 | typedef struct define_statement { |
| 136 | char *name; |
| 137 | string_expression *value; |
| 138 | } define_statement; |
| 139 | |
| 140 | typedef struct include_statement { |
| 141 | string_expression *path; |
| 142 | string_expression *rx; |
| 143 | bool execute; |
| 144 | string_expression *prefix; |
| 145 | } include_statement; |
| 146 | |
| 147 | typedef struct x_include_setenv_statement { |
| 148 | char *variable; |
| 149 | string_expression *value; |
| 150 | } x_include_setenv_statement; |
| 151 | |
| 152 | typedef struct undefine_statement { |
| 153 | char *name; |
| 154 | } undefine_statement; |
| 155 | |
| 156 | typedef struct group_statement { |
| 157 | char *name; |
| 158 | attribute_expression *expr; |
| 159 | } group_statement; |
| 160 | |
| 161 | typedef struct ft_restriction_expression { |
| 162 | char* right; |
| 163 | struct ft_restriction_expression* left; |
| 164 | } ft_restriction_expression; |
| 165 | |
| 166 | typedef struct restriction_expression { |
| 167 | struct ft_restriction_expression* f_types; |
| 168 | char* fs_type; |
| 169 | } restriction_expression; |
| 170 | |
| 171 | typedef struct rule_statement { |
| 172 | AIDE_RULE_TYPE type; |
| 173 | |
| 174 | string_expression *path; |
| 175 | restriction_expression *restriction; |
| 176 | attribute_expression *attributes; |
| 177 | } rule_statement; |
| 178 | |
| 179 | typedef struct ast { |
| 180 | enum { |
| 181 | config_option_type, |
| 182 | |
| 183 | include_statement_type, |
| 184 | x_include_setenv_statement_type, |
| 185 | define_statement_type, |
| 186 | undefine_statement_type, |
| 187 | |
| 188 | group_statement_type, |
| 189 | |
| 190 | if_statement_type, |
| 191 | |
| 192 | rule_statement_type, |
| 193 | } type; |
| 194 | |
| 195 | union { |
| 196 | config_option_statement _config; |
| 197 | include_statement _include; |
| 198 | x_include_setenv_statement _x_include_setenv; |
| 199 | define_statement _define; |
| 200 | undefine_statement _undefine; |
| 201 | group_statement _group; |
| 202 | if_statement _if; |
| 203 | rule_statement _rule; |
| 204 | } statement; |
| 205 | |
| 206 | int linenumber; |
| 207 | char *filename; |
| 208 | char* linebuf; |
| 209 | |
| 210 | struct ast* next; |
| 211 | } ast; |
| 212 | |
| 213 | string_expression* new_string(char*); |
| 214 | string_expression* new_variable(char*); |
| 215 | string_expression* new_string_concat(string_expression*, string_expression*); |
| 216 | |
| 217 | ast* new_string_option_statement(config_option, string_expression*); |
| 218 | ast* new_attribute_option_statement(config_option, attribute_expression*); |
| 219 | |
| 220 | ast* new_define_statement(char*, string_expression*); |
| 221 | ast* new_undefine_statement(char*); |
| 222 | |
| 223 | ast* new_group_statement(char*, attribute_expression*); |
| 224 | |
| 225 | ast* new_include_statement(string_expression*, string_expression*, bool, string_expression*); |
| 226 | ast* new_x_include_setenv_statement(char*, string_expression*); |
| 227 | |
| 228 | ast* new_if_statement(struct if_condition*, struct ast*, struct ast*); |
| 229 | |
| 230 | ast* new_rule_statement(AIDE_RULE_TYPE, string_expression*, restriction_expression*, attribute_expression*); |
| 231 | |
| 232 | if_condition* new_if_condition(struct bool_expression*); |
| 233 | |
| 234 | bool_expression* new_string_bool_expression(bool_operator, string_expression*, string_expression*); |
| 235 | bool_expression* new_bool_expression(bool_operator, bool_expression*, bool_expression*); |
| 236 | |
| 237 | attribute_expression* new_attribute_expression(attribute_operator, attribute_expression*, char*); |
| 238 | |
| 239 | ft_restriction_expression* new_ft_restriction_expression(ft_restriction_expression*, char*); |
| 240 | restriction_expression* new_restriction_expression(ft_restriction_expression*, char*); |
| 241 | |
| 242 | void deep_free(ast*); |
| 243 | |
| 244 | #endif |