Skip to content

Commit aa76714

Browse files
timopollmeiera-h-abdelsalam
authored andcommitted
Remove separate default openvasd scanner
The gvmd startup will no longer create a separate openvasd scanner, but for new databases the "OpenVAS default" scanner will be of the openvasd type if the OPENVASD build flag is set. Actions that require the default scanner like checking the VTs feed status will check the type of the default scanner instead of determining the type of scanner to connect to based on the build flag. This makes the behavior easier to understand by having only one default OpenVAS based scanner and discourages the use of using both ospd-openvas and openvasd on the same system, which may not work correctly.
1 parent 9cb09f0 commit aa76714

7 files changed

Lines changed: 226 additions & 119 deletions

File tree

src/gvmd.c

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,55 +1132,76 @@ update_nvt_cache_retry ()
11321132
}
11331133
else if (child_pid == 0)
11341134
{
1135+
scanner_type_t sc_type;
11351136
init_sentry ();
1136-
#if OPENVASD
1137-
int ret;
11381137

1139-
setproctitle ("openvasd: Updating NVT cache");
1140-
ret = manage_update_nvt_cache_openvasd ();
1141-
if (ret == 1)
1142-
{
1143-
g_message (
1144-
"Rebuilding all NVTs because of a hash value mismatch");
1145-
ret = update_or_rebuild_nvts (0);
1146-
if (ret)
1147-
g_warning ("%s: rebuild failed", __func__);
1148-
else
1149-
g_message ("%s: rebuild successful", __func__);
1150-
}
1138+
sc_type = get_scanner_type_by_uuid (SCANNER_UUID_DEFAULT);
1139+
switch (sc_type)
1140+
{
1141+
case SCANNER_TYPE_OPENVAS:
1142+
{
1143+
const char *osp_update_socket;
1144+
1145+
osp_update_socket = get_osp_vt_update_socket ();
1146+
if (osp_update_socket)
1147+
{
1148+
int ret;
1149+
1150+
setproctitle ("OSP: Updating NVT cache");
1151+
ret = manage_update_nvt_cache_osp (osp_update_socket);
1152+
if (ret == 1)
1153+
{
1154+
g_message ("Rebuilding all NVTs because of a"
1155+
" hash value mismatch");
1156+
ret = update_or_rebuild_nvts (0);
1157+
if (ret)
1158+
g_warning ("%s: rebuild failed", __func__);
1159+
else
1160+
g_message ("%s: rebuild successful", __func__);
1161+
}
1162+
1163+
gvm_close_sentry ();
1164+
exit (ret);
1165+
}
1166+
else
1167+
{
1168+
g_warning ("%s: No OSP VT update socket set", __func__);
1169+
gvm_close_sentry ();
1170+
exit (EXIT_FAILURE);
1171+
}
1172+
}
1173+
case SCANNER_TYPE_OPENVASD:
1174+
{
1175+
#if OPENVASD
1176+
int ret;
1177+
1178+
setproctitle ("openvasd: Updating NVT cache");
1179+
ret = manage_update_nvt_cache_openvasd ();
1180+
if (ret == 1)
1181+
{
1182+
g_message (
1183+
"Rebuilding all NVTs because of a hash value mismatch");
1184+
ret = update_or_rebuild_nvts (0);
1185+
if (ret)
1186+
g_warning ("%s: rebuild failed", __func__);
1187+
else
1188+
g_message ("%s: rebuild successful", __func__);
1189+
}
11511190

1152-
gvm_close_sentry ();
1153-
exit (ret);
1191+
gvm_close_sentry ();
1192+
exit (ret);
11541193
#else
1155-
const char *osp_update_socket;
1156-
1157-
osp_update_socket = get_osp_vt_update_socket ();
1158-
if (osp_update_socket)
1159-
{
1160-
int ret;
1161-
1162-
setproctitle ("OSP: Updating NVT cache");
1163-
ret = manage_update_nvt_cache_osp (osp_update_socket);
1164-
if (ret == 1)
1165-
{
1166-
g_message ("Rebuilding all NVTs because of a hash value mismatch");
1167-
ret = update_or_rebuild_nvts (0);
1168-
if (ret)
1169-
g_warning ("%s: rebuild failed", __func__);
1170-
else
1171-
g_message ("%s: rebuild successful", __func__);
1172-
}
1173-
1174-
gvm_close_sentry ();
1175-
exit (ret);
1176-
}
1177-
else
1178-
{
1179-
g_warning ("%s: No OSP VT update socket set", __func__);
1180-
gvm_close_sentry ();
1181-
exit (EXIT_FAILURE);
1182-
}
1194+
g_critical ("%s: Default scanner is an openvasd one,"
1195+
" but gvmd is not built to support this.",
1196+
__func__);
1197+
exit (EXIT_FAILURE);
11831198
#endif
1199+
}
1200+
default:
1201+
g_critical ("%s: scanner type %d is not supported as default",
1202+
__func__, sc_type);
1203+
exit (EXIT_FAILURE);
1204+
}
11841205
}
11851206
}
11861207
}

