25 #ifndef _GVMD_MANAGE_SQL_H 26 #define _GVMD_MANAGE_SQL_H 29 #include "manage_utils.h" 31 #include <gvm/util/xmlutils.h> 38 #define CONFIG_UUID_FULL_AND_FAST "daba56c8-73ec-11df-a475-002264764cea" 43 #define CONFIG_UUID_FULL_AND_FAST_ULTIMATE \ 44 "698f691e-7489-11df-9d8c-002264764cea" 49 #define CONFIG_UUID_FULL_AND_VERY_DEEP "708f25c4-7489-11df-8094-002264764cea" 54 #define CONFIG_UUID_FULL_AND_VERY_DEEP_ULTIMATE \ 55 "74db13d6-7489-11df-91b9-002264764cea" 60 #define CONFIG_UUID_EMPTY "085569ce-73ed-11df-83c3-002264764cea" 65 #define CONFIG_UUID_DISCOVERY "8715c877-47a0-438d-98a3-27c7a6ab2196" 70 #define CONFIG_UUID_HOST_DISCOVERY "2d3f051c-55ba-11e3-bf43-406186ea4fc5" 75 #define CONFIG_UUID_SYSTEM_DISCOVERY "bbca7412-a950-11e3-9109-406186ea4fc5" 80 #define LOCATION_TABLE 0 85 #define LOCATION_TRASH 1 90 #define MANAGE_NVT_SELECTOR_UUID_ALL "54b45713-d4f4-4435-b20d-304c175ed8c5" 95 #define MANAGE_NVT_SELECTOR_UUID_DISCOVERY \ 96 "0d9a2738-8fe2-4e22-8f26-bb886179e759" 101 #define MANAGE_NVT_SELECTOR_UUID_HOST_DISCOVERY \ 102 "f5f80744-55c7-11e3-8dc6-406186ea4fc5" 107 #define MANAGE_NVT_SELECTOR_UUID_SYSTEM_DISCOVERY \ 108 "07045d1c-a951-11e3-8da7-406186ea4fc5" 113 #define PERMISSION_UUID_ADMIN_EVERYTHING "b3b56a8c-c2fd-11e2-a135-406186ea4fc5" 118 #define PERMISSION_UUID_SUPER_ADMIN_EVERYTHING \ 119 "a9801074-6fe2-11e4-9d81-406186ea4fc5" 124 #define PORT_LIST_UUID_DEFAULT "c7e03b6c-3bbe-11e1-a057-406186ea4fc5" 129 #define PORT_LIST_UUID_ALL_TCP "fd591a34-56fd-11e1-9f27-406186ea4fc5" 134 #define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_100 \ 135 "730ef368-57e2-11e1-a90f-406186ea4fc5" 140 #define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_1000 \ 141 "9ddce1ae-57e7-11e1-b13c-406186ea4fc5" 146 #define PORT_LIST_UUID_ALL_PRIV_TCP "492b72f4-56fe-11e1-98a7-406186ea4fc5" 151 #define PORT_LIST_UUID_ALL_PRIV_TCP_UDP "5f2029f6-56fe-11e1-bb94-406186ea4fc5" 156 #define PORT_LIST_UUID_ALL_IANA_TCP_2012 "33d0cd82-57c6-11e1-8ed1-406186ea4fc5" 161 #define PORT_LIST_UUID_ALL_IANA_TCP_UDP_2012 \ 162 "4a4717fe-57d2-11e1-9a26-406186ea4fc5" 167 #define PORT_LIST_UUID_NMAP_5_51_TOP_2000_TOP_100 \ 168 "ab33f6b0-57f8-11e1-96f5-406186ea4fc5" 173 #define ROLE_UUID_ADMIN "7a8cb5b4-b74d-11e2-8187-406186ea4fc5" 178 #define ROLE_UUID_GUEST "cc9cac5e-39a3-11e4-abae-406186ea4fc5" 183 #define ROLE_UUID_INFO "5f8fd16c-c550-11e3-b6ab-406186ea4fc5" 188 #define ROLE_UUID_MONITOR "12cdb536-480b-11e4-8552-406186ea4fc5" 193 #define ROLE_UUID_USER "8d453140-b74d-11e2-b0be-406186ea4fc5" 198 #define ROLE_UUID_SUPER_ADMIN "9c5a6ec6-6fe2-11e4-8cb6-406186ea4fc5" 203 #define ROLE_UUID_OBSERVER "87a7ebce-b74d-11e2-a81f-406186ea4fc5" 208 #define SCANNER_UUID_DEFAULT "08b69003-5fc2-4037-a479-93b440211c73" 213 #define SCANNER_UUID_CVE "6acd0832-df90-11e4-b9d5-28d24461215b" 218 #define SETTING_UUID_ROWS_PER_PAGE "5f5a8712-8017-11e1-8556-406186ea4fc5" 223 #define SETTING_UUID_MAX_ROWS_PER_PAGE "76374a7a-0569-11e6-b6da-28d24461215b" 228 #define SETTING_UUID_DEFAULT_CA_CERT "9ac801ea-39f8-11e6-bbaa-28d24461215b" 233 #define SETTING_UUID_LSC_DEB_MAINTAINER "2fcbeac8-4237-438f-b52a-540a23e7af97" 238 #define TRUST_ERROR 0 253 #define TRUST_UNKNOWN 3 258 #define TIMEVAL_SUBTRACT_MS(a, b) \ 259 ((((a).tv_sec - (b).tv_sec) * 1000) + ((a).tv_usec - (b).tv_usec) / 1000) 272 #define DEF_ACCESS(name, col) \ 273 const char *name (iterator_t *iterator) \ 276 if (iterator->done) \ 278 ret = iterator_string (iterator, col); \ 297 #define ANON_GET_ITERATOR_FILTER_COLUMNS "uuid", "created", "modified", "_owner" 302 #define GET_ITERATOR_FILTER_COLUMNS \ 303 "uuid", "name", "comment", "created", "modified", "_owner" 310 #define GET_ITERATOR_COLUMNS_STRING \ 311 "id, uuid, name, comment, iso_time (creation_time)," \ 312 " iso_time (modification_time), creation_time AS created," \ 313 " modification_time AS modified" 320 #define GET_ITERATOR_COLUMNS_PREFIX(prefix) \ 321 {prefix "id", NULL, KEYWORD_TYPE_INTEGER}, \ 322 {prefix "uuid", NULL, KEYWORD_TYPE_STRING}, \ 323 {prefix "name", NULL, KEYWORD_TYPE_STRING}, \ 324 {prefix "comment", NULL, KEYWORD_TYPE_STRING}, \ 325 {" iso_time (" prefix "creation_time)", NULL, KEYWORD_TYPE_STRING}, \ 326 {" iso_time (" prefix "modification_time)", NULL, KEYWORD_TYPE_STRING}, \ 327 {prefix "creation_time", "created", KEYWORD_TYPE_INTEGER}, \ 329 prefix "modification_time", "modified", KEYWORD_TYPE_INTEGER \ 337 #define GET_ITERATOR_COLUMNS(table) \ 338 GET_ITERATOR_COLUMNS_PREFIX (""), \ 339 {"(SELECT name FROM users AS inner_users" \ 340 " WHERE inner_users.id = " G_STRINGIFY (table) ".owner)", \ 342 KEYWORD_TYPE_STRING}, \ 344 "owner", NULL, KEYWORD_TYPE_INTEGER \ 350 #define GET_ITERATOR_COLUMN_COUNT 10 358 typedef long long int rowid_t;
370 tag_value (
const gchar *,
const gchar *);
382 update_from_slave (task_t, entity_t, entity_t *,
int *);
418 alert_data (alert_t,
const char *,
const char *);
430 task_schedule_iterator_task_uuid (
iterator_t *);
433 task_schedule_iterator_schedule (
iterator_t *);
436 task_schedule_iterator_icalendar (
iterator_t *);
439 task_schedule_iterator_timezone (
iterator_t *);
442 task_schedule_iterator_owner_uuid (
iterator_t *);
445 task_schedule_iterator_owner_name (
iterator_t *);
457 task_schedule_iterator_initial_offset (
iterator_t *);
469 manage_report_host_details (report_t,
const char *, entity_t);
515 insert_port_range (port_list_t, port_protocol_t,
int,
int);
599 tags_remove_resource (
const char *,
resource_t,
int);
608 permissions_set_orphans (
const char *,
resource_t,
int);
624 create_permission_internal (
const char *,
void trim_report(report_t report)
Prepare a partial report for restarting the scan from the beginning.
Definition: manage_sql.c:26996
char * alert_data(alert_t alert, const char *type, const char *name)
Return data associated with an alert.
Definition: manage_sql.c:8854
void manage_update_scap_db_cleanup()
Database specific cleanup after SCAP update.
Definition: manage_pg.c:436
gchar * filter_clause(const char *type, const char *filter, const char **filter_columns, column_t *select_columns, column_t *where_columns, int trash, gchar **order_return, int *first_return, int *max_return, array_t **permissions, gchar **owner_filter)
Return SQL WHERE clause for restricting a SELECT to a filter term.
Definition: manage_sql.c:3239
gchar * report_host_ip(const char *host)
Get the IP of a host, using the 'hostname' report host details.
Definition: manage_sql.c:32488
int copy_resource(const char *type, const char *name, const char *comment, const char *resource_id, const char *columns, int make_name_unique, resource_t *new_resource, resource_t *old_resource)
Create a resource from an existing resource.
Definition: manage_sql.c:4857
gchar * columns_build_select(column_t *select_columns)
Return column list for SELECT statement.
Definition: manage_sql.c:2811
void reinit_manage_process()
Reinitialize the manage library for a process.
Definition: manage_sql.c:15330
gchar * gvmd_db_name
Name of the database file.
Definition: manage_sql.c:547
gchar * select
Column for SELECT.
Definition: manage_sql.h:289
void update_all_config_caches()
Update count and growing info in every config across all users.
Definition: manage_sql.c:38716
int manage_db_empty()
Check whether database is empty.
Definition: manage_pg.c:81
gboolean host_nthlast_report_host(const char *host, report_host_t *report_host, int position)
Get N'th last report_host given a host.
Definition: manage_sql.c:28043
int manage_db_check(const gchar *name)
Dummy function.
Definition: manage_pg.c:3645
port_list_t target_port_list(target_t target)
Return the port list associated with a target, if any.
Definition: manage_sql.c:36197
credential_t target_ssh_credential(target_t target)
Return the SSH credential associated with a target, if any.
Definition: manage_sql.c:36158
int manage_cert_db_exists()
Check if CERT db exists.
Definition: manage_pg.c:100
int manage_update_scap_db_init()
Database specific setup for SCAP update.
Definition: manage_pg.c:236
A generic SQL iterator structure.
Definition: iterator.h:50
int manage_scap_db_exists()
Check if SCAP db exists.
Definition: manage_pg.c:115
void init_task_file_iterator(iterator_t *iterator, task_t task, const char *file)
Initialise a task file iterator.
Definition: manage_sql.c:33730
gchar * get_ovaldef_short_filename(char *item_id)
Get the short file name for an OVALDEF.
Definition: manage_sql_secinfo.c:641
int valid_gmp_command(const char *name)
Check whether a command name is valid.
Definition: manage_sql.c:691
int set_task_requested(task_t task, task_status_t *status)
Atomically set the run state of a task to requested.
Definition: manage_sql.c:19398
void cleanup_task_schedule_iterator(iterator_t *iterator)
Cleanup a task schedule iterator.
Definition: manage_sql.c:50207
int manage_update_nvti_cache()
Update the memory cache of NVTs, if this has been requested.
Definition: manage_sql.c:15459
void manage_option_cleanup()
Cleanup for an option process.
Definition: manage_sql.c:1338
int parse_iso_time(const char *text_time)
Convert an ISO time into seconds since epoch.
Definition: manage_sql.c:927
void reschedule_task(const gchar *task_id)
Set a task's schedule so that it runs again next scheduling round.
Definition: manage_sql.c:20671
credential_t target_esxi_credential(target_t target)
Return the ESXi credential associated with a target, if any.
Definition: manage_sql.c:36184
void set_task_schedule_next_time_uuid(const gchar *task_id, time_t time)
Set the next time a scheduled task will be due.
Definition: manage_sql.c:20244
keyword_type_t type
Type of column.
Definition: manage_sql.h:291
Command data for a get command.
Definition: manage.h:316
int init_get_iterator(iterator_t *iterator, const char *type, const get_data_t *get, column_t *select_columns, column_t *trash_select_columns, const char **filter_columns, int distinct, const char *extra_tables, const char *extra_where, int owned)
Initialise a GET iterator, including observed resources.
Definition: manage_sql.c:5360
void manage_session_init(const char *uuid)
Setup session.
Definition: manage_pg.c:50
int create_current_report(task_t task, char **report_id, task_status_t status)
Create the current report for a task.
Definition: manage_sql.c:22120
gboolean task_schedule_iterator_stop_due(iterator_t *iterator)
Get the stop due state from a task schedule iterator.
Definition: manage_sql.c:50344
gboolean resource_with_name_exists(const char *name, const char *type, resource_t resource)
Check if a resource with a certain name exists already.
Definition: manage_sql.c:768
Iterator column.
Definition: manage_sql.h:287
void set_report_slave_task_uuid(report_t report, const char *uuid)
Set the UUID of the slave task, on the local task.
Definition: manage_sql.c:26981
gchar * filter
Filter column name. NULL to use select_column.
Definition: manage_sql.h:290
task_t task_schedule_iterator_task(iterator_t *iterator)
Get the task from a task schedule iterator.
Definition: manage_sql.c:50221
void parse_osp_report(task_t task, report_t report, const char *report_xml)
Parse an OSP report.
Definition: manage_sql.c:32534
void init_otp_pref_iterator(iterator_t *iterator, config_t config, const char *section)
Initialise an "OTP" preference iterator.
Definition: manage_sql.c:37853
gboolean task_schedule_iterator_start_due(iterator_t *iterator)
Get the start due state from a task schedule iterator.
Definition: manage_sql.c:50312
void check_alerts()
Check if any SecInfo alerts are due.
Definition: manage_sql.c:6737
gchar * resource_uuid(const gchar *type, resource_t resource)
Get the UUID of a resource.
Definition: manage_sql.c:5026
int delete_report_internal(report_t report)
Delete a report.
Definition: manage_sql.c:26661
int set_report_scan_run_status(report_t report, task_status_t status)
Return the run status of the scan associated with a report.
Definition: manage_sql.c:26084
int set_task_schedule_uuid(const gchar *task_id, schedule_t schedule, int periods)
Set the schedule of a task.
Definition: manage_sql.c:20006
int count(const char *type, const get_data_t *get, column_t *select_columns, column_t *trash_select_columns, const char **filter_columns, int distinct, const char *extra_tables, const char *extra_where, int owned)
Count number of a particular resource.
Definition: manage_sql.c:6105
int init_task_schedule_iterator(iterator_t *iterator)
Initialise a task schedule iterator.
Definition: manage_sql.c:50175
int set_report_slave_progress(report_t report, int progress)
Set slave progress of a report.
Definition: manage_sql.c:26946
gchar * tag_value(const gchar *tags, const gchar *tag)
Extract a tag from an OTP tag list.
Definition: manage_sql.c:1206
void manage_db_check_mode(const gchar *name)
Dummy function.
Definition: manage_pg.c:3632
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:20231
void auto_delete_reports()
Auto delete reports.
Definition: manage_sql.c:20554
const char * run_status_name_internal(task_status_t status)
Get the unique name of a run status.
Definition: manage.c:1527
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.
Definition: manage_sql.c:4516
void set_report_scheduled(report_t report)
Set a report's scheduled flag.
Definition: manage_sql.c:19309
credential_t target_smb_credential(target_t target)
Return the SMB credential associated with a target, if any.
Definition: manage_sql.c:36171
void manage_update_cert_db_cleanup()
Database specific cleanup after CERT update.
Definition: manage_pg.c:213
void check_generate_scripts()
Ensure the generate scripts are all executable.
Definition: manage_sql.c:17813
void event(event_t event, void *event_data, resource_t resource_1, resource_t resource_2)
Produce an event.
Definition: manage_sql.c:14508
alive_test_t target_alive_tests(target_t target)
Return a target's alive tests.
Definition: manage_sql.c:36288
int manage_option_setup(GSList *log_config, const gchar *database)
Setup for an option process.
Definition: manage_sql.c:1299
int manage_update_cert_db_init()
Database specific setup for CERT update.
Definition: manage_pg.c:130
void update_config_cache_init(const char *uuid)
Update count and growing info in config, without checking user.
Definition: manage_sql.c:38740
gboolean task_schedule_iterator_timed_out(iterator_t *iterator)
Get if schedule of task in iterator is timed out.
Definition: manage_sql.c:50390
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:40
gboolean find_trash(const char *type, const char *uuid, resource_t *resource)
Find a resource in the trashcan given a UUID.
Definition: manage_sql.c:881