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

Make --osp-vt-update optional, use default scanner #729

Merged
merged 7 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 34 additions & 13 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#include <gvm/util/serverutils.h>

#include "manage.h"
#include "manage_sql_nvts.h"
#include "manage_sql_secinfo.h"
#include "gmpd.h"
#include "utils.h"
Expand Down Expand Up @@ -292,11 +293,6 @@ static int update_in_progress = 0;
*/
GSList *log_config = NULL;

/**
* @brief File socket for OSP NVT update. NULL to update via OTP.
*/
static gchar *osp_update_socket = NULL;


/* Helpers. */

Expand Down Expand Up @@ -1133,8 +1129,15 @@ update_nvt_cache_retry ()
}
else if (child_pid == 0)
{
const char *osp_update_socket;
osp_update_socket = get_osp_vt_update_socket ();
if (osp_update_socket)
exit (update_nvt_cache_osp (osp_update_socket));
else
{
g_warning ("%s: No OSP VT update socket set", __FUNCTION__);
exit (-1);
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Expand Down Expand Up @@ -2158,7 +2161,7 @@ gvmd (int argc, char** argv)
* release gvm-checking, via option_lock. */

if (osp_vt_update)
osp_update_socket = osp_vt_update;
set_osp_vt_update_socket (osp_vt_update);

if (disable_password_policy)
gvm_disable_password_policy ();
Expand Down Expand Up @@ -2457,13 +2460,6 @@ gvmd (int argc, char** argv)

/* Run the standard manager. */

if (osp_vt_update == NULL)
{
g_critical ("%s: --osp-vt-update required for now",
__FUNCTION__);
return EXIT_FAILURE;
}

if (lockfile_locked ("gvm-helping"))
{
g_warning ("%s: An option process is running", __FUNCTION__);
Expand Down Expand Up @@ -2660,6 +2656,31 @@ gvmd (int argc, char** argv)
if (gvm_auth_init ())
exit (EXIT_FAILURE);

/* Try to get OSP VT update socket from default OpenVAS if it
* was not set with the --osp-vt-update option.
*/
if (get_osp_vt_update_socket () == NULL)
{
char *default_socket = openvas_default_scanner_host ();
if (default_socket)
{
g_debug ("%s: Using OSP VT update socket from default OpenVAS"
" scanner: %s",
__FUNCTION__,
default_socket);
set_osp_vt_update_socket (default_socket);
}
else
{
g_critical ("%s: No OSP VT update socket found."
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
" Use --osp-vt-update or change the 'OpenVAS Default'"
" scanner to use the main ospd-openvas socket.",
__FUNCTION__);
return EXIT_FAILURE;
}
free (default_socket);
}

/* Enter the main forever-loop. */

proctitle_set ("gvmd: Waiting for incoming connections");
Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2781,6 +2781,9 @@ scanner_password (scanner_t);
int
scanner_count (const get_data_t *);

char *
openvas_default_scanner_host ();

int
init_scanner_iterator (iterator_t*, const get_data_t *);

Expand Down
12 changes: 12 additions & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -43639,6 +43639,18 @@ scanner_count (const get_data_t *get)
0, 0, 0, TRUE);
}

/**
* @brief Get the default scanner path or host.
*
* @return Newly allocated scanner path or host.
*/
char *
openvas_default_scanner_host ()
{
return sql_string ("SELECT host FROM scanners WHERE uuid = '%s'",
SCANNER_UUID_DEFAULT);
}

/**
* @brief Create a new connection to an OSP scanner.
*
Expand Down
34 changes: 34 additions & 0 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,40 @@ blank_control_chars (char *string)
if (iscntrl (*string) && *string != '\n') *string = ' ';
}


/* NVT related global options */

/**
* @brief File socket for OSP NVT update. NULL to update via OTP.
*/
static gchar *osp_vt_update_socket = NULL;

/**
* @brief Get the current file socket for OSP NVT update.
*
* @return The path of the file socket for OSP NVT update.
*/
const gchar *
get_osp_vt_update_socket ()
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
{
return osp_vt_update_socket;
}

/**
* @brief Set the file socket for OSP NVT update.
*
* @param new_socket The new path of the file socket for OSP NVT update.
*/
void
set_osp_vt_update_socket (const char *new_socket)
{
if (new_socket)
{
g_free (osp_vt_update_socket);
osp_vt_update_socket = g_strdup (new_socket);
}
}


/* NVT's. */

Expand Down
6 changes: 6 additions & 0 deletions src/manage_sql_nvts.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
{ NULL, NULL, KEYWORD_TYPE_UNKNOWN } \
}

const char *
get_osp_vt_update_socket ();

void
set_osp_vt_update_socket (const char *new_socket);

void
check_db_nvts ();

Expand Down