Greenbone Vulnerability Manager  8.0.1~git
Data Structures | Macros | Functions | Variables
manage_sqlite3.c File Reference

GVM management layer: SQLite3 specific facilities. More...

#include "manage.h"
#include "manage_acl.h"
#include "manage_utils.h"
#include "sql.h"
#include <assert.h>
#include <errno.h>
#include <gvm/base/hosts.h>
#include <gvm/util/uuidutils.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

Data Structures

struct  sql_severity_t
 Severity. More...
 

Macros

#define _XOPEN_SOURCE
 Enable extra functions. More...
 
#define G_LOG_DOMAIN   "md manage"
 GLib log domain.
 
#define SCAP_DB_DIR   GVMD_STATE_DIR "/scap/"
 Location of SCAP db.
 
#define SCAP_DB_FILE   SCAP_DB_DIR "scap.db"
 Location of SCAP db.
 
#define CERT_DB_DIR   GVMD_STATE_DIR "/cert/"
 Location of CERT db.
 
#define CERT_DB_FILE   CERT_DB_DIR "cert.db"
 Location of CERT db.
 
#define VULNS_RESULTS_WHERE
 WHERE clause for view vulns. More...
 

Functions

gchar * clean_hosts (const char *, int *)
 Clean a hosts string. More...
 
char * iso_time (time_t *)
 Create an ISO time from seconds since epoch. More...
 
int days_from_now (time_t *)
 Calculate difference between now and epoch_time in days. More...
 
int resource_name (const char *, const char *, int, char **)
 Get the name of a resource. More...
 
int resource_exists (const char *, resource_t, int)
 Get whether a resource exists. More...
 
void manage_session_init (const char *uuid)
 Setup session. More...
 
void manage_session_set_timezone (const char *zone)
 Setup session timezone. More...
 
int manage_db_empty ()
 Check whether database is empty. More...
 
void sql_t (sqlite3_context *context, int argc, sqlite3_value **argv)
 Return 1. More...
 
