Greenbone Vulnerability Manager  22.4.0~dev1
Macros | Functions
manage_utils.c File Reference

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 GVM_PRODID
 GVM product ID. More...
 
#define ICAL_RETURN_ERROR(message)
 Error return for icalendar_from_string. More...
 

Functions

long current_offset (const char *zone)
 Get the current offset from UTC of a timezone. More...
 
time_t add_months (time_t time, int months)
 Add months to a time. 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)
 Get the minimum severity for a severity level. More...
 
double level_max_severity (const char *level)
 Get the maximum severity for a severity level. 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...
 
icaltimezone * icalendar_timezone_from_string (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, icaltimezone *zone, gchar **error, GString *warnings_buffer)
 Simplify an VEVENT iCal component. More...
 
icalcomponent * icalendar_from_string (const char *ical_string, icaltimezone *zone, 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, time_t reference_time, 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. The reference time is usually the current time. More...
 
time_t icalendar_next_time_from_string (const char *ical_string, time_t reference_time, 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. The reference time is usually the current time. 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, icaltimezone *default_tz)
 Get the first time from a VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably. More...
 
gchar * clean_hosts_string (const char *hosts)
 Cleans up a hosts string, removing extra zeroes from IPv4 addresses. More...
 

Detailed Description

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.

Macro Definition Documentation

◆ GVM_PRODID

#define GVM_PRODID
Value:
"-//Greenbone.net//NONSGML Greenbone Security Manager " \
GVMD_VERSION "//EN"

GVM product ID.

◆ ICAL_RETURN_ERROR

#define ICAL_RETURN_ERROR (   message)
Value:
do \
{ \
if (error) \
*error = message; \
icalcomponent_free (ical_parsed); \
icalcomponent_free (ical_new); \
g_string_free (warnings_buffer, TRUE); \
return NULL; \
} \
while (0)

Error return for icalendar_from_string.

Function Documentation

◆ add_months()

time_t add_months ( time_t  time,
int  months 
)

Add months to a time.

Parameters
[in]timeTime.
[in]monthsMonths.
Returns
Time plus given number of months.

◆ blank_control_chars()

void blank_control_chars ( char *  string)

Replace any control characters in string with spaces.

Parameters
[in,out]stringString to replace in.

◆ clean_hosts_string()

gchar* clean_hosts_string ( const char *  hosts)

Cleans up a hosts string, removing extra zeroes from IPv4 addresses.

Parameters
[in]hostsThe hosts string to clean.
Returns
The newly allocated, cleaned up hosts string.

◆ current_offset()

long current_offset ( const char *  zone)

Get the current offset from UTC of a timezone.

Parameters
[in]zoneTimezone, or NULL for UTC.
Returns
Seconds east of UTC.

◆ hosts_str_contains()

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.

Parameters
[in]hosts_strHosts string to check.
[in]find_host_strThe host to find.
[in]max_hostsMaximum number of hosts allowed in hosts_str.
Returns
1 if host has equal in hosts_str, 0 otherwise.

◆ icalendar_approximate_rrule_from_vcalendar()

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.

Parameters
[in]vcalendarThe VCALENDAR component to get the data from.
[out]periodOutput of the period in seconds.
[out]period_monthsOutput of the period in months.
[out]byday_maskOutput of the GVM byday mask.
Returns
0 success, 1 invalid vcalendar.

◆ icalendar_duration_from_vcalendar()

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.

Parameters
[in]vcalendarThe VCALENDAR component to get the time from.
Returns
The duration in seconds.

◆ icalendar_first_time_from_vcalendar()

time_t icalendar_first_time_from_vcalendar ( icalcomponent *  vcalendar,
icaltimezone *  default_tz 
)

Get the first time from a VCALENDAR component. The VCALENDAR must have simplified with icalendar_from_string for this to work reliably.

Parameters
[in]vcalendarThe VCALENDAR component to get the time from.
[in]default_tzTimezone to use if none is set in the iCal.
Returns
The first time as a time_t.

◆ icalendar_from_old_schedule_data()

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.

Parameters
[in]first_timeThe first run time.
[in]periodThe period in seconds.
[in]period_monthsThe period in months.
[in]durationThe duration in seconds.
[in]byday_maskThe byday mask.
Returns
The generated iCalendar component.

◆ icalendar_from_string()

icalcomponent* icalendar_from_string ( const char *  ical_string,
icaltimezone *  zone,
gchar **  error 
)

Creates a new, simplified VCALENDAR component from a string.

Parameters
[in]ical_stringThe ical_string to create the component from.
[in]zoneTimezone.
[out]errorOutput of iCal errors or warnings.
Returns
A newly allocated, simplified VCALENDAR component.

◆ icalendar_next_time_from_rdates()

static time_t icalendar_next_time_from_rdates ( GPtrArray *  rdates,
icaltimetype  ref_time_ical,
icaltimezone *  tz,
int  periods_offset 
)
static

Get the next or previous time from a list of RDATEs.

Parameters
[in]rdatesThe list of RDATEs.
[in]tzThe icaltimezone to use.
[in]ref_time_icalThe reference time (usually the current time).
[in]periods_offset0 for next, -1 for previous from/before reference.
Returns
The next or previous time as time_t.

◆ icalendar_next_time_from_recurrence()

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 
)
static

