Skip to content

Commit

Permalink
Rename and fix preference allow_simultaneous_ips
Browse files Browse the repository at this point in the history
The target field and scanner preference allow_simult_ips_same_host is
renamed to allow_simultaneous_ips to avoid abbreviations.
Also, sending the preference now uses the correct name and missing GMP
documentation for create_target has been added.
  • Loading branch information
timopollmeier committed Jan 22, 2021
1 parent d10020f commit 2b664a7
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 67 deletions.
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 240)
set (GVMD_DATABASE_VERSION 241)

set (GVMD_SCAP_DATABASE_VERSION 17)

Expand Down
48 changes: 24 additions & 24 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ create_schedule_data_reset (create_schedule_data_t *data)
typedef struct
{
char *alive_tests; ///< Alive tests.
char *allow_simult_ips_same_host; ///< Boolean. Whether to scan multiple IPs of a host simultaneously.
char *allow_simultaneous_ips; ///< Boolean. Whether to scan multiple IPs of a host simultaneously.
char *asset_hosts_filter; ///< Asset hosts.
char *comment; ///< Comment.
char *exclude_hosts; ///< Hosts to exclude from set.
Expand Down Expand Up @@ -946,7 +946,7 @@ static void
create_target_data_reset (create_target_data_t *data)
{
free (data->alive_tests);
free (data->allow_simult_ips_same_host);
free (data->allow_simultaneous_ips);
free (data->asset_hosts_filter);
free (data->comment);
free (data->exclude_hosts);
Expand Down Expand Up @@ -2834,7 +2834,7 @@ modify_setting_data_reset (modify_setting_data_t *data)
typedef struct
{
char *alive_tests; ///< Alive tests.
char *allow_simult_ips_same_host; ///< Boolean. Whether to scan multiple IPs of a host simultaneously.
char *allow_simultaneous_ips; ///< Boolean. Whether to scan multiple IPs of a host simultaneously.
char *comment; ///< Comment.
char *exclude_hosts; ///< Hosts to exclude from set.
char *reverse_lookup_only; ///< Boolean. Whether to consider only hosts that reverse lookup.
Expand Down Expand Up @@ -2863,7 +2863,7 @@ static void
modify_target_data_reset (modify_target_data_t *data)
{
free (data->alive_tests);
free (data->allow_simult_ips_same_host);
free (data->allow_simultaneous_ips);
free (data->exclude_hosts);
free (data->reverse_lookup_only);
free (data->reverse_lookup_unify);
Expand Down Expand Up @@ -4266,7 +4266,7 @@ typedef enum
CLIENT_CREATE_TAG_VALUE,
CLIENT_CREATE_TARGET,
CLIENT_CREATE_TARGET_ALIVE_TESTS,
CLIENT_CREATE_TARGET_ALLOW_SIMULT_IPS_SAME_HOST,
CLIENT_CREATE_TARGET_ALLOW_SIMULTANEOUS_IPS,
CLIENT_CREATE_TARGET_ASSET_HOSTS,
CLIENT_CREATE_TARGET_EXCLUDE_HOSTS,
CLIENT_CREATE_TARGET_REVERSE_LOOKUP_ONLY,
Expand Down Expand Up @@ -4513,7 +4513,7 @@ typedef enum
CLIENT_MODIFY_TAG_VALUE,
CLIENT_MODIFY_TARGET,
CLIENT_MODIFY_TARGET_ALIVE_TESTS,
CLIENT_MODIFY_TARGET_ALLOW_SIMULT_IPS_SAME_HOST,
CLIENT_MODIFY_TARGET_ALLOW_SIMULTANEOUS_IPS,
CLIENT_MODIFY_TARGET_COMMENT,
CLIENT_MODIFY_TARGET_ESXI_CREDENTIAL,
CLIENT_MODIFY_TARGET_ESXI_LSC_CREDENTIAL,
Expand Down Expand Up @@ -6596,8 +6596,8 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
set_client_state (CLIENT_MODIFY_TARGET_REVERSE_LOOKUP_UNIFY);
else if (strcasecmp ("ALIVE_TESTS", element_name) == 0)
set_client_state (CLIENT_MODIFY_TARGET_ALIVE_TESTS);
else if (strcasecmp ("ALLOW_SIMULT_IPS_SAME_HOST", element_name) == 0)
set_client_state (CLIENT_MODIFY_TARGET_ALLOW_SIMULT_IPS_SAME_HOST);
else if (strcasecmp ("ALLOW_SIMULTANEOUS_IPS", element_name) == 0)
set_client_state (CLIENT_MODIFY_TARGET_ALLOW_SIMULTANEOUS_IPS);
else if (strcasecmp ("COMMENT", element_name) == 0)
{
gvm_append_string (&modify_target_data->comment, "");
Expand Down Expand Up @@ -7565,8 +7565,8 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
set_client_state (CLIENT_CREATE_TARGET_REVERSE_LOOKUP_UNIFY);
else if (strcasecmp ("ALIVE_TESTS", element_name) == 0)
set_client_state (CLIENT_CREATE_TARGET_ALIVE_TESTS);
else if (strcasecmp ("ALLOW_SIMULT_IPS_SAME_HOST", element_name) == 0)
set_client_state (CLIENT_CREATE_TARGET_ALLOW_SIMULT_IPS_SAME_HOST);
else if (strcasecmp ("ALLOW_SIMULTANEOUS_IPS", element_name) == 0)
set_client_state (CLIENT_CREATE_TARGET_ALLOW_SIMULTANEOUS_IPS);
else if (strcasecmp ("COMMENT", element_name) == 0)
set_client_state (CLIENT_CREATE_TARGET_COMMENT);
else if (strcasecmp ("COPY", element_name) == 0)
Expand Down Expand Up @@ -16536,7 +16536,7 @@ handle_get_targets (gmp_parser_t *gmp_parser, GError **error)
char *esxi_name, *esxi_uuid, *snmp_name, *snmp_uuid;
const char *port_list_uuid, *port_list_name, *ssh_port;
const char *hosts, *exclude_hosts, *reverse_lookup_only;
const char *reverse_lookup_unify, *allow_simult_ips_same_host;
const char *reverse_lookup_unify, *allow_simultaneous_ips;
credential_t ssh_credential, smb_credential;
credential_t esxi_credential, snmp_credential;
int port_list_trash, max_hosts, port_list_available;
Expand Down Expand Up @@ -16699,8 +16699,8 @@ handle_get_targets (gmp_parser_t *gmp_parser, GError **error)
(&targets);
reverse_lookup_unify = target_iterator_reverse_lookup_unify
(&targets);
allow_simult_ips_same_host
= target_iterator_allow_simult_ips_same_host (&targets);
allow_simultaneous_ips
= target_iterator_allow_simultaneous_ips (&targets);

SENDF_TO_CLIENT_OR_FAIL ("<hosts>%s</hosts>"
"<exclude_hosts>%s</exclude_hosts>"
Expand Down Expand Up @@ -16776,13 +16776,13 @@ handle_get_targets (gmp_parser_t *gmp_parser, GError **error)
"%s"
"</reverse_lookup_unify>"
"<alive_tests>%s</alive_tests>"
"<allow_simult_ips_same_host>"
"<allow_simultaneous_ips>"
"%s"
"</allow_simult_ips_same_host>",
"</allow_simultaneous_ips>",
reverse_lookup_only,
reverse_lookup_unify,
target_iterator_alive_tests (&targets),
allow_simult_ips_same_host);
allow_simultaneous_ips);

if (get_targets_data->get.details)
SENDF_TO_CLIENT_OR_FAIL ("<port_range>%s</port_range>",
Expand Down Expand Up @@ -21885,7 +21885,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
create_target_data->reverse_lookup_only,
create_target_data->reverse_lookup_unify,
create_target_data->alive_tests,
create_target_data->allow_simult_ips_same_host,
create_target_data->allow_simultaneous_ips,
&new_target))
{
case 1:
Expand Down Expand Up @@ -22003,7 +22003,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
CLOSE (CLIENT_CREATE_TARGET, REVERSE_LOOKUP_ONLY);
CLOSE (CLIENT_CREATE_TARGET, REVERSE_LOOKUP_UNIFY);
CLOSE (CLIENT_CREATE_TARGET, ALIVE_TESTS);
CLOSE (CLIENT_CREATE_TARGET, ALLOW_SIMULT_IPS_SAME_HOST);
CLOSE (CLIENT_CREATE_TARGET, ALLOW_SIMULTANEOUS_IPS);
CLOSE (CLIENT_CREATE_TARGET, COPY);
CLOSE (CLIENT_CREATE_TARGET, HOSTS);
CLOSE (CLIENT_CREATE_TARGET, NAME);
Expand Down Expand Up @@ -24505,7 +24505,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
modify_target_data->reverse_lookup_only,
modify_target_data->reverse_lookup_unify,
modify_target_data->alive_tests,
modify_target_data->allow_simult_ips_same_host))
modify_target_data->allow_simultaneous_ips))
{
case 1:
SEND_TO_CLIENT_OR_FAIL
Expand Down Expand Up @@ -24748,7 +24748,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
CLOSE (CLIENT_MODIFY_TARGET, REVERSE_LOOKUP_ONLY);
CLOSE (CLIENT_MODIFY_TARGET, REVERSE_LOOKUP_UNIFY);
CLOSE (CLIENT_MODIFY_TARGET, ALIVE_TESTS);
CLOSE (CLIENT_MODIFY_TARGET, ALLOW_SIMULT_IPS_SAME_HOST);
CLOSE (CLIENT_MODIFY_TARGET, ALLOW_SIMULTANEOUS_IPS);
CLOSE (CLIENT_MODIFY_TARGET, COMMENT);
CLOSE (CLIENT_MODIFY_TARGET, HOSTS);
CLOSE (CLIENT_MODIFY_TARGET, NAME);
Expand Down Expand Up @@ -26594,8 +26594,8 @@ gmp_xml_handle_text (/* unused */ GMarkupParseContext* context,
APPEND (CLIENT_CREATE_TARGET_ALIVE_TESTS,
&create_target_data->alive_tests);

APPEND (CLIENT_CREATE_TARGET_ALLOW_SIMULT_IPS_SAME_HOST,
&create_target_data->allow_simult_ips_same_host);
APPEND (CLIENT_CREATE_TARGET_ALLOW_SIMULTANEOUS_IPS,
&create_target_data->allow_simultaneous_ips);

APPEND (CLIENT_CREATE_TARGET_COMMENT,
&create_target_data->comment);
Expand Down Expand Up @@ -26909,8 +26909,8 @@ gmp_xml_handle_text (/* unused */ GMarkupParseContext* context,
APPEND (CLIENT_MODIFY_TARGET_ALIVE_TESTS,
&modify_target_data->alive_tests);

APPEND (CLIENT_MODIFY_TARGET_ALLOW_SIMULT_IPS_SAME_HOST,
&modify_target_data->allow_simult_ips_same_host);
APPEND (CLIENT_MODIFY_TARGET_ALLOW_SIMULTANEOUS_IPS,
&modify_target_data->allow_simultaneous_ips);

APPEND (CLIENT_MODIFY_TARGET_COMMENT,
&modify_target_data->comment);
Expand Down
14 changes: 7 additions & 7 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ task_scanner_options (task_t task, target_t target)
GHashTable *table;
config_t config;
iterator_t prefs;
char *allow_simult_ips_same_host;
char *allow_simultaneous_ips;

config = task_config (task);
init_config_preference_iterator (&prefs, config);
Expand Down Expand Up @@ -1671,16 +1671,16 @@ task_scanner_options (task_t task, target_t target)
cleanup_iterator (&prefs);

// Target options sent as scanner preferences
allow_simult_ips_same_host = target_allow_simult_ips_same_host (target);
if (allow_simult_ips_same_host)
allow_simultaneous_ips = target_allow_simultaneous_ips (target);
if (allow_simultaneous_ips)
{
g_hash_table_replace (table,
g_strdup (strcmp (allow_simult_ips_same_host, "0")
g_strdup ("allow_simultaneous_ips"),
g_strdup (strcmp (allow_simultaneous_ips, "0")
? "yes"
: "no"),
g_strdup (allow_simult_ips_same_host));
: "no"));
}
free (allow_simult_ips_same_host);
free (allow_simultaneous_ips);

return table;
}
Expand Down
4 changes: 2 additions & 2 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ int
target_iterator_snmp_trash (iterator_t*);

const char*
target_iterator_allow_simult_ips_same_host (iterator_t*);
target_iterator_allow_simultaneous_ips (iterator_t*);

const char*
target_iterator_port_list_uuid (iterator_t*);
Expand Down Expand Up @@ -1693,7 +1693,7 @@ char*
target_reverse_lookup_unify (target_t);

char*
target_allow_simult_ips_same_host (target_t);
target_allow_simultaneous_ips (target_t);

char*
target_port_range (target_t);
Expand Down
39 changes: 38 additions & 1 deletion src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ migrate_238_to_239 ()

/* Update the database. */

/* Table results also got a score column, for extended severities. */
/* Table targets(_trash) got a allow_simult_ips_same_host column. */

sql ("ALTER TABLE targets ADD COLUMN"
" allow_simult_ips_same_host integer DEFAULT 1;");
Expand Down Expand Up @@ -2566,6 +2566,43 @@ migrate_239_to_240 ()
return 0;
}

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

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

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

