Skip to content

Commit

Permalink
Merge pull request #491 from mattmundell/slave-interval-setting-7.0
Browse files Browse the repository at this point in the history
Add setting 'OMP Slave Check Period'
  • Loading branch information
timopollmeier authored Apr 24, 2019
2 parents 10a021a + 5761526 commit 045e273
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
17 changes: 8 additions & 9 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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__);
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down
42 changes: 40 additions & 2 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);");
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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. */

Expand Down
5 changes: 5 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 045e273

Please sign in to comment.