30 #include <openvas/base/openvas_hosts.h> 51 struct tm *time_broken;
55 if (zone == NULL || strcmp (zone,
"UTC") == 0)
59 tz = getenv (
"TZ") ? g_strdup (getenv (
"TZ")) : NULL;
61 if (setenv (
"TZ", zone, 1) == -1)
63 g_warning (
"%s: Failed to switch to timezone", __FUNCTION__);
72 time_broken = localtime (&time);
73 if (strftime (buf, 100,
"%z", time_broken) == 0)
75 g_warning (
"%s: Failed to format timezone", __FUNCTION__);
82 if (strlen (buf) >= 3)
87 mins += atoi (buf + 3);
95 if (setenv (
"TZ", tz, 1) == -1)
97 g_warning (
"%s: Failed to switch to original TZ", __FUNCTION__);
122 struct tm *now_broken;
128 tz = getenv (
"TZ") ? g_strdup (getenv (
"TZ")) : NULL;
130 if (setenv (
"TZ", zone, 1) == -1)
132 g_warning (
"%s: Failed to switch to timezone", __FUNCTION__);
134 setenv (
"TZ", tz, 1);
142 now_broken = localtime (&now);
143 if (setenv (
"TZ",
"UTC", 1) == -1)
145 g_warning (
"%s: Failed to switch to UTC", __FUNCTION__);
147 setenv (
"TZ", tz, 1);
152 offset = - (now - mktime (now_broken));
157 if (setenv (
"TZ", tz, 1) == -1)
159 g_warning (
"%s: Failed to switch to original TZ", __FUNCTION__);
175 #define MONTHS_WITHIN_YEAR() \ 178 : ((broken2->tm_mon - broken1.tm_mon) \ 184 : (broken2->tm_sec < broken1.tm_sec)) \ 185 : (broken2->tm_min < broken1.tm_min)) \ 186 : (broken2->tm_hour < broken1.tm_hour)) \ 187 : (broken2->tm_mday < broken1.tm_mday)))) 204 struct tm broken1, *broken2;
205 int same_year, same_month, same_day, same_hour, same_minute, same_second;
206 int month1_less, day1_less, hour1_less, minute1_less;
209 assert (time1 <= time2);
211 localtime_r (&time1, &broken1);
212 broken2 = localtime (&time2);
214 same_year = (broken1.tm_year == broken2->tm_year);
215 same_month = (broken1.tm_mon == broken2->tm_mon);
216 same_day = (broken1.tm_mday == broken2->tm_mday);
217 same_hour = (broken1.tm_hour == broken2->tm_hour);
218 same_minute = (broken1.tm_min == broken2->tm_min);
219 same_second = (broken1.tm_sec == broken2->tm_sec);
221 month1_less = (broken1.tm_mon < broken2->tm_mon);
222 day1_less = (broken1.tm_mday < broken2->tm_mday);
223 hour1_less = (broken1.tm_hour < broken2->tm_hour);
224 minute1_less = (broken1.tm_min < broken2->tm_min);
225 second1_less = (broken1.tm_sec < broken2->tm_sec);
238 && second1_less))))))))
240 ((broken2->tm_year - broken1.tm_year) * 12)
243 ((broken2->tm_year - broken1.tm_year - 1) * 12)
245 + (11 - broken1.tm_mon)
255 && second1_less)))))))));
269 struct tm *broken = localtime (&time);
270 broken->tm_mon += months;
271 return mktime (broken);
287 next_time (time_t first,
int period,
int period_months,
const char* timezone,
291 time_t now = time (NULL);
295 long first_offset_val, current_offset_val;
298 offset_diff = current_offset_val - first_offset_val;
312 + ((((now - first + offset_diff) / period) + 1 + periods_offset)
316 else if (period_months > 0)
322 tz = getenv (
"TZ") ? g_strdup (getenv (
"TZ")) : NULL;
324 if (setenv (
"TZ", timezone ? timezone :
"UTC", 1) == -1)
326 g_warning (
"%s: Failed to switch to timezone", __FUNCTION__);
328 setenv (
"TZ", tz, 1);
337 periods_diff += periods_offset;
338 ret =
add_months (first, (periods_diff + 1) * period_months);
344 if (setenv (
"TZ", tz, 1) == -1)
346 g_warning (
"%s: Failed to switch to original TZ", __FUNCTION__);
357 else if (periods_offset == -1)
378 openvas_hosts_t *hosts;
380 hosts = openvas_hosts_new_with_max (given_hosts, max_hosts);
386 openvas_hosts_exclude (hosts, exclude_hosts, 0);
388 count = openvas_hosts_count (hosts);
389 openvas_hosts_free (hosts);
405 if (strcasecmp (level,
"Log") == 0)
407 else if (strcasecmp (level,
"False Positive") == 0)
409 else if (strcasecmp (level,
"Debug") == 0)
411 else if (strcasecmp (level,
"Error") == 0)
413 else if (strcasecmp (
class,
"classic") == 0)
415 if (strcasecmp (level,
"high") == 0)
417 else if (strcasecmp (level,
"medium") == 0)
419 else if (strcasecmp (level,
"low") == 0)
424 else if (strcasecmp (
class,
"pci-dss") == 0)
426 if (strcasecmp (level,
"high") == 0)
434 if (strcasecmp (level,
"high") == 0)
436 else if (strcasecmp (level,
"medium") == 0)
438 else if (strcasecmp (level,
"low") == 0)
456 if (strcasecmp (level,
"Log") == 0)
458 else if (strcasecmp (level,
"False Positive") == 0)
460 else if (strcasecmp (level,
"Debug") == 0)
462 else if (strcasecmp (level,
"Error") == 0)
464 else if (strcasecmp (
class,
"classic") == 0)
466 if (strcasecmp (level,
"high") == 0)
468 else if (strcasecmp (level,
"medium") == 0)
470 else if (strcasecmp (level,
"low") == 0)
475 else if (strcasecmp (
class,
"pci-dss") == 0)
477 if (strcasecmp (level,
"high") == 0)
485 if (strcasecmp (level,
"high") == 0)
487 else if (strcasecmp (level,
"medium") == 0)
489 else if (strcasecmp (level,
"low") == 0)
509 return (strcasecmp (type,
"agent") == 0)
510 || (strcasecmp (type,
"alert") == 0)
511 || (strcasecmp (type,
"config") == 0)
512 || (strcasecmp (type,
"cpe") == 0)
513 || (strcasecmp (type,
"credential") == 0)
514 || (strcasecmp (type,
"cve") == 0)
515 || (strcasecmp (type,
"cert_bund_adv") == 0)
516 || (strcasecmp (type,
"dfn_cert_adv") == 0)
517 || (strcasecmp (type,
"filter") == 0)
518 || (strcasecmp (type,
"group") == 0)
519 || (strcasecmp (type,
"host") == 0)
520 || (strcasecmp (type,
"os") == 0)
521 || (strcasecmp (type,
"note") == 0)
522 || (strcasecmp (type,
"nvt") == 0)
523 || (strcasecmp (type,
"ovaldef") == 0)
524 || (strcasecmp (type,
"override") == 0)
525 || (strcasecmp (type,
"port_list") == 0)
526 || (strcasecmp (type,
"permission") == 0)
527 || (strcasecmp (type,
"report") == 0)
528 || (strcasecmp (type,
"report_format") == 0)
529 || (strcasecmp (type,
"result") == 0)
530 || (strcasecmp (type,
"role") == 0)
531 || (strcasecmp (type,
"scanner") == 0)
532 || (strcasecmp (type,
"schedule") == 0)
533 || (strcasecmp (type,
"slave") == 0)
534 || (strcasecmp (type,
"tag") == 0)
535 || (strcasecmp (type,
"target") == 0)
536 || (strcasecmp (type,
"task") == 0)
537 || (strcasecmp (type,
"user") == 0);
time_t months_between(time_t time1, time_t time2)
Count number of full months between two times.
time_t add_months(time_t time, int months)
Add months to a time.
long current_offset(const char *zone)
Get the current offset from UTC of a timezone.
double level_max_severity(const char *level, const char *class)
Get the minimum severity for a severity level and class.
#define MONTHS_WITHIN_YEAR()
Code fragment for months_between.
int manage_count_hosts_max(const char *given_hosts, const char *exclude_hosts, int max_hosts)
Return number of hosts described by a hosts string.
long time_offset(const char *zone, time_t time)
Get the offset from UTC of a timezone at a particular time.
double level_min_severity(const char *level, const char *class)
Get the minimum severity for a severity level and class.
#define SEVERITY_UNDEFINED
int valid_db_resource_type(const char *type)
Check whether a resource type table name is valid.
time_t next_time(time_t first, int period, int period_months, const char *timezone, int periods_offset)
Calculate the next time from now given a start time and a period.