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)
 
char * report_host_ip (const char *)
 
gchar * tag_value (const gchar *, const gchar *)
 Extract a tag from an OTP tag list. More...
 
void trim_report (report_t)
 
int delete_report_internal (report_t)
 
int set_report_scan_run_status (report_t, task_status_t)
 
int set_report_slave_progress (report_t, int)
 
int update_from_slave (task_t, entity_t, entity_t *, int *)
 
void set_report_slave_task_uuid (report_t, const char *)
 
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 *)
 
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 *)
 
const char * otp_pref_iterator_name (iterator_t *)
 
const char * otp_pref_iterator_value (iterator_t *)
 
port_list_t target_port_list (target_t)
 
char * target_port_range (target_t)
 
credential_t target_ssh_credential (target_t)
 
credential_t target_smb_credential (target_t)
 
credential_t target_esxi_credential (target_t)
 
int create_current_report (task_t, char **, task_status_t)
 
char * alert_data (alert_t, const char *, const char *)
 Return data associated with an alert. More...
 
int init_task_schedule_iterator (iterator_t *)
 
void cleanup_task_schedule_iterator (iterator_t *)
 
task_t task_schedule_iterator_task (iterator_t *)
 
const char * task_schedule_iterator_task_uuid (iterator_t *)
 
schedule_t task_schedule_iterator_schedule (iterator_t *)
 
time_t task_schedule_iterator_next_time (iterator_t *)
 
time_t task_schedule_iterator_period (iterator_t *)
 
time_t task_schedule_iterator_period_months (iterator_t *)
 
time_t task_schedule_iterator_duration (iterator_t *)
 
gboolean task_schedule_iterator_timed_out (iterator_t *)
 
gboolean task_schedule_iterator_start_due (iterator_t *)
 
gboolean task_schedule_iterator_stop_due (iterator_t *)
 
time_t task_schedule_iterator_first_time (iterator_t *)
 
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 *)
 
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)
 
const char * run_status_name_internal (task_status_t)
 Get the unique name of a run status. More...
 
gchar * get_ovaldef_short_filename (char *)
 
void update_config_cache_init (const char *)
 
alive_test_t target_alive_tests (target_t)
 
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 ()
 
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)
 
void parse_osp_report (task_t, report_t, const char *)
 
void reschedule_task (const gchar *)
 
void insert_port_range (port_list_t, port_protocol_t, int, int)
 

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ LOCATION_TABLE

#define LOCATION_TABLE   0

Location of a constituent of a trashcan resource.

Definition at line 81 of file manage_sql.h.

◆ LOCATION_TRASH

#define LOCATION_TRASH   1

Location of a constituent of a trashcan resource.

Definition at line 86 of file manage_sql.h.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ PORT_LIST_UUID_DEFAULT

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

UUID of 'OpenVAS Default' port list.

Definition at line 123 of file manage_sql.h.

◆ 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.

◆ ROLE_UUID_ADMIN

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

Predefined role UUID.

Definition at line 168 of file manage_sql.h.

◆ ROLE_UUID_GUEST

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

Predefined role UUID.

Definition at line 173 of file manage_sql.h.

◆ ROLE_UUID_INFO

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

Predefined role UUID.

Definition at line 178 of file manage_sql.h.

◆ ROLE_UUID_MONITOR

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

Predefined role UUID.

Definition at line 183 of file manage_sql.h.

◆ ROLE_UUID_OBSERVER

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

Predefined role UUID.

Definition at line 198 of file manage_sql.h.

◆ ROLE_UUID_SUPER_ADMIN

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

Predefined role UUID.

Definition at line 193 of file manage_sql.h.

◆ ROLE_UUID_USER

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

Predefined role UUID.

Definition at line 188 of file manage_sql.h.

◆ 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.

◆ SCANNER_UUID_DEFAULT

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

UUID of 'OpenVAS Default' scanner.

Definition at line 203 of file manage_sql.h.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ TRUST_YES

#define TRUST_YES   1

Trust constant for yes.

Definition at line 233 of file manage_sql.h.

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.

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

References sql_quote(), and sql_string().

Referenced by alert_condition_description(), and migrate_165_to_166().

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.

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 }

◆ auto_delete_reports()

void auto_delete_reports ( )