void sql_strpos (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get position of a substring like the strpos function in PostgreSQL. More...
 
void sql_order_inet (sqlite3_context *context, int argc, sqlite3_value **argv)
 Convert an IP address into a sortable form. More...
 
void sql_order_message_type (sqlite3_context *context, int argc, sqlite3_value **argv)
 Convert a message type into an integer for sorting. More...
 
void sql_order_port (sqlite3_context *context, int argc, sqlite3_value **argv)
 Convert a port into an integer for sorting. More...
 
void sql_order_role (sqlite3_context *context, int argc, sqlite3_value **argv)
 Convert a role for sorting. More...
 
void sql_order_threat (sqlite3_context *context, int argc, sqlite3_value **argv)
 Convert a threat into an integer for sorting. More...
 
void sql_make_uuid (sqlite3_context *context, int argc, sqlite3_value **argv)
 Make a UUID. More...
 
void sql_hosts_contains (sqlite3_context *context, int argc, sqlite3_value **argv)
 Check if a host list contains a host. More...
 
void sql_clean_hosts (sqlite3_context *context, int argc, sqlite3_value **argv)
 Clean a host list. More...
 
void sql_merge_dfn_cert_adv (sqlite3_context *context, int argc, sqlite3_value **argv)
 Insert or replace a DFN-Cert Advisory. More...
 
void sql_merge_bund_adv (sqlite3_context *context, int argc, sqlite3_value **argv)
 Insert or replace a CERT-Bund Advisory. More...
 
void sql_merge_cpe (sqlite3_context *context, int argc, sqlite3_value **argv)
 Insert or replace a CPE. More...
 
void sql_merge_cve (sqlite3_context *context, int argc, sqlite3_value **argv)
 Insert or replace a CVE. More...
 
void sql_merge_cpe_name (sqlite3_context *context, int argc, sqlite3_value **argv)
 Insert or replace a CPE. More...
 
void sql_merge_affected_product (sqlite3_context *context, int argc, sqlite3_value **argv)
 Insert or replace an affected product. More...
 
void sql_merge_ovaldef (sqlite3_context *context, int argc, sqlite3_value **argv)
 Insert or replace an OVAL def. More...
 
void sql_uniquify (sqlite3_context *context, int argc, sqlite3_value **argv)
 Make a name unique. More...
 
void sql_iso_time (sqlite3_context *context, int argc, sqlite3_value **argv)
 Convert an epoch time into a string in ISO format. More...
 
void sql_days_from_now (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate difference between now and epoch time in days. More...
 
void sql_parse_time (sqlite3_context *context, int argc, sqlite3_value **argv)
 Try convert an OTP NVT tag time string into epoch time. More...
 
void sql_next_time (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate the next time from now given a start time and a period. More...
 
void sql_next_time_ical (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate the next time from now based on an iCalendar string. More...
 
void sql_now (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the current time as an epoch integer. More...
 
void sql_tag (sqlite3_context *context, int argc, sqlite3_value **argv)
 Extract a tag from an OTP tag list. More...
 
void sql_max_hosts (sqlite3_context *context, int argc, sqlite3_value **argv)
 Return number of hosts. More...
 
void sql_rename_column (const char *old_table, const char *new_table, const char *old_name, const char *new_name)
 Move data from a table to a new table, heeding column rename. More...
 
void sql_common_cve (sqlite3_context *context, int argc, sqlite3_value **argv)
 Check if two CVE lists contain a common CVE. More...
 
void sql_cpe_title (sqlite3_context *context, int argc, sqlite3_value **argv)
 Check if two CVE lists contain a common CVE. More...
 
void sql_credential_value (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get a value from the data of a credential. More...
 
void sql_current_offset (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the offset from UTC of the current time for a timezone. More...
 
void sql_task_trend (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate the trend of a task. More...
 
static void clear_cache (void *cache_arg)
 Get task severity, looking in cache. More...
 
static char * cached_task_severity (sqlite3_context *context, task_t task, int overrides, int min_qod)
 Get task severity, looking in cache. More...
 
void sql_task_threat_level (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate the threat level of a task. More...
 
void sql_report_progress (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate the progress of a report. More...
 
void sql_report_severity (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate the severity of a report. More...
 
static int report_severity_count (report_t report, int overrides, int min_qod, char *level)
 Get the number of results of a given severity level in a report. More...
 
void sql_report_severity_count (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the number of results of a given severity level in a report. More...
 
void sql_report_host_count (sqlite3_context *context, int argc, sqlite3_value **argv)
 Count the number of hosts of a report. More...
 
void sql_report_result_host_count (sqlite3_context *context, int argc, sqlite3_value **argv)
 Count the number of hosts of a report with results. More...
 
void sql_task_severity (sqlite3_context *context, int argc, sqlite3_value **argv)
 Calculate the severity of a task. More...
 
void sql_task_last_report (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the last report of a task. More...
 
void sql_severity_matches_ov (sqlite3_context *context, int argc, sqlite3_value **argv)
 Test if a severity score matches an override's severity. More...
 
void sql_severity_to_level (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the threat level matching a severity score. More...
 
void sql_severity_to_type (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the message type matching a severity score. More...
 
void sql_regexp (sqlite3_context *context, int argc, sqlite3_value **argv)
 Do a regexp match. Implements SQL REGEXP. More...
 
void sql_run_status_name (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the name of a task run status. More...
 
void sql_resource_exists (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get if a resource exists by its type and ID. More...
 
void sql_resource_name (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the name of a resource by its type and ID. More...
 
void sql_severity_in_level (sqlite3_context *context, int argc, sqlite3_value **argv)
 Check whether a severity falls within a threat level. More...
 
void sql_target_credential (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get a target credential. More...
 
void sql_trash_target_credential_location (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get the location of a trash target credential. More...
 
void sql_target_login_port (sqlite3_context *context, int argc, sqlite3_value **argv)
 Get a target port. More...
 
void sql_user_can_everything (sqlite3_context *context, int argc, sqlite3_value **argv)
 Check if a user can do anything. More...
 
void sql_user_has_access_uuid (sqlite3_context *context, int argc, sqlite3_value **argv)
 Check if a user has a given permission for a resource. More...
 
void sql_user_owns (sqlite3_context *context, int argc, sqlite3_value **argv)
 Check if a user owns or effectively owns a resource. More...
 
void sql_vuln_results (sqlite3_context *context, int argc, sqlite3_value **argv)
 Gets the number of results for a Vulnerability. More...
 
int manage_create_sql_functions ()
 Create functions. More...
 
void manage_create_result_indexes ()
 Create result indexes.
 
void create_tables ()
 Create all tables.
 
void check_db_sequences ()
 Ensure sequences for automatic ids are in a consistent state. More...
 
void manage_attach_databases ()
 Attach external databases.
 
void manage_db_remove (const gchar *name)
 Remove external database. More...
 
int manage_db_init (const gchar *name)
 Init external database. More...
 
void manage_db_check_mode (const gchar *name)
 Ensure db is in WAL mode. More...
 
int manage_db_check (const gchar *name)
 Check integrity of db. More...
 
int manage_cert_loaded ()
 Check whether CERT is available. More...
 
int manage_scap_loaded ()
 Check whether SCAP is available. More...
 
int manage_cert_db_exists ()
 Check if CERT db exists. More...
 
int manage_scap_db_exists ()
 Check if SCAP db exists. More...
 
int manage_update_cert_db_init ()
 Database specific setup for CERT update. More...
 
void manage_update_cert_db_cleanup ()
 Database specific cleanup after CERT update. More...
 
int manage_update_scap_db_init ()
 Database specific setup for SCAP update. More...
 
void manage_update_scap_db_cleanup ()
 Database specific cleanup after SCAP update. More...
 
static int backup_db (const gchar *database, gchar **backup_file_arg)
 Backup the database to a file. More...
 
int manage_backup_db (const gchar *database)
 Backup the database to a file. More...
 
void migrate_51_to_52_sql_convert (sqlite3_context *context, int argc, sqlite3_value **argv)
 Convert a UTC text time to an integer time since the Epoch. More...
 
int manage_create_migrate_51_to_52_convert ()
 Setup SQL function for migrate_51_to_52. More...
 

Variables

sqlite3 * gvmd_db
 Handle on the database.
 

Detailed Description

GVM management layer: SQLite3 specific facilities.

This file contains the parts of the GVM management layer that need to be coded for each backend. This is the SQLite3 version.

Macro Definition Documentation

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE

Enable extra functions.

Glibc2 needs this for strptime.

◆ VULNS_RESULTS_WHERE

#define VULNS_RESULTS_WHERE
Value:
" WHERE uuid IN" \
" (SELECT nvt FROM results" \
" WHERE (results.severity != " G_STRINGIFY (SEVERITY_ERROR) "))"

WHERE clause for view vulns.

Function Documentation

◆ backup_db()

static int backup_db ( const gchar *  database,
gchar **  backup_file_arg 
)
static

Backup the database to a file.

Parameters
[in]databaseDatabase to backup.
[out]backup_file_argLocation for freshly allocated name of backup file, or NULL. Only set on success.
Returns
0 success, -1 error.

◆ cached_task_severity()

static char* cached_task_severity ( sqlite3_context *  context,
task_t  task,
int  overrides,
int  min_qod 
)
static

Get task severity, looking in cache.

Cache a single severity value because task_threat and task_severity both do the same expensive severity calculation for each row in the task iterator. Use auxdata on the overrides arg to pass the cache between calls with a single statement.

Parameters
[in]contextSQL context.
[in]taskTask.
[in]overridesOverrides flag.
[in]min_qodMinimum QoD of report results to count.
Returns
Severity.

◆ check_db_sequences()

void check_db_sequences ( )

Ensure sequences for automatic ids are in a consistent state.

Caller must organise a transaction.

◆ clean_hosts()

gchar* clean_hosts ( const char *  given_hosts,
int *  max 
)

Clean a hosts string.

Parameters
[in]given_hostsString describing hosts.
[out]maxMax number of hosts, adjusted for duplicates.
Returns
Freshly allocated new hosts string, or NULL on error.

◆ clear_cache()

static void clear_cache ( void *  cache_arg)
static

Get task severity, looking in cache.

Parameters
[in]cache_argCache.

◆ days_from_now()

int days_from_now ( time_t *  epoch_time)

Calculate difference between now and epoch_time in days.

Parameters
[in]epoch_timeTime in seconds from epoch.
Returns
Int days bettween now and epoch_time or -1 if epoch_time is in the past

◆ iso_time()

char* iso_time ( time_t *  epoch_time)

Create an ISO time from seconds since epoch.

Parameters
[in]epoch_timeTime in seconds from epoch.
Returns
Pointer to ISO time in static memory, or NULL on error.

◆ manage_backup_db()

int manage_backup_db ( const gchar *  database)

Backup the database to a file.

Parameters
[in]databaseLocation of manage database.
Returns
0 success, -1 error.

◆ manage_cert_db_exists()

int manage_cert_db_exists ( )

Check if CERT db exists.

Returns
1 if exists, else 0.

◆ manage_cert_loaded()

int manage_cert_loaded ( )

Check whether CERT is available.

Returns
1 if CERT database is loaded, else 0.

◆ manage_create_migrate_51_to_52_convert()

int manage_create_migrate_51_to_52_convert ( )

Setup SQL function for migrate_51_to_52.

Dummy for SQLite3 compatibility.

Returns
0 success, -1 error.

◆ manage_create_sql_functions()

int manage_create_sql_functions ( )

Create functions.

Returns
0 success, -1 error.

◆ manage_db_check()

int manage_db_check ( const gchar *  name)

Check integrity of db.

Dummy function.

Parameters
[in]nameName, like "cert" or "scap".
Returns
0 fine, 1 broken, -1 error.

◆ manage_db_check_mode()

void manage_db_check_mode ( const gchar *  name)

Ensure db is in WAL mode.

Dummy function.

Parameters
[in]nameName, like "cert" or "scap".

◆ manage_db_empty()

int manage_db_empty ( )

Check whether database is empty.

Returns
1 if empty, else 0;

◆ manage_db_init()

int manage_db_init ( const gchar *  name)

Init external database.

Parameters
[in]nameName. "cert" or "scap".
Returns
0 success, -1 error.

◆ manage_db_remove()

void manage_db_remove ( const gchar *  name)

Remove external database.

Attach external databases.

Parameters
[in]nameDatabase name.

◆ manage_scap_db_exists()

int manage_scap_db_exists ( )

Check if SCAP db exists.

Returns
1 if exists, else 0.

◆ manage_scap_loaded()

int manage_scap_loaded ( )

Check whether SCAP is available.

Returns
1 if SCAP database is loaded, else 0.

◆ manage_session_init()

void manage_session_init ( const char *  uuid)

Setup session.

Parameters
[in]uuidUser UUID.

◆ manage_session_set_timezone()

void manage_session_set_timezone ( const char *  zone)

Setup session timezone.

Parameters
[in]zoneTimezone.

◆ manage_update_cert_db_cleanup()

void manage_update_cert_db_cleanup ( )

Database specific cleanup after CERT update.

Returns
1 if empty, else 0.

◆ manage_update_cert_db_init()

int manage_update_cert_db_init ( )

Database specific setup for CERT update.

Returns
0 success, -1 error.

◆ manage_update_scap_db_cleanup()

void manage_update_scap_db_cleanup ( )

Database specific cleanup after SCAP update.

Returns
1 if empty, else 0.

◆ manage_update_scap_db_init()

int manage_update_scap_db_init ( )

Database specific setup for SCAP update.

Returns
0 success, -1 error.

◆ migrate_51_to_52_sql_convert()

void migrate_51_to_52_sql_convert ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Convert a UTC text time to an integer time since the Epoch.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ report_severity_count()

static int report_severity_count ( report_t  report,
int  overrides,
int  min_qod,
char *  level 
)
static

Get the number of results of a given severity level in a report.

Parameters
[in]reportThe report to count the results of.
[in]overridesWhether to apply overrides.
[in]min_qodMinimum QoD of results to count.
[in]levelSeverity level of which to count results.
Returns
The number of results.

◆ resource_exists()

int resource_exists ( const char *  type,
resource_t  resource,
int  location 
)

Get whether a resource exists.

Parameters
[in]typeType.
[in]resourceResource.
[in]locationLocation.
Returns
1 yes, 0 no, -1 error in type.

◆ resource_name()

int resource_name ( const char *  type,
const char *  uuid,
int  location,
char **  name 
)

Get the name of a resource.

Parameters
[in]typeType.
[in]uuidUUID.
[in]locationLocation.
[out]nameReturn for freshly allocated name.
Returns
0 success, 1 error in type.

◆ sql_clean_hosts()

void sql_clean_hosts ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Clean a host list.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_common_cve()

void sql_common_cve ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Check if two CVE lists contain a common CVE.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_cpe_title()

void sql_cpe_title ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Check if two CVE lists contain a common CVE.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_credential_value()

void sql_credential_value ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get a value from the data of a credential.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_current_offset()

void sql_current_offset ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the offset from UTC of the current time for a timezone.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_days_from_now()

void sql_days_from_now ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate difference between now and epoch time in days.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_hosts_contains()

void sql_hosts_contains ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Check if a host list contains a host.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_iso_time()

void sql_iso_time ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Convert an epoch time into a string in ISO format.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_make_uuid()

void sql_make_uuid ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Make a UUID.

This is a callback for a scalar SQL function of zero arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_max_hosts()

void sql_max_hosts ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Return number of hosts.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_merge_affected_product()

void sql_merge_affected_product ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Insert or replace an affected product.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_merge_bund_adv()

void sql_merge_bund_adv ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Insert or replace a CERT-Bund Advisory.

This is a callback for a scalar SQL function of six argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_merge_cpe()

void sql_merge_cpe ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Insert or replace a CPE.

This is a callback for a scalar SQL function of eight argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_merge_cpe_name()

void sql_merge_cpe_name ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Insert or replace a CPE.

This is a callback for a scalar SQL function of 4 arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_merge_cve()

void sql_merge_cve ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Insert or replace a CVE.

This is a callback for a scalar SQL function of 13 arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_merge_dfn_cert_adv()

void sql_merge_dfn_cert_adv ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Insert or replace a DFN-Cert Advisory.

This is a callback for a scalar SQL function of six argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_merge_ovaldef()

void sql_merge_ovaldef ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Insert or replace an OVAL def.

This is a callback for a scalar SQL function of 13 arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_next_time()

void sql_next_time ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate the next time from now given a start time and a period.

This is a callback for a scalar SQL function of four to six arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_next_time_ical()

void sql_next_time_ical ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate the next time from now based on an iCalendar string.

This is a callback for a scalar SQL function of two to three arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_now()

void sql_now ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the current time as an epoch integer.

This is a callback for a scalar SQL function of zero arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_order_inet()

void sql_order_inet ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Convert an IP address into a sortable form.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_order_message_type()

void sql_order_message_type ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Convert a message type into an integer for sorting.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_order_port()

void sql_order_port ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Convert a port into an integer for sorting.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_order_role()

void sql_order_role ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Convert a role for sorting.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_order_threat()

void sql_order_threat ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Convert a threat into an integer for sorting.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_parse_time()

void sql_parse_time ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Try convert an OTP NVT tag time string into epoch time.

This is a callback for a scalar SQL function of one argument.

This is only used by the SQLite backend, in the SQL of some older migrators.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_regexp()

void sql_regexp ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Do a regexp match. Implements SQL REGEXP.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_rename_column()

void sql_rename_column ( const char *  old_table,
const char *  new_table,
const char *  old_name,
const char *  new_name 
)

Move data from a table to a new table, heeding column rename.

Parameters
[in]old_tableExisting table.
[in]new_tableNew empty table with renamed column.
[in]old_nameName of column in old table.
[in]new_nameName of column in new table.

◆ sql_report_host_count()

void sql_report_host_count ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Count the number of hosts of a report.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_report_progress()

void sql_report_progress ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate the progress of a report.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_report_result_host_count()

void sql_report_result_host_count ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Count the number of hosts of a report with results.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_report_severity()

void sql_report_severity ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate the severity of a report.

This is a callback for a scalar SQL function of three arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_report_severity_count()

void sql_report_severity_count ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the number of results of a given severity level in a report.

This is a callback for a scalar SQL function of four arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_resource_exists()

void sql_resource_exists ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get if a resource exists by its type and ID.

This is a callback for a scalar SQL function of three arguments.

Used by migrate_119_to_120 to check if a permission refers to a resource that has been removed.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_resource_name()

void sql_resource_name ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the name of a resource by its type and ID.

This is a callback for a scalar SQL function of three arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_run_status_name()

void sql_run_status_name ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the name of a task run status.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_severity_in_level()

void sql_severity_in_level ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Check whether a severity falls within a threat level.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_severity_matches_ov()

void sql_severity_matches_ov ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Test if a severity score matches an override's severity.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_severity_to_level()

void sql_severity_to_level ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the threat level matching a severity score.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_severity_to_type()

void sql_severity_to_type ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the message type matching a severity score.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_strpos()

void sql_strpos ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get position of a substring like the strpos function in PostgreSQL.

This is a callback for a scalar SQL function of two arguments. The SQLite function instr could be used as replacement, but is only available in versions >= 3.7.15.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_t()

void sql_t ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Return 1.

This is a callback for a scalar SQL function of zero arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_tag()

void sql_tag ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Extract a tag from an OTP tag list.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_target_credential()

void sql_target_credential ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get a target credential.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_target_login_port()

void sql_target_login_port ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get a target port.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_task_last_report()

void sql_task_last_report ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the last report of a task.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_task_severity()

void sql_task_severity ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate the severity of a task.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_task_threat_level()

void sql_task_threat_level ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate the threat level of a task.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_task_trend()

void sql_task_trend ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Calculate the trend of a task.

This is a callback for a scalar SQL function of two argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_trash_target_credential_location()

void sql_trash_target_credential_location ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Get the location of a trash target credential.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_uniquify()

void sql_uniquify ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Make a name unique.

This is a callback for a scalar SQL function of four argument.

It's up to the caller to ensure there is a read-only transaction.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_user_can_everything()

void sql_user_can_everything ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Check if a user can do anything.

This is a callback for a scalar SQL function of one argument.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_user_has_access_uuid()

void sql_user_has_access_uuid ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Check if a user has a given permission for a resource.

This is a callback for a scalar SQL function of four arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_user_owns()

void sql_user_owns ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Check if a user owns or effectively owns a resource.

This is a callback for a scalar SQL function of two arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.

◆ sql_vuln_results()

void sql_vuln_results ( sqlite3_context *  context,
int  argc,
sqlite3_value **  argv 
)

Gets the number of results for a Vulnerability.

This is a callback for a scalar SQL function of four arguments.

Parameters
[in]contextSQL context.
[in]argcNumber of arguments.
[in]argvArgument array.