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