Skip to content

Commit

Permalink
Merge pull request #1362 from timopollmeier/gvmd-feed-dir-check-20.08
Browse files Browse the repository at this point in the history
Check gvmd data feed subdirectories
  • Loading branch information
mattmundell authored Nov 23, 2020
2 parents 1c7c372 + a4c1f50 commit 5360144
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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)
- Add check if gvmd data feed dir exists [#1360](https://github.com/greenbone/gvmd/pull/1360) [#1362](https://github.com/greenbone/gvmd/pull/1362)

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

static gboolean disable_gvmd_data_feed_warning = FALSE;

Expand All @@ -1238,19 +1238,19 @@ fork_feed_sync ()
return -1;
}

gvmd_data_feed_dir_exists = manage_gvmd_data_feed_dir_exists ();
gvmd_data_feed_dirs_exist = manage_gvmd_data_feed_dirs_exist ();

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

Expand All @@ -1276,7 +1276,7 @@ fork_feed_sync ()
/* Check the feed version. */

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

/* Exit. */

Expand Down
9 changes: 6 additions & 3 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -8416,14 +8416,17 @@ sort_data_free (sort_data_t *sort_data)
/* Feeds. */

/**
* @brief Tests if the gvmd data feed directory exists.
* @brief Tests if the gvmd data feed directory and its subdirectories exist.
*
* @return TRUE if the directory exists.
*/
gboolean
manage_gvmd_data_feed_dir_exists ()
manage_gvmd_data_feed_dirs_exist ()
{
return g_file_test (GVMD_FEED_DIR, G_FILE_TEST_EXISTS);
return g_file_test (GVMD_FEED_DIR, G_FILE_TEST_EXISTS)
&& configs_feed_dir_exists ()
&& port_lists_feed_dir_exists ()
&& report_formats_feed_dir_exists ();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3658,7 +3658,10 @@ aggregate_iterator_subgroup_value (iterator_t*);
#define GVMD_DATA_FEED 4

gboolean
manage_gvmd_data_feed_dir_exists ();
manage_gvmd_data_feed_dir_exists (const char *);

gboolean
manage_gvmd_data_feed_dirs_exist ();

const gchar *
get_feed_lock_path ();
Expand Down
13 changes: 12 additions & 1 deletion src/manage_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ sync_configs_with_feed ()

/* Test if base feed directory exists */

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

/* Only sync if NVTs are up to date. */
Expand Down Expand Up @@ -448,6 +448,17 @@ sync_configs_with_feed ()
return 0;
}

/**
* @brief Tests if the configs feed directory exists.
*
* @return TRUE if the directory exists.
*/
gboolean
configs_feed_dir_exists ()
{
return g_file_test (feed_dir_configs (), G_FILE_TEST_EXISTS);
}

/**
* @brief Sync configs with the feed.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/manage_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ void
update_config_preference (const char *, const char *, const char *,
const char *, gboolean);

gboolean
configs_feed_dir_exists ();

void
manage_sync_configs ();

Expand Down
13 changes: 12 additions & 1 deletion src/manage_port_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ sync_port_lists_with_feed ()

/* Test if base feed directory exists */

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

/* Setup owner. */
Expand Down Expand Up @@ -371,6 +371,17 @@ sync_port_lists_with_feed ()
return 0;
}

/**
* @brief Tests if the port lists feed directory exists.
*
* @return TRUE if the directory exists.
*/
gboolean
port_lists_feed_dir_exists ()
{
return g_file_test (feed_dir_port_lists (), G_FILE_TEST_EXISTS);
}

/**
* @brief Sync port lists with the feed.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/manage_port_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ port_list_target_iterator_name (iterator_t *);
int
port_list_target_iterator_readable (iterator_t *);

gboolean
port_lists_feed_dir_exists ();

void
manage_sync_port_lists ();

Expand Down
13 changes: 12 additions & 1 deletion src/manage_report_formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ sync_report_formats_with_feed ()

/* Test if base feed directory exists */

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

/* Setup owner. */
Expand Down Expand Up @@ -732,6 +732,17 @@ sync_report_formats_with_feed ()
return 0;
}

/**
* @brief Tests if the report formats feed directory exists.
*
* @return TRUE if the directory exists.
*/
gboolean
report_formats_feed_dir_exists ()
{
return g_file_test (feed_dir_report_formats (), G_FILE_TEST_EXISTS);
}

/**
* @brief Sync report formats with the feed.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/manage_report_formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ init_param_option_iterator (iterator_t*, report_format_param_t, int,
const char*
param_option_iterator_value (iterator_t *);

gboolean
report_formats_feed_dir_exists ();

void
manage_sync_report_formats ();

Expand Down

0 comments on commit 5360144

Please sign in to comment.