new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / headers / rules_op.h
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All rights reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation.
8  */
9
10 /* Common API for dealing with rules */
11
12 #ifndef _OS_RULESOP_H
13 #define _OS_RULESOP_H
14
15 #include "shared.h"
16
17 /* Event context - stored in a uint8 */
18 #define SAME_USER       0x001 /* 1   */
19 #define SAME_SRCIP      0x002 /* 2   */
20 #define SAME_ID         0x004 /* 4   */
21 #define SAME_LOCATION   0x008 /* 8   */
22 #define DIFFERENT_URL   0x010
23 #define DIFFERENT_SRCIP 0x200
24 #define DIFFERENT_SRCGEOIP 0x400 
25 #define SAME_SRCPORT    0x020
26 #define SAME_DSTPORT    0x040
27 #define SAME_DODIFF     0x100
28 #define NOT_SAME_USER   0xffe /* 0xfff - 0x001 */
29 #define NOT_SAME_SRCIP  0xffd /* 0xfff - 0x002 */
30 #define NOT_SAME_ID     0xffb /* 0xfff - 0x004 */
31 #define NOT_SAME_AGENT  0xff7 /* 0xfff - 0x008 */
32
33 /* Alert options - stored in a uint8 */
34 #define DO_FTS          0x001
35 #define DO_MAILALERT    0x002
36 #define DO_LOGALERT     0x004
37 #define NO_AR           0x008
38 #define NO_ALERT        0x010
39 #define DO_OVERWRITE    0x020
40 #define DO_PACKETINFO   0x040
41 #define DO_EXTRAINFO    0x100
42 #define SAME_EXTRAINFO  0x200
43
44 /* Types of events (from decoders) */
45 #define UNKNOWN             0   /* Unknown */
46 #define SYSLOG              1   /* syslog message */
47 #define IDS                 2   /* IDS alert */
48 #define FIREWALL            3   /* Firewall event */
49 #define WEBLOG              7   /* Apache log */
50 #define SQUID               8   /* Squid log */
51 #define DECODER_WINDOWS     9   /* Windows log */
52 #define HOST_INFO           10  /* Host information log (from nmap or similar) */
53 #define OSSEC_RL            11  /* OSSEC rule */
54
55 /* FTS allowed values */
56 #define FTS_NAME        001000
57 #define FTS_USER        002000
58 #define FTS_DSTUSER     004000
59 #define FTS_SRCIP       000100
60 #define FTS_DSTIP       000200
61 #define FTS_LOCATION    000400
62 #define FTS_ID          000010
63 #define FTS_DATA        000020
64 #define FTS_SYSTEMNAME  000040
65
66 typedef struct _RuleInfo {
67     int sigid;  /* id attribute -- required */
68     int level;  /* level attribute --required */
69     int maxsize;
70     int frequency;
71     int timeframe;
72
73     u_int8_t context; /* Not a user option */
74
75     int firedtimes;   /* Not a user option */
76     int time_ignored; /* Not a user option */
77     int ignore_time;
78     int ignore;
79     int ckignore;
80     int group_prev_matched_sz;
81
82     int __frequency;
83     char **last_events;
84
85     /* Not an option in the rule */
86     u_int16_t alert_opts;
87
88     /* Context options */
89     u_int16_t context_opts;
90
91     /* Category */
92     u_int8_t category;
93
94     /* Decoded as */
95     u_int16_t decoded_as;
96
97     /* List of previously matched events */
98     OSList *sid_prev_matched;
99
100     /* Pointer to a list (points to sid_prev_matched of if_matched_sid */
101     OSList *sid_search;
102
103     /* List of previously matched events in this group
104      *
105      * Every rule that has if_matched_group will have this list. Every rule that
106      * matches this group, is going to have a pointer to it (group_search).
107      */
108     OSList **group_prev_matched;
109
110     /* Pointer to group_prev_matched */
111     OSList *group_search;
112
113     /* Function pointer to the event_search */
114     void *(*event_search)(void *lf, void *rule);
115
116     char *group;
117     OSMatch *match;
118     OSRegex *regex;
119
120     /* Policy-based rules */
121     char *day_time;
122     char *week_day;
123
124     os_ip **srcip;
125     os_ip **dstip;
126     OSMatch *srcport;
127     OSMatch *dstport;
128     OSMatch *user;
129     OSMatch *url;
130     OSMatch *id;
131     OSMatch *status;
132     OSMatch *hostname;
133     OSMatch *program_name;
134     OSMatch *extra_data;
135     char *action;
136
137     char *comment; /* Description in the xml */
138     char *info;
139     char *cve;
140
141     char *if_sid;
142     char *if_level;
143     char *if_group;
144
145     OSRegex *if_matched_regex;
146     OSMatch *if_matched_group;
147     int if_matched_sid;
148
149     void **ar;
150
151 } RuleInfo;
152
153 int OS_ReadXMLRules(const char *rulefile,
154                     void *(*ruleact_function)(RuleInfo *rule_1, void *data_1),
155                     void *data) __attribute__((nonnull(1, 2)));
156
157 #endif
158