Here's a patch to add "soft" pausing to the Scanner. CR to follow.
Index: openvassd/otp_1_0.c
===================================================================
--- openvassd/otp_1_0.c (revision 6944)
+++ openvassd/otp_1_0.c (working copy)
@@ -59,6 +59,8 @@
if (!strcmp(str, "SESSION_RESTORE")) return(CREQ_SESSION_RESTORE);
if (!strcmp(str, "STOP_ATTACK")) return(CREQ_STOP_ATTACK);
if (!strcmp(str, "STOP_WHOLE_TEST")) return(CREQ_STOP_WHOLE_TEST);
+ if (!strcmp(str, "PAUSE_WHOLE_TEST")) return(CREQ_PAUSE_WHOLE_TEST);
+ if (!strcmp(str, "RESUME_WHOLE_TEST")) return(CREQ_RESUME_WHOLE_TEST);
return(CREQ_UNKNOWN);
}
Index: openvassd/ntp_11.c
===================================================================
--- openvassd/ntp_11.c (revision 6944)
+++ openvassd/ntp_11.c (working copy)
@@ -119,6 +119,12 @@
otp_1_0_server_openvas_version (globals);
break;
+ case CREQ_PAUSE_WHOLE_TEST:
+ log_write("Pausing the whole test (requested by client)");
+ hosts_pause_all(globals);
+ result = NTP_PAUSE_WHOLE_TEST;
+ break;
+
case CREQ_PLUGIN_INFO: {
char * t, *s;
t = strstr(&(str[1]), " <|> ");
@@ -135,6 +141,12 @@
ntp_11_read_prefs(globals);
break;
+ case CREQ_RESUME_WHOLE_TEST:
+ log_write("Resuming the whole test (requested by client)");
+ hosts_resume_all(globals);
+ result = NTP_RESUME_WHOLE_TEST;
+ break;
+
case CREQ_RULES:
ntp_11_rules(globals);
break;
Index: openvassd/otp_1_0.h
===================================================================
--- openvassd/otp_1_0.h (revision 6944)
+++ openvassd/otp_1_0.h (working copy)
@@ -32,8 +32,10 @@
CREQ_CERTIFICATES,
CREQ_LONG_ATTACK,
CREQ_OPENVAS_VERSION,
+ CREQ_PAUSE_WHOLE_TEST,
CREQ_PLUGIN_INFO,
CREQ_PREFERENCES,
+ CREQ_RESUME_WHOLE_TEST,
CREQ_RULES,
CREQ_SESSIONS_LIST,
CREQ_SESSION_DELETE,
Index: openvassd/ntp_11.h
===================================================================
--- openvassd/ntp_11.h (revision 6944)
+++ openvassd/ntp_11.h (working copy)
@@ -34,6 +34,8 @@
#include <openvas/arglists.h> /* for struct arglist */
#define NTP_STOP_WHOLE_TEST 2
+#define NTP_PAUSE_WHOLE_TEST 3
+#define NTP_RESUME_WHOLE_TEST 4
int ntp_11_parse_input(struct arglist *, char *);
void ntp_11_show_end(struct arglist *, char *, int);
Index: openvassd/attack.c
===================================================================
--- openvassd/attack.c (revision 6944)
+++ openvassd/attack.c (working copy)
@@ -81,6 +81,11 @@
char hostname[1024];
};
+/**
+ * @brief Flag for pausing and resuming.
+ */
+static int pause_whole_test = 0;
+
/*******************************************************
PRIVATE FUNCTIONS
@@ -102,8 +107,25 @@
}
}
+/**
+ * @brief Set the pause_whole_test flag to pause the scan.
+ */
+static void
+attack_handle_sigusr1 ()
+{
+ pause_whole_test = 1;
+}
/**
+ * @brief Set the pause_whole_test flag to resume the scan.
+ */
+static void
+attack_handle_sigusr2 ()
+{
+ pause_whole_test = 0;
+}
+
+/**
* @brief Inits an arglist which can be used by the plugins.
*
* The arglist will have following keys and (type, value):
@@ -564,6 +586,38 @@
return;
}
+ /* Idle if the scan has been paused. */
+ if (pause_whole_test)
+ {
+ /* Let the running NVTs complete. */
+ pluginlaunch_wait();
+
+ /* Send the PAUSE status to the client. */
+ if (comm_send_status (globals, hostname, "pause", cur_plug, num_plugs)
+ < 0)
+ {
+ pluginlaunch_stop ();
+ goto host_died;
+ }
+
+ /* Wait for resume. */
+ while (pause_whole_test)
+ {
+ struct timeval timeout;
+ timeout.tv_usec = 0;
+ timeout.tv_sec = 1;
+ select (0, NULL, NULL, NULL, &timeout);
+ }
+
+ /* Send the RESUME status to the client. */
+ if (comm_send_status (globals, hostname, "resume", cur_plug, num_plugs)
+ < 0)
+ {
+ pluginlaunch_stop ();
+ goto host_died;
+ }
+ }
+
plugin = plugins_scheduler_next(sched);
if (plugin != NULL && plugin != PLUG_RUNNING)
{
@@ -630,6 +684,9 @@
plugins_scheduler_t sched = args->sched;
int i;
+ openvas_signal (SIGUSR1, attack_handle_sigusr1);
+ openvas_signal (SIGUSR2, attack_handle_sigusr2);
+
thread_socket = dup2 (thread_socket, 4);
// Close all file descriptors >= 5
Index: openvassd/hosts.c
===================================================================
--- openvassd/hosts.c (revision 6944)
+++ openvassd/hosts.c (working copy)
@@ -40,7 +40,7 @@
#include "ntp_11.h"
/**
- * @brief Host information, implementet as doubly linked List.
+ * @brief Host information, implemented as doubly linked List.
*/
struct host {
char * name;
@@ -267,8 +267,39 @@
hosts_stop_host(NULL, hosts->name);
}
}
+
/*-----------------------------------------------------------------*/
+/**
+ * @brief Pause all hosts.
+ */
+void
+hosts_pause_all ()
+{
+ struct host *host = hosts;
+ while (host != NULL)
+ {
+ kill (host->pid, SIGUSR1);
+ host = host->next;
+ }
+}
+
+/**
+ * @brief Resume all hosts.
+ */
+void
+hosts_resume_all ()
+{
+ struct host *host = hosts;
+ while (host != NULL)
+ {
+ kill (host->pid, SIGUSR2);
+ host = host->next;
+ }
+}
+
+/*-----------------------------------------------------------------*/
+
static int hosts_read_data(struct arglist * globals)
{
fd_set rd;
@@ -371,6 +402,10 @@
f = ntp_11_parse_input(globals, buf);
if( f == NTP_STOP_WHOLE_TEST )
return -1;
+ else if( f == NTP_PAUSE_WHOLE_TEST )
+ hosts_pause_all();
+ else if( f == NTP_RESUME_WHOLE_TEST )
+ hosts_resume_all();
}
return 0;
Index: openvassd/hosts.h
===================================================================
--- openvassd/hosts.h (revision 6944)
+++ openvassd/hosts.h (working copy)
@@ -35,6 +35,8 @@
int hosts_new(struct arglist *, char*);
int hosts_set_pid(char*, pid_t);
int hosts_read(struct arglist *);
+void hosts_pause_all();
+void hosts_resume_all();
void hosts_stop_all();
int hosts_stop_host(struct arglist * globals, char *);
Index: ChangeLog
===================================================================
--- ChangeLog (revision 6944)
+++ ChangeLog (working copy)
@@ -1,3 +1,34 @@
+2010-03-11 Matthew Mundell <matthew.mund...@intevation.de>
+
+ Add soft pausing of scans. Implementation of Change Request #45:
+ OpenVAS-Scanner: add pausing of scans,
+ http://www.openvas.org/openvas-cr-44.html.
+
+ * openvassd/otp_1_0.h (client_request_t): Add CREQ_PAUSE_WHOLE_TEST and
+ CREQ_RESUME_WHOLE_TEST.
+
+ * openvassd/otp_1_0.c (otp_1_0_get_client_request): Add PAUSE_WHOLE_TEST
+ and RESUME_WHOLE_TEST commands.
+
+ * openvassd/ntp_11.h (NTP_PAUSE_WHOLE_TEST, NTP_RESUME_WHOLE_TEST): New
+ defines.
+
+ * openvassd/ntp_11.c (ntp_11_parse_input): Add CREQ_PAUSE_WHOLE_TEST and
+ CREQ_RESUME_WHOLE_TEST handling.
+
+ * openvassd/attack.c (pause_whole_test): New variable.
+ (attack_handle_sigusr1, attack_handle_sigusr2): New functions. Set and
+ clear pause_whole_test.
+ (attack_host): Check pause_whole_test between plugins and pause if set.
+ (attack_start): Set attack_handle_sigusr1 and attack_handle_sigusr2 as
+ SIGUSR1 and SIGUSR2 handlers.
+
+ * openvassd/hosts.c (hosts_pause_all, hosts_resume_all): New functions.
+ Send pause and resume signal to host process.
+ (hosts_read_client): Pause or resume if client gave associated command.
+
+ * openvassd/hosts.h: Add headers accordingly.
+
2010-03-10 Michael Wiegand <michael.wieg...@intevation.de>
* openvas-mkcert-client.in: Cleaned and reworked script for generating
--
Intevation GmbH, Neuer Graben 17, 49074 Osnabrück | AG Osnabrück, HR B 18998
Geschäftsführer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner
_______________________________________________
Openvas-devel mailing list
Openvas-devel@wald.intevation.org
http://lists.wald.intevation.org/mailman/listinfo/openvas-devel