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

Add check if gvmd data feed dir exists #1360

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add command line options db-host and db-port [#1308](https://github.com/greenbone/gvmd/pull/1308)
- Add missing config and target to modify_task GMP doc [#1310](https://github.com/greenbone/gvmd/pull/1310)
- Add version for NVTs and CVEs in make_osp_result [#1335](https://github.com/greenbone/gvmd/pull/1335)
- Add check if gvmd data feed dir exists [#1360](https://github.com/greenbone/gvmd/pull/1360)

### Changed
- Extended the output of invalid / missing --feed parameter given to greenbone-feed-sync [#1255](https://github.com/greenbone/gvmd/pull/1255)
Expand Down
22 changes: 21 additions & 1 deletion src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,9 @@ fork_feed_sync ()
{
int pid;
sigset_t sigmask_all, sigmask_current;
gboolean gvmd_data_feed_dir_exists;

static gboolean disable_gvmd_data_feed_warning = FALSE;

if (feed_version_check_in_progress)
{
Expand All @@ -1235,6 +1238,22 @@ fork_feed_sync ()
return -1;
}

gvmd_data_feed_dir_exists = manage_gvmd_data_feed_dir_exists ();

if (disable_gvmd_data_feed_warning && gvmd_data_feed_dir_exists)
{
disable_gvmd_data_feed_warning = FALSE;
g_message ("Previously missing gvmd data feed directory %s found.",
GVMD_FEED_DIR);
}
else if (gvmd_data_feed_dir_exists == FALSE
&& disable_gvmd_data_feed_warning == FALSE)
{
disable_gvmd_data_feed_warning = TRUE;
g_warning ("The gvmd data feed directory %s does not exist.",
GVMD_FEED_DIR);
}

pid = fork_with_handlers ();
switch (pid)
{
Expand All @@ -1256,7 +1275,8 @@ fork_feed_sync ()

/* Check the feed version. */

manage_sync (sigmask_normal, fork_update_nvt_cache);
manage_sync (sigmask_normal, fork_update_nvt_cache,
gvmd_data_feed_dir_exists);

/* Exit. */

Expand Down
26 changes: 22 additions & 4 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -7330,6 +7330,8 @@ feed_sync_required ()
return FALSE;
}



/**
* @brief Perform any syncing that is due.
*
Expand All @@ -7338,10 +7340,12 @@ feed_sync_required ()
* @param[in] sigmask_current Sigmask to restore in child.
* @param[in] fork_update_nvt_cache Function that forks a child that syncs
* the NVTS. Child does not return.
* @param[in] try_gvmd_data_sync Whether to try to sync gvmd data objects.
*/
void
manage_sync (sigset_t *sigmask_current,
int (*fork_update_nvt_cache) ())
int (*fork_update_nvt_cache) (),
gboolean try_gvmd_data_sync)
{
lockfile_t lockfile;

Expand All @@ -7360,9 +7364,12 @@ manage_sync (sigset_t *sigmask_current,
}
}

manage_sync_configs ();
manage_sync_port_lists ();
manage_sync_report_formats ();
if (try_gvmd_data_sync)
{
manage_sync_configs ();
manage_sync_port_lists ();
manage_sync_report_formats ();
}
}

/**
Expand Down Expand Up @@ -8408,6 +8415,17 @@ sort_data_free (sort_data_t *sort_data)

/* Feeds. */

/**
* @brief Tests if the gvmd data feed directory exists.
*
* @return TRUE if the directory exists.
*/
gboolean
manage_gvmd_data_feed_dir_exists ()
{
return g_file_test (GVMD_FEED_DIR, G_FILE_TEST_EXISTS);
}

/**
* @brief Get the feed lock file path.
*
Expand Down
5 changes: 4 additions & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2673,7 +2673,7 @@ void
set_scheduled_user_uuid (const gchar* uuid);

void
manage_sync (sigset_t *, int (*fork_update_nvt_cache) ());
manage_sync (sigset_t *, int (*fork_update_nvt_cache) (), gboolean);

int
manage_schedule (manage_connection_forker_t,
Expand Down Expand Up @@ -3657,6 +3657,9 @@ aggregate_iterator_subgroup_value (iterator_t*);
#define CERT_FEED 3
#define GVMD_DATA_FEED 4

gboolean
manage_gvmd_data_feed_dir_exists ();

const gchar *
get_feed_lock_path ();

Expand Down
5 changes: 5 additions & 0 deletions src/manage_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ sync_configs_with_feed ()
const gchar *config_path;
gchar *nvt_feed_version;

/* Test if base feed directory exists */

if (manage_gvmd_data_feed_dir_exists () == FALSE)
return 0;

/* Only sync if NVTs are up to date. */

nvt_feed_version = nvts_feed_version ();
Expand Down
5 changes: 5 additions & 0 deletions src/manage_port_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ sync_port_lists_with_feed ()
GDir *dir;
const gchar *port_list_path;

/* Test if base feed directory exists */

if (manage_gvmd_data_feed_dir_exists () == FALSE)
return 0;

/* Setup owner. */

setting_value (SETTING_UUID_FEED_IMPORT_OWNER, &current_credentials.uuid);
Expand Down
5 changes: 5 additions & 0 deletions src/manage_report_formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ sync_report_formats_with_feed ()
GDir *dir;
const gchar *report_format_path;

/* Test if base feed directory exists */

if (manage_gvmd_data_feed_dir_exists () == FALSE)
return 0;

/* Setup owner. */

setting_value (SETTING_UUID_FEED_IMPORT_OWNER, &current_credentials.uuid);
Expand Down