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

Drop daemon mode #337

Merged
merged 30 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0b852b0
Remove option --foreground.
janowagner May 31, 2019
1866668
Drop main_loop().
janowagner May 31, 2019
ca6bbe3
Don't create a pidfile anymore.
janowagner May 31, 2019
6f3b053
Remove unneeded includes.
janowagner May 31, 2019
bf126cc
Rename option to update vt info in redis.
janowagner May 31, 2019
30fd2b8
Remove command line options about otp socket.
janowagner May 31, 2019
07c86a5
Move up and comment simple cmd parameters.
janowagner May 31, 2019
3f7dd73
Don't init signal handlers right before exit.
janowagner May 31, 2019
218b83a
Don't open the OTP unix socket anymore.
janowagner May 31, 2019
cc556f9
Remove is_otp_scan() from main module.
janowagner May 31, 2019
95c2058
Drop set_scan_type().
janowagner May 31, 2019
2c451f1
Remove unneeded include.
janowagner May 31, 2019
99a132a
Drop loading handler during vt update.
janowagner May 31, 2019
8b15468
Remove unneeded includes.
janowagner May 31, 2019
7fba00b
Remove module comm.
janowagner May 31, 2019
e1f847b
Remove is_otp_scan() conditionals.
janowagner May 31, 2019
590528d
Remove any unused ntp_ function.
janowagner May 31, 2019
b19eac0
Remove now unused modile otp.
janowagner May 31, 2019
5669fbe
Add generic function host_set_time().
janowagner May 31, 2019
e0cdc58
Drop the now unused module ntp.
janowagner May 31, 2019
cc0f5bc
Drop global_socket handling.
janowagner May 31, 2019
8585952
Improve help text for cmd line option.
janowagner May 31, 2019
148034b
Start renaming openvassd to openvas.
janowagner May 31, 2019
d2b3787
Actually rename the files.
janowagner May 31, 2019
2053945
More renaming from openvassd to openvas.
janowagner May 31, 2019
023a44a
Rename log_conf file.
janowagner May 31, 2019
ff4b6a1
Fixed a start/end confusion.
janowagner Jun 5, 2019
349b4a3
Code formatting improvements.
janowagner Jun 5, 2019
05e6eab
Update man page.
janowagner Jun 5, 2019
c030cd2
A single additional formatting issue.
janowagner Jun 5, 2019
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
4 changes: 0 additions & 4 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ tool with the following command:
src/CMakeLists.txt: GPL-2+
src/attack.c: GPL-2
src/attack.h: GPL-2
src/comm.c: GPL-2
src/comm.h: GPL-2
src/hosts.c: GPL-2
src/hosts.h: GPL-2
src/nasl_plugins.c: GPL-2
src/ntp.c: GPL-2
src/ntp.h: GPL-2
src/openvassd.c: GPL-2
src/otp.c: GPL-2+
src/otp.h: GPL-2+
src/pluginlaunch.c: GPL-2
src/pluginlaunch.h: GPL-2
src/pluginload.c: GPL-2
Expand Down
6 changes: 1 addition & 5 deletions doc/openvassd.8.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH OpenVASSD 8 "January 2011" "Greenbone Vulnerability Management" "User Manuals"
.TH OpenVASSD 8 "June 2019" "Greenbone Vulnerability Management" "User Manuals"
.SH NAME
openvassd \- The Scanner of the Greenbone Vulnerability Management
.SH SYNOPSIS
Expand All @@ -25,10 +25,6 @@ by default (unless you specify \-f as an option).
Use the alternate configuration file instead of
.I @OPENVASSD_CONF@

.TP
.B "-f, --foreground"
Make the scanner stay in foreground (non-daemon mode)

.TP
.B "-v, --version"
Writes the version number and exits
Expand Down
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ else (NOT GCRYPT)
endif (GCRYPT_VERSION VERSION_LESS "1.6")
endif (NOT GCRYPT)

