OpenVAS Manager  7.0.3~git
manage_sql.h File Reference
#include "manage.h"
#include "manage_utils.h"
#include <openvas/omp/xml.h>
Include dependency graph for manage_sql.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CONFIG_UUID_FULL_AND_FAST   "daba56c8-73ec-11df-a475-002264764cea"
 UUID of 'Full and fast' config. More...
 
#define CONFIG_UUID_FULL_AND_FAST_ULTIMATE   "698f691e-7489-11df-9d8c-002264764cea"
 UUID of 'Full and fast ultimate' config. More...
 
#define CONFIG_UUID_FULL_AND_VERY_DEEP   "708f25c4-7489-11df-8094-002264764cea"
 UUID of 'Full and very deep' config. More...
 
#define CONFIG_UUID_FULL_AND_VERY_DEEP_ULTIMATE   "74db13d6-7489-11df-91b9-002264764cea"
 UUID of 'Full and very deep ultimate' config. More...
 
#define CONFIG_UUID_EMPTY   "085569ce-73ed-11df-83c3-002264764cea"
 UUID of 'Empty' config. More...
 
#define CONFIG_UUID_DISCOVERY   "8715c877-47a0-438d-98a3-27c7a6ab2196"
 UUID of 'Discovery' config. More...
 
#define CONFIG_UUID_HOST_DISCOVERY   "2d3f051c-55ba-11e3-bf43-406186ea4fc5"
 UUID of 'Host Discovery' config. More...
 
#define CONFIG_UUID_SYSTEM_DISCOVERY   "bbca7412-a950-11e3-9109-406186ea4fc5"
 UUID of 'System Discovery' config. More...
 
#define LOCATION_TABLE   0
 Location of a constituent of a trashcan resource. More...
 
#define LOCATION_TRASH   1
 Location of a constituent of a trashcan resource. More...
 
#define MANAGE_NVT_SELECTOR_UUID_ALL   "54b45713-d4f4-4435-b20d-304c175ed8c5"
 UUID of 'All' NVT selector. More...
 
#define MANAGE_NVT_SELECTOR_UUID_DISCOVERY   "0d9a2738-8fe2-4e22-8f26-bb886179e759"
 UUID of 'Discovery' NVT selector. More...
 
#define MANAGE_NVT_SELECTOR_UUID_HOST_DISCOVERY   "f5f80744-55c7-11e3-8dc6-406186ea4fc5"
 UUID of 'Host Discovery' NVT selector. More...
 
#define MANAGE_NVT_SELECTOR_UUID_SYSTEM_DISCOVERY   "07045d1c-a951-11e3-8da7-406186ea4fc5"
 UUID of 'System Discovery' NVT selector. More...
 
#define PERMISSION_UUID_ADMIN_EVERYTHING   "b3b56a8c-c2fd-11e2-a135-406186ea4fc5"
 Predefined role UUID. More...
 
#define PERMISSION_UUID_SUPER_ADMIN_EVERYTHING   "a9801074-6fe2-11e4-9d81-406186ea4fc5"
 Predefined role UUID. More...
 
#define PORT_LIST_UUID_DEFAULT   "c7e03b6c-3bbe-11e1-a057-406186ea4fc5"
 UUID of 'OpenVAS Default' port list. More...
 
#define PORT_LIST_UUID_ALL_TCP   "fd591a34-56fd-11e1-9f27-406186ea4fc5"
 UUID of 'All TCP' port list. More...
 
#define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_100   "730ef368-57e2-11e1-a90f-406186ea4fc5"
 UUID of 'All TCP and Nmap 5.51 Top 100 UDP' port list. More...
 
#define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_1000   "9ddce1ae-57e7-11e1-b13c-406186ea4fc5"
 UUID of 'All TCP and Nmap 5.51 Top 1000 UDP' port list. More...
 
#define PORT_LIST_UUID_ALL_PRIV_TCP   "492b72f4-56fe-11e1-98a7-406186ea4fc5"
 UUID of 'All privileged TCP' port list. More...
 
#define PORT_LIST_UUID_ALL_PRIV_TCP_UDP   "5f2029f6-56fe-11e1-bb94-406186ea4fc5"
 UUID of 'All privileged TCP and UDP' port list. More...
 
#define PORT_LIST_UUID_ALL_IANA_TCP_2012   "33d0cd82-57c6-11e1-8ed1-406186ea4fc5"
 UUID of 'All privileged TCP and UDP' port list. More...
 
#define PORT_LIST_UUID_ALL_IANA_TCP_UDP_2012   "4a4717fe-57d2-11e1-9a26-406186ea4fc5"
 UUID of 'All privileged TCP and UDP' port list. More...
 
#define PORT_LIST_UUID_NMAP_5_51_TOP_2000_TOP_100   "ab33f6b0-57f8-11e1-96f5-406186ea4fc5"
 UUID of 'Nmap 5.51 top 2000 TCP top 100 UDP' port list. More...
 
#define ROLE_UUID_ADMIN   "7a8cb5b4-b74d-11e2-8187-406186ea4fc5"
 Predefined role UUID. More...
 
#define ROLE_UUID_GUEST   "cc9cac5e-39a3-11e4-abae-406186ea4fc5"
 Predefined role UUID. More...
 
#define ROLE_UUID_INFO   "5f8fd16c-c550-11e3-b6ab-406186ea4fc5"
 Predefined role UUID. More...
 
#define ROLE_UUID_MONITOR   "12cdb536-480b-11e4-8552-406186ea4fc5"
 Predefined role UUID. More...
 
#define ROLE_UUID_USER   "8d453140-b74d-11e2-b0be-406186ea4fc5"
 Predefined role UUID. More...
 
#define ROLE_UUID_SUPER_ADMIN   "9c5a6ec6-6fe2-11e4-8cb6-406186ea4fc5"
 Predefined role UUID. More...
 
#define ROLE_UUID_OBSERVER   "87a7ebce-b74d-11e2-a81f-406186ea4fc5"
 Predefined role UUID. More...
 
#define SCANNER_UUID_DEFAULT   "08b69003-5fc2-4037-a479-93b440211c73"
 UUID of 'OpenVAS Default' scanner. More...
 
#define SCANNER_UUID_CVE   "6acd0832-df90-11e4-b9d5-28d24461215b"
 UUID of 'CVE' scanner. More...
 
#define SETTING_UUID_ROWS_PER_PAGE   "5f5a8712-8017-11e1-8556-406186ea4fc5"
 UUID of 'Rows Per Page' setting. More...
 
#define SETTING_UUID_MAX_ROWS_PER_PAGE   "76374a7a-0569-11e6-b6da-28d24461215b"
 UUID of 'Max Rows Per Page' setting. More...
 
#define SETTING_UUID_DEFAULT_CA_CERT   "9ac801ea-39f8-11e6-bbaa-28d24461215b"
 UUID of 'Default CA Cert' setting. More...
 
#define TRUST_ERROR   0
 Trust constant for error. More...
 
#define TRUST_YES   1
 Trust constant for yes. More...
 
#define TRUST_NO   2
 Trust constant for no. More...
 
#define TRUST_UNKNOWN   3
 Trust constant for unknown. More...
 
#define TIMEVAL_SUBTRACT_MS(a, b)
 Number of milliseconds between timevals a and b (performs a-b). More...
 

Typedefs

typedef long long int rowid_t
 

Functions

void array_add_new_string (array_t *, const gchar *)
 Ensure a string is in an array. More...
 
int manage_db_empty ()
 Check whether database is empty. More...
 
gboolean host_nthlast_report_host (const char *, report_host_t *, int)
 Get N'th last report_host given a host. More...
 
char * report_host_ip (const char *)
 Get the IP of a host, using the 'hostname' report host details. More...
 
gchar * tag_value (const gchar *, const gchar *)
 Extract a tag from an OTP tag list. More...
 
void trim_report (report_t)
 Prepare a partial report for restarting the scan from the beginning. More...
 
int delete_report_internal (report_t)
 Delete a report. More...
 
int set_report_scan_run_status (report_t, task_status_t)
 Return the run status of the scan associated with a report. More...
 
int set_report_slave_progress (report_t, int)
 Set slave progress of a report. More...
 
int update_from_slave (task_t, entity_t, entity_t *, int *)
 Update the local task from the slave task. More...
 
void set_report_slave_task_uuid (report_t, const char *)
 Set the UUID of the slave task, on the local task. More...
 
int set_task_requested (task_t, task_status_t *)
 Atomically set the run state of a task to requested. More...
 
void init_task_file_iterator (iterator_t *, task_t, const char *)
 Initialise a task file iterator. More...
 
const char * task_file_iterator_name (iterator_t *)
 
const char * task_file_iterator_content (iterator_t *)
 
void set_task_schedule_next_time (task_t, time_t)
 Set the next time a scheduled task will be due. More...
 
void set_task_schedule_next_time_uuid (const gchar *, time_t)
 Set the next time a scheduled task will be due. More...
 
void init_otp_pref_iterator (iterator_t *, config_t, const char *)
 Initialise an "OTP" preference iterator. More...
 
const char * otp_pref_iterator_name (iterator_t *)
 
const char * otp_pref_iterator_value (iterator_t *)
 
port_list_t target_port_list (target_t)
 Return the port list associated with a target, if any. More...
 
char * target_port_range (target_t)
 Return the port range of a target, in OTP format. More...
 
credential_t target_ssh_credential (target_t)
 Return the SSH credential associated with a target, if any. More...
 
credential_t target_smb_credential (target_t)
 Return the SMB credential associated with a target, if any. More...
 
credential_t target_esxi_credential (target_t)
 Return the ESXi credential associated with a target, if any. More...
 
int create_current_report (task_t, char **, task_status_t)
 Create the current report for a task. More...
 
char * alert_data (alert_t, const char *, const char *)
 Return data associated with an alert. More...
 
int init_task_schedule_iterator (iterator_t *)
 Initialise a task schedule iterator. More...
 
void cleanup_task_schedule_iterator (iterator_t *)
 Cleanup a task schedule iterator. More...
 
task_t task_schedule_iterator_task (iterator_t *)
 Get the task from a task schedule iterator. More...
 
const char * task_schedule_iterator_task_uuid (iterator_t *)
 
schedule_t task_schedule_iterator_schedule (iterator_t *)
 Get the schedule from a task schedule iterator. More...
 
time_t task_schedule_iterator_next_time (iterator_t *)
 Get the next time from a task schedule iterator. More...
 
time_t task_schedule_iterator_period (iterator_t *)
 Get the period from a task schedule iterator. More...
 
time_t task_schedule_iterator_period_months (iterator_t *)
 Get the period months from a task schedule iterator. More...
 
time_t task_schedule_iterator_duration (iterator_t *)
 Get the duration from a task schedule iterator. More...
 
gboolean task_schedule_iterator_timed_out (iterator_t *)
 Get if schedule of task in iterator is timed out. More...
 
gboolean task_schedule_iterator_start_due (iterator_t *)
 Get the start due state from a task schedule iterator. More...
 
gboolean task_schedule_iterator_stop_due (iterator_t *)
 Get the stop due state from a task schedule iterator. More...
 
time_t task_schedule_iterator_first_time (iterator_t *)
 Get the first time from a task schedule iterator. More...
 
const char * task_schedule_iterator_owner_uuid (iterator_t *)
 
const char * task_schedule_iterator_owner_name (iterator_t *)
 
const char * task_schedule_iterator_timezone (iterator_t *)
 
time_t task_schedule_iterator_initial_offset (iterator_t *)
 Get the initial offset from a task schedule iterator. More...
 
int set_task_schedule_uuid (const gchar *, schedule_t, int)
 Set the schedule of a task. More...
 
void reinit_manage_process ()
 Reinitialize the manage library for a process. More...
 
int manage_update_nvti_cache ()
 Update the memory cache of NVTs, if this has been requested. More...
 
int manage_report_host_details (report_t, const char *, entity_t)
 Add host details to a report host. More...
 
const char * run_status_name_internal (task_status_t)
 Get the unique name of a run status. More...
 
gchar * get_ovaldef_short_filename (char *)
 Get the short file name for an OVALDEF. More...
 
void update_config_cache_init (const char *)
 Update count and growing info in config, without checking user. More...
 
alive_test_t target_alive_tests (target_t)
 Return a target's alive tests. More...
 
void manage_session_init (const char *)
 Setup session. More...
 
int valid_omp_command (const char *)
 Check whether a command name is valid. More...
 
void check_generate_scripts ()
 Ensure the generate scripts are all executable. More...
 
void auto_delete_reports ()
 Auto delete reports. More...
 
int parse_iso_time (const char *)
 Convert an ISO time into seconds since epoch. More...
 
int days_from_now (time_t *epoch_time)
 Calculate difference between now and epoch_time in days. More...
 
void set_report_scheduled (report_t)
 Set a report's scheduled flag. More...
 
gchar * resource_uuid (const gchar *, resource_t)
 Get the UUID of a resource. More...
 
gboolean find_resource_with_permission (const char *, const char *, resource_t *, const char *, int)
 Find a resource given a UUID and a permission. More...
 
char * task_definitions_file (task_t)
 Get definitions file from a task's config. More...
 
void parse_osp_report (task_t, report_t, const char *)
 Parse an OSP report. More...
 
void reschedule_task (const gchar *)
 Set a task's schedule so that it runs again next scheduling round. More...
 
void insert_port_range (port_list_t, port_protocol_t, int, int)
 Create a port range. More...
 

Variables

gchar * task_db_name
 Name of the database file. More...
 

Macro Definition Documentation

◆ CONFIG_UUID_DISCOVERY

#define CONFIG_UUID_DISCOVERY   "8715c877-47a0-438d-98a3-27c7a6ab2196"

UUID of 'Discovery' config.

Definition at line 66 of file manage_sql.h.

Referenced by config_in_use(), delete_config(), and migrate_78_to_79().

◆ CONFIG_UUID_EMPTY

#define CONFIG_UUID_EMPTY   "085569ce-73ed-11df-83c3-002264764cea"

UUID of 'Empty' config.

Definition at line 61 of file manage_sql.h.

Referenced by config_in_use(), delete_config(), and migrate_18_to_19().

◆ CONFIG_UUID_FULL_AND_FAST

#define CONFIG_UUID_FULL_AND_FAST   "daba56c8-73ec-11df-a475-002264764cea"

UUID of 'Full and fast' config.

Definition at line 39 of file manage_sql.h.

Referenced by config_in_use(), delete_config(), and migrate_18_to_19().

◆ CONFIG_UUID_FULL_AND_FAST_ULTIMATE

#define CONFIG_UUID_FULL_AND_FAST_ULTIMATE   "698f691e-7489-11df-9d8c-002264764cea"

UUID of 'Full and fast ultimate' config.

Definition at line 44 of file manage_sql.h.

Referenced by config_in_use(), delete_config(), and migrate_18_to_19().

◆ CONFIG_UUID_FULL_AND_VERY_DEEP

