Greenbone Vulnerability Manager
9.0.1
|
25 #ifndef _GVMD_MANAGE_SQL_H
26 #define _GVMD_MANAGE_SQL_H
28 #include <gvm/util/xmlutils.h>
31 #include "manage_utils.h"
39 #define CONFIG_UUID_BASE "d21f6c81-2b88-4ac1-b7b4-a2a9f2ad4663"
44 #define CONFIG_UUID_FULL_AND_FAST "daba56c8-73ec-11df-a475-002264764cea"
49 #define CONFIG_UUID_FULL_AND_FAST_ULTIMATE \
50 "698f691e-7489-11df-9d8c-002264764cea"
55 #define CONFIG_UUID_FULL_AND_VERY_DEEP "708f25c4-7489-11df-8094-002264764cea"
60 #define CONFIG_UUID_FULL_AND_VERY_DEEP_ULTIMATE \
61 "74db13d6-7489-11df-91b9-002264764cea"
66 #define CONFIG_UUID_EMPTY "085569ce-73ed-11df-83c3-002264764cea"
71 #define CONFIG_UUID_DISCOVERY "8715c877-47a0-438d-98a3-27c7a6ab2196"
76 #define CONFIG_UUID_HOST_DISCOVERY "2d3f051c-55ba-11e3-bf43-406186ea4fc5"
81 #define CONFIG_UUID_SYSTEM_DISCOVERY "bbca7412-a950-11e3-9109-406186ea4fc5"
86 #define LOCATION_TABLE 0
91 #define LOCATION_TRASH 1
96 #define MANAGE_NVT_SELECTOR_UUID_ALL "54b45713-d4f4-4435-b20d-304c175ed8c5"
101 #define MANAGE_NVT_SELECTOR_UUID_BASE "dd4a4170-0b5e-43fb-9bae-6ce93c19e893"
106 #define MANAGE_NVT_SELECTOR_UUID_DISCOVERY "0d9a2738-8fe2-4e22-8f26-bb886179e759"
111 #define MANAGE_NVT_SELECTOR_UUID_HOST_DISCOVERY \
112 "f5f80744-55c7-11e3-8dc6-406186ea4fc5"
117 #define MANAGE_NVT_SELECTOR_UUID_SYSTEM_DISCOVERY \
118 "07045d1c-a951-11e3-8da7-406186ea4fc5"
123 #define PERMISSION_UUID_ADMIN_EVERYTHING "b3b56a8c-c2fd-11e2-a135-406186ea4fc5"
128 #define PERMISSION_UUID_SUPER_ADMIN_EVERYTHING "a9801074-6fe2-11e4-9d81-406186ea4fc5"
133 #define PORT_LIST_UUID_DEFAULT "c7e03b6c-3bbe-11e1-a057-406186ea4fc5"
138 #define PORT_LIST_UUID_ALL_TCP "fd591a34-56fd-11e1-9f27-406186ea4fc5"
143 #define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_100 "730ef368-57e2-11e1-a90f-406186ea4fc5"
148 #define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_1000 "9ddce1ae-57e7-11e1-b13c-406186ea4fc5"
153 #define PORT_LIST_UUID_ALL_PRIV_TCP "492b72f4-56fe-11e1-98a7-406186ea4fc5"
158 #define PORT_LIST_UUID_ALL_PRIV_TCP_UDP "5f2029f6-56fe-11e1-bb94-406186ea4fc5"
163 #define PORT_LIST_UUID_ALL_IANA_TCP_2012 "33d0cd82-57c6-11e1-8ed1-406186ea4fc5"
168 #define PORT_LIST_UUID_ALL_IANA_TCP_UDP_2012 "4a4717fe-57d2-11e1-9a26-406186ea4fc5"
173 #define PORT_LIST_UUID_NMAP_5_51_TOP_2000_TOP_100 "ab33f6b0-57f8-11e1-96f5-406186ea4fc5"
178 #define ROLE_UUID_ADMIN "7a8cb5b4-b74d-11e2-8187-406186ea4fc5"
183 #define ROLE_UUID_GUEST "cc9cac5e-39a3-11e4-abae-406186ea4fc5"
188 #define ROLE_UUID_INFO "5f8fd16c-c550-11e3-b6ab-406186ea4fc5"
193 #define ROLE_UUID_MONITOR "12cdb536-480b-11e4-8552-406186ea4fc5"
198 #define ROLE_UUID_USER "8d453140-b74d-11e2-b0be-406186ea4fc5"
203 #define ROLE_UUID_SUPER_ADMIN "9c5a6ec6-6fe2-11e4-8cb6-406186ea4fc5"
208 #define ROLE_UUID_OBSERVER "87a7ebce-b74d-11e2-a81f-406186ea4fc5"
213 #define SCANNER_UUID_DEFAULT "08b69003-5fc2-4037-a479-93b440211c73"
218 #define SCANNER_UUID_CVE "6acd0832-df90-11e4-b9d5-28d24461215b"
223 #define SETTING_UUID_ROWS_PER_PAGE "5f5a8712-8017-11e1-8556-406186ea4fc5"
228 #define SETTING_UUID_MAX_ROWS_PER_PAGE "76374a7a-0569-11e6-b6da-28d24461215b"
233 #define SETTING_UUID_DEFAULT_CA_CERT "9ac801ea-39f8-11e6-bbaa-28d24461215b"
238 #define SETTING_UUID_SLAVE_CHECK_PERIOD "63adb79a-62ae-11e9-91ba-28d24461215b"
243 #define SETTING_UUID_LSC_DEB_MAINTAINER "2fcbeac8-4237-438f-b52a-540a23e7af97"
248 #define TRUST_ERROR 0
263 #define TRUST_UNKNOWN 3
268 #define TIMEVAL_SUBTRACT_MS(a,b) ((((a).tv_sec - (b).tv_sec) * 1000) + \
269 ((a).tv_usec - (b).tv_usec) / 1000)
283 #define DEF_ACCESS(name, col) \
285 name (iterator_t* iterator) \
288 if (iterator->done) return NULL; \
289 ret = iterator_string (iterator, col); \
309 #define ANON_GET_ITERATOR_FILTER_COLUMNS "uuid", \
310 "created", "modified", "_owner"
315 #define GET_ITERATOR_FILTER_COLUMNS "uuid", "name", "comment", \
316 "created", "modified", "_owner"
323 #define GET_ITERATOR_COLUMNS_STRING \
324 "id, uuid, name, comment, iso_time (creation_time)," \
325 " iso_time (modification_time), creation_time AS created," \
326 " modification_time AS modified"
333 #define GET_ITERATOR_COLUMNS_PREFIX(prefix) \
334 { prefix "id", NULL, KEYWORD_TYPE_INTEGER }, \
335 { prefix "uuid", NULL, KEYWORD_TYPE_STRING }, \
336 { prefix "name", NULL, KEYWORD_TYPE_STRING }, \
337 { prefix "comment", NULL, KEYWORD_TYPE_STRING }, \
338 { " iso_time (" prefix "creation_time)", NULL, KEYWORD_TYPE_STRING }, \
339 { " iso_time (" prefix "modification_time)", NULL, KEYWORD_TYPE_STRING }, \
340 { prefix "creation_time", "created", KEYWORD_TYPE_INTEGER }, \
341 { prefix "modification_time", "modified", KEYWORD_TYPE_INTEGER }
348 #define GET_ITERATOR_COLUMNS(table) \
349 GET_ITERATOR_COLUMNS_PREFIX(""), \
351 "(SELECT name FROM users AS inner_users" \
352 " WHERE inner_users.id = " G_STRINGIFY (table) ".owner)", \
354 KEYWORD_TYPE_STRING \
356 { "owner", NULL, KEYWORD_TYPE_INTEGER }
361 #define GET_ITERATOR_COLUMN_COUNT 10
371 typedef long long int rowid_t;
381 gchar *
tag_value (
const gchar *,
const gchar *);
391 int update_from_slave (task_t, entity_t, entity_t *,
int *);
398 const char *task_file_iterator_name (
iterator_t *);
399 const char *task_file_iterator_content (
iterator_t *);
406 const char *preference_iterator_name (
iterator_t *);
407 const char *preference_iterator_value (
iterator_t *);
416 char *
alert_data (alert_t,
const char *,
const char *);
424 const char *task_schedule_iterator_task_uuid (
iterator_t *);
426 schedule_t task_schedule_iterator_schedule (
iterator_t *);
428 const char *task_schedule_iterator_icalendar (
iterator_t *);
430 const char *task_schedule_iterator_timezone (
iterator_t *);
432 const char *task_schedule_iterator_owner_uuid (
iterator_t *);
434 const char *task_schedule_iterator_owner_name (
iterator_t *);
442 time_t task_schedule_iterator_initial_offset (
iterator_t *);
450 int manage_report_host_details (report_t,
const char *, entity_t);
481 void insert_port_range (port_list_t, port_protocol_t,
int,
int);
501 int,
const char *,
const char *,
int);
505 column_t *,
const char **,
int,
const char *,
const char *,
513 column_t *,
int, gchar **,
int *,
int *, array_t **, gchar **);
534 tags_remove_resource (
const char *,
resource_t,
int);
543 permissions_set_orphans (
const char *,
resource_t,
int);
546 copy_resource (
const char *,
const char *,
const char *,
const char *,
553 create_permission_internal (
const char *,
const char *,
const char *,
const char *,
554 const char *,
const char *, permission_t *);
int set_report_slave_progress(report_t report, int progress)
Set slave progress of a report.
Definition: manage_sql.c:26884
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:5000
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:6246
gchar * columns_build_select(column_t *select_columns)
Return column list for SELECT statement.
Definition: manage_sql.c:2878
int valid_gmp_command(const char *name)
Check whether a command name is valid.
Definition: manage_sql.c:669
char * alert_data(alert_t alert, const char *type, const char *name)
Return data associated with an alert.
Definition: manage_sql.c:8996
gboolean task_schedule_iterator_stop_due(iterator_t *iterator)
Get the stop due state from a task schedule iterator.
Definition: manage_sql.c:45709
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:746
void check_alerts()
Check if any SecInfo alerts are due.
Definition: manage_sql.c:6879
int manage_update_scap_db_init()
Database specific setup for SCAP update.
Definition: manage_pg.c:239
credential_t target_smb_credential(target_t target)
Return the SMB credential associated with a target, if any.
Definition: manage_sql.c:35372
void init_preference_iterator(iterator_t *iterator, config_t config, const char *section)
Initialise a config preference iterator, with defaults.
Definition: manage_sql_configs.c:3557
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:20633
keyword_type_t type
Type of column.
Definition: manage_sql.h:303
gchar * gvmd_db_name
Name of the database file.
Definition: manage_sql.c:521
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:841
void reinit_manage_process()
Reinitialize the manage library for a process.
Definition: manage_sql.c:15672
void trim_report(report_t report)
Prepare a partial report for restarting the scan from the beginning.
Definition: manage_sql.c:26934
gboolean task_schedule_iterator_start_due(iterator_t *iterator)
Get the start due state from a task schedule iterator.
Definition: manage_sql.c:45677
gchar * resource_uuid(const gchar *type, resource_t resource)
Get the UUID of a resource.
Definition: manage_sql.c:5169
gchar * select
Column for SELECT.
Definition: manage_sql.h:301
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:40
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:3306
void reschedule_task(const gchar *task_id)
Set a task's schedule so that it runs again next scheduling round.
Definition: manage_sql.c:21024
Iterator column.
Definition: manage_sql.h:299
void check_generate_scripts()
Ensure the generate scripts are all executable.
Definition: manage_sql.c:18276
int init_task_schedule_iterator(iterator_t *iterator)
Initialise a task schedule iterator.
Definition: manage_sql.c:45540
void auto_delete_reports()
Auto delete reports.
Definition: manage_sql.c:20915
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:20620
int manage_option_setup(GSList *log_config, const gchar *database)
Setup for an option process.
Definition: manage_sql.c:1259
gchar * filter
Filter column name. NULL to use select_column.
Definition: manage_sql.h:302
void update_all_config_caches()
Update count and growing info in every config across all users.
Definition: manage_sql_configs.c:4419
gboolean task_schedule_iterator_timed_out(iterator_t *iterator)
Get if schedule of task in iterator is timed out.
Definition: manage_sql.c:45755
A generic SQL iterator structure.
Definition: iterator.h:50
int manage_update_cert_db_init()
Database specific setup for CERT update.
Definition: manage_pg.c:133
task_t task_schedule_iterator_task(iterator_t *iterator)
Get the task from a task schedule iterator.
Definition: manage_sql.c:45586
int manage_cert_db_exists()
Check if CERT db exists.
Definition: manage_pg.c:103
gchar * get_ovaldef_short_filename(char *item_id)
Get the short file name for an OVALDEF.
Definition: manage_sql_secinfo.c:948
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:4628
void parse_osp_report(task_t task, report_t report, const char *report_xml)
Parse an OSP report.
Definition: manage_sql.c:31921
credential_t target_ssh_credential(target_t target)
Return the SSH credential associated with a target, if any.
Definition: manage_sql.c:35359
void event(event_t event, void *event_data, resource_t resource_1, resource_t resource_2)
Produce an event.
Definition: manage_sql.c:14813
int manage_update_nvti_cache()
Update the memory cache of NVTs, if this has been requested.
Definition: manage_sql.c:15839
Command data for a get command.
Definition: manage.h:354
const char * run_status_name_internal(task_status_t status)
Get the unique name of a run status.
Definition: manage.c:1589
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:26026
int manage_db_check(const gchar *name)
Dummy function.
Definition: manage_pg.c:3735
int manage_scap_db_exists()
Check if SCAP db exists.
Definition: manage_pg.c:118
void manage_option_cleanup()
Cleanup for an option process.
Definition: manage_sql.c:1298
void manage_update_scap_db_cleanup()
Database specific cleanup after SCAP update.
Definition: manage_pg.c:439
void cleanup_task_schedule_iterator(iterator_t *iterator)
Cleanup a task schedule iterator.
Definition: manage_sql.c:45572
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:5503
void manage_session_init(const char *uuid)
Setup session.
Definition: manage_pg.c:51
int set_task_schedule_uuid(const gchar *task_id, schedule_t schedule, int periods)
Set the schedule of a task.
Definition: manage_sql.c:20399
void init_task_file_iterator(iterator_t *iterator, task_t task, const char *file)
Initialise a task file iterator.
Definition: manage_sql.c:33045
int parse_iso_time(const char *text_time)
Convert an ISO time into seconds since epoch.
Definition: manage_sql.c:887
void manage_update_cert_db_cleanup()
Database specific cleanup after CERT update.
Definition: manage_pg.c:216
int copy_resource_lock(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:4798
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:26919
gchar * report_host_ip(const char *host)
Get the IP of a host, using the 'hostname' report host details.
Definition: manage_sql.c:31875
port_list_t target_port_list(target_t target)
Return the port list associated with a target, if any.
Definition: manage_sql.c:35398
gchar * tag_value(const gchar *tags, const gchar *tag)
Extract a tag from a pipe separated tag list.
Definition: manage_sql.c:1166
int delete_report_internal(report_t report)
Delete a report.
Definition: manage_sql.c:26603
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:19803
void set_report_scheduled(report_t report)
Set a report's scheduled flag.
Definition: manage_sql.c:19714
credential_t target_esxi_credential(target_t target)
Return the ESXi credential associated with a target, if any.
Definition: manage_sql.c:35385
void update_config_cache_init(const char *uuid)
Update count and growing info in config, without checking user.
Definition: manage_sql_configs.c:4443
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:22235
int manage_db_empty()
Check whether database is empty.
Definition: manage_pg.c:83
alive_test_t target_alive_tests(target_t target)
Return a target's alive tests.
Definition: manage_sql.c:35489
nvti_t * lookup_nvti(const gchar *nvt)
Update the memory cache of NVTs.
Definition: manage_sql.c:15772
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:27985
void manage_db_check_mode(const gchar *name)
Dummy function.
Definition: manage_pg.c:3722