add_executable (openvassd attack.c comm.c hosts.c
nasl_plugins.c ntp.c openvassd.c otp.c
add_executable (openvassd attack.c hosts.c
nasl_plugins.c ntp.c openvassd.c
pluginlaunch.c pluginload.c
pluginscheduler.c plugs_req.c
processes.c sighand.c utils.c)
Expand Down Expand Up @@ -160,8 +160,8 @@ add_dependencies (check cppcheck)

## Tag files

set (C_FILES "attack.c" "comm.c" "hosts.c"
"nasl_plugins.c" "ntp.c" "openvassd.c" "otp.c"
set (C_FILES "attack.c" "hosts.c"
"nasl_plugins.c" "ntp.c" "openvassd.c"
"pluginlaunch.c" "pluginload.c"
"pluginscheduler.c" "plugs_req.c"
"processes.c" "sighand.c" "utils.c")
Expand Down
71 changes: 18 additions & 53 deletions src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "../misc/nvt_categories.h" /* for ACT_INIT */
#include "../misc/pcap_openvas.h" /* for v6_is_local_ip */
#include "../nasl/nasl_debug.h" /* for nasl_*_filename */
#include "comm.h"
#include "hosts.h"
#include "pluginlaunch.h"
#include "pluginload.h"
Expand Down Expand Up @@ -141,16 +140,6 @@ comm_send_status (kb_t kb, char *hostname, int curr, int max)
return 0;
}

static void
error_message_to_client (int soc, const char *msg, const char *hostname,
const char *port)
{
if (is_otp_scan ())
send_printf (
soc, "SERVER <|> ERRMSG <|> %s <|> <|> %s <|> %s <|> <|> SERVER\n",
hostname ?: "", port ?: "", msg ?: "No error.");
}

static void
error_message_to_client2 (kb_t kb, const char *msg, const char *port)
{
Expand All @@ -161,15 +150,14 @@ error_message_to_client2 (kb_t kb, const char *msg, const char *port)
}

static void
report_kb_failure (int soc, int errcode)
report_kb_failure (int errcode)
{
gchar *msg;

errcode = abs (errcode);
msg = g_strdup_printf ("WARNING: Cannot connect to KB at '%s': %s'",
prefs_get ("db_address"), strerror (errcode));
g_warning ("%s", msg);
error_message_to_client (soc, msg, NULL, NULL);
g_free (msg);
}

Expand Down Expand Up @@ -406,17 +394,16 @@ init_host_kb (struct scan_globals *globals, char *ip_str, kb_t *network_kb)
gchar *hostname_pattern;
enum net_scan_status nss;
const gchar *kb_path = prefs_get ("db_address");
int rc, soc;
int rc;

nss = network_scan_status (globals);
soc = globals->global_socket;
switch (nss)
{
case NSS_DONE:
rc = kb_new (&kb, kb_path);
if (rc)
{
report_kb_failure (soc, rc);
report_kb_failure (rc);
return NULL;
}

Expand All @@ -435,7 +422,7 @@ init_host_kb (struct scan_globals *globals, char *ip_str, kb_t *network_kb)
rc = kb_new (&kb, kb_path);
if (rc)
{
report_kb_failure (soc, rc);
report_kb_failure (rc);
return NULL;
}
}
Expand Down Expand Up @@ -705,8 +692,7 @@ attack_start (struct attack_start_args *args)
gettimeofday (&then, NULL);

kb_item_set_str (kb, "internal/scan_id", globals->scan_id, 0);
if (!is_otp_scan ())
set_kb_readable (kb_get_kb_index (kb));
set_kb_readable (kb_get_kb_index (kb));

/* The reverse lookup is delayed to this step in order to not slow down the
* main scan process eg. case of target with big range of IP addresses. */
Expand Down Expand Up @@ -737,14 +723,12 @@ attack_start (struct attack_start_args *args)

if (!scan_is_stopped () && !all_scans_are_stopped ())
{
if (!is_otp_scan ())
{
char key[1024];
snprintf (key, sizeof (key), "internal/%s", globals->scan_id);
kb_item_set_str (kb, key, "finished", 0);
}
char key[1024];
struct timeval now;

snprintf (key, sizeof (key), "internal/%s", globals->scan_id);
kb_item_set_str (kb, key, "finished", 0);

gettimeofday (&now, NULL);
if (now.tv_usec < then.tv_usec)
{
Expand Down Expand Up @@ -872,7 +856,7 @@ iface_authorized (const char *iface)
* unauthorized value, -2 if iface can't be used.
*/
static int
apply_source_iface_preference (int soc)
apply_source_iface_preference ()
{
const char *source_iface = prefs_get ("source_iface");
int ret;
Expand All @@ -887,7 +871,6 @@ apply_source_iface_preference (int soc)
g_strdup_printf ("Unauthorized source interface: %s", source_iface);
g_warning ("source_iface: Unauthorized source interface %s.",
source_iface);
error_message_to_client (soc, msg, NULL, NULL);

g_free (msg);
return -1;
Expand All @@ -900,7 +883,6 @@ apply_source_iface_preference (int soc)
g_warning ("source_iface: Unauthorized source interface %s."
" (sys_* preference restriction.)",
source_iface);
error_message_to_client (soc, msg, NULL, NULL);

g_free (msg);
return -1;
Expand All @@ -911,7 +893,6 @@ apply_source_iface_preference (int soc)
gchar *msg =
g_strdup_printf ("Erroneous source interface: %s", source_iface);
g_debug ("source_iface: Error with %s interface.", source_iface);
error_message_to_client (soc, msg, NULL, NULL);

g_free (msg);
return -2;
Expand All @@ -931,14 +912,14 @@ apply_source_iface_preference (int soc)
}

static int
check_kb_access (int soc)
check_kb_access ()
{
int rc;
kb_t kb;

rc = kb_new (&kb, prefs_get ("db_address"));
if (rc)
report_kb_failure (soc, rc);
report_kb_failure (rc);
else
kb_delete (kb);

Expand Down Expand Up @@ -1016,24 +997,20 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)
network_kb = NULL;

global_socket = globals->global_socket;
if (check_kb_access (global_socket))
if (check_kb_access ())
return;

/* Init and check Target List */
hostlist = prefs_get ("TARGET");
if (hostlist == NULL)
{
error_message_to_client (global_socket, "Missing target hosts", NULL,
NULL);
return;
}

/* Verify the port range is a valid one */
port_range = prefs_get ("port_range");
if (validate_port_range (port_range))
{
error_message_to_client (global_socket, "Invalid port range", NULL,
port_range);
return;
}

Expand All @@ -1043,10 +1020,6 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)
network_phase);
if (!sched)
{
error_message_to_client (global_socket,
"Couldn't initialize "
"the plugin scheduler",
NULL, NULL);
g_message ("Couldn't initialize the plugin scheduler");
return;
}
Expand All @@ -1073,7 +1046,7 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)
rc = kb_new (network_kb, prefs_get ("db_address"));
if (rc)
{
report_kb_failure (global_socket, rc);
report_kb_failure (rc);
host = NULL;
}
else
Expand All @@ -1090,20 +1063,16 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)
while (unresolved)
{
g_warning ("Couldn't resolve hostname '%s'", (char *) unresolved->data);
error_message_to_client (global_socket, "Couldn't resolve hostname",
unresolved->data, NULL);
unresolved = unresolved->next;
}
g_slist_free_full (unresolved, g_free);
/* Apply Hosts preferences. */
apply_hosts_preferences (hosts);