src/manage.c

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,27 @@ scanner_type_supports_unix_sockets (scanner_type_t scanner_type)
807807
return 0;
808808
}
809809

810+
/**
811+
* @brief Gets the type of a scanner given its uuid.
812+
*
813+
* @param[in] scanner_id UUID of the scanner
814+
*
815+
* @return The scanner type or SCANNER_TYPE_NONE if scanner could not be found.
816+
*/
817+
scanner_type_t
818+
get_scanner_type_by_uuid (const char *scanner_id)
819+
{
820+
scanner_t scanner;
821+
if (scanner_id == NULL)
822+
return SCANNER_TYPE_NONE;
823+
if (find_resource_no_acl ("scanner", scanner_id, &scanner))
824+
{
825+
g_warning ("%s: Error finding scanner %s", __func__, scanner_id);
826+
return SCANNER_TYPE_NONE;
827+
}
828+
return get_scanner_type (scanner);
829+
}
830+
810831

811832
/* Severity related functions. */
812833

@@ -6172,7 +6193,6 @@ gvm_get_sync_script_feed_version (const gchar * sync_script,
61726193
return TRUE;
61736194
}
61746195

6175-
#if OPENVASD == 0
61766196
/**
61776197
* @brief Get VTs feed information from a scanner.
61786198
*
@@ -6227,7 +6247,6 @@ nvts_feed_info_internal (const gchar *update_socket,
62276247

62286248
return 0;
62296249
}
6230-
#endif
62316250

62326251
/**
62336252
* @brief Get VTs feed information from the scanner using VT update socket.
@@ -6244,20 +6263,32 @@ int
62446263
nvts_feed_info (gchar **vts_version, gchar **feed_name, gchar **feed_vendor,
62456264
gchar **feed_home)
62466265
{
6266+
scanner_type_t sc_type = get_scanner_type_by_uuid (SCANNER_UUID_DEFAULT);
6267+
switch (sc_type)
6268+
{
6269+
case SCANNER_TYPE_OPENVAS:
6270+
return nvts_feed_info_internal (get_osp_vt_update_socket (),
6271+
vts_version,
6272+
feed_name,
6273+
feed_vendor,
6274+
feed_home);
6275+
case SCANNER_TYPE_OPENVASD:
62476276
#if OPENVASD == 1
6248-
return nvts_feed_info_internal_from_openvasd (SCANNER_UUID_OPENVASD_DEFAULT,
6249-
vts_version);
6277+
return nvts_feed_info_internal_from_openvasd (SCANNER_UUID_DEFAULT,
6278+
vts_version);
62506279
#else
6251-
return nvts_feed_info_internal (get_osp_vt_update_socket (),
6252-
vts_version,
6253-
feed_name,
6254-
feed_vendor,
6255-
feed_home);
6256-
6280+
g_critical ("%s: Default scanner is an openvasd one,"
6281+
" but gvmd is not built to support this.",
6282+
__func__);
6283+
return -1;
62576284
#endif
6285+
default:
6286+
g_critical ("%s: scanner type %d is not supported as default",
6287+
__func__, sc_type);
6288+
return -1;
6289+
}
62586290
}
62596291

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

63016332
return 0;
63026333
}
6303-
#endif
63046334

63056335
/**
63066336
* @brief Check the VTs feed sync for information using the default OSP socket.
@@ -6316,30 +6346,45 @@ nvts_check_feed (int *lockfile_in_use,
63166346
int *self_test_exit_error,
63176347
char **self_test_error_msg)
63186348
{
6349+
scanner_type_t sc_type = get_scanner_type_by_uuid (SCANNER_UUID_DEFAULT);
6350+
switch (sc_type)
6351+
{
6352+
case SCANNER_TYPE_OPENVAS:
6353+
return nvts_check_feed_internal (get_osp_vt_update_socket (),
6354+
lockfile_in_use,
6355+
self_test_exit_error,
6356+
self_test_error_msg);
6357+
case SCANNER_TYPE_OPENVASD:
63196358
#if OPENVASD == 1
6320-
int ret = 0;
6321-
char *vts_version = NULL;
6322-
6323-
ret = nvts_feed_info_internal_from_openvasd (SCANNER_UUID_OPENVASD_DEFAULT,
6324-
&vts_version);
6325-
self_test_exit_error = 0;
6326-
*self_test_error_msg = NULL;
6327-
if (ret == 0 && vts_version)
6328-
lockfile_in_use = 0;
6329-
else if (ret == 2)
6330-
{
6331-
ret = 0;
6332-
*lockfile_in_use = 1;
6333-
}
6334-
6335-
return ret;
6359+
{
6360+
int ret = 0;
6361+
char *vts_version = NULL;
6362+
6363+
ret = nvts_feed_info_internal_from_openvasd (SCANNER_UUID_DEFAULT,
6364+
&vts_version);
6365+
self_test_exit_error = 0;
6366+
*self_test_error_msg = NULL;
6367+
if (ret == 0 && vts_version)
6368+
lockfile_in_use = 0;
6369+
else if (ret == 2)
6370+
{
6371+
ret = 0;
6372+
*lockfile_in_use = 1;
6373+
}
63366374

6375+
return ret;
6376+
}
63376377
#else
6338-
return nvts_check_feed_internal (get_osp_vt_update_socket (),
6339-
lockfile_in_use,
6340-
self_test_exit_error,
6341-
self_test_error_msg);
6378+
g_critical ("%s: Default scanner is an openvasd one,"
6379+
" but gvmd is not built to support this.",
6380+
__func__);
6381+
return -1;
63426382
#endif
6383+
default:
6384+
g_critical ("%s: scanner type %d is not supported as default",
6385+
__func__, sc_type);
6386+
return -1;
6387+
}
63436388
}
63446389

63456390
/**

src/manage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ scanner_type_valid (scanner_type_t);
356356
int
357357
scanner_type_supports_unix_sockets (scanner_type_t);
358358

359+
scanner_type_t
360+
get_scanner_type (scanner_t);
361+
362+
scanner_type_t
363+
get_scanner_type_by_uuid (const char *);
364+
359365

360366
/* Resources. */
361367

