| 1 | /* |
| 2 | * AIDE (Advanced Intrusion Detection Environment) |
| 3 | * |
| 4 | * Copyright (C) 1999-2002, 2006, 2010, 2019-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 _REPORT_H_INCLUDED |
| 23 | #define _REPORT_H_INCLUDED |
| 24 | #include <stdbool.h> |
| 25 | #include <stdio.h> |
| 26 | #include "attributes.h" |
| 27 | #include "seltree.h" |
| 28 | #include "config.h" |
| 29 | #include "conf_ast.h" |
| 30 | #include "log.h" |
| 31 | #include "url.h" |
| 32 | #include "db_line.h" |
| 33 | |
| 34 | /* report level */ |
| 35 | typedef enum { /* preserve order */ |
| 36 | REPORT_LEVEL_UNKNOWN = 0, |
| 37 | REPORT_LEVEL_MINIMAL = 1, |
| 38 | REPORT_LEVEL_SUMMARY = 2, |
| 39 | REPORT_LEVEL_DATABASE_ATTRIBUTES = 3, |
| 40 | REPORT_LEVEL_LIST_ENTRIES = 4, |
| 41 | REPORT_LEVEL_CHANGED_ATTRIBUTES = 5, |
| 42 | REPORT_LEVEL_ADDED_REMOVED_ATTRIBUTES = 6, |
| 43 | REPORT_LEVEL_ADDED_REMOVED_ENTRIES = 7, |
| 44 | } REPORT_LEVEL; |
| 45 | |
| 46 | /* report format */ |
| 47 | typedef enum { |
| 48 | REPORT_FORMAT_UNKNOWN = 0, |
| 49 | REPORT_FORMAT_PLAIN = 1, |
| 50 | REPORT_FORMAT_JSON = 2, |
| 51 | } REPORT_FORMAT; |
| 52 | |
| 53 | extern const ATTRIBUTE report_attrs_order[]; |
| 54 | extern int report_attrs_order_length; |
| 55 | |
| 56 | bool init_report_urls(void); |
| 57 | |
| 58 | bool add_report_url(url_t* url, int, char*, char*); |
| 59 | |
| 60 | REPORT_LEVEL get_report_level(char *); |
| 61 | REPORT_FORMAT get_report_format(char *); |
| 62 | |
| 63 | void log_report_urls(LOG_LEVEL); |
| 64 | |
| 65 | /* |
| 66 | * gen_report() |
| 67 | * Generate report based on the given node |
| 68 | */ |
| 69 | int gen_report(seltree* node); |
| 70 | |
| 71 | typedef struct report_options { |
| 72 | REPORT_LEVEL level; |
| 73 | REPORT_FORMAT format; |
| 74 | } report_options; |
| 75 | |
| 76 | extern report_options default_report_options; |
| 77 | |
| 78 | typedef struct diff_attrs_entry { |
| 79 | char* entry; |
| 80 | DB_ATTR_TYPE old_attrs; |
| 81 | DB_ATTR_TYPE new_attrs; |
| 82 | } diff_attrs_entry; |
| 83 | |
| 84 | typedef struct report_t { |
| 85 | url_t* url; |
| 86 | FILE* fd; |
| 87 | |
| 88 | REPORT_LEVEL level; |
| 89 | REPORT_FORMAT format; |
| 90 | |
| 91 | int detailed_init; |
| 92 | int base16; |
| 93 | int quiet; |
| 94 | int summarize_changes; |
| 95 | int grouped; |
| 96 | bool append; |
| 97 | |
| 98 | #ifdef WITH_E2FSATTRS |
| 99 | long ignore_e2fsattrs; |
| 100 | #endif |
| 101 | |
| 102 | DB_ATTR_TYPE ignore_added_attrs; |
| 103 | DB_ATTR_TYPE ignore_removed_attrs; |
| 104 | DB_ATTR_TYPE ignore_changed_attrs; |
| 105 | DB_ATTR_TYPE force_attrs; |
| 106 | |
| 107 | long ntotal; |
| 108 | long nadd, nrem, nchg; |
| 109 | |
| 110 | diff_attrs_entry *diff_attrs_entries; |
| 111 | int num_diff_attrs_entries; |
| 112 | |
| 113 | int linenumber; |
| 114 | char* filename; |
| 115 | char* linebuf; |
| 116 | |
| 117 | } report_t; |
| 118 | |
| 119 | void report_printf(report_t*, const char*, ...) |
| 120 | #ifdef __GNUC__ |
| 121 | __attribute__ ((format (printf, 2, 3))) |
| 122 | #endif |
| 123 | ; |
| 124 | |
| 125 | typedef struct report_format_module { |
| 126 | void (*print_report_config_options)(report_t*); |
| 127 | void (*print_report_databases)(report_t*); |
| 128 | void (*print_report_details)(report_t*, seltree*); |
| 129 | void (*print_report_diff_attrs_entries)(report_t*); |
| 130 | void (*print_report_endtime_runtime)(report_t*, const char*, long); |
| 131 | void (*print_report_entries)(report_t*, seltree*, const int); |
| 132 | void (*print_report_footer)(report_t*); |
| 133 | void (*print_report_header)(report_t*); |
| 134 | void (*print_report_new_database_written)(report_t*); |
| 135 | void (*print_report_outline)(report_t*); |
| 136 | void (*print_report_report_options)(report_t*); |
| 137 | void (*print_report_starttime_version)(report_t*, const char*, const char*); |
| 138 | void (*print_report_summary)(report_t*); |
| 139 | } report_format_module; |
| 140 | |
| 141 | char* get_file_type_string(mode_t); |
| 142 | char* get_summarize_changes_string(report_t*, seltree*); |
| 143 | char* get_summary_string(report_t*); |
| 144 | const char* get_report_level_string(REPORT_LEVEL); |
| 145 | int get_attribute_values(DB_ATTR_TYPE, db_line*,char* **, report_t*); |
| 146 | void print_databases_attrs(report_t *, void (*)(report_t *, db_line*)); |
| 147 | void print_dbline_attrs(report_t *, db_line*, db_line*, DB_ATTR_TYPE, void (*)(report_t *, db_line*, db_line*, ATTRIBUTE)); |
| 148 | void print_report_config_options(report_t *, void (*)(report_t *, config_option, const char*)); |
| 149 | void print_report_details(report_t *, seltree*, void (*)(report_t *, db_line*, db_line*, DB_ATTR_TYPE)); |
| 150 | void print_report_entries(report_t*, seltree*, const int, void (*)(report_t*, char*, int, seltree*)); |
| 151 | void print_report_report_options(report_t *, void (*)(report_t *, config_option, const char*)); |
| 152 | |
| 153 | #endif |