Calculate the next time of a recurrence.

Parameters
[in]recurrenceThe recurrence rule to evaluate.
[in]dtstartThe start time of the recurrence.
[in]reference_timeThe reference time (usually the current time).
[in]tzThe icaltimezone to use.
[in]exdatesGList of EXDATE dates or datetimes to skip.
[in]rdatesGList of RDATE datetimes to include.
[in]periods_offset0 for next, -1 for previous from/before reference.
Returns
The next time.

◆ icalendar_next_time_from_string()

time_t icalendar_next_time_from_string ( const char *  ical_string,
time_t  reference_time,
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. The reference time is usually the current time.

Parameters
[in]ical_stringThe VCALENDAR string to get the time from.
[in]reference_timeThe reference time for calculating the next time.
[in]default_tzidTimezone id to use if none is set in the iCal.
[in]periods_offset0 for next, -1 for previous from/before now.
Returns
The next or previous time as a time_t.

◆ icalendar_next_time_from_vcalendar()

time_t icalendar_next_time_from_vcalendar ( icalcomponent *  vcalendar,
time_t  reference_time,
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. The reference time is usually the current time.

Parameters
[in]vcalendarThe VCALENDAR component to get the time from.
[in]reference_timeThe reference time for calculating the next time.
[in]default_tzidTimezone id to use if none is set in the iCal.
[in]periods_offset0 for next, -1 for previous from/before now.
Returns
The next or previous time as a time_t.

◆ icalendar_simplify_vevent()

static icalcomponent* icalendar_simplify_vevent ( icalcomponent *  vevent,
icaltimezone *  zone,
gchar **  error,
GString *  warnings_buffer 
)
static

Simplify an VEVENT iCal component.

Parameters
[in]veventThe VEVENT component to simplify.
[in]zoneTimezone.
[out]errorOutput of iCal errors or warnings.
[out]warnings_bufferGString buffer to write warnings to.
Returns
A newly allocated, simplified VEVENT component.

◆ icalendar_time_matches_array()

static gboolean icalendar_time_matches_array ( icaltimetype  time,
GPtrArray *  times_array 
)
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.

Parameters
[in]timeThe icaltimetype to try to find a match of.
[in]times_arrayArray of pointers to check for a matching time.
Returns
Whether a match was found.

◆ icalendar_times_from_vevent()

static GPtrArray* icalendar_times_from_vevent ( icalcomponent *  vevent,
icalproperty_kind  type 
)
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.

Parameters
[in]veventThe VEVENT component to collect times.
[in]typeThe property to get the times from.
Returns
GPtrArray with pointers to collected times or NULL on error.

◆ icalendar_timezone_from_string()

icaltimezone* icalendar_timezone_from_string ( const char *  tzid)

Try to get a built-in libical timezone from a tzid or city name.

Parameters
[in]tzidThe tzid or Olson city name.
Returns
The built-in timezone if found, else NULL.

◆ level_max_severity()

double level_max_severity ( const char *  level)

Get the maximum severity for a severity level.

This function has a database equivalent in manage_pg_server.c. These two functions must stay in sync.

Parameters
[in]levelThe name of the severity level.
Returns
The maximunm severity.

◆ level_min_severity()

double level_min_severity ( const char *  level)

Get the minimum severity for a severity level.

This function has a database equivalent in manage_pg_server.c. These two functions must stay in sync.

Parameters
[in]levelThe name of the severity level.
Returns
The minimum severity.

◆ manage_count_hosts_max()

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.

Parameters
[in]given_hostsString describing hosts.
[in]exclude_hostsString describing hosts excluded from given set.
[in]max_hostsMax hosts.
Returns
Number of hosts, or -1 on error.

◆ valid_db_resource_type()

int valid_db_resource_type ( const char *  type)

Check whether a resource type table name is valid.

Parameters
[in]typeType of resource.
Returns
1 yes, 0 no.