/* Don't start if the provided interface is unauthorized. */
if (apply_source_iface_preference (global_socket) != 0)
if (apply_source_iface_preference () != 0)
{
gvm_hosts_free (hosts);
error_message_to_client (
global_socket, "Interface not authorized for scanning", NULL, NULL);
return;
}
host = gvm_hosts_next (hosts);
Expand All @@ -1124,11 +1093,11 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)
rc = kb_new (&host_kb, prefs_get ("db_address"));
if (rc)
{
report_kb_failure (global_socket, rc);
report_kb_failure (rc);
goto scan_stop;
}
host_str = gvm_host_value_str (host);
if (hosts_new (globals, host_str, host_kb) < 0)
if (hosts_new (host_str, host_kb) < 0)
{
g_free (host_str);
goto scan_stop;
Expand Down Expand Up @@ -1182,7 +1151,7 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)

/* Every host is being tested... We have to wait for the processes
* to terminate. */
while (hosts_read (globals) == 0)
while (hosts_read () == 0)
;
g_message ("Test complete");

Expand All @@ -1196,10 +1165,6 @@ attack_network (struct scan_globals *globals, kb_t *network_kb)

if (all_scans_are_stopped ())
{
error_message_to_client (global_socket,
"The whole scan was stopped. "
"Fatal Redis connection error.",
"", NULL);
}

gvm_hosts_free (hosts);
Expand Down
Loading