Skip to content

Commit

Permalink
handle feed update
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Jul 29, 2024
1 parent 85e646a commit ed0b115
Show file tree
Hide file tree
Showing 4 changed files with 461 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,15 @@ handle_sigabrt_simple (int signal)
static int
update_nvt_cache_osp (const gchar *update_socket)
{
#ifdef OPENVASD
setproctitle ("Openvasd: Updating NVT cache");
#else
setproctitle ("OSP: Updating NVT cache");

#endif
return manage_update_nvts_osp (update_socket);
}


/**
* @brief Update NVT cache in forked child, retrying if scanner loading.
*
Expand Down
70 changes: 70 additions & 0 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -6991,6 +6991,50 @@ nvts_feed_info_internal (const gchar *update_socket,
return 0;
}

/**
* @brief Get VTs feed information from a scanner.
*
* @param[in] scanner_uuid The uuid of the scanner to be used.
* @param[out] vts_version Output of scanner feed version.
*
* @return 0 success, 1 connection to scanner failed, 2 scanner still starting,
* -1 other error.
*/
static int
nvts_feed_info_internal_from_openvasd (const gchar *scanner_uuid,
gchar **vts_version)
{
scanner_t scan;
openvasd_connector_t connector = NULL;
openvasd_resp_t resp = NULL;
int ret;
if (find_resource_no_acl ("scanner", scanner_uuid, &scan))
return -1;

connector = openvasd_scanner_connect (scan, NULL);
if (!connector)
return 1;

resp = openvasd_get_health_ready (&connector);
if (resp->code == -1)
{
g_warning ("%s: failed to connect to %s:%d", __func__,
scanner_host (scan), scanner_port (scan));
ret = 1;
}
else if (resp->code == 503)
ret = 2;
else
{
*vts_version = g_strdup (resp->header);
ret = 0;
}

openvasd_response_free (resp);
openvasd_connector_free (&connector);
return ret;
}

/**
* @brief Get VTs feed information from the scanner using VT update socket.
*
Expand All @@ -7006,11 +7050,17 @@ int
nvts_feed_info (gchar **vts_version, gchar **feed_name, gchar **feed_vendor,
gchar **feed_home)
{
#if OPENVASD == 1
return nvts_feed_info_internal_from_openvasd (SCANNER_UUID_OPENVASD_DEFAULT,
vts_version);
#else
return nvts_feed_info_internal (get_osp_vt_update_socket (),
vts_version,
feed_name,
feed_vendor,
feed_home);

#endif
}

/**
Expand Down Expand Up @@ -7070,10 +7120,30 @@ nvts_check_feed (int *lockfile_in_use,
int *self_test_exit_error,
char **self_test_error_msg)
{
#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;

#else
return nvts_check_feed_internal (get_osp_vt_update_socket (),
lockfile_in_use,
self_test_exit_error,
self_test_error_msg);
#endif
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
*/
#define SCANNER_UUID_DEFAULT "08b69003-5fc2-4037-a479-93b440211c73"

/**
* @brief UUID of 'Openvasd Default' scanner.
*/
#define SCANNER_UUID_OPENVASD_DEFAULT "8154d8e3-30ee-4959-9151-1863c89a8e62"

/**
* @brief UUID of 'CVE' scanner.
*/
Expand Down
Loading

0 comments on commit ed0b115

Please sign in to comment.