OpenVAS Manager  7.0.3~git
manage_sql.h
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: Manager Manage library: SQL backend headers.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  * Timo Pollmeier <timo.pollmeier@greenbone.net>
8  *
9  * Copyright:
10  * Copyright (C) 2010-2013 Greenbone Networks GmbH
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26 
27 #ifndef OPENVAS_MANAGER_MANAGE_SQL_H
28 #define OPENVAS_MANAGER_MANAGE_SQL_H
29 
30 #include "manage.h"
31 #include "manage_utils.h"
32 #include <openvas/omp/xml.h>
33 
34 /* Internal types and preprocessor definitions. */
35 
39 #define CONFIG_UUID_FULL_AND_FAST "daba56c8-73ec-11df-a475-002264764cea"
40 
44 #define CONFIG_UUID_FULL_AND_FAST_ULTIMATE \
45  "698f691e-7489-11df-9d8c-002264764cea"
46 
50 #define CONFIG_UUID_FULL_AND_VERY_DEEP "708f25c4-7489-11df-8094-002264764cea"
51 
55 #define CONFIG_UUID_FULL_AND_VERY_DEEP_ULTIMATE \
56  "74db13d6-7489-11df-91b9-002264764cea"
57 
61 #define CONFIG_UUID_EMPTY "085569ce-73ed-11df-83c3-002264764cea"
62 
66 #define CONFIG_UUID_DISCOVERY "8715c877-47a0-438d-98a3-27c7a6ab2196"
67 
71 #define CONFIG_UUID_HOST_DISCOVERY "2d3f051c-55ba-11e3-bf43-406186ea4fc5"
72 
76 #define CONFIG_UUID_SYSTEM_DISCOVERY "bbca7412-a950-11e3-9109-406186ea4fc5"
77 
81 #define LOCATION_TABLE 0
82 
86 #define LOCATION_TRASH 1
87 
91 #define MANAGE_NVT_SELECTOR_UUID_ALL "54b45713-d4f4-4435-b20d-304c175ed8c5"
92 
96 #define MANAGE_NVT_SELECTOR_UUID_DISCOVERY "0d9a2738-8fe2-4e22-8f26-bb886179e759"
97 
101 #define MANAGE_NVT_SELECTOR_UUID_HOST_DISCOVERY \
102  "f5f80744-55c7-11e3-8dc6-406186ea4fc5"
103 
107 #define MANAGE_NVT_SELECTOR_UUID_SYSTEM_DISCOVERY \
108  "07045d1c-a951-11e3-8da7-406186ea4fc5"
109 
113 #define PERMISSION_UUID_ADMIN_EVERYTHING "b3b56a8c-c2fd-11e2-a135-406186ea4fc5"
114 
118 #define PERMISSION_UUID_SUPER_ADMIN_EVERYTHING "a9801074-6fe2-11e4-9d81-406186ea4fc5"
119 
123 #define PORT_LIST_UUID_DEFAULT "c7e03b6c-3bbe-11e1-a057-406186ea4fc5"
124 
128 #define PORT_LIST_UUID_ALL_TCP "fd591a34-56fd-11e1-9f27-406186ea4fc5"
129 
133 #define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_100 "730ef368-57e2-11e1-a90f-406186ea4fc5"
134 
138 #define PORT_LIST_UUID_ALL_TCP_NMAP_5_51_TOP_1000 "9ddce1ae-57e7-11e1-b13c-406186ea4fc5"
139 
143 #define PORT_LIST_UUID_ALL_PRIV_TCP "492b72f4-56fe-11e1-98a7-406186ea4fc5"
144 
148 #define PORT_LIST_UUID_ALL_PRIV_TCP_UDP "5f2029f6-56fe-11e1-bb94-406186ea4fc5"
149 
153 #define PORT_LIST_UUID_ALL_IANA_TCP_2012 "33d0cd82-57c6-11e1-8ed1-406186ea4fc5"
154 
158 #define PORT_LIST_UUID_ALL_IANA_TCP_UDP_2012 "4a4717fe-57d2-11e1-9a26-406186ea4fc5"
159 
163 #define PORT_LIST_UUID_NMAP_5_51_TOP_2000_TOP_100 "ab33f6b0-57f8-11e1-96f5-406186ea4fc5"
164 
168 #define ROLE_UUID_ADMIN "7a8cb5b4-b74d-11e2-8187-406186ea4fc5"
169 
173 #define ROLE_UUID_GUEST "cc9cac5e-39a3-11e4-abae-406186ea4fc5"
174 
178 #define ROLE_UUID_INFO "5f8fd16c-c550-11e3-b6ab-406186ea4fc5"
179 
183 #define ROLE_UUID_MONITOR "12cdb536-480b-11e4-8552-406186ea4fc5"
184 
188 #define ROLE_UUID_USER "8d453140-b74d-11e2-b0be-406186ea4fc5"
189 
193 #define ROLE_UUID_SUPER_ADMIN "9c5a6ec6-6fe2-11e4-8cb6-406186ea4fc5"
194 
198 #define ROLE_UUID_OBSERVER "87a7ebce-b74d-11e2-a81f-406186ea4fc5"
199 
203 #define SCANNER_UUID_DEFAULT "08b69003-5fc2-4037-a479-93b440211c73"
204 
208 #define SCANNER_UUID_CVE "6acd0832-df90-11e4-b9d5-28d24461215b"
209 
213 #define SETTING_UUID_ROWS_PER_PAGE "5f5a8712-8017-11e1-8556-406186ea4fc5"
214 
218 #define SETTING_UUID_MAX_ROWS_PER_PAGE "76374a7a-0569-11e6-b6da-28d24461215b"
219 
223 #define SETTING_UUID_DEFAULT_CA_CERT "9ac801ea-39f8-11e6-bbaa-28d24461215b"
224 
228 #define TRUST_ERROR 0
229 
233 #define TRUST_YES 1
234 
238 #define TRUST_NO 2
239 
243 #define TRUST_UNKNOWN 3
244 
248 #define TIMEVAL_SUBTRACT_MS(a,b) ((((a).tv_sec - (b).tv_sec) * 1000) + \
249  ((a).tv_usec - (b).tv_usec) / 1000)
250 
251 
252 /* Variables */
253 
254 extern gchar *task_db_name;
255 
256 
257 /* Function prototypes */
258 
259 typedef long long int rowid_t;
260 
261 void
262 array_add_new_string (array_t *, const gchar *);
263 
264 int manage_db_empty ();
265 
266 gboolean
267 host_nthlast_report_host (const char *, report_host_t *, int);
268 
269 char*
270 report_host_ip (const char *);
271 
272 gchar *tag_value (const gchar *, const gchar *);
273 
274 void trim_report (report_t);
275 
277 
279 
281 
282 int update_from_slave (task_t, entity_t, entity_t *, int *);
283 
284 void set_report_slave_task_uuid (report_t, const char *);
285 
287 
288 void init_task_file_iterator (iterator_t *, task_t, const char *);
289 const char *task_file_iterator_name (iterator_t *);
290 const char *task_file_iterator_content (iterator_t *);
291 
292 void set_task_schedule_next_time (task_t, time_t);
293 
294 void set_task_schedule_next_time_uuid (const gchar *, time_t);
295 
296 void init_otp_pref_iterator (iterator_t *, config_t, const char *);
297 const char *otp_pref_iterator_name (iterator_t *);
298 const char *otp_pref_iterator_value (iterator_t *);
299 
305 
307 
308 char *alert_data (alert_t, const char *, const char *);
309 
311 
313 
315 
317 
319 
321 
323 
325 
327 
329 
331 
333 
335 
337 
339 
341 
343 
344 int set_task_schedule_uuid (const gchar*, schedule_t, int);
345 
346 void reinit_manage_process ();
347 
349 
350 int manage_report_host_details (report_t, const char *, entity_t);
351 
353 
354 gchar *get_ovaldef_short_filename (char*);
355 
356 void update_config_cache_init (const char *);
357 
359 
360 void manage_session_init (const char *);
361 
362 int valid_omp_command (const char *);
363 
364 void check_generate_scripts ();
365 
366 void auto_delete_reports ();
367 
368 int parse_iso_time (const char *);
369 
370 int days_from_now (time_t *epoch_time);
371 
373 
374 gchar *resource_uuid (const gchar *, resource_t);
375 
376 gboolean find_resource_with_permission (const char *, const char *,
377  resource_t *, const char *, int);
378 
380 
381 void parse_osp_report (task_t, report_t, const char *);
382 
383 void reschedule_task (const gchar *);
384 
385 void insert_port_range (port_list_t, port_protocol_t, int, int);
386 
387 #endif /* not OPENVAS_MANAGER_MANAGE_SQL_H */
void auto_delete_reports()
Auto delete reports.
Definition: manage_sql.c:19380
const char * task_file_iterator_name(iterator_t *)
long long int schedule_t
Definition: manage.h:299
task_status_t
Task statuses, also used as scan/report statuses.
Definition: manage.h:218
gchar * task_db_name
Name of the database file.
Definition: manage_sql.c:403
long long int credential_t
Definition: manage.h:279
int set_report_slave_progress(report_t, int)
Set slave progress of a report.
Definition: manage_sql.c:25451
long long int alert_t
Definition: manage.h:280
credential_t target_ssh_credential(target_t)
Return the SSH credential associated with a target, if any.
Definition: manage_sql.c:34957
time_t task_schedule_iterator_initial_offset(iterator_t *)
Get the initial offset from a task schedule iterator.
Definition: manage_sql.c:49493
long long int target_t
Definition: manage.h:285
gchar * resource_uuid(const gchar *, resource_t)
Get the UUID of a resource.
Definition: manage_sql.c:4971
void reschedule_task(const gchar *)
Set a task&#39;s schedule so that it runs again next scheduling round.
Definition: manage_sql.c:19482
long long int config_t
Definition: manage.h:278
const char * otp_pref_iterator_name(iterator_t *)
char * task_definitions_file(task_t)
Get definitions file from a task&#39;s config.
Definition: manage_sql.c:19468
int set_report_scan_run_status(report_t, task_status_t)
Return the run status of the scan associated with a report.
Definition: manage_sql.c:24512
time_t task_schedule_iterator_duration(iterator_t *)
Get the duration from a task schedule iterator.
Definition: manage_sql.c:49449
void set_report_scheduled(report_t)
Set a report&#39;s scheduled flag.
Definition: manage_sql.c:18252
A generic SQL iterator.
Definition: iterator.h:52
void set_task_schedule_next_time_uuid(const gchar *, time_t)
Set the next time a scheduled task will be due.
Definition: manage_sql.c:19071
int set_task_requested(task_t, task_status_t *)
Atomically set the run state of a task to requested.
Definition: manage_sql.c:18336
char * alert_data(alert_t, const char *, const char *)
Return data associated with an alert.
Definition: manage_sql.c:8810
int manage_db_empty()
Check whether database is empty.
Definition: manage_pg.c:78
void check_generate_scripts()
Ensure the generate scripts are all executable.
Definition: manage_sql.c:16716
int update_from_slave(task_t, entity_t, entity_t *, int *)
Update the local task from the slave task.
Definition: manage_sql.c:53064
void array_add_new_string(array_t *, const gchar *)
Ensure a string is in an array.
Definition: manage_sql.c:710
void reinit_manage_process()
Reinitialize the manage library for a process.
Definition: manage_sql.c:14347
const char * task_schedule_iterator_task_uuid(iterator_t *)
int set_task_schedule_uuid(const gchar *, schedule_t, int)
Set the schedule of a task.
Definition: manage_sql.c:18836
alive_test_t target_alive_tests(target_t)
Return a target&#39;s alive tests.
Definition: manage_sql.c:35087
schedule_t task_schedule_iterator_schedule(iterator_t *)
Get the schedule from a task schedule iterator.
Definition: manage_sql.c:49379
gboolean host_nthlast_report_host(const char *, report_host_t *, int)
Get N&#39;th last report_host given a host.
Definition: manage_sql.c:26519
const char * task_schedule_iterator_owner_uuid(iterator_t *)
gchar * tag_value(const gchar *, const gchar *)
Extract a tag from an OTP tag list.
Definition: manage_sql.c:1269
char * target_port_range(target_t)
Return the port range of a target, in OTP format.
Definition: manage_sql.c:35030
long long int report_t
Definition: manage.h:288
void init_task_file_iterator(iterator_t *, task_t, const char *)
Initialise a task file iterator.
Definition: manage_sql.c:32760
alive_test_t
Alive tests.
Definition: manage.h:252
const char * run_status_name_internal(task_status_t)
Get the unique name of a run status.
Definition: manage.c:1288
task_t task_schedule_iterator_task(iterator_t *)
Get the task from a task schedule iterator.
Definition: manage_sql.c:49355
const char * otp_pref_iterator_value(iterator_t *)
void trim_report(report_t)
Prepare a partial report for restarting the scan from the beginning.
Definition: manage_sql.c:25501
void update_config_cache_init(const char *)
Update count and growing info in config, without checking user.
Definition: manage_sql.c:38210
int days_from_now(time_t *epoch_time)
Calculate difference between now and epoch_time in days.
Definition: manage_sql.c:1072
long long int port_list_t
Definition: manage.h:297
const char * task_file_iterator_content(iterator_t *)
int parse_iso_time(const char *)
Convert an ISO time into seconds since epoch.
Definition: manage_sql.c:875
credential_t target_esxi_credential(target_t)
Return the ESXi credential associated with a target, if any.
Definition: manage_sql.c:34983
void insert_port_range(port_list_t, port_protocol_t, int, int)
Create a port range.
Definition: manage_sql.c:56393
time_t task_schedule_iterator_next_time(iterator_t *)
Get the next time from a task schedule iterator.
Definition: manage_sql.c:49393
time_t task_schedule_iterator_period_months(iterator_t *)
Get the period months from a task schedule iterator.
Definition: manage_sql.c:49421
int delete_report_internal(report_t)
Delete a report.
Definition: manage_sql.c:25198
gboolean task_schedule_iterator_stop_due(iterator_t *)
Get the stop due state from a task schedule iterator.
Definition: manage_sql.c:49539
long long int rowid_t
Definition: manage_sql.h:259
time_t task_schedule_iterator_period(iterator_t *)
Get the period from a task schedule iterator.
Definition: manage_sql.c:49407
gboolean find_resource_with_permission(const char *, const char *, resource_t *, const char *, int)
Find a resource given a UUID and a permission.
Definition: manage_sql.c:4459
port_list_t target_port_list(target_t)
Return the port list associated with a target, if any.
Definition: manage_sql.c:34996
void init_otp_pref_iterator(iterator_t *, config_t, const char *)
Initialise an "OTP" preference iterator.
Definition: manage_sql.c:36649
gchar * get_ovaldef_short_filename(char *)
Get the short file name for an OVALDEF.
Definition: manage_sql.c:64305
int init_task_schedule_iterator(iterator_t *)
Initialise a task schedule iterator.
Definition: manage_sql.c:49284
const char * task_schedule_iterator_owner_name(iterator_t *)
time_t task_schedule_iterator_first_time(iterator_t *)
Get the first time from a task schedule iterator.
Definition: manage_sql.c:49435
void parse_osp_report(task_t, report_t, const char *)
Parse an OSP report.
Definition: manage_sql.c:31533
int manage_update_nvti_cache()
Update the memory cache of NVTs, if this has been requested.
Definition: manage_sql.c:14475
gboolean task_schedule_iterator_start_due(iterator_t *)
Get the start due state from a task schedule iterator.
Definition: manage_sql.c:49507
long long int report_host_t
Definition: manage.h:289
int create_current_report(task_t, char **, task_status_t)
Create the current report for a task.
Definition: manage_sql.c:21002
credential_t target_smb_credential(target_t)
Return the SMB credential associated with a target, if any.
Definition: manage_sql.c:34970
gboolean task_schedule_iterator_timed_out(iterator_t *)
Get if schedule of task in iterator is timed out.
Definition: manage_sql.c:49587
void manage_session_init(const char *)
Setup session.
Definition: manage_pg.c:46
void set_report_slave_task_uuid(report_t, const char *)
Set the UUID of the slave task, on the local task.
Definition: manage_sql.c:25486
void cleanup_task_schedule_iterator(iterator_t *)
Cleanup a task schedule iterator.
Definition: manage_sql.c:49341
void set_task_schedule_next_time(task_t, time_t)
Set the next time a scheduled task will be due.
Definition: manage_sql.c:19058
char * report_host_ip(const char *)
Get the IP of a host, using the &#39;hostname&#39; report host details.
Definition: manage_sql.c:31487
long long int task_t
Definition: manage.h:286
int manage_report_host_details(report_t, const char *, entity_t)
Add host details to a report host.
Definition: manage_sql.c:60642
int valid_omp_command(const char *)
Check whether a command name is valid.
Definition: manage_sql.c:545
const char * task_schedule_iterator_timezone(iterator_t *)
long long int resource_t
A resource, like a task or target.
Definition: iterator.h:42