#define CONFIG_UUID_FULL_AND_VERY_DEEP   "708f25c4-7489-11df-8094-002264764cea"

UUID of 'Full and very deep' config.

Definition at line 50 of file manage_sql.h.

Referenced by config_in_use(), delete_config(), and migrate_18_to_19().

◆ CONFIG_UUID_FULL_AND_VERY_DEEP_ULTIMATE

#define CONFIG_UUID_FULL_AND_VERY_DEEP_ULTIMATE   "74db13d6-7489-11df-91b9-002264764cea"

UUID of 'Full and very deep ultimate' config.

Definition at line 55 of file manage_sql.h.

Referenced by config_in_use(), delete_config(), and migrate_18_to_19().

◆ CONFIG_UUID_HOST_DISCOVERY

#define CONFIG_UUID_HOST_DISCOVERY   "2d3f051c-55ba-11e3-bf43-406186ea4fc5"

UUID of 'Host Discovery' config.

Definition at line 71 of file manage_sql.h.

Referenced by config_in_use(), delete_config(), and migrate_111_to_112().

◆ CONFIG_UUID_SYSTEM_DISCOVERY

#define CONFIG_UUID_SYSTEM_DISCOVERY   "bbca7412-a950-11e3-9109-406186ea4fc5"

UUID of 'System Discovery' config.

Definition at line 76 of file manage_sql.h.

Referenced by config_in_use(), and delete_config().

◆ LOCATION_TABLE

◆ LOCATION_TRASH

◆ MANAGE_NVT_SELECTOR_UUID_ALL

#define MANAGE_NVT_SELECTOR_UUID_ALL   "54b45713-d4f4-4435-b20d-304c175ed8c5"

UUID of 'All' NVT selector.

Definition at line 91 of file manage_sql.h.

Referenced by migrate_12_to_13(), and migrate_17_to_18().

◆ MANAGE_NVT_SELECTOR_UUID_DISCOVERY

#define MANAGE_NVT_SELECTOR_UUID_DISCOVERY   "0d9a2738-8fe2-4e22-8f26-bb886179e759"

UUID of 'Discovery' NVT selector.

Definition at line 96 of file manage_sql.h.

Referenced by migrate_115_to_116(), and migrate_78_to_79().

◆ MANAGE_NVT_SELECTOR_UUID_HOST_DISCOVERY

#define MANAGE_NVT_SELECTOR_UUID_HOST_DISCOVERY   "f5f80744-55c7-11e3-8dc6-406186ea4fc5"

UUID of 'Host Discovery' NVT selector.

Definition at line 101 of file manage_sql.h.

◆ MANAGE_NVT_SELECTOR_UUID_SYSTEM_DISCOVERY

#define MANAGE_NVT_SELECTOR_UUID_SYSTEM_DISCOVERY   "07045d1c-a951-11e3-8da7-406186ea4fc5"

UUID of 'System Discovery' NVT selector.

Definition at line 107 of file manage_sql.h.

◆ PERMISSION_UUID_ADMIN_EVERYTHING

#define PERMISSION_UUID_ADMIN_EVERYTHING   "b3b56a8c-c2fd-11e2-a135-406186ea4fc5"

Predefined role UUID.

Definition at line 113 of file manage_sql.h.

Referenced by delete_permission(), permission_is_admin(), and permission_is_predefined().

◆ PERMISSION_UUID_SUPER_ADMIN_EVERYTHING

#define PERMISSION_UUID_SUPER_ADMIN_EVERYTHING   "a9801074-6fe2-11e4-9d81-406186ea4fc5"

Predefined role UUID.

Definition at line 118 of file manage_sql.h.

◆ PORT_LIST_UUID_ALL_IANA_TCP_2012

#define PORT_LIST_UUID_ALL_IANA_TCP_2012   "33d0cd82-57c6-11e1-8ed1-406186ea4fc5"

UUID of 'All privileged TCP and UDP' port list.

Definition at line 153 of file manage_sql.h.

Referenced by delete_port_range(), and port_list_is_predefined().

◆ PORT_LIST_UUID_ALL_IANA_TCP_UDP_2012

#define PORT_LIST_UUID_ALL_IANA_TCP_UDP_2012   "4a4717fe-57d2-11e1-9a26-406186ea4fc5"

UUID of 'All privileged TCP and UDP' port list.

Definition at line 158 of file manage_sql.h.

Referenced by delete_port_range(), and port_list_is_predefined().

◆ PORT_LIST_UUID_ALL_PRIV_TCP

#define PORT_LIST_UUID_ALL_PRIV_TCP   "492b72f4-56fe-11e1-98a7-406186ea4fc5"

UUID of 'All privileged TCP' port list.

Definition at line 143 of file manage_sql.h.

Referenced by delete_port_range(), and port_list_is_predefined().

◆ PORT_LIST_UUID_ALL_PRIV_TCP_UDP

#define PORT_LIST_UUID_ALL_PRIV_TCP_UDP   "5f2029f6-56fe-11e1-bb94-406186ea4fc5"

UUID of 'All privileged TCP and UDP' port list.

Definition at line 148 of file manage_sql.h.

Referenced by delete_port_range(), and port_list_is_predefined().

◆ PORT_LIST_UUID_ALL_TCP

#define PORT_LIST_UUID_ALL_TCP   "fd591a34-56fd-11e1-9f27-406186ea4fc5"

UUID of 'All TCP' port list.

Definition at line 128 of file manage_sql.h.

Referenced by port_list_is_predefined().

◆ PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_100

#define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_100   "730ef368-57e2-11e1-a90f-406186ea4fc5"

UUID of 'All TCP and Nmap 5.51 Top 100 UDP' port list.

Definition at line 133 of file manage_sql.h.

Referenced by delete_port_range(), and port_list_is_predefined().

◆ PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_1000

#define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_1000   "9ddce1ae-57e7-11e1-b13c-406186ea4fc5"

UUID of 'All TCP and Nmap 5.51 Top 1000 UDP' port list.

Definition at line 138 of file manage_sql.h.

Referenced by delete_port_range(), and port_list_is_predefined().

◆ PORT_LIST_UUID_DEFAULT

#define PORT_LIST_UUID_DEFAULT   "c7e03b6c-3bbe-11e1-a057-406186ea4fc5"

◆ PORT_LIST_UUID_NMAP_5_51_TOP_2000_TOP_100

#define PORT_LIST_UUID_NMAP_5_51_TOP_2000_TOP_100   "ab33f6b0-57f8-11e1-96f5-406186ea4fc5"

UUID of 'Nmap 5.51 top 2000 TCP top 100 UDP' port list.

Definition at line 163 of file manage_sql.h.

Referenced by delete_port_range(), and port_list_is_predefined().

◆ ROLE_UUID_ADMIN

#define ROLE_UUID_ADMIN   "7a8cb5b4-b74d-11e2-8187-406186ea4fc5"

◆ ROLE_UUID_GUEST

#define ROLE_UUID_GUEST   "cc9cac5e-39a3-11e4-abae-406186ea4fc5"

Predefined role UUID.

Definition at line 173 of file manage_sql.h.

Referenced by migrate_137_to_138(), permission_is_predefined(), role_is_predefined(), and role_is_predefined_id().

◆ ROLE_UUID_INFO

#define ROLE_UUID_INFO   "5f8fd16c-c550-11e3-b6ab-406186ea4fc5"

◆ ROLE_UUID_MONITOR

#define ROLE_UUID_MONITOR   "12cdb536-480b-11e4-8552-406186ea4fc5"

Predefined role UUID.

Definition at line 183 of file manage_sql.h.

Referenced by permission_is_predefined(), role_is_predefined(), and role_is_predefined_id().

◆ ROLE_UUID_OBSERVER

#define ROLE_UUID_OBSERVER   "87a7ebce-b74d-11e2-a81f-406186ea4fc5"

◆ ROLE_UUID_SUPER_ADMIN

#define ROLE_UUID_SUPER_ADMIN   "9c5a6ec6-6fe2-11e4-8cb6-406186ea4fc5"

◆ ROLE_UUID_USER

#define ROLE_UUID_USER   "8d453140-b74d-11e2-b0be-406186ea4fc5"

◆ SCANNER_UUID_CVE

#define SCANNER_UUID_CVE   "6acd0832-df90-11e4-b9d5-28d24461215b"

UUID of 'CVE' scanner.

Definition at line 208 of file manage_sql.h.

Referenced by copy_scanner(), delete_scanner(), and manage_delete_scanner().

◆ SCANNER_UUID_DEFAULT

#define SCANNER_UUID_DEFAULT   "08b69003-5fc2-4037-a479-93b440211c73"

◆ SETTING_UUID_DEFAULT_CA_CERT

#define SETTING_UUID_DEFAULT_CA_CERT   "9ac801ea-39f8-11e6-bbaa-28d24461215b"

UUID of 'Default CA Cert' setting.

Definition at line 223 of file manage_sql.h.

Referenced by manage_default_ca_cert(), manage_modify_setting(), and setting_is_default_ca_cert().

◆ SETTING_UUID_MAX_ROWS_PER_PAGE

#define SETTING_UUID_MAX_ROWS_PER_PAGE   "76374a7a-0569-11e6-b6da-28d24461215b"

UUID of 'Max Rows Per Page' setting.

Definition at line 218 of file manage_sql.h.

Referenced by manage_max_rows(), and manage_modify_setting().

◆ SETTING_UUID_ROWS_PER_PAGE

#define SETTING_UUID_ROWS_PER_PAGE   "5f5a8712-8017-11e1-8556-406186ea4fc5"

UUID of 'Rows Per Page' setting.

Definition at line 213 of file manage_sql.h.

Referenced by manage_filter_controls(), and manage_report_filter_controls().

◆ TIMEVAL_SUBTRACT_MS

#define TIMEVAL_SUBTRACT_MS (   a,
 
)
Value:
((((a).tv_sec - (b).tv_sec) * 1000) + \
((a).tv_usec - (b).tv_usec) / 1000)

Number of milliseconds between timevals a and b (performs a-b).

Definition at line 248 of file manage_sql.h.

◆ TRUST_ERROR

#define TRUST_ERROR   0

Trust constant for error.

Definition at line 228 of file manage_sql.h.

◆ TRUST_NO

#define TRUST_NO   2

Trust constant for no.

Definition at line 238 of file manage_sql.h.

◆ TRUST_UNKNOWN

#define TRUST_UNKNOWN   3

Trust constant for unknown.

Definition at line 243 of file manage_sql.h.

Referenced by create_agent(), create_report_format(), migrate_19_to_20(), migrate_22_to_23(), and verify_agent().

◆ TRUST_YES

#define TRUST_YES   1

Trust constant for yes.

Definition at line 233 of file manage_sql.h.

Referenced by manage_report().

Typedef Documentation

◆ rowid_t

typedef long long int rowid_t

Definition at line 259 of file manage_sql.h.

Function Documentation

◆ alert_data()

char* alert_data ( alert_t  alert,
const char *  type,
const char *  name 
)

Return data associated with an alert.

Parameters
[in]alertAlert.
[in]typeType of data: "condition", "event" or "method".
[in]nameName of the data.
Returns
Freshly allocated data if it exists, else NULL.

Definition at line 8810 of file manage_sql.c.

References sql_quote(), and sql_string().

Referenced by alert_condition_description(), and migrate_165_to_166().

8811 {
8812  gchar *quoted_name;
8813  char *data;
8814 
8815  assert (strcmp (type, "condition") == 0
8816  || strcmp (type, "event") == 0
8817  || strcmp (type, "method") == 0);
8818 
8819  quoted_name = sql_quote (name);
8820  data = sql_string ("SELECT data FROM alert_%s_data"
8821  " WHERE alert = %llu AND name = '%s';",
8822  type,
8823  alert,
8824  quoted_name);
8825  g_free (quoted_name);
8826  return data;
8827 }
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:469
Here is the call graph for this function:
Here is the caller graph for this function:

◆ array_add_new_string()

void array_add_new_string ( array_t *  array,
const gchar *  string 
)

Ensure a string is in an array.

Parameters
[in]arrayArray.
[in]stringString. Copied into array.

Definition at line 710 of file manage_sql.c.

Referenced by manage_report_host_details().

711 {
712  guint index;
713  for (index = 0; index < array->len; index++)
714  if (strcmp (g_ptr_array_index (array, index), string) == 0)
715  return;
716  array_add (array, g_strdup (string));
717 }
Here is the caller graph for this function:

◆ auto_delete_reports()

void auto_delete_reports ( )

Auto delete reports.

Definition at line 19380 of file manage_sql.c.

References AUTO_DELETE_KEEP_MAX, cleanup_iterator(), delete_report_internal(), init_iterator(), iterator_int64(), iterator_string(), next(), sql_begin_exclusive_giveup(), sql_commit(), sql_rollback(), and sql_select_limit().

Referenced by manage_schedule().

19381 {
19382  iterator_t tasks;
19383 
19384  g_debug ("%s", __FUNCTION__);
19385 
19387  return;
19388 
19389  init_iterator (&tasks,
19390  "SELECT id, name,"
19391  " (SELECT value FROM task_preferences"
19392  " WHERE name = 'auto_delete_data'"
19393  " AND task = tasks.id)"
19394  " FROM tasks"
19395  " WHERE owner is NOT NULL"
19396  " AND hidden = 0"
19397  " AND EXISTS (SELECT * FROM task_preferences"
19398  " WHERE task = tasks.id"
19399  " AND name = 'auto_delete'"
19400  " AND value = 'keep');");
19401  while (next (&tasks))
19402  {
19403  task_t task;
19404  iterator_t reports;
19405  const char *keep_string;
19406  int keep;
19407 
19408  task = iterator_int64 (&tasks, 0);
19409 
19410  keep_string = iterator_string (&tasks, 2);
19411  if (keep_string == NULL)
19412  continue;
19413  keep = atoi (keep_string);
19414  if (keep < AUTO_DELETE_KEEP_MIN || keep > AUTO_DELETE_KEEP_MAX)
19415  continue;
19416 
19417  g_debug ("%s: %s (%i)", __FUNCTION__,
19418  iterator_string (&tasks, 1),
19419  keep);
19420 
19421  init_iterator (&reports,
19422  "SELECT id FROM reports"
19423  " WHERE task = %llu"
19424  " AND start_time IS NOT NULL"
19425  " AND start_time > 0"
19426  " ORDER BY start_time DESC LIMIT %s OFFSET %i;",
19427  task,
19428  sql_select_limit (-1),
19429  keep);
19430  while (next (&reports))
19431  {
19432  int ret;
19433  report_t report;
19434 
19435  report = iterator_int64 (&reports, 0);
19436  assert (report);
19437 
19438  g_debug ("%s: delete %llu", __FUNCTION__, report);
19439  ret = delete_report_internal (report);
19440  if (ret == 2)
19441  {
19442  /* Report is in use. */
19443  g_debug ("%s: %llu is in use", __FUNCTION__, report);
19444  continue;
19445  }
19446  if (ret)
19447  {
19448  g_warning ("%s: failed to delete %llu (%i)\n",
19449  __FUNCTION__, report, ret);
19450  sql_rollback ();
19451  }
19452  }
19453  cleanup_iterator (&reports);
19454  }
19455  cleanup_iterator (&tasks);
19456  sql_commit ();
19457 }
int sql_begin_exclusive_giveup()
Begin an exclusive transaction, giving up on failure.
Definition: sql_pg.c:610
A generic SQL iterator.
Definition: iterator.h:52
void sql_rollback()
Roll a transaction back.
Definition: sql_pg.c:658
long long int report_t
Definition: manage.h:288
#define AUTO_DELETE_KEEP_MAX
Definition: manage.h:243
int delete_report_internal(report_t report)
Delete a report.
Definition: manage_sql.c:25198
void cleanup_iterator(iterator_t *)
Cleanup an iterator.
Definition: sql.c:664
const char * iterator_string(iterator_t *iterator, int col)
Get a string column from an iterator.
Definition: sql.c:652
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:649
gboolean next(iterator_t *)
Increment an iterator.
Definition: sql.c:689
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:577
const char * sql_select_limit(int)
Setup a LIMIT argument.
Definition: sql_pg.c:127
long long int task_t
Definition: manage.h:286
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_generate_scripts()