Referenced by manage_schedule().

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.

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,
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 * user_uuid(user_t)
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
char * report_format_uuid(report_format_t)
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

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

Referenced by migrate_147_to_148().

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 )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ create_current_report()

int create_current_report ( task_t  ,
char **  ,
task_status_t   
)

◆ 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  )

Referenced by delete_reports().

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.

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

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

Referenced by find_alert_with_permission().

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 *  )

◆ host_nthlast_report_host()

gboolean host_nthlast_report_host ( const char *  ,
report_host_t ,
int   
)

◆ init_otp_pref_iterator()

void init_otp_pref_iterator ( iterator_t ,
config_t  ,
const char *   
)

◆ init_task_file_iterator()

void init_task_file_iterator ( iterator_t ,
task_t  ,
const char *   
)

◆ init_task_schedule_iterator()

int init_task_schedule_iterator ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ insert_port_range()

void insert_port_range ( port_list_t  ,
port_protocol_t  ,
int  ,
int   
)

◆ 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.

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

References sql_database(), and sql_int().

Referenced by manage_db_version().

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  ,
const char *  ,
entity_t   
)

Referenced by update_end_times().

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.

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

References sql().

Referenced by acl_users_with_access_sql(), and manage_schedule().

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.

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

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

Referenced by manage_schedule().

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.

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

Referenced by manage_system_report(), and set_task_start_time().

Here is the caller graph for this function:

◆ parse_osp_report()

void parse_osp_report ( task_t  ,
report_t  ,
const char *   
)

◆ 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.

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

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

Referenced by manage_schedule().

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 *  )

◆ reschedule_task()

void reschedule_task ( const gchar *  )

Referenced by manage_schedule().

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.

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

References sql_string(), and valid_db_resource_type().

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.

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 }

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.

◆ set_report_scan_run_status()

int set_report_scan_run_status ( report_t  ,
task_status_t   
)

◆ 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.

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

References authenticate_allow_all, and sql().

Here is the call graph for this function:

◆ set_report_slave_progress()

int set_report_slave_progress ( report_t  ,
int   
)

Referenced by update_slave_progress().

Here is the caller graph for this function:

◆ set_report_slave_task_uuid()

void set_report_slave_task_uuid ( report_t  ,
const char *   
)

◆ 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.

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

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.

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.

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

References sql().

Referenced by manage_schedule().

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.

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

References sql(), sql_quote(), and task_id().

Referenced by manage_schedule().

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.

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

References sql(), sql_quote(), and task_id().

Referenced by manage_schedule().

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_esxi_credential()

credential_t target_esxi_credential ( target_t  )

◆ target_port_list()

port_list_t target_port_list ( target_t  )

◆ target_port_range()

char* target_port_range ( target_t  )

◆ target_smb_credential()

credential_t target_smb_credential ( target_t  )

◆ target_ssh_credential()

credential_t target_ssh_credential ( target_t  )

◆ task_definitions_file()

char* task_definitions_file ( task_t  )

◆ 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 )

◆ task_schedule_iterator_first_time()

time_t task_schedule_iterator_first_time ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_initial_offset()

time_t task_schedule_iterator_initial_offset ( iterator_t )

◆ task_schedule_iterator_next_time()

time_t task_schedule_iterator_next_time ( iterator_t )

◆ 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 )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_period_months()

time_t task_schedule_iterator_period_months ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_schedule()

schedule_t task_schedule_iterator_schedule ( iterator_t )

◆ task_schedule_iterator_start_due()

gboolean task_schedule_iterator_start_due ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_stop_due()

gboolean task_schedule_iterator_stop_due ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_task()

task_t task_schedule_iterator_task ( iterator_t )

Referenced by manage_schedule().

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 )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ task_schedule_iterator_timezone()

const char* task_schedule_iterator_timezone ( iterator_t )

Referenced by manage_schedule().

Here is the caller graph for this function:

◆ trim_report()

void trim_report ( report_t  )

◆ update_config_cache_init()

void update_config_cache_init ( const char *  )

Referenced by check_config_host_discovery(), and check_config_system_discovery().

Here is the caller graph for this function:

◆ update_from_slave()

int update_from_slave ( task_t  ,
entity_t  ,
entity_t *  ,
int *   
)

◆ 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.

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

References omp_commands.

Referenced by acl_user_has_access_uuid().

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().