Skip to content
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
109 changes: 65 additions & 44 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,55 +1132,76 @@ update_nvt_cache_retry ()
}
else if (child_pid == 0)
{
scanner_type_t sc_type;
init_sentry ();
#if OPENVASD
int ret;

setproctitle ("openvasd: Updating NVT cache");
ret = manage_update_nvt_cache_openvasd ();
if (ret == 1)
{
g_message (
"Rebuilding all NVTs because of a hash value mismatch");
ret = update_or_rebuild_nvts (0);
if (ret)
g_warning ("%s: rebuild failed", __func__);
else
g_message ("%s: rebuild successful", __func__);
}
sc_type = get_scanner_type_by_uuid (SCANNER_UUID_DEFAULT);
switch (sc_type)
{
case SCANNER_TYPE_OPENVAS:
{
const char *osp_update_socket;

osp_update_socket = get_osp_vt_update_socket ();
if (osp_update_socket)
{
int ret;

setproctitle ("OSP: Updating NVT cache");
ret = manage_update_nvt_cache_osp (osp_update_socket);
if (ret == 1)
{
g_message ("Rebuilding all NVTs because of a"
" hash value mismatch");
ret = update_or_rebuild_nvts (0);
if (ret)
g_warning ("%s: rebuild failed", __func__);
else
g_message ("%s: rebuild successful", __func__);
}

gvm_close_sentry ();
exit (ret);
}
else
{
g_warning ("%s: No OSP VT update socket set", __func__);
gvm_close_sentry ();
exit (EXIT_FAILURE);
}
}
case SCANNER_TYPE_OPENVASD:
{
#if OPENVASD
int ret;

setproctitle ("openvasd: Updating NVT cache");
ret = manage_update_nvt_cache_openvasd ();
if (ret == 1)
{
g_message (
"Rebuilding all NVTs because of a hash value mismatch");
ret = update_or_rebuild_nvts (0);
if (ret)
g_warning ("%s: rebuild failed", __func__);
else
g_message ("%s: rebuild successful", __func__);
}

gvm_close_sentry ();
exit (ret);
gvm_close_sentry ();
exit (ret);
#else
const char *osp_update_socket;

osp_update_socket = get_osp_vt_update_socket ();
if (osp_update_socket)
{
int ret;

setproctitle ("OSP: Updating NVT cache");
ret = manage_update_nvt_cache_osp (osp_update_socket);
if (ret == 1)
{
g_message ("Rebuilding all NVTs because of a hash value mismatch");
ret = update_or_rebuild_nvts (0);
if (ret)
g_warning ("%s: rebuild failed", __func__);
else
g_message ("%s: rebuild successful", __func__);
}

gvm_close_sentry ();
exit (ret);
}
else
{
g_warning ("%s: No OSP VT update socket set", __func__);
gvm_close_sentry ();
exit (EXIT_FAILURE);
}
g_critical ("%s: Default scanner is an openvasd one,"
" but gvmd is not built to support this.",
__func__);
exit (EXIT_FAILURE);
#endif
}
default:
g_critical ("%s: scanner type %d is not supported as default",
__func__, sc_type);
exit (EXIT_FAILURE);
}
}
}
}
Expand Down
109 changes: 77 additions & 32 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,27 @@ scanner_type_supports_unix_sockets (scanner_type_t scanner_type)
return 0;
}

/**
* @brief Gets the type of a scanner given its uuid.
*
* @param[in] scanner_id UUID of the scanner
*
* @return The scanner type or SCANNER_TYPE_NONE if scanner could not be found.
*/
scanner_type_t
get_scanner_type_by_uuid (const char *scanner_id)
{
scanner_t scanner;
if (scanner_id == NULL)
return SCANNER_TYPE_NONE;
if (find_resource_no_acl ("scanner", scanner_id, &scanner))
{
g_warning ("%s: Error finding scanner %s", __func__, scanner_id);
return SCANNER_TYPE_NONE;
}
return get_scanner_type (scanner);
}


/* Severity related functions. */

Expand Down Expand Up @@ -6172,7 +6193,6 @@ gvm_get_sync_script_feed_version (const gchar * sync_script,
return TRUE;
}

