Greenbone Vulnerability Manager
9.0.1
|
Module for Greenbone Vulnerability Manager: Manage library utilities. More...
#include "manage_utils.h"
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gvm/base/hosts.h>
#include <gvm/util/uuidutils.h>
Macros | |
#define | G_LOG_DOMAIN "md utils" |
GLib log domain. | |
#define | SECS_PER_DAY 86400 |
Number of seconds in a day. | |
#define | MONTHS_WITHIN_YEAR() |
Code fragment for months_between. More... | |
#define | SECONDS_PER_DAY 86400 |
Number of seconds in a day. | |
#define | GVM_PRODID |
GVM product ID. More... | |
#define | ICAL_RETURN_ERROR(message) |
Error return for icalendar_from_string. More... | |
Functions | |
static long | time_offset (const char *zone, time_t time) |
Get the offset from UTC of a timezone at a particular time. More... | |
long | current_offset (const char *zone) |
Get the current offset from UTC of a timezone. More... | |
static time_t | months_between (time_t time1, time_t time2) |
Count number of full months between two times. More... | |
time_t | add_months (time_t time, int months) |
Add months to a time. More... | |
static int | day_of_week (time_t time) |
Calculate day of week corresponding to a time. More... | |
static int | next_day (int day_of_week, int byday) |
Get days till next occurrence. More... | |
time_t | next_time (time_t first, int period, int period_months, int byday, const char *zone, int periods_offset) |
Calculate the next time from now given a start time and a period. More... | |
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. More... | |
double | level_min_severity (const char *level, const char *class) |
Get the minimum severity for a severity level and class. More... | |
double | level_max_severity (const char *level, const char *class) |
Get the minimum severity for a severity level and class. More... | |
int | hosts_str_contains (const char *hosts_str, const char *find_host_str, int max_hosts) |
Returns whether a host has an equal host in a hosts string. More... | |
int | valid_db_resource_type (const char *type) |
Check whether a resource type table name is valid. More... | |
void | blank_control_chars (char *string) |
Replace any control characters in string with spaces. More... | |
static icaltimezone * | icalendar_timezone_from_tzid (const char *tzid) |
Try to get a built-in libical timezone from a tzid or city name. More... | |
icalcomponent * | icalendar_from_old_schedule_data (time_t first_time, time_t period, time_t period_months, time_t duration, int byday_mask) |
Create an iCalendar component from old schedule data. More... | |
static icalcomponent * | icalendar_simplify_vevent (icalcomponent *vevent, gchar **error, GString *warnings_buffer) |
Simplify an VEVENT iCal component. More... | |
icalcomponent * | icalendar_from_string (const char *ical_string, gchar **error) |
Creates a new, simplified VCALENDAR component from a string. More... | |
int | icalendar_approximate_rrule_from_vcalendar (icalcomponent *vcalendar, time_t *period, time_t *period_months, int *byday_mask) |
Approximate the recurrence of a VCALENDAR as classic schedule data. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably. More... | |
static GPtrArray * | icalendar_times_from_vevent (icalcomponent *vevent, icalproperty_kind type) |
Collect the times of EXDATE or RDATE properties from an VEVENT. The returned GPtrArray will contain pointers to icaltimetype structs, which will be freed with g_ptr_array_free. More... | |
static gboolean | icalendar_time_matches_array (icaltimetype time, GPtrArray *times_array) |
Tests if an icaltimetype matches one in a GPtrArray. When an icaltimetype is a date, only the date must match, otherwise both date and time must match. More... | |
static time_t | icalendar_next_time_from_rdates (GPtrArray *rdates, icaltimetype ref_time_ical, icaltimezone *tz, int periods_offset) |
Get the next or previous time from a list of RDATEs. More... | |
static time_t | icalendar_next_time_from_recurrence (struct icalrecurrencetype recurrence, icaltimetype dtstart, icaltimetype reference_time, icaltimezone *tz, GPtrArray *exdates, GPtrArray *rdates, int periods_offset) |
Calculate the next time of a recurrence. More... | |
time_t | icalendar_next_time_from_vcalendar (icalcomponent *vcalendar, const char *default_tzid, int periods_offset) |
Get the next or previous due time from a VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably. More... | |
time_t | icalendar_next_time_from_string (const char *ical_string, const char *default_tzid, int periods_offset) |
Get the next or previous due time from a VCALENDAR string. The string must be a VCALENDAR simplified with icalendar_from_string for this to work reliably. More... | |
int | icalendar_duration_from_vcalendar (icalcomponent *vcalendar) |
Get the duration VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably. More... | |
time_t | icalendar_first_time_from_vcalendar (icalcomponent *vcalendar, const char *default_tzid) |
Get the first time from a VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably. More... | |
Module for Greenbone Vulnerability Manager: Manage library utilities.
The Greenbone Vulnerability Manager management library.
Utilities used by the manage library that do not depend on anything.
#define GVM_PRODID |
GVM product ID.
#define ICAL_RETURN_ERROR | ( | message | ) |
Error return for icalendar_from_string.
#define MONTHS_WITHIN_YEAR | ( | ) |
Code fragment for months_between.
time_t add_months | ( | time_t | time, |
int | months | ||
) |
Add months to a time.
[in] | time | Time. |
[in] | months | Months. |
void blank_control_chars | ( | char * | string | ) |
Replace any control characters in string with spaces.
[in,out] | string | String to replace in. |
long current_offset | ( | const char * | zone | ) |
Get the current offset from UTC of a timezone.
[in] | zone | Timezone, or NULL for UTC. |
|
static |
Calculate day of week corresponding to a time.
[in] | time | Time. |
int hosts_str_contains | ( | const char * | hosts_str, |
const char * | find_host_str, | ||
int | max_hosts | ||
) |
Returns whether a host has an equal host in a hosts string.
For example, 192.168.10.1 has an equal in a hosts string "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't.
[in] | hosts_str | Hosts string to check. |
[in] | find_host_str | The host to find. |
[in] | max_hosts | Maximum number of hosts allowed in hosts_str. |
int icalendar_approximate_rrule_from_vcalendar | ( | icalcomponent * | vcalendar, |
time_t * | period, | ||
time_t * | period_months, | ||
int * | byday_mask | ||
) |
Approximate the recurrence of a VCALENDAR as classic schedule data. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably.
[in] | vcalendar | The VCALENDAR component to get the data from. |
[out] | period | Output of the period in seconds. |
[out] | period_months | Output of the period in months. |
[out] | byday_mask | Output of the GVM byday mask. |
int icalendar_duration_from_vcalendar | ( | icalcomponent * | vcalendar | ) |
Get the duration VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably.
[in] | vcalendar | The VCALENDAR component to get the time from. |
time_t icalendar_first_time_from_vcalendar | ( | icalcomponent * | vcalendar, |
const char * | default_tzid | ||
) |
Get the first time from a VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably.
[in] | vcalendar | The VCALENDAR component to get the time from. |
[in] | default_tzid | Timezone id to use if none is set in the iCal. |
icalcomponent* icalendar_from_old_schedule_data | ( | time_t | first_time, |
time_t | period, | ||
time_t | period_months, | ||
time_t | duration, | ||
int | byday_mask | ||
) |
Create an iCalendar component from old schedule data.
[in] | first_time | The first run time. |
[in] | period | The period in seconds. |
[in] | period_months | The period in months. |
[in] | duration | The duration in seconds. |
[in] | byday_mask | The byday mask. |
icalcomponent* icalendar_from_string | ( | const char * | ical_string, |
gchar ** | error | ||
) |
Creates a new, simplified VCALENDAR component from a string.
[in] | ical_string | The ical_string to create the component from. |
[out] | error | Output of iCal errors or warnings. |
|
static |
Get the next or previous time from a list of RDATEs.
[in] | rdates | The list of RDATEs. |
[in] | tz | The icaltimezone to use. |
[in] | ref_time_ical | The reference time (usually the current time). |
[in] | periods_offset | 0 for next, -1 for previous from/before reference. |
|
static |
Calculate the next time of a recurrence.
[in] | recurrence | The recurrence rule to evaluate. |
[in] | dtstart | The start time of the recurrence. |
[in] | reference_time | The reference time (usually the current time). |
[in] | tz | The icaltimezone to use. |
[in] | exdates | GList of EXDATE dates or datetimes to skip. |
[in] | rdates | GList of RDATE datetimes to include. |
[in] | periods_offset | 0 for next, -1 for previous from/before reference. |
time_t icalendar_next_time_from_string | ( | const char * | ical_string, |
const char * | default_tzid, | ||
int | periods_offset | ||
) |
Get the next or previous due time from a VCALENDAR string. The string must be a VCALENDAR simplified with icalendar_from_string for this to work reliably.
[in] | ical_string | The VCALENDAR string to get the time from. |
[in] | default_tzid | Timezone id to use if none is set in the iCal. |
[in] | periods_offset | 0 for next, -1 for previous from/before now. |
time_t icalendar_next_time_from_vcalendar | ( | icalcomponent * | vcalendar, |
const char * | default_tzid, | ||
int | periods_offset | ||
) |
Get the next or previous due time from a VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably.
[in] | vcalendar | The VCALENDAR component to get the time from. |
[in] | default_tzid | Timezone id to use if none is set in the iCal. |
[in] | periods_offset | 0 for next, -1 for previous from/before now. |
|
static |
Simplify an VEVENT iCal component.
[in] | vevent | The VEVENT component to simplify. |
[out] | error | Output of iCal errors or warnings. |
[out] | warnings_buffer | GString buffer to write warnings to. |
|
static |
Tests if an icaltimetype matches one in a GPtrArray. When an icaltimetype is a date, only the date must match, otherwise both date and time must match.
[in] | time | The icaltimetype to try to find a match of. |
[in] | times_array | Array of pointers to check for a matching time. |
|
static |
Collect the times of EXDATE or RDATE properties from an VEVENT. The returned GPtrArray will contain pointers to icaltimetype structs, which will be freed with g_ptr_array_free.
[in] | vevent | The VEVENT component to collect times. |
[in] | type | The property to get the times from. |
|
static |
Try to get a built-in libical timezone from a tzid or city name.
[in] | tzid | The tzid or Olson city name. |
double level_max_severity | ( | const char * | level, |
const char * | class | ||
) |
Get the minimum severity for a severity level and class.
[in] | level | The name of the severity level. |
[in] | class | The severity class. |
double level_min_severity | ( | const char * | level, |
const char * | class | ||
) |
Get the minimum severity for a severity level and class.
[in] | level | The name of the severity level. |
[in] | class | The severity class, NULL to get from current user setting. |
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.
[in] | given_hosts | String describing hosts. |
[in] | exclude_hosts | String describing hosts excluded from given set. |
[in] | max_hosts | Max hosts. |
|
static |
Count number of full months between two times.
There are two full months between 0h00.00 1 February 2010 and 0h00.00 1 April 2010. There is one full month between 0h00.00 1 February 2010 and 23h59.59 31 March 2010.
[in] | time1 | Earlier time. |
[in] | time2 | Later time. |
|
static |
Get days till next occurrence.
[in] | day_of_week | Day of week flag: 1 Monday, 2 Tuesday, 4 Wednesday... |
[in] | byday | Byday mask. |
time_t next_time | ( | time_t | first, |
int | period, | ||
int | period_months, | ||
int | byday, | ||
const char * | zone, | ||
int | periods_offset | ||
) |
Calculate the next time from now given a start time and a period.
[in] | first | The first time. |
[in] | period | The period in seconds. |
[in] | period_months | The period in months. |
[in] | byday | Days of week to run schedule. |
[in] | zone | The timezone to use. |
[in] | periods_offset | Number of periods to offset. e.g. 0 = next time, -1 current/last time |
|
static |
Get the offset from UTC of a timezone at a particular time.
[in] | zone | Timezone, or NULL for UTC. |
[in] | time | Time. |
int valid_db_resource_type | ( | const char * | type | ) |
Check whether a resource type table name is valid.
[in] | type | Type of resource. |