Skip to content

Commit

Permalink
Deleted the code for the field scanner of table configs from gvmd.
Browse files Browse the repository at this point in the history
Since the field "scanner" of the database table "configs" was only
used in connection with OSP scanners and OSP scanners are no longer
supported the corresponding code is removed from the gvmd-sources.
  • Loading branch information
jhelmold committed Oct 4, 2021
1 parent 52f3c3a commit 9d95703
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 204 deletions.
29 changes: 2 additions & 27 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,6 @@ typedef struct
int family_selection_growing; ///< Whether families in selection grow.
char *family_selection_growing_text; ///< Text version of above.
char *name; ///< New name for config.
char *scanner_id; ///< New scanner UUID for config.
array_t *nvt_selection; ///< OID array. New NVT set for config.
char *nvt_selection_family; ///< Family of NVT selection.
char *nvt_selection_nvt_oid; ///< OID during NVT_selection/NVT.
Expand Down Expand Up @@ -15294,31 +15293,7 @@ handle_get_scanners (gmp_parser_t *gmp_parser, GError **error)
count++;
if (get_scanners_data->get.details)
{
iterator_t configs, tasks;

SEND_TO_CLIENT_OR_FAIL ("<configs>");
init_scanner_config_iterator (&configs,
get_iterator_resource (&scanners));
while (next (&configs))
{
if (scanner_task_iterator_readable (&configs) == 0)
/* Only show configs the user may see. */
continue;

SENDF_TO_CLIENT_OR_FAIL
("<config id=\"%s\">"
"<name>%s</name>",
scanner_config_iterator_uuid (&configs),
scanner_config_iterator_name (&configs));

if (scanner_config_iterator_readable (&configs))
SEND_TO_CLIENT_OR_FAIL ("</config>");
else
SEND_TO_CLIENT_OR_FAIL ("<permissions/>"
"</config>");
}
cleanup_iterator (&configs);
SEND_TO_CLIENT_OR_FAIL ("</configs>");
iterator_t tasks;

SEND_TO_CLIENT_OR_FAIL ("<tasks>");
init_scanner_task_iterator (&tasks,
Expand Down Expand Up @@ -21841,7 +21816,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
goto create_task_fail;
}

if (!create_task_check_config_scanner (config, scanner))
if (!create_task_check_config_scanner (scanner))
{
SEND_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("create_task",
Expand Down
19 changes: 1 addition & 18 deletions src/gmp_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ modify_config_element_start (gmp_parser_t *gmp_parser, const gchar *name,
* @param[in] config The config to modify.
* @param[in] name The name to set or NULL to keep old value.
* @param[in] comment The comment to set or NULL to keep old value.
* @param[in] scanner_id The scanner ID to set or NULL to keep old value.
* @param[in] gmp_parser GMP parser.
* @param[out] error GError output.
*
Expand All @@ -711,32 +710,17 @@ static int
modify_config_handle_basic_fields (config_t config,
const char *name,
const char *comment,
const char *scanner_id,
gmp_parser_t *gmp_parser,
GError **error)
{
switch (manage_set_config (config, name, comment, scanner_id))
switch (manage_set_config (config, name, comment))
{
case 0:
return 0;
case 1:
SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN
(-1, XML_ERROR_SYNTAX ("modify_config", "Name must be unique"));
return -1;
case 2:
if (send_find_error_to_client ("modify_config",
"scanner",
scanner_id,
gmp_parser))
{
error_send_to_client (error);
return -1;
}
return -1;
case 3:
SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN
(-1, XML_ERROR_SYNTAX ("modify_config", "Config is in use"));
return -1;
case -1:
SENDF_TO_CLIENT_OR_FAIL_WITH_RETURN
(-1, XML_INTERNAL_ERROR ("modify_config"));
Expand Down Expand Up @@ -1072,7 +1056,6 @@ modify_config_run (gmp_parser_t *gmp_parser, GError **error)
(config,
text_or_null (entity_child (entity, "name")),
text_or_null (entity_child (entity, "comment")),
text_or_null (entity_child (entity, "scanner")),
gmp_parser,
error))
{
Expand Down
5 changes: 1 addition & 4 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1754,11 +1754,8 @@ target_login_port (target_t, const char*);
*
* These are here because they need definitions that are still in manage.h. */

scanner_t
config_iterator_scanner (iterator_t*);

int
create_task_check_config_scanner (config_t, scanner_t);
create_task_check_config_scanner (scanner_t);

int
modify_task_check_config_scanner (task_t, const char *, const char *);
Expand Down
5 changes: 1 addition & 4 deletions src/manage_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ config_iterator_type (iterator_t*);
int
config_iterator_families_growing (iterator_t*);

int
config_iterator_scanner_trash (iterator_t*);

const char*
config_iterator_usage_type (iterator_t*);

Expand Down Expand Up @@ -153,7 +150,7 @@ const char*
config_preference_iterator_default (iterator_t *);

int
manage_set_config (config_t, const char*, const char *, const char *);
manage_set_config (config_t, const char*, const char *);

int
manage_set_config_nvts (config_t, const char*, GPtrArray*);
Expand Down
34 changes: 34 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2851,6 +2851,40 @@ migrate_247_to_248 ()
return 0;
}

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

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

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

/* Update the database. */

/* Remove config data for OSP-Scanners */
sql ("DELETE FROM config_preferences WHERE config IN"
" (SELECT id FROM configs WHERE usage_type = 'scan' AND type = 1);");
sql (" DELETE FROM configs WHERE usage_type = 'scan' AND type = 1;");

/* Set the database version to 247. */

set_db_version (249);

sql_commit ();

return 0;
}


#undef UPDATE_DASHBOARD_SETTINGS

Expand Down
2 changes: 0 additions & 2 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,6 @@ create_tables ()
" families_growing integer,"
" nvts_growing integer,"
" type integer,"
" scanner integer REFERENCES scanners (id) ON DELETE RESTRICT,"
" predefined integer,"
" creation_time integer,"
" modification_time integer,"
Expand All @@ -2257,7 +2256,6 @@ create_tables ()
" families_growing integer,"
" nvts_growing integer,"
" type integer,"
" scanner integer," /* REFERENCES scanners (id) */
" predefined integer,"
" creation_time integer,"
" modification_time integer,"
Expand Down
92 changes: 5 additions & 87 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -39142,12 +39142,7 @@ delete_scanner (const char *scanner_id, int ultimate)
if (sql_int ("SELECT count(*) FROM tasks"
" WHERE scanner = %llu"
" AND scanner_location = " G_STRINGIFY (LOCATION_TRASH) ";",
scanner)
|| sql_int ("SELECT count(*) FROM configs_trash"
" WHERE scanner = %llu"
" AND scanner_location"
" = " G_STRINGIFY (LOCATION_TRASH) ";",
scanner))
scanner))
{
sql_rollback ();
return 1;
Expand All @@ -39169,10 +39164,7 @@ delete_scanner (const char *scanner_id, int ultimate)
" WHERE scanner = %llu"
" AND scanner_location = " G_STRINGIFY (LOCATION_TABLE)
" AND hidden = 0;",
scanner)
|| sql_int ("SELECT count(*) FROM configs"
" WHERE scanner = %llu;",
scanner))
scanner))
{
sql_rollback ();
return 1;
Expand All @@ -39189,14 +39181,6 @@ delete_scanner (const char *scanner_id, int ultimate)

trash_scanner = sql_last_insert_id ();

/* Update the location of the scanner in any trashcan configs & tasks. */
sql ("UPDATE configs_trash"
" SET scanner = %llu,"
" scanner_location = " G_STRINGIFY (LOCATION_TRASH)
" WHERE scanner = %llu;",
trash_scanner,
scanner);

sql ("UPDATE tasks"
" SET scanner = %llu,"
" scanner_location = " G_STRINGIFY (LOCATION_TRASH)
Expand Down Expand Up @@ -39455,59 +39439,6 @@ scanner_iterator_key_priv (iterator_t* iterator)
*/
DEF_ACCESS (scanner_iterator_credential_type, GET_ITERATOR_COLUMN_COUNT + 10);

/**
* @brief Initialise a scanner config iterator.
*
* @param[in] iterator Iterator.
* @param[in] scanner Scanner.
*/
void
init_scanner_config_iterator (iterator_t* iterator, scanner_t scanner)
{
gchar *available, *with_clause;
get_data_t get;
array_t *permissions;

assert (scanner);

get.trash = 0;
permissions = make_array ();
array_add (permissions, g_strdup ("get_configs"));
available = acl_where_owned ("config", &get, 1, "any", 0, permissions, 0,
&with_clause);
array_free (permissions);

init_iterator (iterator,
"%s"
" SELECT id, uuid, name, %s FROM configs"
" WHERE scanner = %llu"
" ORDER BY name ASC;",
with_clause ? with_clause : "",
available,
scanner);

g_free (with_clause);
g_free (available);
}

/**
* @brief Get the UUID from a scanner config iterator.
*
* @param[in] iterator Iterator.
*
* @return UUID, or NULL if iteration is complete. Freed by cleanup_iterator.
*/
DEF_ACCESS (scanner_config_iterator_uuid, 1);

/**
* @brief Get the name from a scanner config iterator.
*
* @param[in] iterator Iterator.
*
* @return Name, or NULL if iteration is complete. Freed by cleanup_iterator.
*/
DEF_ACCESS (scanner_config_iterator_name, 2);

/**
* @brief Get the read permission status from a GET iterator.
*
Expand Down Expand Up @@ -39600,9 +39531,7 @@ int
scanner_in_use (scanner_t scanner)
{
return !!(sql_int ("SELECT count(*) FROM tasks WHERE scanner = %llu"
" AND hidden = 0;", scanner)
|| sql_int ("SELECT count(*) FROM configs WHERE scanner = %llu",
scanner));
" AND hidden = 0;", scanner));
}

/**
Expand All @@ -39618,10 +39547,6 @@ trash_scanner_in_use (scanner_t scanner)
return !!(sql_int ("SELECT count(*) FROM tasks"
" WHERE scanner = %llu"
" AND scanner_location = " G_STRINGIFY (LOCATION_TRASH),
scanner)
|| sql_int ("SELECT count(*) FROM configs_trash"
" WHERE scanner = %llu"
" AND scanner_location = " G_STRINGIFY (LOCATION_TRASH),
scanner));
}

Expand Down Expand Up @@ -45972,10 +45897,10 @@ manage_restore (const char *id)

sql ("INSERT INTO configs"
" (uuid, owner, name, nvt_selector, comment, family_count,"
" nvt_count, families_growing, nvts_growing, type, scanner,"
" nvt_count, families_growing, nvts_growing, type,"
" predefined, creation_time, modification_time, usage_type)"
" SELECT uuid, owner, name, nvt_selector, comment, family_count,"
" nvt_count, families_growing, nvts_growing, type, scanner,"
" nvt_count, families_growing, nvts_growing, type,"
" predefined, creation_time, modification_time, usage_type"
" FROM configs_trash WHERE id = %llu;",
resource);
Expand Down Expand Up @@ -46574,13 +46499,6 @@ manage_restore (const char *id)
/* Update the scanner in any trashcan configs and tasks. */
scanner = sql_last_insert_id ();

sql ("UPDATE configs_trash"
" SET scanner = %llu,"
" scanner_location = " G_STRINGIFY (LOCATION_TABLE)
" WHERE scanner = %llu"
" AND scanner_location = " G_STRINGIFY (LOCATION_TRASH),
scanner, resource);

sql ("UPDATE tasks"
" SET scanner = %llu,"
" scanner_location = " G_STRINGIFY (LOCATION_TABLE)
Expand Down
Loading

0 comments on commit 9d95703

Please sign in to comment.