Skip to content

Commit

Permalink
Fix prototype and simplify check_db_... functions
Browse files Browse the repository at this point in the history
The new parameter has been added to the check_db_port_lists prototype
and various check_db_... functions that would only return if
the avoid_db_check_inserts parameter is true have the parameter removed
and are instead wrapped in if conditions.

(cherry picked from commit 5c0d5fa)
  • Loading branch information
timopollmeier authored and mergify[bot] committed Nov 29, 2024
1 parent f036edc commit 4805971
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 39 deletions.
57 changes: 19 additions & 38 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -15924,16 +15924,11 @@ manage_update_nvti_cache ()
/**
* @brief Ensure the predefined scanner exists.
*
* @param[in] avoid_db_check_inserts Whether to avoid inserts.
*
* @return 0 if success, -1 if error.
*/
static int
check_db_scanners (int avoid_db_check_inserts)
check_db_scanners ()
{
if (avoid_db_check_inserts)
return 0;

if (sql_int ("SELECT count(*) FROM scanners WHERE uuid = '%s';",
SCANNER_UUID_DEFAULT) == 0)
{
Expand Down Expand Up @@ -15962,16 +15957,11 @@ check_db_scanners (int avoid_db_check_inserts)
/**
* @brief Initialize the default settings.
*
* @param[in] avoid_db_check_inserts Whether to avoid inserts.
*
* Ensure all the default manager settings exist.
*/
static void
check_db_settings (int avoid_db_check_inserts)
check_db_settings ()
{
if (avoid_db_check_inserts)
return;

if (sql_int ("SELECT count(*) FROM settings"
" WHERE uuid = '6765549a-934e-11e3-b358-406186ea4fc5'"
" AND " ACL_IS_GLOBAL () ";")
Expand Down Expand Up @@ -16329,15 +16319,10 @@ check_db_versions ()

/**
* @brief Ensures the sanity of nvts cache in DB.
*
* @param[in] avoid_db_check_inserts Whether to avoid inserts.
*/
static void
check_db_nvt_selectors (int avoid_db_check_inserts)
check_db_nvt_selectors ()
{
if (avoid_db_check_inserts)
return;

/* Ensure every part of the predefined selector exists.
* This restores entries lost due to the error solved 2010-08-13 by r8805. */
if (sql_int ("SELECT count(*) FROM nvt_selectors WHERE name ="
Expand Down Expand Up @@ -16474,15 +16459,10 @@ add_permissions_on_globals (const gchar *role_uuid)

/**
* @brief Ensure the predefined permissions exists.
*
* @param[in] avoid_db_check_inserts Whether to avoid inserts.
*/
static void
check_db_permissions (int avoid_db_check_inserts)
check_db_permissions ()
{
if (avoid_db_check_inserts)
return;

command_t *command;

if (sql_int ("SELECT count(*) FROM permissions"
Expand Down Expand Up @@ -16641,15 +16621,10 @@ check_db_permissions (int avoid_db_check_inserts)

/**
* @brief Ensure the predefined roles exists.
*
* @param[in] avoid_db_check_inserts Whether to avoid inserts.
*/
static void
check_db_roles (int avoid_db_check_inserts)
check_db_roles ()
{
if (avoid_db_check_inserts)
return;

if (sql_int ("SELECT count(*) FROM roles WHERE uuid = '" ROLE_UUID_ADMIN "';")
== 0)
sql ("INSERT INTO roles"
Expand Down Expand Up @@ -16820,19 +16795,25 @@ check_db (int check_encryption_key, int avoid_db_check_inserts)
create_tables ();
check_db_sequences ();
set_db_version (GVMD_DATABASE_VERSION);
check_db_roles (avoid_db_check_inserts);
check_db_nvt_selectors (avoid_db_check_inserts);
if (avoid_db_check_inserts == 0)
{
check_db_roles ();
check_db_nvt_selectors ();

Check warning on line 16801 in src/manage_sql.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql.c#L16800-L16801

Added lines #L16800 - L16801 were not covered by tests
}
check_db_nvts ();
check_db_port_lists (avoid_db_check_inserts);

Check warning on line 16804 in src/manage_sql.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql.c#L16804

Added line #L16804 was not covered by tests
clean_auth_cache ();
if (check_db_scanners (avoid_db_check_inserts))
if (avoid_db_check_inserts == 0 && check_db_scanners ())
goto fail;
if (check_db_report_formats (avoid_db_check_inserts))
goto fail;
if (check_db_report_formats_trash ())
goto fail;
check_db_permissions (avoid_db_check_inserts);
check_db_settings (avoid_db_check_inserts);
if (avoid_db_check_inserts == 0)
{
check_db_permissions ();
check_db_settings ();

Check warning on line 16815 in src/manage_sql.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql.c#L16814-L16815

Added lines #L16814 - L16815 were not covered by tests
}
cleanup_schedule_times ();
if (check_encryption_key && check_db_encryption_key ())
goto fail;
Expand Down Expand Up @@ -17181,7 +17162,7 @@ init_manage (GSList *log_config, const db_conn_info_t *database,
fork_connection,
skip_db_check,
1, /* Check encryption key if checking db. */
0 /* Do not avoid inserts if checking db. */);
0 /* Do not avoid inserts if checking db. */);
}

/**
Expand Down Expand Up @@ -17220,7 +17201,7 @@ init_manage_helper (GSList *log_config, const db_conn_info_t *database,
? 1 /* Skip DB check. */
: 0, /* Do DB check. */
0, /* Dummy. */
avoid_db_check_inserts);
avoid_db_check_inserts);
}

/**
Expand Down Expand Up @@ -59597,7 +59578,7 @@ manage_optimize (GSList *log_config, const db_conn_info_t *database,
*/
if (strcasecmp (name, "cleanup-sequences") == 0)
avoid_db_check_inserts = 1;

Check warning on line 59580 in src/manage_sql.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql.c#L59580

Added line #L59580 was not covered by tests

ret = manage_option_setup (log_config, database, avoid_db_check_inserts);

Check warning on line 59582 in src/manage_sql.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql.c#L59582

Added line #L59582 was not covered by tests
if (ret)
return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/manage_sql_port_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ update_port_list (port_list_t, const gchar *, const gchar *, array_t *,
const gchar *);

void
check_db_port_lists ();
check_db_port_lists (int);

#endif /* not _GVMD_MANAGE_SQL_PORT_LISTS_H */

0 comments on commit 4805971

Please sign in to comment.