1 /* Copyright (C) 2009 Trend Micro Inc.
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
14 typedef struct _os_ip {
16 struct sockaddr_storage ss;
17 unsigned int prefixlength;
20 /* Run-time definitions */
21 int getDefine_Int(const char *high_name, const char *low_name, int min, int max) __attribute__((nonnull));
23 /* Check if IP_address is present at that_ip
24 * Returns 1 on success or 0 on failure
26 int OS_IPFound(const char *ip_address, const os_ip *that_ip) __attribute__((nonnull));
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
32 int OS_IPFoundList(const char *ip_address, os_ip **list_of_ips) __attribute__((nonnull));
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
38 int OS_IsValidIP(const char *ip_address, os_ip *final_ip);
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.
44 int sacmp(struct sockaddr *sa1, struct sockaddr *sa2, int prefixlength);
46 /** Time range validations **/
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
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)
59 char *OS_IsValidTime(const char *time_str);
61 /* Same as above, but only accepts a unique time, not a range */
62 char *OS_IsValidUniqueTime(const char *time_str) __attribute__((nonnull));
64 /* Must be a valid string, called after OS_IsValidTime
65 * Returns 1 on success or 0 on failure
67 int OS_IsonTime(const char *time_str, const char *ossec_time) __attribute__((nonnull));
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));
72 /** Day validations **/
74 /* Check if the specified week day is in the range */
75 int OS_IsonDay(int week_day, const char *ossec_day) __attribute__((nonnull));
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
82 * weekdays, weekends, monday, tuesday, thursday,..
86 char *OS_IsValidDay(const char *day_str);
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))