Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Handle timeout more like other VT prefs #2377

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 257)
set (GVMD_DATABASE_VERSION 258)

set (GVMD_SCAP_DATABASE_VERSION 22)

Expand Down
43 changes: 9 additions & 34 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8731,6 +8731,11 @@ buffer_config_preference_xml (GString *buffer, iterator_t *prefs,
oid = nvt_preference_iterator_oid (prefs);
type = nvt_preference_iterator_type (prefs);
real_name = nvt_preference_iterator_real_name (prefs);
if (strcmp (real_name, "timeout") == 0)
{
g_free (real_name);
real_name = g_strdup ("Timeout");
}
default_value = nvt_preference_iterator_value (prefs);
value = nvt_preference_iterator_config_value (prefs, config);
id = nvt_preference_iterator_id (prefs);
Expand Down Expand Up @@ -12147,33 +12152,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)

SEND_TO_CLIENT_OR_FAIL ("<preferences>");

/* Send NVT timeout preferences where a timeout has been
* specified. */
init_config_timeout_iterator (&prefs, config);
while (next (&prefs))
{
const char *timeout;

timeout = config_timeout_iterator_value (&prefs);

if (timeout && strlen (timeout))
SENDF_TO_CLIENT_OR_FAIL
("<preference>"
"<nvt oid=\"%s\">"
"<name>%s</name>"
"</nvt>"
"<id>0</id>"
"<name>Timeout</name>"
"<type>entry</type>"
"<value>%s</value>"
"</preference>",
config_timeout_iterator_oid (&prefs),
config_timeout_iterator_nvt_name (&prefs),
timeout);
}
cleanup_iterator (&prefs);

init_nvt_preference_iterator (&prefs, NULL);
init_nvt_preference_iterator (&prefs, NULL, TRUE);
while (next (&prefs))
{
GString *buffer = g_string_new ("");
Expand Down Expand Up @@ -14246,15 +14225,10 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)
int pref_count = -1;
char *timeout = NULL;

if (get_nvts_data->timeout)
if (get_nvts_data->timeout || get_nvts_data->preferences)
timeout = config_nvt_timeout (config,
nvt_iterator_oid (&nvts));

if (get_nvts_data->preferences && (timeout == NULL))
timeout = config_nvt_timeout
(config,
nvt_iterator_oid (&nvts));

if (get_nvts_data->preference_count)
{
const char *nvt_oid;
Expand All @@ -14268,6 +14242,7 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)
else
pref_count = nvt_preference_count (nvt_oid);
}

if (send_nvt (&nvts, 1, get_nvts_data->preferences,
pref_count, timeout, config,
get_nvts_data->skip_cert_refs,
Expand Down Expand Up @@ -14829,7 +14804,7 @@ handle_get_preferences (gmp_parser_t *gmp_parser, GError **error)
SEND_TO_CLIENT_OR_FAIL ("<get_preferences_response"
" status=\"" STATUS_OK "\""
" status_text=\"" STATUS_OK_TEXT "\">");
init_nvt_preference_iterator (&prefs, nvt_oid);
init_nvt_preference_iterator (&prefs, nvt_oid, FALSE);
if (get_preferences_data->preference)
while (next (&prefs))
{
Expand Down
17 changes: 5 additions & 12 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -2828,19 +2828,12 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id,
g_strdup (name),
g_strdup (osp_value));
}
/* Timeouts are stored as SERVER_PREFS, but are actually
script preferences. This prefs is converted into a
script preference to be sent to the scanner. */
else if (name && value && g_str_has_prefix (name, "timeout."))
{
char **oid = NULL;
osp_vt_single_t *osp_vt = NULL;

oid = g_strsplit (name, ".", 2);
osp_vt = g_hash_table_lookup (vts_hash_table, oid[1]);
if (osp_vt)
osp_vt_single_add_value (osp_vt, "0", value);
g_strfreev (oid);
/* Timeouts used to be stored as SERVER_PREFS, but were
* converted into a script preference to be sent to the scanner. */
g_warning ("%s: Timeout preference using obsolete format: %s",
__func__, name);
}

}
Expand Down Expand Up @@ -6565,7 +6558,7 @@ get_nvt_xml (iterator_t *nvts, int details, int pref_count,
timeout ? timeout : "",
default_timeout ? default_timeout : "");

init_nvt_preference_iterator (&prefs, nvt_oid);
init_nvt_preference_iterator (&prefs, nvt_oid, FALSE);
while (next (&prefs))
buffer_config_preference_xml (buffer, &prefs, config, 1);
cleanup_iterator (&prefs);
Expand Down
2 changes: 1 addition & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ void
manage_nvt_preferences_enable ();

void
init_nvt_preference_iterator (iterator_t*, const char*);
init_nvt_preference_iterator (iterator_t*, const char*, gboolean);

const char*
nvt_preference_iterator_name (iterator_t*);
Expand Down
12 changes: 0 additions & 12 deletions src/manage_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ int
manage_set_config_families (config_t, GPtrArray*, GPtrArray*, GPtrArray*, int,
gchar **);

void
init_config_timeout_iterator (iterator_t*, config_t);

const char*
config_timeout_iterator_oid (iterator_t *);

const char*
config_timeout_iterator_nvt_name (iterator_t *);

const char*
config_timeout_iterator_value (iterator_t *);

gboolean
configs_feed_dir_exists ();

Expand Down
51 changes: 51 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -3255,6 +3255,56 @@ migrate_256_to_257 ()
return 0;
}

/**
* @brief Migrate the database from version 256 to version 257.
*
* @return 0 success, -1 error.
*/
int
migrate_257_to_258 ()
{
sql_begin_immediate ();

/* Ensure that the database is currently version 257. */

if (manage_db_version () != 257)
{
sql_rollback ();
return -1;
}

/* Update the database. */

// Change timeout config preferences to normal VT preferences

sql ("UPDATE config_preferences SET"
" type = 'PLUGINS_PREFS',"
" name = substring(name, 9) || ':0:entry:timeout',"
" pref_nvt = substring(name, 9),"
" pref_id = 0,"
" pref_type = 'entry',"
" pref_name = 'timeout'"
" WHERE name LIKE 'timeout.%%' AND type = 'SERVER_PREFS';");


sql ("UPDATE config_preferences_trash SET"
" type = 'PLUGINS_PREFS',"
" name = substring(name, 9) || ':0:entry:timeout',"
" pref_nvt = substring(name, 9),"
" pref_id = 0,"
" pref_type = 'entry',"
" pref_name = 'timeout'"
" WHERE name LIKE 'timeout.%%' AND type = 'SERVER_PREFS';");

/* Set the database version to 258. */

set_db_version (258);

sql_commit ();

return 0;
}

#undef UPDATE_DASHBOARD_SETTINGS

/**
Expand Down Expand Up @@ -3318,6 +3368,7 @@ static migrator_t database_migrators[] = {
{255, migrate_254_to_255},
{256, migrate_255_to_256},
{257, migrate_256_to_257},
{258, migrate_257_to_258},
/* End marker. */
{-1, NULL}};

Expand Down
Loading
Loading