void check_generate_scripts ( )

Ensure the generate scripts are all executable.

Used by a migrator.

Definition at line 16716 of file manage_sql.c.

References cleanup_iterator(), init_iterator(), iterator_int64(), iterator_string(), next(), report_format_uuid(), and user_uuid().

Referenced by migrate_147_to_148().

16717 {
16718  iterator_t rows;
16719 
16720  init_iterator (&rows, "SELECT owner,"
16721  " uuid,"
16722  " (SELECT uuid FROM users"
16723  " WHERE users.id = report_formats.owner)"
16724  " FROM report_formats;");
16725  while (next (&rows))
16726  {
16727  resource_t owner;
16728 
16729  owner = iterator_int64 (&rows, 0);
16730  if (owner)
16731  {
16732  const gchar *report_format_uuid, *user_uuid;
16733  gchar *path;
16734 
16735  report_format_uuid = iterator_string (&rows, 1);
16736  if (report_format_uuid == NULL)
16737  continue;
16738 
16739  user_uuid = iterator_string (&rows, 2);
16740  if (user_uuid == NULL)
16741  continue;
16742 
16743  path = g_build_filename (OPENVAS_STATE_DIR,
16744  "openvasmd",
16745  "report_formats",
16746  user_uuid,
16747  report_format_uuid,
16748  "generate",
16749  NULL);
16750 
16751  if (chmod (path, 0755 /* rwxr-xr-x */))
16752  g_warning ("%s: chmod %s failed: %s\n",
16753  __FUNCTION__,
16754  path,
16755  strerror (errno));
16756 
16757  g_free (path);
16758  }
16759  }
16760  cleanup_iterator (&rows);
16761 }
char * report_format_uuid(report_format_t report_format)
Return the UUID of a report format.
Definition: manage_sql.c:51487
char * user_uuid(user_t user)
Return the UUID of a user.
Definition: manage_sql.c:66308
A generic SQL iterator.
Definition: iterator.h:52
void cleanup_iterator(iterator_t *)
Cleanup an iterator.
Definition: sql.c:664
const char * iterator_string(iterator_t *iterator, int col)
Get a string column from an iterator.
Definition: sql.c:652
gboolean next(iterator_t *)
Increment an iterator.
Definition: sql.c:689
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:577
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_task_schedule_iterator()

void cleanup_task_schedule_iterator ( iterator_t iterator)

Cleanup a task schedule iterator.

Parameters
[in]iteratorIterator.

Definition at line 49341 of file manage_sql.c.

References cleanup_iterator(), and sql_commit().

Referenced by manage_schedule().

49342 {
49343  cleanup_iterator (iterator);
49344  sql_commit ();
49345 }
void cleanup_iterator(iterator_t *)
Cleanup an iterator.
Definition: sql.c:664
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:649
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_current_report()

int create_current_report ( task_t  task,
char **  report_id,
task_status_t  status 
)

Create the current report for a task.

Parameters
[in]taskThe task.
[out]report_idReport ID.
[in]statusRun status of scan associated with report.
Returns
0 success, -1 current_report is already set, -2 failed to generate ID.

Definition at line 21002 of file manage_sql.c.

References current_report, make_report(), and set_report_scheduled().

21003 {
21004  char *id;
21005 
21006  assert (current_report == (report_t) 0);
21007 
21008  if (current_report) return -1;
21009 
21010  if (report_id == NULL) report_id = &id;
21011 
21012  /* Generate report UUID. */
21013 
21014  *report_id = openvas_uuid_make ();
21015  if (*report_id == NULL) return -2;
21016 
21017  /* Create the report. */
21018 
21019  current_report = make_report (task, *report_id, status);
21020 
21022 
21023  return 0;
21024 }
long long int report_t
Definition: manage.h:288
report_t current_report
The report of the current task.
Definition: manage.c:1003
report_t make_report(task_t task, const char *uuid, task_status_t status)
Make a report.
Definition: manage_sql.c:20981
void set_report_scheduled(report_t report)
Set a report&#39;s scheduled flag.
Definition: manage_sql.c:18252
Here is the call graph for this function:

◆ 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

Definition at line 1072 of file manage_sql.c.

1073 {
1074  time_t now = time (NULL);
1075  int diff = *epoch_time - now;
1076 
1077  if (diff < 0) return -1;
1078  return diff / 86400; /* 60 sec * 60 min * 24 h */
1079 }

◆ delete_report_internal()

int delete_report_internal ( report_t  report)

Delete a report.

It's up to the caller to provide the transaction.

Parameters
[in]reportReport.
Returns
0 success, 1 report is hidden, 2 report is in use, -1 error.

Definition at line 25198 of file manage_sql.c.

References delete_slave_task(), LOCATION_TABLE, permissions_set_orphans(), report_scan_run_status(), report_slave_host(), report_slave_port_int(), report_slave_task_uuid(), report_task(), scanner_login(), scanner_password(), slave_task_uuid, sql(), sql_int(), sql_int64(), tags_set_orphans(), task_scanner(), TASK_STATUS_DELETE_REQUESTED, TASK_STATUS_DELETE_ULTIMATE_REQUESTED, TASK_STATUS_NEW, TASK_STATUS_REQUESTED, TASK_STATUS_RUNNING, TASK_STATUS_STOP_REQUESTED, TASK_STATUS_STOP_REQUESTED_GIVEUP, and TASK_STATUS_STOP_WAITING.

Referenced by auto_delete_reports(), delete_report(), and delete_reports().

