| 1 | /* |
| 2 | * AIDE (Advanced Intrusion Detection Environment) |
| 3 | * |
| 4 | * Copyright (C) 1999-2002, 2006, 2016, 2020-2025 Rami Lehti, Pablo Virolainen, |
| 5 | * Richard van den Berg, Hannes von Haugwitz |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of the |
| 10 | * License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
| 22 | #ifndef _RX_RULE_H_INCLUDED |
| 23 | #define _RX_RULE_H_INCLUDED |
| 24 | |
| 25 | #include "config.h" |
| 26 | #include "file.h" |
| 27 | #include <sys/stat.h> |
| 28 | #define PCRE2_CODE_UNIT_WIDTH 8 |
| 29 | #include <pcre2.h> |
| 30 | #include "attributes.h" |
| 31 | |
| 32 | typedef struct rx_restriction_t { |
| 33 | FT_TYPE f_type; |
| 34 | #ifdef HAVE_FSTYPE |
| 35 | FS_TYPE fs_type; |
| 36 | #endif |
| 37 | } rx_restriction_t; |
| 38 | |
| 39 | typedef enum { |
| 40 | AIDE_RECURSIVE_NEGATIVE_RULE=0, |
| 41 | AIDE_NON_RECURSIVE_NEGATIVE_RULE=1, |
| 42 | AIDE_SELECTIVE_RULE=2, |
| 43 | AIDE_EQUAL_RULE=3, |
| 44 | } AIDE_RULE_TYPE; |
| 45 | |
| 46 | typedef struct rx_rule { |
| 47 | char* rx; /* Regular expression in text form */ |
| 48 | pcre2_code* crx; /* Compiled regexp */ |
| 49 | pcre2_match_data *md; |
| 50 | AIDE_RULE_TYPE type; |
| 51 | DB_ATTR_TYPE attr; /* Which attributes to save */ |
| 52 | char *config_filename; |
| 53 | int config_linenumber; |
| 54 | char *config_line; |
| 55 | char *prefix; |
| 56 | rx_restriction_t restriction; |
| 57 | } rx_rule; |
| 58 | |
| 59 | typedef enum match_result { |
| 60 | RESULT_NO_RULE_MATCH = 0, |
| 61 | RESULT_RECURSIVE_NEGATIVE_MATCH = (1<<0), |
| 62 | RESULT_NON_RECURSIVE_NEGATIVE_MATCH = (1<<1), |
| 63 | RESULT_SELECTIVE_MATCH = (1<<2), |
| 64 | RESULT_EQUAL_MATCH = (1<<3), |
| 65 | RESULT_PARTIAL_MATCH = (1<<4), |
| 66 | RESULT_NO_LIMIT_MATCH = (1<<5), |
| 67 | RESULT_PARTIAL_LIMIT_MATCH = (1<<6), |
| 68 | RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH = (1<<7), |
| 69 | RESULT_NEGATIVE_PARENT_MATCH = (1<<8), |
| 70 | } match_result; |
| 71 | |
| 72 | typedef struct match_t { |
| 73 | match_result result; |
| 74 | rx_rule* rule; |
| 75 | int length; |
| 76 | } match_t; |
| 77 | |
| 78 | char* get_rule_type_long_string(AIDE_RULE_TYPE); |
| 79 | char* get_rule_type_char(AIDE_RULE_TYPE); |
| 80 | |
| 81 | /* memory for the returned string is obtained with malloc(3), and should be freed with free(3). */ |
| 82 | char *get_restriction_string(rx_restriction_t); |
| 83 | |
| 84 | char *get_match_result_string(match_result); |
| 85 | char *get_match_result_desc(match_result); |
| 86 | #endif /* RX_RULE_H_INCLUDED */ |