Imported Upstream version 2.7
[ossec-hids.git] / src / headers / validate_op.h
1 /* @(#) $Id: ./src/headers/validate_op.h, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights reserved.
6  *
7  * This program is a free software; you can redistribute it
8  * and/or modify it under the terms of the GNU General Public
9  * License (version 2) as published by the FSF - Free Software
10  * Foundation
11  */
12
13 /* Part of the OSSEC HIDS
14  * Available at http://www.ossec.net
15  */
16
17
18 #ifndef __VALIDATE_H
19
20 #define __VALIDATE_H
21
22 /* IP structure */
23 typedef struct _os_ip
24 {
25     char *ip;
26     unsigned int ip_address;
27     unsigned int netmask;
28 }os_ip;
29
30
31 /* Getting the netmask based on the integer value. */
32 int getNetmask(int mask, char *strmask, int size);
33
34
35 /* Run time definitions. */
36 int getDefine_Int(char *high_name, char *low_name, int min, int max);
37
38
39
40 /** int OS_IPFound(char *ip_address, os_ip *that_ip)
41  * Checks if ip_address is present at that_ip.
42  * Returns 1 on success or 0 on failure.
43  */
44 int OS_IPFound(char *ip_address, os_ip *that_ip);
45
46
47
48 /** int OS_IPFoundList(char *ip_address, char **list_of_ips)
49  * Checks if ip_address is present on the "list_of_ips".
50  * Returns 1 on success or 0 on failure.
51  * The list MUST be NULL terminated
52  */
53 int OS_IPFoundList(char *ip_address, os_ip **list_of_ips);
54
55
56
57 /** int OS_IsValidIP(char *ip)
58  * Validates if an ip address is in the right
59  * format.
60  * Returns 0 if doesn't match or 1 if it does (or 2 if it has a cidr).
61  * ** On success this function may modify the value of ip_address
62  */
63 int OS_IsValidIP(char *ip_address, os_ip *final_ip);
64
65
66 /** Time range validations **/
67
68 /** char *OS_IsValidTime(char *time_str)
69  * Validates if a time is in an acceptable format
70  * for ossec.
71  * Returns 0 if doesn't match or a valid string for
72  * ossec usage in success.
73  * ** On success this function may modify the value of date
74  * Acceptable formats:
75  * hh:mm - hh:mm (24 hour format)
76  * !hh:mm -hh:mm (24 hour format)
77  * hh - hh (24 hour format)
78  * hh:mm am - hh:mm pm (12 hour format)
79  * hh am - hh pm (12 hour format)
80  */
81 char *OS_IsValidTime(char *time_str);
82
83 /* Same as above, but only accepts a unique time, not a range. */
84 char *OS_IsValidUniqueTime(char *time_str);
85
86
87
88 /** int OS_IsonTime(char *time_str, char *ossec_time)
89  * Must be a valid string, called after OS_IsValidTime.
90  * Returns 1 on success or 0 on failure.
91  */
92 int OS_IsonTime(char *time_str, char *ossec_time);
93
94 /* Same as above, but checks if time is the same or has passed a specified one. */
95 int OS_IsAfterTime(char *time_str, char *ossec_time);
96
97
98
99 /** Day validations **/
100
101
102 /** int OS_IsonDay(int week_day, char *ossec_day)
103  * Checks if the specified week day is in the
104  * range.
105  */
106 int OS_IsonDay(int week_day, char *ossec_day);
107
108
109 /** char *OS_IsValidDay(char *day_str)
110  * Validates if an day is in an acceptable format
111  * for ossec.
112  * Returns 0 if doesn't match or a valid string for
113  * ossec usage in success.
114  * ** On success this function may modify the value of date
115  * Acceptable formats:
116  * weekdays, weekends, monday, tuesday, thursday,..
117  * monday,tuesday
118  * mon,tue wed
119  */
120 char *OS_IsValidDay(char *day_str);
121
122
123 /* Macros */
124
125 /* Checks if the ip is a single host, not a network with a netmask */
126 #define isSingleHost(x) (x->netmask == 0xFFFFFFFF)
127
128 #endif
129
130 /* EOF */