25199 {
25200  task_t task;
25201  char *slave_task_uuid;
25202 
25203  if (sql_int ("SELECT hidden FROM reports WHERE id = %llu;", report))
25204  return 1;
25205 
25206  if (sql_int ("SELECT count(*) FROM reports WHERE id = %llu"
25207  " AND (scan_run_status = %u OR scan_run_status = %u"
25208  " OR scan_run_status = %u OR scan_run_status = %u"
25209  " OR scan_run_status = %u);",
25210  report,
25218  return 2;
25219 
25220  if (report_task (report, &task))
25221  return -1;
25222 
25223  /* Remove any associated slave task. */
25224 
25225  slave_task_uuid = report_slave_task_uuid (report);
25226  g_debug ("%s: slave_task_uuid: %s", __FUNCTION__, slave_task_uuid);
25227  if (slave_task_uuid)
25228  {
25229  scanner_t slave;
25230 
25231  /* A stopped report leaves the task on the slave. Try delete the task. */
25232 
25233  slave = task_scanner (task);
25234  if (slave)
25235  {
25236  char *username, *password;
25237 
25238  username = scanner_login (slave);
25239  password = scanner_password (slave);
25240  if (username && password)
25241  {
25242  char *host;
25243  int port;
25244 
25245  /* Try with values stored on report. */
25246  host = report_slave_host (report);
25247  port = report_slave_port_int (report);
25248  if (host)
25249  delete_slave_task (host, port, username, password,
25250  slave_task_uuid);
25251  g_free (host);
25252 
25253  /* TODO If that fails, try with the current values from the
25254  * slave/scanner stored on the report. And if that fails,
25255  * try with the values from the current slave of the task. */
25256  }
25257  free (username);
25258  free (password);
25259  }
25260  }
25261 
25262  /* Remove the report data. */
25263 
25264  sql ("DELETE FROM report_host_details WHERE report_host IN"
25265  " (SELECT id FROM report_hosts WHERE report = %llu);",
25266  report);
25267  sql ("DELETE FROM report_hosts WHERE report = %llu;", report);
25268 
25269  sql ("UPDATE tags"
25270  " SET resource = 0, resource_location = " G_STRINGIFY (LOCATION_TABLE)
25271  " WHERE resource IN"
25272  " (SELECT id FROM results WHERE report = %llu);",
25273  report);
25274  sql ("UPDATE tags_trash"
25275  " SET resource = 0, resource_location = " G_STRINGIFY (LOCATION_TABLE)
25276  " WHERE resource IN"
25277  " (SELECT id FROM results WHERE report = %llu);",
25278  report);
25279  sql ("DELETE FROM results WHERE report = %llu;", report);
25280 
25281  sql ("DELETE FROM report_counts WHERE report = %llu;", report);
25282  sql ("DELETE FROM reports WHERE id = %llu;", report);
25283 
25284  /* Adjust permissions. */
25285 
25286  permissions_set_orphans ("report", report, LOCATION_TABLE);
25287  tags_set_orphans ("report", report, LOCATION_TABLE);
25288 
25289  /* Update the task state. */
25290 
25291  switch (sql_int64 (&report,
25292  "SELECT max (id) FROM reports WHERE task = %llu",
25293  task))
25294  {
25295  case 0:
25296  if (report)
25297  {
25298  int status;
25299  if (report_scan_run_status (report, &status))
25300  return -1;
25301  sql ("UPDATE tasks SET run_status = %u WHERE id = %llu;",
25302  status,
25303  task);
25304  }
25305  else
25306  sql ("UPDATE tasks SET run_status = %u WHERE id = %llu;",
25308  task);
25309  break;
25310  case 1: /* Too few rows in result of query. */
25311  break;
25312  default: /* Programming error. */
25313  assert (0);
25314  case -1:
25315  return -1;
25316  break;
25317  }
25318 
25319  return 0;
25320 }
void tags_set_orphans(const char *, resource_t, int)
Set tags to orphan.
Definition: manage_sql.c:68232
char * scanner_login(scanner_t scanner)
Return the login associated with a scanner.
Definition: manage_sql.c:48269
char * scanner_password(scanner_t scanner)
Return the password associated with a scanner.
Definition: manage_sql.c:48287
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
int delete_slave_task(const char *, int, const char *, const char *, const char *)
scanner_t task_scanner(task_t task)
Return the scanner of a task.
Definition: manage_sql.c:18183
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:501
char * report_slave_task_uuid(report_t report)
Return the UUID of the task on the slave.
Definition: manage_sql.c:25467
gboolean report_task(report_t report, task_t *task)
Return the task of a report.
Definition: manage_sql.c:21397
int report_scan_run_status(report_t report, int *status)
Return the run status of the scan associated with a report.
Definition: manage_sql.c:24495
void permissions_set_orphans(const char *, resource_t, int)
Set permissions to orphan.
Definition: manage_sql.c:53902
int report_slave_port_int(report_t report)
Return the port of a report&#39;s slave.
Definition: manage_sql.c:21481
char * report_slave_host(report_t report)
Return the host of a report&#39;s slave.
Definition: manage_sql.c:21453
gchar * slave_task_uuid
Slave task UUID.
Definition: manage.c:2005
#define LOCATION_TABLE
Location of a constituent of a trashcan resource.
Definition: manage_sql.h:81
long long int task_t
Definition: manage.h:286
long long int scanner_t
Definition: manage.h:300
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_resource_with_permission()

gboolean find_resource_with_permission ( const char *  type,
const char *  uuid,
resource_t resource,
const char *  permission,
int  trash 
)

Find a resource given a UUID and a permission.

Parameters
[in]typeType of resource.
[in]uuidUUID of resource.
[out]resourceResource return, 0 if succesfully failed to find resource.
[in]permissionPermission.
[in]trashWhether resource is in trashcan.
Returns
FALSE on success (including if failed to find resource), TRUE on error.

Definition at line 4459 of file manage_sql.c.

References acl_user_has_access_uuid(), sql_int64(), sql_quote(), and valid_type().

Referenced by create_tag(), find_agent_with_permission(), find_alert_with_permission(), find_config_with_permission(), find_credential_with_permission(), find_filter_with_permission(), find_group_with_permission(), find_host_with_permission(), find_note_with_permission(), find_override_with_permission(), find_port_list_with_permission(), find_report_format_with_permission(), find_report_with_permission(), find_role_with_permission(), find_scanner_with_permission(), find_schedule_with_permission(), find_tag_with_permission(), find_target_with_permission(), find_task_with_permission(), find_trash_task_with_permission(), find_user_with_permission(), modify_tag(), permission_iterator_resource_readable(), permission_iterator_subject_readable(), and tag_iterator_resource_readable().

4462 {
4463  gchar *quoted_uuid;
4464  if (uuid == NULL)
4465  return TRUE;
4466  if ((type == NULL) || (valid_type (type) == 0))
4467  return TRUE;
4468  quoted_uuid = sql_quote (uuid);
4469  if (acl_user_has_access_uuid (type, quoted_uuid, permission, trash) == 0)
4470  {
4471  g_free (quoted_uuid);
4472  *resource = 0;
4473  return FALSE;
4474  }
4475  switch (sql_int64 (resource,
4476  "SELECT id FROM %ss%s WHERE uuid = '%s'%s;",
4477  type,
4478  (strcmp (type, "task") && trash) ? "_trash" : "",
4479  quoted_uuid,
4480  strcmp (type, "task")
4481  ? ""
4482  : (trash ? " AND hidden = 2" : " AND hidden < 2")))
4483  {
4484  case 0:
4485  break;
4486  case 1: /* Too few rows in result of query. */
4487  *resource = 0;
4488  break;
4489  default: /* Programming error. */
4490  assert (0);
4491  case -1:
4492  g_free (quoted_uuid);
4493  return TRUE;
4494  break;
4495  }
4496 
4497  g_free (quoted_uuid);
4498  return FALSE;
4499 }
int acl_user_has_access_uuid(const char *type, const char *uuid, const char *permission, int trash)
Test whether the user may access a resource.
Definition: manage_acl.c:758
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:501
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
int valid_type(const char *)
Check whether a resource type name is valid.
Definition: manage_sql.c:4201
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_ovaldef_short_filename()

gchar* get_ovaldef_short_filename ( char *  item_id)

Get the short file name for an OVALDEF.

Parameters
[in]item_idFull OVAL identifier with file suffix.
Returns
The file name of the OVAL definition relative to the SCAP directory, Freed by g_free.

Definition at line 64305 of file manage_sql.c.

References sql_string().

64306 {
64307  return sql_string ("SELECT xml_file FROM ovaldefs WHERE uuid = '%s';",
64308  item_id);
64309 }
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:469
Here is the call graph for this function:

◆ host_nthlast_report_host()

gboolean host_nthlast_report_host ( const char *  host,
report_host_t report_host,
int  position 
)

Get N'th last report_host given a host.

The last report_host is at position 1, the second last at position 2, and so on.

Parameters
[in]hostHost.
[in]report_hostReport host.
[in]positionPosition from end.

Definition at line 26519 of file manage_sql.c.

References current_credentials, sql_int64(), and sql_quote().

26521 {
26522  gchar *quoted_host;
26523 
26524  assert (current_credentials.uuid);
26525 
26526  if (position == 0)
26527  position = 1;
26528 
26529  quoted_host = sql_quote (host);
26530  switch (sql_int64 (report_host,
26531  "SELECT id FROM report_hosts WHERE host = '%s'"
26532  " AND user_owns ('task',"
26533  " (SELECT reports.task FROM reports"
26534  " WHERE reports.id"
26535  " = report_hosts.report))"
26536  " AND (SELECT tasks.hidden FROM tasks, reports"
26537  " WHERE reports.task = tasks.id"
26538  " AND reports.id = report_hosts.report)"
26539  " = 0"
26540  " AND (SELECT value FROM task_preferences, tasks,"
26541  " reports"
26542  " WHERE reports.task = tasks.id"
26543  " AND reports.id = report_hosts.report"
26544  " AND task_preferences.task = tasks.id"
26545  " AND task_preferences.name = 'in_assets')"
26546  " = 'yes'"
26547  " AND report_hosts.end_time IS NOT NULL"
26548  " AND NOT EXISTS (SELECT * FROM report_host_details"
26549  " WHERE report_host = report_hosts.id"
26550  " AND name = 'CVE Scan')"
26551  " ORDER BY id DESC LIMIT 1 OFFSET %i;",
26552  quoted_host,
26553  position - 1))
26554  {
26555  case 0:
26556  break;
26557  case 1: /* Too few rows in result of query. */
26558  *report_host = 0;
26559  break;
26560  default: /* Programming error. */
26561  assert (0);
26562  case -1:
26563  return TRUE;
26564  break;
26565  }
26566 
26567  g_free (quoted_host);
26568  return FALSE;
26569 }
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:501
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
credentials_t current_credentials
Current credentials during any OMP command.
Definition: manage.c:717
Here is the call graph for this function:

◆ init_otp_pref_iterator()

void init_otp_pref_iterator ( iterator_t iterator,
config_t  config,
const char *  section 
)

Initialise an "OTP" preference iterator.

Assume the caller has permission to access the config.

This version substitutes the scanner preference when the NVT preference is missing.

Parameters
[in]iteratorIterator.
[in]configConfig containing preferences.
[in]sectionPreference section, NULL for general preferences.

Definition at line 36649 of file manage_sql.c.

References init_iterator(), and sql_quote().

36652 {
36653  gchar *quoted_section;
36654 
36655  assert (config);
36656  assert (section);
36657  assert ((strcmp (section, "PLUGINS_PREFS") == 0)
36658  || (strcmp (section, "SERVER_PREFS") == 0));
36659 
36660  quoted_section = sql_quote (section);
36661 
36662  init_iterator (iterator,
36663  "SELECT config_preferences.name, config_preferences.value"
36664  " FROM config_preferences, nvt_preferences"
36665  " WHERE config_preferences.config = %llu"
36666  " AND config_preferences.type = '%s'"
36667  " AND (config_preferences.name = nvt_preferences.name"
36668  " OR config_preferences.name LIKE 'timeout.%')"
36669  " AND config_preferences.name != 'max_checks'"
36670  " AND config_preferences.name != 'max_hosts'"
36671  " UNION"
36672  " SELECT nvt_preferences.name, nvt_preferences.value"
36673  " FROM nvt_preferences"
36674  " WHERE nvt_preferences.name %s"
36675  " AND (SELECT COUNT(*) FROM config_preferences"
36676  " WHERE config = %llu"
36677  " AND config_preferences.name = nvt_preferences.name) = 0;",
36678  config,
36679  quoted_section,
36680  strcmp (quoted_section, "SERVER_PREFS") == 0
36681  ? "NOT LIKE '%[%]%'" : "LIKE '%[%]%'",
36682  config);
36683  g_free (quoted_section);
36684 }
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:577
Here is the call graph for this function:

◆ init_task_file_iterator()

void init_task_file_iterator ( iterator_t iterator,
task_t  task,
const char *  file 
)

Initialise a task file iterator.

Parameters
[in]iteratorIterator.
[in]taskTask.
[in]fileFile name, NULL for all files.

Definition at line 32760 of file manage_sql.c.

References init_iterator(), sql(), and sql_nquote().

32761 {
32762  gchar* sql;
32763  if (file)
32764  {
32765  gchar *quoted_file = sql_nquote (file, strlen (file));
32766  sql = g_strdup_printf ("SELECT name, content, length(content)"
32767  " FROM task_files"
32768  " WHERE task = %llu"
32769  " AND name = '%s';",
32770  task, quoted_file);
32771  g_free (quoted_file);
32772  }
32773  else
32774  sql = g_strdup_printf ("SELECT name, content, length(content)"
32775  " FROM task_files"
32776  " WHERE task = %llu;",
32777  task);
32778  init_iterator (iterator, sql);
32779  g_free (sql);
32780 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:577
gchar * sql_nquote(const char *string, size_t length)
Quotes a string of a known length to be passed to sql statements.
Definition: sql.c:76
Here is the call graph for this function:

◆ init_task_schedule_iterator()

int init_task_schedule_iterator ( iterator_t iterator)

Initialise a task schedule iterator.

Lock the database before initialising.

Parameters
[in]iteratorIterator.
Returns
0 success, 1 failed to get lock, -1 error.

Definition at line 49284 of file manage_sql.c.

References acl_where_owned_user(), init_iterator(), and sql_begin_exclusive_giveup().

Referenced by manage_schedule().

49285 {
49286  int ret;
49287  gchar *task_clause, *schedule_clause;
49288  get_data_t get;
49289  array_t *permissions;
49290 
49291  ret = sql_begin_exclusive_giveup ();
49292  if (ret)
49293  return ret;
49294 
49295  get.trash = 0;
49296  permissions = make_array ();
49297  array_add (permissions, g_strdup ("start_task"));
49298  task_clause = acl_where_owned_user ("", "users.id", "task", &get, 1,
49299  "any", 0, permissions);
49300  array_free (permissions);
49301 
49302  permissions = make_array ();
49303  array_add (permissions, g_strdup ("get_schedules"));
49304  schedule_clause = acl_where_owned_user ("", "users.id", "schedule", &get, 1,
49305  "any", 0, permissions);
49306  array_free (permissions);
49307 
49308  init_iterator (iterator,
49309  "SELECT tasks.id, tasks.uuid,"
49310  " schedules.id, tasks.schedule_next_time,"
49311  " schedules.period, schedules.period_months,"
49312  " schedules.first_time,"
49313  " schedules.duration,"
49314  " users.uuid, users.name,"
49315  " schedules.timezone, schedules.initial_offset"
49316  " FROM tasks, schedules, users"
49317  " WHERE tasks.schedule = schedules.id"
49318  " AND tasks.hidden = 0"
49319  /* And a user may run the task. */
49320  " AND %s"
49321  /* And the same user has access to the schedule. */
49322  " AND %s"
49323  /* Sort by task and prefer owner of task or schedule as user */
49324  " ORDER BY tasks.id,"
49325  " (users.id = tasks.owner) DESC,"
49326  " (users.id = schedules.owner) DESC;",
49327  task_clause,
49328  schedule_clause);
49329 
49330  g_free (task_clause);
49331  g_free (schedule_clause);
49332  return 0;
49333 }
int sql_begin_exclusive_giveup()
Begin an exclusive transaction, giving up on failure.
Definition: sql_pg.c:610
Command data for a get command.
Definition: manage.h:310
gchar * acl_where_owned_user(const char *user_id, const char *user_sql, const char *type, const get_data_t *get, int owned, const gchar *owner_filter, resource_t resource, array_t *permissions)
Generate the ownership part of an SQL WHERE clause for a given user.
Definition: manage_acl.c:948
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:577
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_port_range()

void insert_port_range ( port_list_t  port_list,
port_protocol_t  type,
int  start,
int  end 
)

Create a port range.

Parameters
[in]port_listPort list to insert into.
[in]typeProtocol: PORT_PROTOCOL_UDP or PORT_PROTOCOL_TCP.
[in]startStart of range.
[in]endEnd of range.

Definition at line 56393 of file manage_sql.c.

References sql().

56395 {
56396  sql ("INSERT INTO port_ranges"
56397  " (uuid, port_list, type, start, \"end\", comment, exclude)"
56398  " VALUES"
56399  " (make_uuid (), %llu, %i, '%i', '%i', '', 0);",
56400  port_list,
56401  type,
56402  start,
56403  end);
56404 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
Here is the call graph for this function:

◆ manage_db_empty()

int manage_db_empty ( )

Check whether database is empty.

Returns
1 if empty, else 0.
1 if empty, else 0;

Definition at line 78 of file manage_pg.c.

References sql_database(), and sql_int().

Referenced by manage_db_version().

79 {
80  return sql_int ("SELECT EXISTS (SELECT * FROM information_schema.tables"
81  " WHERE table_catalog = '%s'"
82  " AND table_schema = 'public'"
83  " AND table_name = 'meta')"
84  " ::integer;",
85  sql_database ())
86  == 0;
87 }
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
const char * sql_database()
Return name of current database.
Definition: sql_pg.c:226
Here is the call graph for this function:
Here is the caller graph for this function:

◆ manage_report_host_details()

int manage_report_host_details ( report_t  report,
const char *  ip,
entity_t  entity 
)

Add host details to a report host.

Parameters
[in]reportUUID of resource.
[in]ipHost.
[in]entityXML entity containing details.
Returns
0 success, -1 failed to parse XML.

Definition at line 60642 of file manage_sql.c.

References array_add_new_string(), insert_report_host_detail(), identifier_t::ip, identifier_t::name, report_uuid(), identifier_t::source_data, identifier_t::source_id, identifier_t::source_type, sql_int(), and identifier_t::value.

Referenced by manage_report_host_detail(), and update_end_times().

60643 {
60644  int in_assets;
60645  entities_t details;
60646  entity_t detail;
60647  char *uuid;
60648 
60649  in_assets = sql_int ("SELECT not(value = 'no') FROM task_preferences"
60650  " WHERE task = (SELECT task FROM reports"
60651  " WHERE id = %llu)"
60652  " AND name = 'in_assets';",
60653  report);
60654 
60655  details = entity->entities;
60656  if (identifiers == NULL)
60657  identifiers = make_array ();
60658  if (identifier_hosts == NULL)
60659  identifier_hosts = make_array ();
60660  uuid = report_uuid (report);
60661  while ((detail = first_entity (details)))
60662  {
60663  if (strcmp (entity_name (detail), "detail") == 0)
60664  {
60665  entity_t source, source_type, source_name, source_desc, name, value;
60666 
60667  /* Parse host detail and add to report */
60668  source = entity_child (detail, "source");
60669  if (source == NULL)
60670  goto error;
60671  source_type = entity_child (source, "type");
60672  if (source_type == NULL)
60673  goto error;
60674  source_name = entity_child (source, "name");
60675  if (source_name == NULL)
60676  goto error;
60677  source_desc = entity_child (source, "description");
60678  if (source_desc == NULL)
60679  goto error;
60680  name = entity_child (detail, "name");
60681  if (name == NULL)
60682  goto error;
60683  value = entity_child (detail, "value");
60684  if (value == NULL)
60685  goto error;
60687  (report, ip, entity_text (source_type), entity_text (source_name),
60688  entity_text (source_desc), entity_text (name), entity_text (value));
60689 
60690  /* Only add to assets if "Add to Assets" is set on the task. */
60691  if (in_assets)
60692  {
60693  if (strcmp (entity_text (name), "hostname") == 0)
60694  {
60695  identifier_t *identifier;
60696 
60697  identifier = g_malloc (sizeof (identifier_t));
60698  identifier->ip = g_strdup (ip);
60699  identifier->name = g_strdup ("hostname");
60700  identifier->value = g_strdup (entity_text (value));
60701  identifier->source_id = g_strdup (uuid);
60702  identifier->source_type = g_strdup ("Report Host Detail");
60703  identifier->source_data
60704  = g_strdup (entity_text (source_name));
60705  array_add (identifiers, identifier);
60706  array_add_new_string (identifier_hosts, g_strdup (ip));
60707  }
60708  if (strcmp (entity_text (name), "MAC") == 0)
60709  {
60710  identifier_t *identifier;
60711 
60712  identifier = g_malloc (sizeof (identifier_t));
60713  identifier->ip = g_strdup (ip);
60714  identifier->name = g_strdup ("MAC");
60715  identifier->value = g_strdup (entity_text (value));
60716  identifier->source_id = g_strdup (uuid);
60717  identifier->source_type = g_strdup ("Report Host Detail");
60718  identifier->source_data
60719  = g_strdup (entity_text (source_name));
60720  array_add (identifiers, identifier);
60721  array_add_new_string (identifier_hosts, g_strdup (ip));
60722  }
60723  if (strcmp (entity_text (name), "DNS-via-TargetDefinition") == 0)
60724  {
60725  identifier_t *identifier;
60726 
60727  identifier = g_malloc (sizeof (identifier_t));
60728  identifier->ip = g_strdup (ip);
60729  identifier->name = g_strdup ("DNS-via-TargetDefinition");
60730  identifier->value = g_strdup (entity_text (value));
60731  identifier->source_id = g_strdup (uuid);
60732  identifier->source_type = g_strdup ("Report Host Detail");
60733  identifier->source_data
60734  = g_strdup (entity_text (source_name));
60735  array_add (identifiers, identifier);
60736  array_add_new_string (identifier_hosts, g_strdup (ip));
60737  }
60738  if (strcmp (entity_text (name), "OS") == 0
60739  && g_str_has_prefix (entity_text (value), "cpe:"))
60740  {
60741  identifier_t *identifier;
60742 
60743  identifier = g_malloc (sizeof (identifier_t));
60744  identifier->ip = g_strdup (ip);
60745  identifier->name = g_strdup ("OS");
60746  identifier->value = g_strdup (entity_text (value));
60747  identifier->source_id = g_strdup (uuid);
60748  identifier->source_type = g_strdup ("Report Host Detail");
60749  identifier->source_data
60750  = g_strdup (entity_text (source_name));
60751  array_add (identifiers, identifier);
60752  array_add_new_string (identifier_hosts, g_strdup (ip));
60753  }
60754  if (strcmp (entity_text (name), "ssh-key") == 0)
60755  {
60756  identifier_t *identifier;
60757 
60758  identifier = g_malloc (sizeof (identifier_t));
60759  identifier->ip = g_strdup (ip);
60760  identifier->name = g_strdup ("ssh-key");
60761  identifier->value = g_strdup (entity_text (value));
60762  identifier->source_id = g_strdup (uuid);
60763  identifier->source_type = g_strdup ("Report Host Detail");
60764  identifier->source_data
60765  = g_strdup (entity_text (source_name));
60766  array_add (identifiers, identifier);
60767  array_add_new_string (identifier_hosts, g_strdup (ip));
60768  }
60769  }
60770  }
60771  details = next_entities (details);
60772  }
60773  free (uuid);
60774 
60775  return 0;
60776 
60777  error:
60778  free (uuid);
60779  return -1;
60780 }
Host identifier type.
Definition: manage_sql.c:60090
gchar * source_type
Type of identifier source, like "Report Host".
Definition: manage_sql.c:60095
char * report_uuid(report_t report)
Return the UUID of a report.
Definition: manage_sql.c:21382
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
gchar * value
Value of identifier.
Definition: manage_sql.c:60094
void insert_report_host_detail(report_t report, const char *host, const char *s_type, const char *s_name, const char *s_desc, const char *name, const char *value)
Insert a host detail into a report.
Definition: manage_sql.c:21054
array_t * identifiers
Host identifiers for the current scan.
Definition: manage_sql.c:60080
gchar * ip
IP of host.
Definition: manage_sql.c:60092
array_t * identifier_hosts
Unique hosts listed in host_identifiers.
Definition: manage_sql.c:60085
gchar * name
Name of identifier, like "hostname".
Definition: manage_sql.c:60093
gchar * source_id
ID of source.
Definition: manage_sql.c:60096
gchar * source_data
Extra data for source.
Definition: manage_sql.c:60097
void array_add_new_string(array_t *array, const gchar *string)
Ensure a string is in an array.
Definition: manage_sql.c:710
Here is the call graph for this function:
Here is the caller graph for this function:

◆ manage_session_init()

void manage_session_init ( const char *  uuid)

Setup session.

Parameters
[in]uuidUser UUID.

Definition at line 46 of file manage_pg.c.

References sql().

Referenced by acl_users_with_access_sql(), manage_schedule(), and report_cache_counts().

47 {
48  sql ("CREATE TEMPORARY TABLE IF NOT EXISTS current_credentials"
49  " (id SERIAL PRIMARY KEY,"
50  " uuid text UNIQUE NOT NULL,"
51  " tz_override text);");
52  sql ("DELETE FROM current_credentials;");
53  if (uuid)
54  sql ("INSERT INTO current_credentials (uuid) VALUES ('%s');", uuid);
55 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
Here is the call graph for this function:
Here is the caller graph for this function:

◆ manage_update_nvti_cache()

int manage_update_nvti_cache ( )

Update the memory cache of NVTs, if this has been requested.

Returns
0 success, 1 failed to get lock, -1 error.

Definition at line 14475 of file manage_sql.c.

References sql_begin_immediate_giveup(), sql_int(), and sql_schema().

Referenced by manage_schedule().

14476 {
14477  int ret;
14478 
14479  ret = sql_begin_immediate_giveup ();
14480  if (ret)
14481  return ret;
14482  if (sql_int ("SELECT value FROM %s.meta"
14483  " WHERE name = 'update_nvti_cache';",
14484  sql_schema ()))
14485  {
14486  update_nvti_cache ();
14487  sql ("UPDATE %s.meta SET value = 0 WHERE name = 'update_nvti_cache';",
14488  sql_schema ());
14489  }
14490  sql_commit ();
14491  return 0;
14492 }
const char * sql_schema()
Get main schema name.
Definition: sql_pg.c:103
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
int sql_begin_immediate_giveup()
Begin an immediate transaction.
Definition: sql_pg.c:639
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:649
Here is the call graph for this function:
Here is the caller graph for this function:

◆ otp_pref_iterator_name()

const char* otp_pref_iterator_name ( iterator_t )

◆ otp_pref_iterator_value()

const char* otp_pref_iterator_value ( iterator_t )

◆ parse_iso_time()

int parse_iso_time ( const char *  text_time)

Convert an ISO time into seconds since epoch.

For backward compatibility, if the conversion fails try parse in ctime format.

Parameters
[in]text_timeTime as text in ISO format: 2011-11-03T09:23:28+02:00.
Returns
Time since epoch. 0 on error.

Definition at line 875 of file manage_sql.c.

Referenced by manage_system_report(), set_scan_end_time(), set_scan_host_end_time(), set_scan_host_start_time(), set_scan_start_time(), set_task_end_time(), and set_task_start_time().

876 {
877  int epoch_time;
878  struct tm tm;
879 
880  memset (&tm, 0, sizeof (struct tm));
881  tm.tm_isdst = -1;
882  if (strptime ((char*) text_time, "%FT%T%z", &tm) == NULL)
883  {
884  gchar *tz;
885 
886  memset (&tm, 0, sizeof (struct tm));
887  tm.tm_isdst = -1;
888  if (strptime ((char*) text_time, "%FT%TZ", &tm) == NULL)
889  {
890  /* Try time without timezone suffix, applying timezone of user */
891 
892  memset (&tm, 0, sizeof (struct tm));
893  tm.tm_isdst = -1;
894  if (strptime ((char*) text_time, "%FT%T", &tm) == NULL)
895  return parse_ctime (text_time);
896 
897  /* Store current TZ. */
898  tz = getenv ("TZ") ? g_strdup (getenv ("TZ")) : NULL;
899 
900  if (setenv ("TZ", current_credentials.timezone, 1) == -1)
901  {
902  g_warning ("%s: Failed to switch to timezone %s",
903  __FUNCTION__, current_credentials.timezone);
904  if (tz != NULL)
905  setenv ("TZ", tz, 1);
906  g_free (tz);
907  return 0;
908  }
909 
910  memset (&tm, 0, sizeof (struct tm));
911  tm.tm_isdst = -1;
912  if (strptime ((char*) text_time, "%FT%T", &tm) == NULL)
913  {
914  assert (0);
915  g_warning ("%s: Failed to parse time", __FUNCTION__);
916  if (tz != NULL)
917  setenv ("TZ", tz, 1);
918  g_free (tz);
919  return 0;
920  }
921  }
922  else
923  {
924  /* Time has "Z" suffix for UTC */
925 
926  /* Store current TZ. */
927  tz = getenv ("TZ") ? g_strdup (getenv ("TZ")) : NULL;
928 
929  if (setenv ("TZ", "UTC", 1) == -1)
930  {
931  g_warning ("%s: Failed to switch to UTC", __FUNCTION__);
932  if (tz != NULL)
933  setenv ("TZ", tz, 1);
934  g_free (tz);
935  return 0;
936  }
937 
938  memset (&tm, 0, sizeof (struct tm));
939  tm.tm_isdst = -1;
940  if (strptime ((char*) text_time, "%FT%TZ", &tm) == NULL)
941  {
942  assert (0);
943  g_warning ("%s: Failed to parse time", __FUNCTION__);
944  if (tz != NULL)
945  setenv ("TZ", tz, 1);
946  g_free (tz);
947  return 0;
948  }
949  }
950 
951  epoch_time = mktime (&tm);
952  if (epoch_time == -1)
953  {
954  g_warning ("%s: Failed to make time", __FUNCTION__);
955  if (tz != NULL)
956  setenv ("TZ", tz, 1);
957  g_free (tz);
958  return 0;
959  }
960 
961  /* Revert to stored TZ. */
962  if (tz)
963  {
964  if (setenv ("TZ", tz, 1) == -1)
965  {
966  g_warning ("%s: Failed to switch to original TZ", __FUNCTION__);
967  g_free (tz);
968  return 0;
969  }
970  }
971  else
972  unsetenv ("TZ");
973 
974  g_free (tz);
975  }
976  else
977  {
978  gchar *tz, *new_tz;
979  int offset_hour, offset_minute;
980  char sign;
981 
982  /* Get the timezone offset from the string. */
983 
984  if (sscanf ((char*) text_time,
985  "%*u-%*u-%*uT%*u:%*u:%*u%[-+]%d:%d",
986  &sign, &offset_hour, &offset_minute)
987  != 3)
988  {
989  /* Perhaps %z is an acronym like "CEST". Assume it's local time. */
990  epoch_time = mktime (&tm);
991  if (epoch_time == -1)
992  {
993  g_warning ("%s: Failed to make time", __FUNCTION__);
994  return 0;
995  }
996  return epoch_time;
997  }
998 
999  /* Store current TZ. */
1000 
1001  tz = getenv ("TZ") ? g_strdup (getenv ("TZ")) : NULL;
1002 
1003  /* Switch to the timezone in the time string. */
1004 
1005  new_tz = g_strdup_printf ("UTC%c%d:%d",
1006  sign == '-' ? '+' : '-',
1007  offset_hour,
1008  offset_minute);
1009  if (setenv ("TZ", new_tz, 1) == -1)
1010  {
1011  g_warning ("%s: Failed to switch to %s", __FUNCTION__, new_tz);
1012  g_free (new_tz);
1013  if (tz != NULL)
1014  setenv ("TZ", tz, 1);
1015  g_free (tz);
1016  return 0;
1017  }
1018  g_free (new_tz);
1019 
1020  /* Parse time again under the new timezone. */
1021 
1022  memset (&tm, 0, sizeof (struct tm));
1023  tm.tm_isdst = -1;
1024  if (strptime ((char*) text_time, "%FT%T%z", &tm) == NULL)
1025  {
1026  assert (0);
1027  g_warning ("%s: Failed to parse time", __FUNCTION__);
1028  if (tz != NULL)
1029  setenv ("TZ", tz, 1);
1030  g_free (tz);
1031  return 0;
1032  }
1033 
1034  epoch_time = mktime (&tm);
1035  if (epoch_time == -1)
1036  {
1037  g_warning ("%s: Failed to make time", __FUNCTION__);
1038  if (tz != NULL)
1039  setenv ("TZ", tz, 1);
1040  g_free (tz);
1041  return 0;
1042  }
1043 
1044  /* Revert to stored TZ. */
1045  if (tz)
1046  {
1047  if (setenv ("TZ", tz, 1) == -1)
1048  {
1049  g_warning ("%s: Failed to switch to original TZ", __FUNCTION__);
1050  g_free (tz);
1051  return 0;
1052  }
1053  }
1054  else
1055  unsetenv ("TZ");
1056 
1057  g_free (tz);
1058  }
1059 
1060  return epoch_time;
1061 }
credentials_t current_credentials
Current credentials during any OMP command.
Definition: manage.c:717
Here is the caller graph for this function:

◆ parse_osp_report()

void parse_osp_report ( task_t  task,
report_t  report,
const char *  report_xml 
)

Parse an OSP report.

Parameters
[in]taskTask.
[in]reportReport.
[in]report_xmlReport XML.

Definition at line 31533 of file manage_sql.c.

References result_buffer::host, insert_report_host_detail(), make_osp_result(), manage_report_host_add(), nvt_severity(), ovaldef_severity(), ovaldef_uuid(), result_buffer::port, QOD_DEFAULT, report_add_result(), set_scan_end_time_epoch(), set_scan_start_time_epoch(), result_buffer::severity, sql_begin_immediate(), sql_commit(), and task_definitions_file().

31534 {
31535  entity_t entity, child;
31536  entities_t results;
31537  const char *str;
31538  char *defs_file = NULL;
31539  time_t start_time, end_time;
31540 
31541  assert (task);
31542  assert (report);
31543  assert (report_xml);
31544 
31545  if (parse_entity (report_xml, &entity))
31546  {
31547  g_warning ("Couldn't parse %s OSP scan report\n", report_xml);
31548  return;
31549  }
31550 
31552  /* Set the report's start and end times. */
31553  str = entity_attribute (entity, "start_time");
31554  if (!str)
31555  {
31556  g_warning ("Missing start_time in OSP report %s", report_xml);
31557  goto end_parse_osp_report;
31558  }
31559  start_time = atoi (str);
31560  set_scan_start_time_epoch (report, start_time);
31561  str = entity_attribute (entity, "end_time");
31562  if (!str)
31563  {
31564  g_warning ("Missing end_time in OSP report %s", report_xml);
31565  goto end_parse_osp_report;
31566  }
31567  end_time = atoi (str);
31568  set_scan_end_time_epoch (report, end_time);
31569 
31570  /* Insert results. */
31571  child = entity_child (entity, "results");
31572  if (!child)
31573  {
31574  g_warning ("Missing results element in OSP report %s", report_xml);
31575  goto end_parse_osp_report;
31576  }
31577  results = child->entities;
31578  defs_file = task_definitions_file (task);
31579  while (results)
31580  {
31581  result_t result;
31582  const char *type, *name, *severity, *host, *test_id, *port, *qod;
31583  char *desc = NULL, *nvt_id = NULL, *severity_str = NULL;
31584  entity_t r_entity = results->data;
31585  int qod_int;
31586 
31587  if (strcmp (entity_name (r_entity), "result"))
31588  {
31589  g_warning ("Erroneous entry in OSP results %s",
31590  entity_name (r_entity));
31591  results = next_entities (results);
31592  continue;
31593  }
31594  type = entity_attribute (r_entity, "type");
31595  name = entity_attribute (r_entity, "name");
31596  severity = entity_attribute (r_entity, "severity");
31597  test_id = entity_attribute (r_entity, "test_id");
31598  host = entity_attribute (r_entity, "host");
31599  port = entity_attribute (r_entity, "port") ?: "";
31600  qod = entity_attribute (r_entity, "qod") ?: "";
31601  if (!name || !type || !severity || !test_id || !host)
31602  {
31603  GString *string = g_string_new ("");
31604 
31605  print_entity_to_string (r_entity, string);
31606  g_warning ("Erroneous attribute in OSP result %s", string->str);
31607  g_string_free (string, TRUE);
31608  results = next_entities (results);
31609  continue;
31610  }
31611 
31612  /* Add report host if it doesn't exist. */
31613  manage_report_host_add (report, host, start_time, end_time);
31614  if (!strcmp (type, "Host Detail"))
31615  {
31616  insert_report_host_detail (report, host, "osp", "", "OSP Host Detail",
31617  name, entity_text (r_entity));
31618  results = next_entities (results);
31619  continue;
31620  }
31621  else if (g_str_has_prefix (test_id, "1.3.6.1.4.1.25623.1.0."))
31622  {
31623  nvt_id = g_strdup (test_id);
31624  severity_str = nvt_severity (test_id, type);
31625  desc = g_strdup (entity_text (r_entity));
31626  }
31627  else if (g_str_has_prefix (test_id, "oval:"))
31628  {
31629  nvt_id = ovaldef_uuid (test_id, defs_file);
31630  severity_str = ovaldef_severity (nvt_id);
31631  }
31632  else
31633  {
31634  nvt_id = g_strdup (name);
31635  desc = g_strdup (entity_text (r_entity));
31636  }
31637 
31638  qod_int = atoi (qod);
31639  if (qod_int <= 0 || qod_int > 100)
31640  qod_int = QOD_DEFAULT;
31641  result = make_osp_result (task, host, nvt_id, type, desc, port ?: "",
31642  severity_str ?: severity, qod_int);
31643  report_add_result (report, result);
31644  g_free (nvt_id);
31645  g_free (desc);
31646  g_free (severity_str);
31647  results = next_entities (results);
31648  }
31649 
31650  end_parse_osp_report:
31651  sql_commit ();
31652  g_free (defs_file);
31653  free_entity (entity);
31654 }
void insert_report_host_detail(report_t report, const char *host, const char *s_type, const char *s_name, const char *s_desc, const char *name, const char *value)
Insert a host detail into a report.
Definition: manage_sql.c:21054
char * ovaldef_severity(const char *id)
Get the severity of an OVALDEF using an ID.
Definition: manage_sql.c:64344
#define QOD_DEFAULT
Default quality of detection percentage.
Definition: manage.h:1105
char * ovaldef_uuid(const char *name, const char *fname)
Get the uuid for an OVALDEF from a name and file name.
Definition: manage_sql.c:64320
long long int result_t
Definition: manage.h:287
void set_scan_start_time_epoch(report_t report, time_t timestamp)
Set the start time of a scan.
Definition: manage_sql.c:24243
char * nvt_severity(const char *nvt_id, const char *type)
Get a severity string from an nvt and result type.
Definition: manage_sql.c:19859
void sql_begin_immediate()
Begin an immediate transaction.
Definition: sql_pg.c:627
report_host_t manage_report_host_add(report_t report, const char *host, time_t start, time_t end)
Add a report host.
Definition: manage_sql.c:60014
void set_scan_end_time_epoch(report_t report, time_t timestamp)
Set the end time of a scan.
Definition: manage_sql.c:24304
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:649
void report_add_result(report_t report, result_t result)
Add a result to a report.
Definition: manage_sql.c:21590
result_t make_osp_result(task_t task, const char *host, const char *nvt, const char *type, const char *description, const char *port, const char *severity, int qod)
Make an OSP result.
Definition: manage_sql.c:19565
char * task_definitions_file(task_t task)
Get definitions file from a task&#39;s config.
Definition: manage_sql.c:19468
Here is the call graph for this function:

◆ reinit_manage_process()

void reinit_manage_process ( )

Reinitialize the manage library for a process.

This is mandatory after a fork, to not carry open databases around (refer to database documentation).

Definition at line 14347 of file manage_sql.c.

References cleanup_manage_process(), init_manage_process(), and task_db_name.

Referenced by manage_schedule().

14348 {
14349  cleanup_manage_process (FALSE);
14351 }
void init_manage_process(int update_nvt_cache, const gchar *database)
Initialize the manage library for a process.
Definition: manage_sql.c:14303
gchar * task_db_name
Name of the database file.
Definition: manage_sql.c:403
void cleanup_manage_process(gboolean cleanup)
Cleanup the manage library.
Definition: manage_sql.c:17128
Here is the call graph for this function:
Here is the caller graph for this function:

◆ report_host_ip()

char* report_host_ip ( const char *  host)

Get the IP of a host, using the 'hostname' report host details.

The most recent host detail takes preference.

Parameters
[in]hostHost name or IP.
Returns
Newly allocated UUID if available, else NULL.

Definition at line 31487 of file manage_sql.c.

References sql_quote(), and sql_string().

31488 {
31489  gchar *quoted_host, *ret;
31490  quoted_host = sql_quote (host);
31491  ret = sql_string ("SELECT host FROM report_hosts"
31492  " WHERE id = (SELECT report_host FROM report_host_details"
31493  " WHERE name = 'hostname'"
31494  " AND value = '%s'"
31495  " ORDER BY id DESC LIMIT 1);",
31496  quoted_host);
31497  g_free (quoted_host);
31498  return ret;
31499 }
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:469
Here is the call graph for this function:

◆ reschedule_task()

void reschedule_task ( const gchar *  task_id)

Set a task's schedule so that it runs again next scheduling round.

Parameters
task_idUUID of task.

Definition at line 19482 of file manage_sql.c.

References set_task_schedule_next_time(), and sql_int64().

Referenced by manage_schedule().

19483 {
19484  task_t task;
19485  task = 0;
19486  switch (sql_int64 (&task,
19487  "SELECT id FROM tasks WHERE uuid = '%s'"
19488  " AND hidden != 2;",
19489  task_id))
19490  {
19491  case 0:
19492  g_warning ("%s: rescheduling task '%s'\n", __FUNCTION__, task_id);
19493  set_task_schedule_next_time (task, time (NULL) - 1);
19494  break;
19495  case 1: /* Too few rows in result of query. */
19496  break;
19497  default: /* Programming error. */
19498  assert (0);
19499  case -1:
19500  break;
19501  }
19502 }
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:501
unsigned int task_id(task_t task)
Return the identifier of a task.
Definition: manage_sql.c:17869
void set_task_schedule_next_time(task_t task, time_t time)
Set the next time a scheduled task will be due.
Definition: manage_sql.c:19058
long long int task_t
Definition: manage.h:286
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resource_uuid()

gchar* resource_uuid ( const gchar *  type,
resource_t  resource 
)

Get the UUID of a resource.

Parameters
[in]typeType.
[in]resourceResource.
Returns
Freshly allocated UUID on success, else NULL.

Definition at line 4971 of file manage_sql.c.

References sql_string(), and valid_db_resource_type().

4972 {
4973  assert (valid_db_resource_type (type));
4974 
4975  return sql_string ("SELECT uuid FROM %ss WHERE id = %llu;",
4976  type,
4977  resource);
4978 }
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:469
int valid_db_resource_type(const char *)
Check whether a resource type table name is valid.
Definition: manage_utils.c:504
Here is the call graph for this function:

◆ run_status_name_internal()

const char* run_status_name_internal ( task_status_t  status)

Get the unique name of a run status.

Parameters
[in]statusRun status.
Returns
The name of the status (for example, "Done" or "Running").

Definition at line 1288 of file manage.c.

References TASK_STATUS_DELETE_REQUESTED, TASK_STATUS_DELETE_ULTIMATE_REQUESTED, TASK_STATUS_DELETE_ULTIMATE_WAITING, TASK_STATUS_DELETE_WAITING, TASK_STATUS_DONE, TASK_STATUS_NEW, TASK_STATUS_REQUESTED, TASK_STATUS_RUNNING, TASK_STATUS_STOP_REQUESTED, TASK_STATUS_STOP_REQUESTED_GIVEUP, TASK_STATUS_STOP_WAITING, and TASK_STATUS_STOPPED.

1289 {
1290  switch (status)
1291  {
1292  case TASK_STATUS_DELETE_REQUESTED: return "Delete Requested";
1294  return "Ultimate Delete Requested";
1296  return "Ultimate Delete Waiting";
1297  case TASK_STATUS_DELETE_WAITING: return "Delete Waiting";
1298  case TASK_STATUS_DONE: return "Done";
1299  case TASK_STATUS_NEW: return "New";
1300 
1301  case TASK_STATUS_REQUESTED: return "Requested";
1302 
1303  case TASK_STATUS_RUNNING: return "Running";
1304 
1307  return "Stop Requested";
1308 
1310  return "Stop Waiting";
1311 
1312  case TASK_STATUS_STOPPED: return "Stopped";
1313  default: return "Internal Error";
1314  }
1315 }

◆ set_report_scan_run_status()

int set_report_scan_run_status ( report_t  report,
task_status_t  status 
)

Return the run status of the scan associated with a report.

Parameters
[in]reportReport.
[out]statusScan run status.
Returns
0 on success, -1 on error.

Definition at line 24512 of file manage_sql.c.

References report_cache_counts(), setting_auto_cache_rebuild_int(), and sql().

24513 {
24514  sql ("UPDATE reports SET scan_run_status = %u WHERE id = %llu;",
24515  status,
24516  report);
24518  report_cache_counts (report, 0, 0, NULL);
24519  return 0;
24520 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
int setting_auto_cache_rebuild_int()
Return the Auto Cache Rebuild user setting as an int.
Definition: manage_sql.c:62173
void report_cache_counts(report_t report, int clear_original, int clear_overridden, const char *users_where)
Cache report counts and clear existing caches if requested.
Definition: manage_sql.c:20879
Here is the call graph for this function:

◆ set_report_scheduled()

void set_report_scheduled ( report_t  report)

Set a report's scheduled flag.

Set flag if task was scheduled, else clear flag.

Parameters
[in]reportReport.

Definition at line 18252 of file manage_sql.c.

References authenticate_allow_all, and sql().

Referenced by create_current_report().

18253 {
18254  if (authenticate_allow_all == 1)
18255  /* The task was scheduled. */
18256  sql ("UPDATE reports SET flags = 1 WHERE id = %llu;",
18257  report);
18258  else
18259  sql ("UPDATE reports SET flags = 0 WHERE id = %llu;",
18260  report);
18261 }
int authenticate_allow_all
Flag to force authentication to succeed.
Definition: manage_sql.c:120
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_report_slave_progress()

int set_report_slave_progress ( report_t  report,
int  progress 
)

Set slave progress of a report.

Parameters
[in]reportThe report.
[in]progressThe new progress value.
Returns
0 success.

Definition at line 25451 of file manage_sql.c.

References sql().

Referenced by update_slave_progress().

25452 {
25453  sql ("UPDATE reports SET slave_progress = %i WHERE id = %llu;",
25454  progress,
25455  report);
25456  return 0;
25457 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
void(* progress)()
Function to mark progress.
Definition: manage_sql.c:352
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_report_slave_task_uuid()

void set_report_slave_task_uuid ( report_t  report,
const char *  uuid 
)

Set the UUID of the slave task, on the local task.

Parameters
[in]reportThe report.
[in]uuidUUID.

Definition at line 25486 of file manage_sql.c.

References sql(), and sql_quote().

25487 {
25488  gchar *quoted_uuid = sql_quote (uuid);
25489  sql ("UPDATE reports SET slave_task_uuid = '%s' WHERE id = %llu;",
25490  quoted_uuid,
25491  report);
25492  g_free (quoted_uuid);
25493 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
Here is the call graph for this function:

◆ set_task_requested()

int set_task_requested ( task_t  task,
task_status_t status 
)

Atomically set the run state of a task to requested.

Parameters
[in]taskTask.
[out]statusOld run status of task.
Returns
0 success, 1 task is active already.

Definition at line 18336 of file manage_sql.c.

References set_task_run_status(), sql_begin_exclusive(), sql_commit(), task_run_status(), TASK_STATUS_DELETE_REQUESTED, TASK_STATUS_DELETE_ULTIMATE_REQUESTED, TASK_STATUS_DELETE_ULTIMATE_WAITING, TASK_STATUS_DELETE_WAITING, TASK_STATUS_REQUESTED, TASK_STATUS_RUNNING, TASK_STATUS_STOP_REQUESTED, TASK_STATUS_STOP_REQUESTED_GIVEUP, and TASK_STATUS_STOP_WAITING.

18337 {
18338  task_status_t run_status;
18339 
18341 
18342  run_status = task_run_status (task);
18343  if (run_status == TASK_STATUS_REQUESTED
18344  || run_status == TASK_STATUS_RUNNING
18345  || run_status == TASK_STATUS_STOP_REQUESTED
18346  || run_status == TASK_STATUS_STOP_REQUESTED_GIVEUP
18347  || run_status == TASK_STATUS_STOP_WAITING
18348  || run_status == TASK_STATUS_DELETE_REQUESTED
18349  || run_status == TASK_STATUS_DELETE_ULTIMATE_REQUESTED
18350  || run_status == TASK_STATUS_DELETE_ULTIMATE_WAITING
18351  || run_status == TASK_STATUS_DELETE_WAITING)
18352  {
18353  sql_commit ();
18354  *status = run_status;
18355  return 1;
18356  }
18357 
18359 
18360  sql_commit ();
18361 
18362  *status = run_status;
18363  return 0;
18364 }
task_status_t
Task statuses, also used as scan/report statuses.
Definition: manage.h:218
void sql_begin_exclusive()
Begin an exclusive transaction.
Definition: sql_pg.c:598
task_status_t task_run_status(task_t task)
Return the run state of a task.
Definition: manage_sql.c:18238
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:649
void set_task_run_status(task_t task, task_status_t status)
Set the run state of a task.
Definition: manage_sql.c:18307
Here is the call graph for this function:

◆ set_task_schedule_next_time()

void set_task_schedule_next_time ( task_t  task,
time_t  time 
)

Set the next time a scheduled task will be due.

Parameters
[in]taskTask.
[in]timeNew next time.

Definition at line 19058 of file manage_sql.c.

References sql().

Referenced by manage_schedule(), and reschedule_task().

19059 {
19060  sql ("UPDATE tasks SET schedule_next_time = %i WHERE id = %llu;",
19061  time, task);
19062 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_task_schedule_next_time_uuid()

void set_task_schedule_next_time_uuid ( const gchar *  task_id,
time_t  time 
)

Set the next time a scheduled task will be due.

Parameters
[in]task_idTask UUID.
[in]timeNew next time.

Definition at line 19071 of file manage_sql.c.

References sql(), and sql_quote().

Referenced by manage_schedule().

19072 {
19073  gchar *quoted_task_id;
19074 
19075  quoted_task_id = sql_quote (task_id);
19076  sql ("UPDATE tasks SET schedule_next_time = %i WHERE uuid = '%s';",
19077  time, quoted_task_id);
19078  g_free (quoted_task_id);
19079 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
unsigned int task_id(task_t task)
Return the identifier of a task.
Definition: manage_sql.c:17869
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_task_schedule_uuid()

int set_task_schedule_uuid ( const gchar *  task_id,
schedule_t  schedule,
int  periods 
)

Set the schedule of a task.

Parameters
[in]task_idTask UUID.
[in]scheduleSchedule.
[in]periodsNumber of schedule periods.
Returns
0 success, -1 error.

Definition at line 18836 of file manage_sql.c.

References sql(), and sql_quote().

Referenced by manage_schedule().

18837 {
18838  gchar *quoted_task_id;
18839 
18840  quoted_task_id = sql_quote (task_id);
18841  sql ("UPDATE tasks"
18842  " SET schedule = %llu,"
18843  " schedule_periods = %i,"
18844  " schedule_next_time = (SELECT next_time (first_time,"
18845  " period,"
18846  " period_months,"
18847  " timezone)"
18848  " FROM schedules"
18849  " WHERE id = %llu),"
18850  " modification_time = m_now ()"
18851  " WHERE uuid = '%s';",
18852  schedule, periods, schedule, quoted_task_id);
18853  g_free (quoted_task_id);
18854 
18855  return 0;
18856 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
gchar * sql_quote(const char *string)
Quotes a string to be passed to sql statements.
Definition: sql.c:121
unsigned int task_id(task_t task)
Return the identifier of a task.
Definition: manage_sql.c:17869
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tag_value()

gchar* tag_value ( const gchar *  tags,
const gchar *  tag 
)

Extract a tag from an OTP tag list.

Parameters
[in]tagsTag list.
[out]tagTag name.
Returns
Newly allocated tag value.

Definition at line 1269 of file manage_sql.c.

1270 {
1271  gchar **split, **point;
1272 
1273  /* creation_date=2009-04-09 14:18:58 +0200 (Thu, 09 Apr 2009)|... */
1274 
1275  if (tags == NULL)
1276  return g_strdup ("");
1277 
1278  split = g_strsplit (tags, "|", 0);
1279  point = split;
1280 
1281  while (*point)
1282  {
1283  if ((strlen (*point) > strlen (tag))
1284  && (strncmp (*point, tag, strlen (tag)) == 0)
1285  && ((*point)[strlen (tag)] == '='))
1286  {
1287  gchar *ret;
1288  ret = g_strdup (*point + strlen (tag) + 1);
1289  g_strfreev (split);
1290  return ret;
1291  }
1292  point++;
1293  }
1294  g_strfreev (split);
1295  return g_strdup ("");
1296 }

◆ target_alive_tests()

alive_test_t target_alive_tests ( target_t  target)

Return a target's alive tests.

Parameters
[in]targetTarget.
Returns
Alive test bitfield.

Definition at line 35087 of file manage_sql.c.

References sql_int().

35088 {
35089  return sql_int ("SELECT alive_test FROM targets WHERE id = %llu;",
35090  target);
35091 }
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
Here is the call graph for this function:

◆ target_esxi_credential()

credential_t target_esxi_credential ( target_t  target)

Return the ESXi credential associated with a target, if any.

Parameters
[in]targetTarget.
Returns
ESXi credential if any, else 0.

Definition at line 34983 of file manage_sql.c.

References target_credential().

34984 {
34985  return target_credential (target, "esxi");
34986 }
credential_t target_credential(target_t target, const char *type)
Get a credential from a target.
Definition: manage_sql.c:33168
Here is the call graph for this function:

◆ target_port_list()

port_list_t target_port_list ( target_t  target)

Return the port list associated with a target, if any.

Parameters
[in]targetTarget.
Returns
Port list
Todo:
Move return to arg; return -1.

Definition at line 34996 of file manage_sql.c.

References sql_int64().

Referenced by target_port_range().

34997 {
34998  port_list_t port_list;
34999 
35000  switch (sql_int64 (&port_list,
35001  "SELECT port_list FROM targets"
35002  " WHERE id = %llu;",
35003  target))
35004  {
35005  case 0:
35006  break;
35007  case 1: /* Too few rows in result of query. */
35008  return 0;
35009  break;
35010  default: /* Programming error. */
35011  assert (0);
35012  case -1:
35014  return 0;
35015  break;
35016  }
35017  return port_list;
35018 }
int sql_int64(long long int *ret, char *sql,...)
Get a particular cell from a SQL query, as an int64.
Definition: sql.c:501
long long int port_list_t
Definition: manage.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ target_port_range()

char* target_port_range ( target_t  target)

Return the port range of a target, in OTP format.

For "OpenVAS Default", return the explicit port ranges instead of "default".

Parameters
[in]targetTarget.
Returns
Newly allocated port range if available, else NULL.

Definition at line 35030 of file manage_sql.c.

References cleanup_iterator(), init_port_range_iterator(), next(), port_range_iterator_end(), port_range_iterator_start(), port_range_iterator_type_int(), and target_port_list().

35031 {
35032  GString *range;
35033  iterator_t ranges;
35034  range = g_string_new ("");
35035  init_port_range_iterator (&ranges, target_port_list (target), 0, 1,
35036  "type, CAST (start AS INTEGER)");
35037  if (next (&ranges))
35038  {
35039  const char *start, *end;
35040  int type;
35041 
35042  start = port_range_iterator_start (&ranges);
35043  end = port_range_iterator_end (&ranges);
35044  type = port_range_iterator_type_int (&ranges);
35045 
35046  /* Scanner can only handle: T:1-3,5-6,9,U:1-2 */
35047 
35048  if (end && strcmp (end, "0") && strcmp (end, start))
35049  g_string_append_printf (range, "%s%s-%s",
35050  (type == PORT_PROTOCOL_UDP ? "U:" : "T:"),
35051  start, end);
35052  else
35053  g_string_append_printf (range, "%s%s",
35054  (type == PORT_PROTOCOL_UDP ? "U:" : "T:"),
35055  start);
35056  while (next (&ranges))
35057  {
35058  int tcp;
35059 
35060  start = port_range_iterator_start (&ranges);
35061  end = port_range_iterator_end (&ranges);
35062  tcp = (type == PORT_PROTOCOL_TCP);
35063  type = port_range_iterator_type_int (&ranges);
35064 
35065  if (end && strcmp (end, "0") && strcmp (end, start))
35066  g_string_append_printf (range, ",%s%s-%s",
35067  (tcp && type == PORT_PROTOCOL_UDP ? "U:" : ""),
35068  start, end);
35069  else
35070  g_string_append_printf (range, ",%s%s",
35071  (tcp && type == PORT_PROTOCOL_UDP ? "U:" : ""),
35072  start);
35073  }
35074  }
35075  cleanup_iterator (&ranges);
35076  return g_string_free (range, FALSE);
35077 }
void init_port_range_iterator(iterator_t *iterator, port_list_t port_list, int trash, int ascending, const char *sort_field)
Initialise a port_range iterator.
Definition: manage_sql.c:56790
port_list_t target_port_list(target_t target)
Return the port list associated with a target, if any.
Definition: manage_sql.c:34996
port_protocol_t port_range_iterator_type_int(iterator_t *iterator)
Get the type from a port range iterator.
Definition: manage_sql.c:56925
A generic SQL iterator.
Definition: iterator.h:52
const char * port_range_iterator_start(iterator_t *)
const char * port_range_iterator_end(iterator_t *)
void cleanup_iterator(iterator_t *)
Cleanup an iterator.
Definition: sql.c:664
gboolean next(iterator_t *)
Increment an iterator.
Definition: sql.c:689
Here is the call graph for this function:

◆ target_smb_credential()

credential_t target_smb_credential ( target_t  target)

Return the SMB credential associated with a target, if any.

Parameters
[in]targetTarget.
Returns
SMB credential if any, else 0.

Definition at line 34970 of file manage_sql.c.

References target_credential().

34971 {
34972  return target_credential (target, "smb");
34973 }
credential_t target_credential(target_t target, const char *type)
Get a credential from a target.
Definition: manage_sql.c:33168
Here is the call graph for this function:

◆ target_ssh_credential()

credential_t target_ssh_credential ( target_t  target)

Return the SSH credential associated with a target, if any.

Parameters
[in]targetTarget.
Returns
SSH credential if any, else 0.

Definition at line 34957 of file manage_sql.c.

References target_credential().

34958 {
34959  return target_credential (target, "ssh");
34960 }
credential_t target_credential(target_t target, const char *type)
Get a credential from a target.
Definition: manage_sql.c:33168
Here is the call graph for this function:

◆ task_definitions_file()

char* task_definitions_file ( task_t  task)

Get definitions file from a task's config.

Parameters
[in]taskTask.
Returns
Definitions file.

Definition at line 19468 of file manage_sql.c.

References sql_string(), and task_config().

Referenced by parse_osp_report().

19469 {
19470  assert (task);
19471  return sql_string ("SELECT value FROM config_preferences"
19472  " WHERE name = 'definitions_file' AND config = %llu;",
19473  task_config (task));
19474 }
config_t task_config(task_t task)
Return the config of a task.
Definition: manage_sql.c:18016
char * sql_string(char *sql,...)
Get a particular cell from a SQL query, as an string.
Definition: sql.c:469
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_file_iterator_content()

const char* task_file_iterator_content ( iterator_t )

◆ task_file_iterator_name()

const char* task_file_iterator_name ( iterator_t )

◆ task_schedule_iterator_duration()

time_t task_schedule_iterator_duration ( iterator_t iterator)

Get the duration from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
Duration.

Definition at line 49449 of file manage_sql.c.

References iterator::done, and iterator_int64().

Referenced by task_schedule_iterator_stop_due(), and task_schedule_iterator_timed_out().

49450 {
49451  if (iterator->done) return 0;
49452  return (time_t) iterator_int64 (iterator, 7);
49453 }
gboolean done
End flag.
Definition: iterator.h:55
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_first_time()

time_t task_schedule_iterator_first_time ( iterator_t iterator)

Get the first time from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
First time.

Definition at line 49435 of file manage_sql.c.

References iterator::done, and iterator_int64().

Referenced by manage_schedule(), and task_schedule_iterator_stop_due().

49436 {
49437  if (iterator->done) return 0;
49438  return (time_t) iterator_int64 (iterator, 6);
49439 }
gboolean done
End flag.
Definition: iterator.h:55
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_initial_offset()

time_t task_schedule_iterator_initial_offset ( iterator_t iterator)

Get the initial offset from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
Initial offset.

Definition at line 49493 of file manage_sql.c.

References iterator::done, and iterator_int64().

49494 {
49495  if (iterator->done) return 0;
49496  return (time_t) iterator_int64 (iterator, 11);
49497 }
gboolean done
End flag.
Definition: iterator.h:55
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:

◆ task_schedule_iterator_next_time()

time_t task_schedule_iterator_next_time ( iterator_t iterator)

Get the next time from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
Next time.

Definition at line 49393 of file manage_sql.c.

References iterator::done, and iterator_int64().

Referenced by task_schedule_iterator_start_due(), and task_schedule_iterator_timed_out().

49394 {
49395  if (iterator->done) return 0;
49396  return (time_t) iterator_int64 (iterator, 3);
49397 }
gboolean done
End flag.
Definition: iterator.h:55
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_owner_name()

const char* task_schedule_iterator_owner_name ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_owner_uuid()

const char* task_schedule_iterator_owner_uuid ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_period()

time_t task_schedule_iterator_period ( iterator_t iterator)

Get the period from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
period.

Definition at line 49407 of file manage_sql.c.

References iterator::done, and iterator_int64().

Referenced by manage_schedule(), and task_schedule_iterator_stop_due().

49408 {
49409  if (iterator->done) return 0;
49410  return (time_t) iterator_int64 (iterator, 4);
49411 }
gboolean done
End flag.
Definition: iterator.h:55
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_period_months()

time_t task_schedule_iterator_period_months ( iterator_t iterator)

Get the period months from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
Period months.

Definition at line 49421 of file manage_sql.c.

References iterator::done, and iterator_int64().

Referenced by manage_schedule(), and task_schedule_iterator_stop_due().

49422 {
49423  if (iterator->done) return 0;
49424  return (time_t) iterator_int64 (iterator, 5);
49425 }
gboolean done
End flag.
Definition: iterator.h:55
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_schedule()

schedule_t task_schedule_iterator_schedule ( iterator_t iterator)

Get the schedule from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
The schedule.

Definition at line 49379 of file manage_sql.c.

References iterator::done, and iterator_int64().

49380 {
49381  if (iterator->done) return 0;
49382  return (schedule_t) iterator_int64 (iterator, 2);
49383 }
long long int schedule_t
Definition: manage.h:299
gboolean done
End flag.
Definition: iterator.h:55
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:

◆ task_schedule_iterator_start_due()

gboolean task_schedule_iterator_start_due ( iterator_t iterator)

Get the start due state from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
Start due flag.

Definition at line 49507 of file manage_sql.c.

References iterator::done, task_run_status(), task_schedule_iterator_next_time(), task_schedule_iterator_task(), TASK_STATUS_DONE, TASK_STATUS_INTERNAL_ERROR, TASK_STATUS_NEW, and TASK_STATUS_STOPPED.

Referenced by manage_schedule().

49508 {
49509  task_status_t run_status;
49510  time_t start_time;
49511 
49512  if (iterator->done) return FALSE;
49513 
49514  if (task_schedule_iterator_next_time (iterator) == 0)
49515  return FALSE;
49516 
49517  run_status = task_run_status (task_schedule_iterator_task (iterator));
49518  start_time = task_schedule_iterator_next_time (iterator);
49519 
49520  if ((run_status == TASK_STATUS_DONE
49521  || run_status == TASK_STATUS_INTERNAL_ERROR
49522  || run_status == TASK_STATUS_NEW
49523  || run_status == TASK_STATUS_STOPPED)
49524  && (start_time > 0)
49525  && (start_time <= time (NULL)))
49526  return TRUE;
49527 
49528  return FALSE;
49529 }
task_status_t
Task statuses, also used as scan/report statuses.
Definition: manage.h:218
gboolean done
End flag.
Definition: iterator.h:55
task_status_t task_run_status(task_t task)
Return the run state of a task.
Definition: manage_sql.c:18238
task_t task_schedule_iterator_task(iterator_t *iterator)
Get the task from a task schedule iterator.
Definition: manage_sql.c:49355
time_t task_schedule_iterator_next_time(iterator_t *iterator)
Get the next time from a task schedule iterator.
Definition: manage_sql.c:49393
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_stop_due()

gboolean task_schedule_iterator_stop_due ( iterator_t iterator)

Get the stop due state from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
Stop due flag.

Definition at line 49539 of file manage_sql.c.

References iterator::done, task_running_report(), task_schedule_iterator_duration(), task_schedule_iterator_first_time(), task_schedule_iterator_period(), task_schedule_iterator_period_months(), task_schedule_iterator_task(), and task_schedule_iterator_timezone().

Referenced by manage_schedule().

49540 {
49541  time_t first, period, period_months, duration;
49542  const char *timezone;
49543 
49544  if (iterator->done) return FALSE;
49545 
49546  first = task_schedule_iterator_first_time (iterator);
49547  period = task_schedule_iterator_period (iterator);
49548  period_months = task_schedule_iterator_period_months (iterator);
49549  duration = task_schedule_iterator_duration (iterator);
49550  timezone = task_schedule_iterator_timezone (iterator);
49551 
49552  if (duration)
49553  {
49554  report_t report;
49555  task_status_t run_status;
49556 
49557  report = task_running_report (task_schedule_iterator_task (iterator));
49558  if (report && (report_scheduled (report) == 0))
49559  return FALSE;
49560 
49561  run_status = task_run_status (task_schedule_iterator_task (iterator));
49562 
49563  if (run_status == TASK_STATUS_RUNNING
49564  || run_status == TASK_STATUS_REQUESTED)
49565  {
49566  time_t now, start;
49567 
49568  now = time (NULL);
49569 
49570  start = next_time (first, period, period_months, timezone, -1);
49571  if ((start + duration) < now)
49572  return TRUE;
49573  }
49574  }
49575 
49576  return FALSE;
49577 }
task_status_t
Task statuses, also used as scan/report statuses.
Definition: manage.h:218
time_t task_schedule_iterator_period(iterator_t *iterator)
Get the period from a task schedule iterator.
Definition: manage_sql.c:49407
gboolean done
End flag.
Definition: iterator.h:55
long long int report_t
Definition: manage.h:288
task_status_t task_run_status(task_t task)
Return the run state of a task.
Definition: manage_sql.c:18238
task_t task_schedule_iterator_task(iterator_t *iterator)
Get the task from a task schedule iterator.
Definition: manage_sql.c:49355
time_t task_schedule_iterator_period_months(iterator_t *iterator)
Get the period months from a task schedule iterator.
Definition: manage_sql.c:49421
time_t task_schedule_iterator_duration(iterator_t *iterator)
Get the duration from a task schedule iterator.
Definition: manage_sql.c:49449
time_t task_schedule_iterator_first_time(iterator_t *iterator)
Get the first time from a task schedule iterator.
Definition: manage_sql.c:49435
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.
Definition: manage_utils.c:287
report_t task_running_report(task_t task)
Return the running report of a task.
Definition: manage_sql.c:18393
const char * task_schedule_iterator_timezone(iterator_t *)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_task()

task_t task_schedule_iterator_task ( iterator_t iterator)

Get the task from a task schedule iterator.

Parameters
[in]iteratorIterator.
Returns
task.

Definition at line 49355 of file manage_sql.c.

References iterator::done, and iterator_int64().

Referenced by manage_schedule(), task_schedule_iterator_start_due(), task_schedule_iterator_stop_due(), and task_schedule_iterator_timed_out().

49356 {
49357  if (iterator->done) return 0;
49358  return (task_t) iterator_int64 (iterator, 0);
49359 }
gboolean done
End flag.
Definition: iterator.h:55
long long int task_t
Definition: manage.h:286
long long int iterator_int64(iterator_t *iterator, int col)
Get an integer column from an iterator.
Definition: sql.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_task_uuid()

const char* task_schedule_iterator_task_uuid ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_timed_out()

gboolean task_schedule_iterator_timed_out ( iterator_t iterator)

Get if schedule of task in iterator is timed out.

Parameters
[in]iteratorIterator.
Returns
Whether task schedule is timed out.

Definition at line 49587 of file manage_sql.c.

References iterator::done, get_schedule_timeout(), SCHEDULE_TIMEOUT_MIN_SECS, task_run_status(), task_schedule_iterator_duration(), task_schedule_iterator_next_time(), task_schedule_iterator_task(), TASK_STATUS_DONE, TASK_STATUS_INTERNAL_ERROR, TASK_STATUS_NEW, and TASK_STATUS_STOPPED.

Referenced by manage_schedule().

49588 {
49589  time_t schedule_timeout_secs;
49590  int duration;
49591  task_status_t run_status;
49592  time_t start_time, timeout_time;
49593 
49594  if (get_schedule_timeout () < 0)
49595  return FALSE;
49596 
49597  if (iterator->done) return FALSE;
49598 
49599  start_time = task_schedule_iterator_next_time (iterator);
49600 
49601  if (start_time == 0)
49602  return FALSE;
49603 
49604  schedule_timeout_secs = get_schedule_timeout () * 60;
49605  if (schedule_timeout_secs < SCHEDULE_TIMEOUT_MIN_SECS)
49606  schedule_timeout_secs = SCHEDULE_TIMEOUT_MIN_SECS;
49607 
49608  run_status = task_run_status (task_schedule_iterator_task (iterator));
49609  duration = task_schedule_iterator_duration (iterator);
49610 
49611  if (duration && (duration < schedule_timeout_secs))
49612  timeout_time = start_time + duration;
49613  else
49614  timeout_time = start_time + schedule_timeout_secs;
49615 
49616  if ((run_status == TASK_STATUS_DONE
49617  || run_status == TASK_STATUS_INTERNAL_ERROR
49618  || run_status == TASK_STATUS_NEW
49619  || run_status == TASK_STATUS_STOPPED)
49620  && (timeout_time <= time (NULL)))
49621  return TRUE;
49622 
49623  return FALSE;
49624 }
task_status_t
Task statuses, also used as scan/report statuses.
Definition: manage.h:218
gboolean done
End flag.
Definition: iterator.h:55
int get_schedule_timeout()
Get the current schedule timeout.
Definition: manage.c:6917
task_status_t task_run_status(task_t task)
Return the run state of a task.
Definition: manage_sql.c:18238
task_t task_schedule_iterator_task(iterator_t *iterator)
Get the task from a task schedule iterator.
Definition: manage_sql.c:49355
time_t task_schedule_iterator_duration(iterator_t *iterator)
Get the duration from a task schedule iterator.
Definition: manage_sql.c:49449
#define SCHEDULE_TIMEOUT_MIN_SECS
Minimum schedule timeout seconds. This value must be greater than SCHEDULE_PERIOD.
Definition: manage.h:2798
time_t task_schedule_iterator_next_time(iterator_t *iterator)
Get the next time from a task schedule iterator.
Definition: manage_sql.c:49393
Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_schedule_iterator_timezone()

const char* task_schedule_iterator_timezone ( iterator_t )

Referenced by manage_schedule(), and task_schedule_iterator_stop_due().

Here is the caller graph for this function:

◆ trim_report()

void trim_report ( report_t  report)

Prepare a partial report for restarting the scan from the beginning.

Parameters
[in]reportThe report.

Definition at line 25501 of file manage_sql.c.

References report_cache_counts(), report_clear_count_cache(), setting_auto_cache_rebuild_int(), and sql().

25502 {
25503  /* Remove results for all hosts. */
25504 
25505  sql ("DELETE FROM results WHERE id IN"
25506  " (SELECT results.id FROM results"
25507  " WHERE results.report = %llu);",
25508  report);
25509 
25510  /* Remove all hosts and host details. */
25511 
25512  sql ("DELETE FROM report_host_details WHERE report_host IN"
25513  " (SELECT id FROM report_hosts WHERE report = %llu);",
25514  report);
25515  sql ("DELETE FROM report_hosts"
25516  " WHERE report = %llu;",
25517  report);
25518 
25519  /* Clear and rebuild counts cache */
25521  report_cache_counts (report, 1, 1, NULL);
25522  else
25523  report_clear_count_cache (report, 1, 1, NULL);
25524 }
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
int setting_auto_cache_rebuild_int()
Return the Auto Cache Rebuild user setting as an int.
Definition: manage_sql.c:62173
void report_cache_counts(report_t report, int clear_original, int clear_overridden, const char *users_where)
Cache report counts and clear existing caches if requested.
Definition: manage_sql.c:20879
void report_clear_count_cache(report_t report, int clear_original, int clear_overridden, const char *users_where)
Clear report counts .
Definition: manage_sql.c:20938
Here is the call graph for this function:

◆ update_config_cache_init()

void update_config_cache_init ( const char *  uuid)

Update count and growing info in config, without checking user.

For use during initialisation.

Parameters
[in]uuidConfig UUID.

It's up to the caller to organise a transaction.

Definition at line 38210 of file manage_sql.c.

References CONFIG_ITERATOR_COLUMNS.

Referenced by check_config_host_discovery(), and check_config_system_discovery().

38211 {
38212  static column_t select_columns[] = CONFIG_ITERATOR_COLUMNS;
38213  gchar *columns;
38214  iterator_t configs;
38215 
38216  columns = columns_build_select (select_columns);
38217  init_iterator (&configs,
38218  "SELECT %s FROM configs WHERE uuid = '%s';",
38219  columns,
38220  uuid);
38221  g_free (columns);
38222  while (next (&configs))
38223  update_config_cache (&configs);
38224  cleanup_iterator (&configs);
38225 }
A generic SQL iterator.
Definition: iterator.h:52
Iterator column.
Definition: manage_sql.c:1512
#define CONFIG_ITERATOR_COLUMNS
Scan config iterator columns.
Definition: manage_sql.c:36259
void cleanup_iterator(iterator_t *)
Cleanup an iterator.
Definition: sql.c:664
gboolean next(iterator_t *)
Increment an iterator.
Definition: sql.c:689
void init_iterator(iterator_t *iterator, const char *sql,...)
Initialise an iterator.
Definition: sql.c:577
Here is the caller graph for this function:

◆ update_from_slave()

int update_from_slave ( task_t  task,
entity_t  get_report,
entity_t *  report,
int *  next_result 
)

Update the local task from the slave task.

Parameters
[in]taskThe local task.
[in]get_reportSlave GET_REPORT response.
[out]reportReport from get_report.
[out]next_resultNext result counter.
Returns
0 success, -1 error.

Definition at line 53064 of file manage_sql.c.

References current_report, current_scanner_task, result_buffer::host, host_notice(), make_result(), result_buffer::port, report_add_result(), report_uuid(), set_scan_host_start_time(), set_scan_start_time(), set_task_start_time(), sql_begin_immediate(), sql_commit(), sql_rollback(), and threat_message_type().

53066 {
53067  entity_t entity, host_start, start;
53068  entities_t results, hosts, entities;
53069 
53070  entity = entity_child (get_report, "report");
53071  if (entity == NULL)
53072  return -1;
53073 
53074  *report = entity_child (entity, "report");
53075  if (*report == NULL)
53076  return -1;
53077 
53078  /* Set the scan start time. */
53079 
53080  entities = (*report)->entities;
53081  while ((start = first_entity (entities)))
53082  {
53083  if (strcmp (entity_name (start), "scan_start") == 0)
53084  {
53086  g_strdup (entity_text (start)));
53087  set_scan_start_time (current_report, entity_text (start));
53088  break;
53089  }
53090  entities = next_entities (entities);
53091  }
53092 
53093  /* Get any new results and hosts from the slave. */
53094 
53096  hosts = (*report)->entities;
53097  while ((host_start = first_entity (hosts)))
53098  {
53099  if (strcmp (entity_name (host_start), "host_start") == 0)
53100  {
53101  entity_t host;
53102  char *uuid;
53103 
53104  host = entity_child (host_start, "host");
53105  if (host == NULL)
53106  goto rollback_fail;
53107 
53108  uuid = report_uuid (current_report);
53109  host_notice (entity_text (host), "ip", entity_text (host),
53110  "Report Host", uuid, 1, 1);
53111  free (uuid);
53112 
53114  entity_text (host),
53115  entity_text (host_start));
53116  }
53117  hosts = next_entities (hosts);
53118  }
53119  sql_commit ();
53120 
53121  entity = entity_child (*report, "results");
53122  if (entity == NULL)
53123  return -1;
53124 
53125  assert (current_report);
53126 
53128  results = entity->entities;
53129  while ((entity = first_entity (results)))
53130  {
53131  if (strcmp (entity_name (entity), "result") == 0)
53132  {
53133  entity_t host, port, nvt, threat, description;
53134  const char *oid;
53135 
53136  host = entity_child (entity, "host");
53137  if (host == NULL)
53138  goto rollback_fail;
53139 
53140  port = entity_child (entity, "port");
53141  if (port == NULL)
53142  goto rollback_fail;
53143 
53144  nvt = entity_child (entity, "nvt");
53145  if (nvt == NULL)
53146  goto rollback_fail;
53147  oid = entity_attribute (nvt, "oid");
53148  if ((oid == NULL) || (strlen (oid) == 0))
53149  goto rollback_fail;
53150 
53151  threat = entity_child (entity, "threat");
53152  if (threat == NULL)
53153  goto rollback_fail;
53154 
53155  description = entity_child (entity, "description");
53156  if (description == NULL)
53157  goto rollback_fail;
53158 
53159  {
53160  result_t result;
53161 
53162  result = make_result (task,
53163  entity_text (host),
53164  entity_text (port),
53165  oid,
53166  threat_message_type (entity_text (threat)),
53167  entity_text (description));
53169  }
53170 
53171  (*next_result)++;
53172  }
53173  results = next_entities (results);
53174  }
53175  sql_commit ();
53176  return 0;
53177 
53178  rollback_fail:
53179  sql_rollback ();
53180  return -1;
53181 }
result_t make_result(task_t task, const char *host, const char *port, const char *nvt, const char *type, const char *description)
Make a result.
Definition: manage_sql.c:19892
char * report_uuid(report_t report)
Return the UUID of a report.
Definition: manage_sql.c:21382
void sql_rollback()
Roll a transaction back.
Definition: sql_pg.c:658
task_t current_scanner_task
The task currently running on the scanner.
Definition: manage.c:998
long long int result_t
Definition: manage.h:287
void set_scan_start_time(report_t report, const char *timestamp)
Set the start time of a scan.
Definition: manage_sql.c:24229
report_t current_report
The report of the current task.
Definition: manage.c:1003
void sql_begin_immediate()
Begin an immediate transaction.
Definition: sql_pg.c:627
const char * threat_message_type(const char *)
Get the message type of a threat.
Definition: manage.c:526
void sql_commit()
Commit a transaction.
Definition: sql_pg.c:649
host_t host_notice(const char *host_name, const char *identifier_type, const char *identifier_value, const char *source_type, const char *source_id, int check_add_to_assets, int check_for_existing_identifier)
Notice a host.
Definition: manage_sql.c:19765
void set_scan_host_start_time(report_t report, const char *host, const char *timestamp)
Set the start time of a scanned host.
Definition: manage_sql.c:24422
void report_add_result(report_t report, result_t result)
Add a result to a report.
Definition: manage_sql.c:21590
void set_task_start_time(task_t task, char *time)
Set the start time of a task.
Definition: manage_sql.c:18493
Here is the call graph for this function:

◆ valid_omp_command()

int valid_omp_command ( const char *  name)

Check whether a command name is valid.

Parameters
[in]nameCommand name.
Returns
1 yes, 0 no.

Definition at line 545 of file manage_sql.c.

References omp_commands.

Referenced by acl_user_has_access_uuid().

546 {
547  command_t *command;
548  command = omp_commands;
549  while (command[0].name)
550  if (strcasecmp (command[0].name, name) == 0)
551  return 1;
552  else
553  command++;
554  return 0;
555 }
A command.
Definition: manage.h:95
command_t omp_commands[]
The OMP command list.
Definition: manage_sql.c:422
Here is the caller graph for this function:

Variable Documentation

◆ task_db_name

gchar* task_db_name

Name of the database file.

Definition at line 403 of file manage_sql.c.

Referenced by migrate_43_to_44(), and reinit_manage_process().