-/* @(#) $Id: validate_op.c,v 1.28 2009/08/05 18:02:13 dcid Exp $ */
+/* @(#) $Id: ./src/shared/validate_op.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
* This program is a free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
- * License (version 3) as published by the FSF - Free Software
+ * License (version 2) as published by the FSF - Free Software
* Foundation
*/
#include "shared.h"
-char *ip_address_regex =
- "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/?"
+char *ip_address_regex =
+ "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/?"
"([0-9]{0,2}|[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$";
/* Global vars */
char *buf_pt;
char *tmp_buffer;
char *ret;
-
+
#ifndef WIN32
if(isChroot())
{
snprintf(def_file,OS_FLSIZE,"%s", defines_file);
#endif
-
+
fp = fopen(def_file, "r");
if(!fp)
{
}
tmp_buffer = buf_pt;
-
+
/* Getting the equal */
buf_pt = strchr(buf_pt, '=');
if(!buf_pt)
{
*tmp_buffer = '\0';
}
-
+
os_strdup(buf_pt, ret);
fclose(fp);
return(ret);
}
-
+
fclose(fp);
return(NULL);
}
char *value;
char *pt;
-
+
/* We first try to read from the local define file. */
value = _read_file(high_name, low_name, OSSEC_LDEFINES);
if(!value)
{
return(!_true);
}
-
+
/* If negate is set */
if(that_ip->ip[0] == '!')
{
_true = 0;
}
-
+
/* Checking if ip is in thatip & netmask */
if((net.s_addr & that_ip->netmask) == that_ip->ip_address)
{
return(!_true);
}
-
+
/** int OS_IPFoundList(char *ip_address, os_ip **list_of_ips)
* Checks if ip_address is present on the "list_of_ips".
* Returns 1 on success or 0 on failure.
{
return(!_true);
}
-
+
while(*list_of_ips)
{
os_ip *l_ip = *list_of_ips;
-
+
if(l_ip->ip[0] == '!')
{
_true = 0;
}
-
+
if((net.s_addr & l_ip->netmask) == l_ip->ip_address)
{
return(_true);
}
return(!_true);
-}
+}
+
-
/** int OS_IsValidIP(char *ip)
* Validates if an ip address is in the right
* format.
{
os_strdup(ip_address, final_ip->ip);
}
-
+
if(*ip_address == '!')
{
ip_address++;
}
-
- #ifndef WIN32
+
+ #ifndef WIN32
/* checking against the basic regex */
if(!OS_PRegex(ip_address, ip_address_regex))
{
tmp_ip = ip_address;
while(*tmp_ip != '\0')
{
- if((*tmp_ip < '0' ||
- *tmp_ip > '9') &&
+ if((*tmp_ip < '0' ||
+ *tmp_ip > '9') &&
*tmp_ip != '.' &&
*tmp_ip != '/')
{
- /* Getting the cidr/netmask if available */
+ /* Getting the cidr/netmask if available */
tmp_str = strchr(ip_address,'/');
if(tmp_str)
{
int cidr;
struct in_addr net;
-
+
*tmp_str = '\0';
tmp_str++;
}
}
}
-
+
if((net.s_addr = inet_addr(ip_address)) <= 0)
{
if(strcmp("0.0.0.0", ip_address) == 0)
{
struct in_addr net;
nmask = 32;
-
+
if(strcmp("any", ip_address) == 0)
{
net.s_addr = 0;
{
return(0);
}
-
+
if(final_ip)
{
final_ip->ip_address = net.s_addr;
if(!_mask_inited)
_init_masks();
-
+
final_ip->netmask = htonl(_netmasks[nmask]);
}
/* Comparing against min/max value */
if((strncmp(time_str, ossec_time, 5) >= 0)&&
- (strncmp(time_str, ossec_time+5,5) <= 0))
+ (strncmp(time_str, ossec_time+5,5) <= 0))
{
return(_true);
}
-
+
return(!_true);
}
int _size = 0;
int chour = 0;
int cmin = 0;
-
+
/* Invalid time format */
if(!isdigit((int)*str))
{
merror(INVALID_TIME, __local_name, str);
}
-
+
/* Hour */
chour = atoi(str);
return(NULL);
}
-
+
/* Going after the hour */
while(isdigit((int)*str))
{
merror(INVALID_TIME, __local_name, str);
return(NULL);
}
-
-
+
+
/* Getting minute */
if(*str == ':')
{
/* Removing spaces */
RM_WHITE(str);
-
+
if((*str == 'a') || (*str == 'A'))
{
str++;
if((*str == 'm') || (*str == 'M'))
{
chour += 12;
-
+
/* New hour must be valid */
if(chour < 0 || chour >= 24)
{
merror(INVALID_TIME, __local_name, str);
return(NULL);
}
-
+
snprintf(ossec_hour, 6, "%02d:%02d", chour, cmin);
str++;
return(str);
}
-
+
}
else
{
char first_hour[7];
char second_hour[7];
int ng = 0;
-
+
/* Must be not null */
if(!time_str)
return(NULL);
-
-
+
+
/* Clearing memory */
memset(first_hour, '\0', 7);
memset(second_hour, '\0', 7);
-
-
+
+
/* Removing white spaces */
RM_WHITE(time_str);
RM_WHITE(time_str);
}
-
+
/* Getting first hour */
time_str = __gethour(time_str, first_hour);
if(!time_str)
/* Removing white spaces */
RM_WHITE(time_str);
-
+
if(*time_str != '-')
{
return(NULL);
time_str = __gethour(time_str, second_hour);
if(!time_str)
return(NULL);
-
+
RM_WHITE(time_str);
if(*time_str != '\0')
{
}
os_calloc(13, sizeof(char), ret);
-
+
/* Fixing dump hours */
if(strcmp(first_hour,second_hour) > 0)
{
snprintf(ret, 12, "!%s%s", second_hour, first_hour);
return(ret);
}
-
+
/* For the normal times */
snprintf(ret, 12, "%c%s%s", ng == 0?'.':'!', first_hour, second_hour);
return(ret);
/* Unique times can't have a !. */
if(*ossec_time == '!')
return(0);
-
-
+
+
ossec_time++;
/* Comparing against min/max value */
/* Negative */
if(ossec_day[7] == '!')
_true = 0;
-
+
if(week_day < 0 || week_day > 7)
{
return(0);
/* It is on the right day */
if(ossec_day[week_day] == 1)
return(_true);
-
- return(!_true);
+
+ return(!_true);
}
int i = 0, ng = 0;
char *ret;
char day_ret[9] = {0,0,0,0,0,0,0,0,0};
- char *(days[]) =
+ char *(days[]) =
{
"sunday", "sun", "monday", "mon", "tuesday", "tue",
"wednesday", "wed", "thursday", "thu", "friday",
/* Must be a valid string */
if(!day_str)
return(NULL);
-
-
+
+
RM_WHITE(day_str);
-
+
/* checking for negatives */
if(*day_str == '!')
{
merror(INVALID_DAY, __local_name, day_str);
return(NULL);
}
-
+
day_str += strlen(days[i]);
if(IS_SEP(day_str))
merror(INVALID_DAY, __local_name, day_str);
return(NULL);
}
-
+
return(ret);
}