#if OPENVASD == 0
/**
* @brief Get VTs feed information from a scanner.
*
Expand Down Expand Up @@ -6227,7 +6247,6 @@ nvts_feed_info_internal (const gchar *update_socket,

return 0;
}
#endif

/**
* @brief Get VTs feed information from the scanner using VT update socket.
Expand All @@ -6244,20 +6263,32 @@ int
nvts_feed_info (gchar **vts_version, gchar **feed_name, gchar **feed_vendor,
gchar **feed_home)
{
scanner_type_t sc_type = get_scanner_type_by_uuid (SCANNER_UUID_DEFAULT);
switch (sc_type)
{
case SCANNER_TYPE_OPENVAS:
return nvts_feed_info_internal (get_osp_vt_update_socket (),
vts_version,
feed_name,
feed_vendor,
feed_home);
case SCANNER_TYPE_OPENVASD:
#if OPENVASD == 1
return nvts_feed_info_internal_from_openvasd (SCANNER_UUID_OPENVASD_DEFAULT,
vts_version);
return nvts_feed_info_internal_from_openvasd (SCANNER_UUID_DEFAULT,
vts_version);
#else
return nvts_feed_info_internal (get_osp_vt_update_socket (),
vts_version,
feed_name,
feed_vendor,
feed_home);

g_critical ("%s: Default scanner is an openvasd one,"
" but gvmd is not built to support this.",
__func__);
return -1;
#endif
default:
g_critical ("%s: scanner type %d is not supported as default",
__func__, sc_type);
return -1;
}
}

#if OPENVASD == 0
/**
* @brief Check the VTs feed sync for information using a OSP socket.
*
Expand Down Expand Up @@ -6300,7 +6331,6 @@ nvts_check_feed_internal (const char *update_socket,

return 0;
}
#endif

/**
* @brief Check the VTs feed sync for information using the default OSP socket.
Expand All @@ -6316,30 +6346,45 @@ nvts_check_feed (int *lockfile_in_use,
int *self_test_exit_error,
char **self_test_error_msg)
{
scanner_type_t sc_type = get_scanner_type_by_uuid (SCANNER_UUID_DEFAULT);
switch (sc_type)
{
case SCANNER_TYPE_OPENVAS:
return nvts_check_feed_internal (get_osp_vt_update_socket (),
lockfile_in_use,
self_test_exit_error,
self_test_error_msg);
case SCANNER_TYPE_OPENVASD:
#if OPENVASD == 1
int ret = 0;
char *vts_version = NULL;

ret = nvts_feed_info_internal_from_openvasd (SCANNER_UUID_OPENVASD_DEFAULT,
&vts_version);
self_test_exit_error = 0;
*self_test_error_msg = NULL;
if (ret == 0 && vts_version)
lockfile_in_use = 0;
else if (ret == 2)
{
ret = 0;
*lockfile_in_use = 1;
}

return ret;
{
int ret = 0;
char *vts_version = NULL;

ret = nvts_feed_info_internal_from_openvasd (SCANNER_UUID_DEFAULT,
&vts_version);
self_test_exit_error = 0;
*self_test_error_msg = NULL;
if (ret == 0 && vts_version)
lockfile_in_use = 0;
else if (ret == 2)
{
ret = 0;
*lockfile_in_use = 1;
}

return ret;
}
#else
return nvts_check_feed_internal (get_osp_vt_update_socket (),
lockfile_in_use,
self_test_exit_error,
self_test_error_msg);
g_critical ("%s: Default scanner is an openvasd one,"
" but gvmd is not built to support this.",
__func__);
return -1;
#endif
default:
g_critical ("%s: scanner type %d is not supported as default",
__func__, sc_type);
return -1;
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ scanner_type_valid (scanner_type_t);
int
scanner_type_supports_unix_sockets (scanner_type_t);

scanner_type_t
get_scanner_type (scanner_t);

scanner_type_t
get_scanner_type_by_uuid (const char *);


/* Resources. */

Expand Down
32 changes: 19 additions & 13 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -6422,29 +6422,25 @@ check_db_scanners ()
if (sql_int ("SELECT count(*) FROM scanners WHERE uuid = '%s';",
SCANNER_UUID_DEFAULT) == 0)
{
#if OPENVASD
sql ("INSERT INTO scanners"
" (uuid, owner, name, host, port, type, ca_pub, credential,"
" creation_time, modification_time)"
" VALUES ('" SCANNER_UUID_DEFAULT "', NULL, 'OpenVAS Default',"
" '%s', 0, %d, NULL, NULL, m_now (),"
" 'localhost', 3000, %d, NULL, NULL, m_now (),"
" m_now ());",
OPENVAS_DEFAULT_SOCKET,
SCANNER_TYPE_OPENVAS);
}

#if OPENVASD
if (sql_int ("SELECT count(*) FROM scanners WHERE uuid = '%s';",
SCANNER_UUID_OPENVASD_DEFAULT) == 0)
{
SCANNER_TYPE_OPENVASD);
#else
sql ("INSERT INTO scanners"
" (uuid, owner, name, host, port, type, ca_pub, credential,"
" creation_time, modification_time)"
" VALUES ('" SCANNER_UUID_OPENVASD_DEFAULT "', NULL, 'OpenVASD',"
" 'localhost', 3000, %d, NULL, NULL, m_now (),"
" VALUES ('" SCANNER_UUID_DEFAULT "', NULL, 'OpenVAS Default',"
" '%s', 0, %d, NULL, NULL, m_now (),"
" m_now ());",
SCANNER_TYPE_OPENVASD);
}
OPENVAS_DEFAULT_SOCKET,
SCANNER_TYPE_OPENVAS);
#endif
}

#if ENABLE_CONTAINER_SCANNING
if (sql_int ("SELECT count(*) FROM scanners WHERE uuid = '%s';",
Expand Down Expand Up @@ -32012,6 +32008,15 @@ find_scanner_with_permission (const char* uuid, scanner_t* scanner,
0);
}

scanner_type_t
get_scanner_type (scanner_t scanner)
{
if (scanner == 0)
return SCANNER_TYPE_NONE;
return sql_int ("SELECT type FROM scanners WHERE id=%llu", scanner);
}


/**
* @brief Insert a scanner for create_scanner.
*
Expand Down Expand Up @@ -33786,6 +33791,7 @@ manage_get_scanners (GSList *log_config, const db_conn_info_t *database)
break;
case SCANNER_TYPE_OPENVASD:
scanner_type_str = "openvasd";
break;
case SCANNER_TYPE_OPENVASD_SENSOR:
scanner_type_str = "openvasd-sensor";
break;
Expand Down
Loading
Loading