new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / headers / validate_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 #ifndef __VALIDATE_H
11 #define __VALIDATE_H
12
13 /* IP structure */
14 typedef struct _os_ip {
15     char *ip;
16     struct sockaddr_storage ss;
17     unsigned int prefixlength;
18 }os_ip;
19
20 /* Run-time definitions */
21 int getDefine_Int(const char *high_name, const char *low_name, int min, int max) __attribute__((nonnull));
22
23 /* Check if IP_address is present at that_ip
24  * Returns 1 on success or 0 on failure
25  */
26 int OS_IPFound(const char *ip_address, const os_ip *that_ip) __attribute__((nonnull));
27
28 /* Check if IP_address is present in the list_of_ips
29  * Returns 1 on success or 0 on failure.
30  * The list MUST be NULL terminated
31  */
32 int OS_IPFoundList(const char *ip_address, os_ip **list_of_ips) __attribute__((nonnull));
33
34 /* Validate if an IP address is in the right format
35  * Returns 0 if doesn't match or 1 if it does (or 2 if it has a CIDR)
36  * WARNING: On success this function may modify the value of IP_address
37  */
38 int OS_IsValidIP(const char *ip_address, os_ip *final_ip);
39
40 /** int sacmp(struct sockaddr *sa1, struct sockaddr *sa2, int prefixlength)
41  * Compares two sockaddrs up to prefixlength.
42  * Returns 0 if doesn't match or 1 if they do.
43  */
44 int sacmp(struct sockaddr *sa1, struct sockaddr *sa2, int prefixlength);
45
46 /** Time range validations **/
47
48 /* Validate if a time is in an acceptable format for OSSEC
49  * Returns 0 if doesn't match or a valid string for OSSEC usage in success.
50  * WARNING: On success this function may modify the value of date
51  *
52  * Acceptable formats:
53  *      hh:mm - hh:mm (24 hour format)
54  *      !hh:mm -hh:mm (24 hour format)
55  *      hh - hh (24 hour format)
56  *      hh:mm am - hh:mm pm (12 hour format)
57  *      hh am - hh pm (12 hour format)
58  */
59 char *OS_IsValidTime(const char *time_str);
60
61 /* Same as above, but only accepts a unique time, not a range */
62 char *OS_IsValidUniqueTime(const char *time_str) __attribute__((nonnull));
63
64 /* Must be a valid string, called after OS_IsValidTime
65  * Returns 1 on success or 0 on failure
66  */
67 int OS_IsonTime(const char *time_str, const char *ossec_time) __attribute__((nonnull));
68
69 /* Same as above, but checks if time is the same or has passed a specified one */
70 int OS_IsAfterTime(const char *time_str, const char *ossec_time) __attribute__((nonnull));
71
72 /** Day validations **/
73
74 /* Check if the specified week day is in the range */
75 int OS_IsonDay(int week_day, const char *ossec_day) __attribute__((nonnull));
76
77 /* Validate if a day is in an acceptable format for OSSEC
78  * Returns 0 if doesn't match or a valid string for ossec usage in success
79  * WARNING: On success this function may modify the value of date
80  *
81  * Acceptable formats:
82  *      weekdays, weekends, monday, tuesday, thursday,..
83  *      monday,tuesday
84  *      mon,tue wed
85  */
86 char *OS_IsValidDay(const char *day_str);
87
88 /* Macros */
89
90 /* Check if the IP is a single host, not a network with a netmask */
91 #define isSingleHost(x) ((x->ss.ss_family == AF_INET) ? (x->prefixlength == 32) : (x->prefixlength == 128))
92
93 #endif
94