diff --git a/src/manage.c b/src/manage.c index bf0cd03a2..aefa21fd9 100644 --- a/src/manage.c +++ b/src/manage.c @@ -2117,11 +2117,6 @@ send_alive_test_preferences (target_t target) /* Defined in omp.c. */ void buffer_config_preference_xml (GString *, iterator_t *, config_t, int); -/** - * @brief Number of seconds to sleep between polls to slave. - */ -#define RUN_SLAVE_TASK_SLEEP_SECONDS 25 - /** * @brief Slave credential UUID. */ @@ -2341,8 +2336,8 @@ slave_sleep_connect (openvas_connection_t *connection, task_t task) return 3; } g_debug (" %s: sleeping for %i\n", __FUNCTION__, - RUN_SLAVE_TASK_SLEEP_SECONDS); - openvas_sleep (RUN_SLAVE_TASK_SLEEP_SECONDS); + manage_slave_check_period ()); + openvas_sleep (manage_slave_check_period ()); } while (slave_connect (connection)); g_debug (" %s: connected\n", __FUNCTION__); @@ -3540,7 +3535,9 @@ slave_setup (openvas_connection_t *connection, const char *name, task_t task, free_entity (get_tasks); - openvas_sleep (RUN_SLAVE_TASK_SLEEP_SECONDS); + g_debug (" %s: sleeping for %i\n", __FUNCTION__, + manage_slave_check_period ()); + openvas_sleep (manage_slave_check_period ()); } /* Cleanup. */ @@ -3746,7 +3743,9 @@ handle_slave_task (task_t task, target_t target, g_free (slave_task_name); return 0; } - openvas_sleep (RUN_SLAVE_TASK_SLEEP_SECONDS); + g_debug (" %s: sleeping for %i\n", __FUNCTION__, + manage_slave_check_period ()); + openvas_sleep (manage_slave_check_period ()); } while (1) diff --git a/src/manage.h b/src/manage.h index 2d2a46c0c..14f400547 100644 --- a/src/manage.h +++ b/src/manage.h @@ -3902,6 +3902,9 @@ manage_modify_setting (GSList *, const gchar *, const gchar *, const gchar *, co char * manage_default_ca_cert (); +int +manage_slave_check_period (); + /* Users. */ diff --git a/src/manage_sql.c b/src/manage_sql.c index 4c17a75c7..b31db9fb4 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -16388,6 +16388,17 @@ check_db_settings () " 'Auto Cache Rebuild'," " 'Whether to rebuild report caches on changes affecting severity.'," " '1');"); + + if (sql_int ("SELECT count(*) FROM settings" + " WHERE uuid = '" SETTING_UUID_SLAVE_CHECK_PERIOD "'" + " AND " ACL_IS_GLOBAL () ";") + == 0) + sql ("INSERT into settings (uuid, owner, name, comment, value)" + " VALUES" + " ('" SETTING_UUID_SLAVE_CHECK_PERIOD "', NULL," + " 'OMP Slave Check Period'," + " 'Period in seconds when polling an OMP slave'," + " 25);"); } /** @@ -64354,6 +64365,8 @@ setting_name (const gchar *uuid) return "Default CA Cert"; if (strcmp (uuid, SETTING_UUID_MAX_ROWS_PER_PAGE) == 0) return "Max Rows Per Page"; + if (strcmp (uuid, SETTING_UUID_SLAVE_CHECK_PERIOD) == 0) + return "OMP Slave Check Period"; return NULL; } @@ -64384,6 +64397,8 @@ setting_description (const gchar *uuid) return "Default CA Certificate for Scanners"; if (strcmp (uuid, SETTING_UUID_MAX_ROWS_PER_PAGE) == 0) return "The default maximum number of rows displayed in any listing."; + if (strcmp (uuid, SETTING_UUID_SLAVE_CHECK_PERIOD) == 0) + return "Period in seconds when polling an OMP slave"; return NULL; } @@ -64417,6 +64432,15 @@ setting_verify (const gchar *uuid, const gchar *value, const gchar *user) else if (max_rows < 0) return 1; } + + if (strcmp (uuid, SETTING_UUID_SLAVE_CHECK_PERIOD) == 0) + { + int period; + period = atoi (value); + if (period <= 0) + return 1; + } + return 0; } @@ -64469,7 +64493,8 @@ manage_modify_setting (GSList *log_config, const gchar *database, g_info (" Modifying setting.\n"); if (strcmp (uuid, SETTING_UUID_DEFAULT_CA_CERT) - && strcmp (uuid, SETTING_UUID_MAX_ROWS_PER_PAGE)) + && strcmp (uuid, SETTING_UUID_MAX_ROWS_PER_PAGE) + && strcmp (uuid, SETTING_UUID_SLAVE_CHECK_PERIOD)) { fprintf (stderr, "Error in setting UUID.\n"); return 3; @@ -64491,7 +64516,8 @@ manage_modify_setting (GSList *log_config, const gchar *database, { user_t user; - if (strcmp (uuid, SETTING_UUID_DEFAULT_CA_CERT) == 0) + if ((strcmp (uuid, SETTING_UUID_DEFAULT_CA_CERT) == 0) + || (strcmp (uuid, SETTING_UUID_SLAVE_CHECK_PERIOD) == 0)) { sql_rollback (); fprintf (stderr, @@ -64581,6 +64607,18 @@ manage_default_ca_cert () " WHERE uuid = '" SETTING_UUID_DEFAULT_CA_CERT "';"); } +/** + * @brief Get the slave check period. + * + * @return Number of seconds. + */ +int +manage_slave_check_period () +{ + return sql_int ("SELECT value FROM settings" + " WHERE uuid = '" SETTING_UUID_SLAVE_CHECK_PERIOD "';"); +} + /* SCAP. */ diff --git a/src/manage_sql.h b/src/manage_sql.h index ee36b7d63..8fbd57f9d 100644 --- a/src/manage_sql.h +++ b/src/manage_sql.h @@ -222,6 +222,11 @@ */ #define SETTING_UUID_DEFAULT_CA_CERT "9ac801ea-39f8-11e6-bbaa-28d24461215b" +/** + * @brief UUID of 'OMP Slave Check Period' setting. + */ +#define SETTING_UUID_SLAVE_CHECK_PERIOD "63adb79a-62ae-11e9-91ba-28d24461215b" + /** * @brief Trust constant for error. */