src/manage_sql.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6422,29 +6422,25 @@ check_db_scanners ()
64226422
if (sql_int ("SELECT count(*) FROM scanners WHERE uuid = '%s';",
64236423
SCANNER_UUID_DEFAULT) == 0)
64246424
{
6425+
#if OPENVASD
64256426
sql ("INSERT INTO scanners"
64266427
" (uuid, owner, name, host, port, type, ca_pub, credential,"
64276428
" creation_time, modification_time)"
64286429
" VALUES ('" SCANNER_UUID_DEFAULT "', NULL, 'OpenVAS Default',"
6429-
" '%s', 0, %d, NULL, NULL, m_now (),"
6430+
" 'localhost', 3000, %d, NULL, NULL, m_now (),"
64306431
" m_now ());",
6431-
OPENVAS_DEFAULT_SOCKET,
6432-
SCANNER_TYPE_OPENVAS);
6433-
}
6434-
6435-
#if OPENVASD
6436-
if (sql_int ("SELECT count(*) FROM scanners WHERE uuid = '%s';",
6437-
SCANNER_UUID_OPENVASD_DEFAULT) == 0)
6438-
{
6432+
SCANNER_TYPE_OPENVASD);
6433+
#else
64396434
sql ("INSERT INTO scanners"
64406435
" (uuid, owner, name, host, port, type, ca_pub, credential,"
64416436
" creation_time, modification_time)"
6442-
" VALUES ('" SCANNER_UUID_OPENVASD_DEFAULT "', NULL, 'OpenVASD',"
6443-
" 'localhost', 3000, %d, NULL, NULL, m_now (),"
6437+
" VALUES ('" SCANNER_UUID_DEFAULT "', NULL, 'OpenVAS Default',"
6438+
" '%s', 0, %d, NULL, NULL, m_now (),"
64446439
" m_now ());",
6445-
SCANNER_TYPE_OPENVASD);
6446-
}
6440+
OPENVAS_DEFAULT_SOCKET,
6441+
SCANNER_TYPE_OPENVAS);
64476442
#endif
6443+
}
64486444

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

32011+
scanner_type_t
32012+
get_scanner_type (scanner_t scanner)
32013+
{
32014+
if (scanner == 0)
32015+
return SCANNER_TYPE_NONE;
32016+
return sql_int ("SELECT type FROM scanners WHERE id=%llu", scanner);
32017+
}
32018+
32019+
3201532020
/**
3201632021
* @brief Insert a scanner for create_scanner.
3201732022
*
@@ -33786,6 +33791,7 @@ manage_get_scanners (GSList *log_config, const db_conn_info_t *database)
3378633791
break;
3378733792
case SCANNER_TYPE_OPENVASD:
3378833793
scanner_type_str = "openvasd";
33794+
break;
3378933795
case SCANNER_TYPE_OPENVASD_SENSOR:
3379033796
scanner_type_str = "openvasd-sensor";
3379133797
break;

0 commit comments

Comments
 (0)