/* Update the database. */

/* Rename allow_simult_ips_same_host column to allow_simultaneous_ips */

sql ("ALTER TABLE targets RENAME COLUMN"
" allow_simult_ips_same_host TO allow_simultaneous_ips;");

sql ("ALTER TABLE targets_trash RENAME COLUMN"
" allow_simult_ips_same_host TO allow_simultaneous_ips;");

/* Set the database version to 241. */

set_db_version (241);

sql_commit ();

return 0;
}

#undef UPDATE_DASHBOARD_SETTINGS

/**
Expand Down
4 changes: 2 additions & 2 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ create_tables ()
" alive_test integer,"
" creation_time integer,"
" modification_time integer,"
" allow_simult_ips_same_host integer DEFAULT 1);");
" allow_simultaneous_ips integer DEFAULT 1);");

sql ("CREATE TABLE IF NOT EXISTS targets_trash"
" (id SERIAL PRIMARY KEY,"
Expand All @@ -2060,7 +2060,7 @@ create_tables ()
" alive_test integer,"
" creation_time integer,"
" modification_time integer,"
" allow_simult_ips_same_host integer DEFAULT 1);");
" allow_simultaneous_ips integer DEFAULT 1);");

sql ("CREATE TABLE IF NOT EXISTS targets_login_data"
" (id SERIAL PRIMARY KEY,"
Expand Down
Loading

0 comments on commit 2b664a7

Please sign in to comment.