[Openvas-commits] r3061 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Apr 8 15:17:44 CEST 2009
Author: mattm
Date: 2009-04-08 15:17:43 +0200 (Wed, 08 Apr 2009)
New Revision: 3061
Added:
trunk/openvas-manager/src/types.h
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/manage.c
trunk/openvas-manager/src/manage.h
trunk/openvas-manager/src/omp.c
trunk/openvas-manager/src/omp.h
trunk/openvas-manager/src/ompd.c
trunk/openvas-manager/src/ompd.h
trunk/openvas-manager/src/openvasmd.c
trunk/openvas-manager/src/otp.c
trunk/openvas-manager/src/otp.h
trunk/openvas-manager/src/otpd.c
trunk/openvas-manager/src/ovas-mngr-comm.c
trunk/openvas-manager/src/splint.h
Log:
Cleanup and annotate more, from Splint.
* src/types.h: New file.
* src/splint.h (g_malloc, g_malloc0, g_ptr_array_add, g_slist_append,
g_hash_table_destroy): New headers.
(dirent_pointer_pointer): Remove "out" annotation.
* src/ompd.h: Turn off exportlocal around server_address.
(to_client_start, to_client_end): Change to buffer_size_t.
* src/ompd.c (from_buffer_size, from_client_start, from_client_end,
from_server_start, from_server_end): Change to buffer_size_t.
(read_from_server): Remove tracing. Cast count for += and gnutls_perror.
Add count assertion.
(serve_omp): Use buffer_size_t format in tracefs. Change lastfds and fds
to uint8_t. Make fds checks explicitly boolean. Change initial_start
to buffer_size_t.
* src/otp.h: Turn off exportlocal around server.
* src/otp.c (from_buffer_size): Change to buffer_size_t.
(tcp_string, udp_string, other_string, empty_string): New variables.
(port_protocol_name): Return refs to variables instead of strings. Add
shared annotation.
(print_port): Update format specifier for type change.
(current_message): Add only annotation.
(make_message): Annotate. Cast g_malloc return.
(message_data_t): Annotate members temp.
(append_debug_message, append_hole_message, append_info_message,
append_log_message, append_note_message): Annotate message arg keep.
(current_server_preference, current_server_plugin_dependency_name,
current_server_plugin_dependency_dependencies): Annotate only.
(add_server_preference,
append_to_current_server_plugin_dependency): Annotate args keep.
(add_server_plugins_dependency): Annotate args keep. Make assert
explicitly boolean.
(finish_current_server_plugin_dependency): Make assert explicitly
boolean.
(free_rule): Annotate rule arg. Check rule before freeing.
(add_server_rule): Change arg annotation to keep.
(from_server_start, from_server_end): Change to buffer_size_t.
(parse_server_preference_value, parse_server_preference_value): Make
assert explicitly boolean. Cast char for memchr.
(parse_server_plugin_dependency_dependency, parse_server_server): Make
from_start and from_end buffer_size_t. Annotate dependent variables.
Correct <|> checks.
(sync_buffer): Use buffer_size_t format in tracef.
(process_otp_server_input): Make from_start and from_end size_t.
Annotate dependent variables. Cast char for memchr. Ensure pointer
comparisons are explicitly boolean. Use g_malloc0 instead of g_newa.
* src/manage.h: Turn off exportlocal around report_path_task_name and
report_task.
(set_task_parameter): Add null annotation to arg.
(port_t): Add unsigned to type of number.
* src/manage.c (set_task_parameter): Fail if value is NULL.
(start_task): Send ntp_opt_show_end "no".
(grow_description): Remove tracing.
(append_task_open_port): Check task->open_ports before use. Cast away
g_array_append_val return.
* src/ovas-mngr-comm.c (end_session): Pass fcntl a long zero. Handle
gnutls_bye return.
(to_server_buffer_space): Check end and start before use. Cast return.
(connect_to_server): Cast socklen_t for fprintf and size_t for
gnutls_perror. Use z modifier for size_t tracef.
* src/omp.h (to_client_start, to_client_end): Change type to buffer_size_t.
* src/omp.c (to_client_start, to_client_end): Change type to buffer_size_t.
(current_client_task): Add dependent annotation.
(xml_context): Initialise.
(SEND_TO_CLIENT): Remove.
(send_to_client, error_send_to_client): New functions.
(SEND_TO_CLIENT_OR_FAIL): New macro.
(omp_xml_handle_start_element, send_requirement, send_dependency,
send_preference, send_rule, send_reports): Replace old SEND_TO_CLIENT macro
with new functions.
(omp_xml_handle_end_element): Use SEND_TO_CLIENT_OR_FAIL and new send
functions instead of SEND_TO_CLIENT. Always check current_task_task_id
before use. Change pointer comparisons to be explicitly boolean.
(from_client_start, from_client_end): Change to buffer_size_t.
(init_omp_data): Free xml_context before setting it.
(process_omp_client_input): Check xml_context before use.
* src/otpd.c (from_buffer_size, from_client_start, from_client_end,
from_server_start, from_server_end): Change to buffer_size_t.
(serve_otp): Use buffer_size_t format for tracef. Make fds checks
explicitly boolean. Change initial_start to buffer_size_t. Cast count
for gnutls_perror.
* src/openvasmd.c (from_buffer_size, from_client_start, from_client_end,
from_server_start, from_server_end): Change to buffer_size_t.
(read_protocol): Pass fcntl a long zero.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/ChangeLog 2009-04-08 13:17:43 UTC (rev 3061)
@@ -1,3 +1,102 @@
+2009-04-01 Matthew Mundell <matt at mundell.ukfsn.org>
+
+ Cleanup and annotate more, from Splint.
+
+ * src/types.h: New file.
+
+ * src/splint.h (g_malloc, g_malloc0, g_ptr_array_add, g_slist_append,
+ g_hash_table_destroy): New headers.
+ (dirent_pointer_pointer): Remove "out" annotation.
+
+ * src/ompd.h: Turn off exportlocal around server_address.
+ (to_client_start, to_client_end): Change to buffer_size_t.
+
+ * src/ompd.c (from_buffer_size, from_client_start, from_client_end,
+ from_server_start, from_server_end): Change to buffer_size_t.
+ (read_from_server): Remove tracing. Cast count for += and gnutls_perror.
+ Add count assertion.
+ (serve_omp): Use buffer_size_t format in tracefs. Change lastfds and fds
+ to uint8_t. Make fds checks explicitly boolean. Change initial_start
+ to buffer_size_t.
+
+ * src/otp.h: Turn off exportlocal around server.
+
+ * src/otp.c (from_buffer_size): Change to buffer_size_t.
+ (tcp_string, udp_string, other_string, empty_string): New variables.
+ (port_protocol_name): Return refs to variables instead of strings. Add
+ shared annotation.
+ (print_port): Update format specifier for type change.
+ (current_message): Add only annotation.
+ (make_message): Annotate. Cast g_malloc return.
+ (message_data_t): Annotate members temp.
+ (append_debug_message, append_hole_message, append_info_message,
+ append_log_message, append_note_message): Annotate message arg keep.
+ (current_server_preference, current_server_plugin_dependency_name,
+ current_server_plugin_dependency_dependencies): Annotate only.
+ (add_server_preference,
+ append_to_current_server_plugin_dependency): Annotate args keep.
+ (add_server_plugins_dependency): Annotate args keep. Make assert
+ explicitly boolean.
+ (finish_current_server_plugin_dependency): Make assert explicitly
+ boolean.
+ (free_rule): Annotate rule arg. Check rule before freeing.
+ (add_server_rule): Change arg annotation to keep.
+ (from_server_start, from_server_end): Change to buffer_size_t.
+ (parse_server_preference_value, parse_server_preference_value): Make
+ assert explicitly boolean. Cast char for memchr.
+ (parse_server_plugin_dependency_dependency, parse_server_server): Make
+ from_start and from_end buffer_size_t. Annotate dependent variables.
+ Correct <|> checks.
+ (sync_buffer): Use buffer_size_t format in tracef.
+ (process_otp_server_input): Make from_start and from_end size_t.
+ Annotate dependent variables. Cast char for memchr. Ensure pointer
+ comparisons are explicitly boolean. Use g_malloc0 instead of g_newa.
+
+ * src/manage.h: Turn off exportlocal around report_path_task_name and
+ report_task.
+ (set_task_parameter): Add null annotation to arg.
+ (port_t): Add unsigned to type of number.
+
+ * src/manage.c (set_task_parameter): Fail if value is NULL.
+ (start_task): Send ntp_opt_show_end "no".
+ (grow_description): Remove tracing.
+ (append_task_open_port): Check task->open_ports before use. Cast away
+ g_array_append_val return.
+
+ * src/ovas-mngr-comm.c (end_session): Pass fcntl a long zero. Handle
+ gnutls_bye return.
+ (to_server_buffer_space): Check end and start before use. Cast return.
+ (connect_to_server): Cast socklen_t for fprintf and size_t for
+ gnutls_perror. Use z modifier for size_t tracef.
+
+ * src/omp.h (to_client_start, to_client_end): Change type to buffer_size_t.
+
+ * src/omp.c (to_client_start, to_client_end): Change type to buffer_size_t.
+ (current_client_task): Add dependent annotation.
+ (xml_context): Initialise.
+ (SEND_TO_CLIENT): Remove.
+ (send_to_client, error_send_to_client): New functions.
+ (SEND_TO_CLIENT_OR_FAIL): New macro.
+ (omp_xml_handle_start_element, send_requirement, send_dependency,
+ send_preference, send_rule, send_reports): Replace old SEND_TO_CLIENT macro
+ with new functions.
+ (omp_xml_handle_end_element): Use SEND_TO_CLIENT_OR_FAIL and new send
+ functions instead of SEND_TO_CLIENT. Always check current_task_task_id
+ before use. Change pointer comparisons to be explicitly boolean.
+ (from_client_start, from_client_end): Change to buffer_size_t.
+ (init_omp_data): Free xml_context before setting it.
+ (process_omp_client_input): Check xml_context before use.
+
+ * src/otpd.c (from_buffer_size, from_client_start, from_client_end,
+ from_server_start, from_server_end): Change to buffer_size_t.
+ (serve_otp): Use buffer_size_t format for tracef. Make fds checks
+ explicitly boolean. Change initial_start to buffer_size_t. Cast count
+ for gnutls_perror.
+
+ * src/openvasmd.c (from_buffer_size, from_client_start, from_client_end,
+ from_server_start, from_server_end): Change to buffer_size_t.
+ (read_protocol): Pass fcntl a long zero.
+
2009-04-07 Jan-Oliver Wagner <jan-oliver.wagner at intevation.de>
* CMakeLists.txt, doc/CMakeLists.txt, doc/openvasmd.8.xml,
Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/manage.c 2009-04-08 13:17:43 UTC (rev 3061)
@@ -1133,7 +1133,8 @@
* @param[in] value The value of the parameter, in base64 if parameter
* is "TASK_FILE".
*
- * @return 0 on success, -1 when out of memory, -2 if parameter name error.
+ * @return 0 on success, -1 when out of memory, -2 if parameter name error,
+ * -3 value error (NULL).
*/
int
set_task_parameter (task_t* task, const char* parameter, /*@only@*/ char* value)
@@ -1141,6 +1142,7 @@
tracef (" set_task_parameter %u %s\n",
task->id,
parameter ? parameter : "(null)");
+ if (value == NULL) return -3;
if (parameter == NULL)
{
free (value);
@@ -1199,6 +1201,7 @@
if (send_to_server ("ntp_keep_communication_alive <|> yes\n")) return -1;
if (send_to_server ("ntp_client_accepts_notes <|> yes\n")) return -1;
+ if (send_to_server ("ntp_opt_show_end <|> no\n")) return -1;
//if (send_to_server ("ntp_short_status <|> yes\n")) return -1;
if (send_to_server ("plugin_set <|> \n")) return -1;
// FIX
@@ -1469,7 +1472,6 @@
char* new = realloc (task->description, new_size);
if (new == NULL) return -1;
memset (new, (int) '\0', new_size - task->description_size);
- tracef (" grew description to %u (at %p).\n", new_size, new);
task->description = new;
task->description_size = new_size;
return 0;
@@ -1520,16 +1522,20 @@
void
append_task_open_port (task_t *task, unsigned int number, char* protocol)
{
- port_t port;
+ assert (task->open_ports != NULL);
+ if (task->open_ports)
+ {
+ port_t port;
- port.number = number;
- if (strncasecmp ("udp", protocol, 3) == 0)
- port.protocol = PORT_PROTOCOL_UDP;
- else if (strncasecmp ("tcp", protocol, 3) == 0)
- port.protocol = PORT_PROTOCOL_TCP;
- else
- port.protocol = PORT_PROTOCOL_OTHER;
+ port.number = number;
+ if (strncasecmp ("udp", protocol, 3) == 0)
+ port.protocol = PORT_PROTOCOL_UDP;
+ else if (strncasecmp ("tcp", protocol, 3) == 0)
+ port.protocol = PORT_PROTOCOL_TCP;
+ else
+ port.protocol = PORT_PROTOCOL_OTHER;
- task->open_ports = g_array_append_val (task->open_ports, port);
- task->open_ports_size++;
+ (void) g_array_append_val (task->open_ports, port);
+ task->open_ports_size++;
+ }
}
Modified: trunk/openvas-manager/src/manage.h
===================================================================
--- trunk/openvas-manager/src/manage.h 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/manage.h 2009-04-08 13:17:43 UTC (rev 3061)
@@ -75,7 +75,7 @@
*/
typedef struct
{
- int number; ///< Port number.
+ unsigned int number; ///< Port number.
port_protocol_t protocol; ///< Port protocol (TCP, UDP, ...).
} port_t;
@@ -171,7 +171,9 @@
find_task (unsigned int id);
int
-set_task_parameter (task_t*, /*@null@*/ const char*, /*@only@*/ char*);
+set_task_parameter (task_t*,
+ /*@null@*/ const char*,
+ /*@null@*/ /*@only@*/ char*);
int
start_task (task_t*);
@@ -207,12 +209,14 @@
char*
make_report_id ();
+/*@-exportlocal@*/
gchar*
report_path_task_name (gchar*);
/*@shared@*/ /*@null@*/
task_t*
report_task (const char*);
+/*@=exportlocal@*/
int
delete_report (const char*);
Modified: trunk/openvas-manager/src/omp.c
===================================================================
--- trunk/openvas-manager/src/omp.c 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/omp.c 2009-04-08 13:17:43 UTC (rev 3061)
@@ -66,16 +66,17 @@
/**
* @brief The start of the data in the \ref to_client buffer.
*/
-size_t to_client_start = 0;
+buffer_size_t to_client_start = 0;
/**
* @brief The end of the data in the \ref to_client buffer.
*/
-size_t to_client_end = 0;
+buffer_size_t to_client_end = 0;
/**
* @brief Current client task during OMP commands like NEW_TASK and MODIFY_TASK.
*/
-static /*@null@*/ task_t* current_client_task = NULL;
+/*@null@*/ /*@dependent@*/
+static task_t* current_client_task = NULL;
/**
* @brief Task ID during OMP MODIFY_TASK and START_TASK.
@@ -99,7 +100,7 @@
* @brief Client input parsing context.
*/
static /*@null@*/ /*@only@*/ GMarkupParseContext*
-xml_context;
+xml_context = NULL;
/**
* @brief Client input parser.
@@ -181,18 +182,30 @@
* Queue a message in \ref to_client.
*
* @param[in] msg The message, a string.
+ *
+ * @return TRUE if out of space in to_client, else FALSE.
*/
-#define SEND_TO_CLIENT(msg) \
- do \
- { \
- if (((size_t) TO_CLIENT_BUFFER_SIZE) - to_client_end < strlen (msg)) \
- goto send_to_client_fail; \
- memcpy (to_client + to_client_end, msg, strlen (msg)); \
- tracef ("-> client: %s\n", msg); \
- to_client_end += strlen (msg); \
- } \
- while (0)
+static gboolean
+send_to_client (char* msg)
+{
+ assert (to_client_end <= TO_CLIENT_BUFFER_SIZE);
+ if (((buffer_size_t) TO_CLIENT_BUFFER_SIZE) - to_client_end
+ < strlen (msg))
+ return TRUE;
+ memmove (to_client + to_client_end, msg, strlen (msg));
+ tracef ("-> client: %s\n", msg);
+ to_client_end += strlen (msg);
+ return FALSE;
+}
+static void
+error_send_to_client (GError** error)
+{
+ tracef (" send_to_client out of space in to_client\n");
+ g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
+ "Manager out of space for reply to client.");
+}
+
/* XML parser handlers. */
@@ -201,7 +214,7 @@
*
* React to the start of an XML element according to the current value
* of \ref client_state, usually adjusting \ref client_state to indicate
- * the change (with \ref set_client_state). Call \ref SEND_TO_CLIENT to
+ * the change (with \ref set_client_state). Call \ref send_to_client to
* queue any responses for the client.
*
* Set error parameter on encountering an error.
@@ -238,9 +251,13 @@
}
else
{
- SEND_TO_CLIENT ("<omp_response>"
- "<status>401</status>"
- "</omp_response>");
+ if (send_to_client ("<omp_response>"
+ "<status>401</status>"
+ "</omp_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
"Must authenticate first.");
}
@@ -295,9 +312,13 @@
set_client_state (CLIENT_STATUS);
else
{
- SEND_TO_CLIENT ("<omp_response>"
- "<status>402</status>"
- "</omp_response>");
+ if (send_to_client ("<omp_response>"
+ "<status>402</status>"
+ "</omp_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
g_set_error (error,
G_MARKUP_ERROR,
G_MARKUP_ERROR_UNKNOWN_ELEMENT,
@@ -310,9 +331,13 @@
set_client_state (CLIENT_CREDENTIALS);
else
{
- SEND_TO_CLIENT ("<authenticate_response>"
- "<status>402</status>"
- "</authenticate_response>");
+ if (send_to_client ("<authenticate_response>"
+ "<status>402</status>"
+ "</authenticate_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
free_credentials (¤t_credentials);
set_client_state (CLIENT_TOP);
g_set_error (error,
@@ -329,9 +354,13 @@
set_client_state (CLIENT_CREDENTIALS_PASSWORD);
else
{
- SEND_TO_CLIENT ("<authenticate_response>"
- "<status>402</status>"
- "</authenticate_response>");
+ if (send_to_client ("<authenticate_response>"
+ "<status>402</status>"
+ "</authenticate_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
free_credentials (¤t_credentials);
set_client_state (CLIENT_TOP);
g_set_error (error,
@@ -346,9 +375,13 @@
set_client_state (CLIENT_DELETE_REPORT_ID);
else
{
- SEND_TO_CLIENT ("<delete_report_response>"
- "<status>402</status>"
- "</delete_report_response>");
+ if (send_to_client ("<delete_report_response>"
+ "<status>402</status>"
+ "</delete_report_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -362,9 +395,13 @@
set_client_state (CLIENT_DELETE_TASK_TASK_ID);
else
{
- SEND_TO_CLIENT ("<delete_task_response>"
- "<status>402</status>"
- "</delete_task_response>");
+ if (send_to_client ("<delete_task_response>"
+ "<status>402</status>"
+ "</delete_task_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -375,9 +412,13 @@
case CLIENT_GET_DEPENDENCIES:
{
- SEND_TO_CLIENT ("<get_dependencies_response>"
- "<status>402</status>"
- "</get_dependencies_response>");
+ if (send_to_client ("<get_dependencies_response>"
+ "<status>402</status>"
+ "</get_dependencies_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -388,9 +429,13 @@
case CLIENT_GET_NVT_FEED_ALL:
{
- SEND_TO_CLIENT ("<get_nvt_feed_all>"
- "<status>402</status>"
- "</get_nvt_feed_all>");
+ if (send_to_client ("<get_nvt_feed_all>"
+ "<status>402</status>"
+ "</get_nvt_feed_all>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -401,9 +446,13 @@
case CLIENT_GET_NVT_FEED_CHECKSUM:
{
- SEND_TO_CLIENT ("<get_nvt_feed_checksum>"
- "<status>402</status>"
- "</get_nvt_feed_checksum>");
+ if (send_to_client ("<get_nvt_feed_checksum>"
+ "<status>402</status>"
+ "</get_nvt_feed_checksum>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -414,9 +463,13 @@
case CLIENT_GET_NVT_FEED_DETAILS:
{
- SEND_TO_CLIENT ("<get_nvt_feed_details>"
- "<status>402</status>"
- "</get_nvt_feed_details>");
+ if (send_to_client ("<get_nvt_feed_details>"
+ "<status>402</status>"
+ "</get_nvt_feed_details>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -427,9 +480,13 @@
case CLIENT_GET_PREFERENCES:
{
- SEND_TO_CLIENT ("<get_preferences_response>"
- "<status>402</status>"
- "</get_preferences_response>");
+ if (send_to_client ("<get_preferences_response>"
+ "<status>402</status>"
+ "</get_preferences_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -443,9 +500,13 @@
set_client_state (CLIENT_GET_REPORT_ID);
else
{
- SEND_TO_CLIENT ("<get_report_response>"
- "<status>402</status>"
- "</get_report_response>");
+ if (send_to_client ("<get_report_response>"
+ "<status>402</status>"
+ "</get_report_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -456,9 +517,13 @@
case CLIENT_GET_RULES:
{
- SEND_TO_CLIENT ("<get_rules_response>"
- "<status>402</status>"
- "</get_rules_response>");
+ if (send_to_client ("<get_rules_response>"
+ "<status>402</status>"
+ "</get_rules_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -476,9 +541,13 @@
set_client_state (CLIENT_MODIFY_REPORT_VALUE);
else
{
- SEND_TO_CLIENT ("<modify_report_response>"
- "<status>402</status>"
- "</modify_report_response>");
+ if (send_to_client ("<modify_report_response>"
+ "<status>402</status>"
+ "</modify_report_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -496,9 +565,13 @@
set_client_state (CLIENT_MODIFY_TASK_VALUE);
else
{
- SEND_TO_CLIENT ("<modify_task_response>"
- "<status>402</status>"
- "</modify_task_response>");
+ if (send_to_client ("<modify_task_response>"
+ "<status>402</status>"
+ "</modify_task_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -516,9 +589,13 @@
#endif
else
{
- SEND_TO_CLIENT ("<abort_task_response>"
- "<status>402</status>"
- "</abort_task_response>");
+ if (send_to_client ("<abort_task_response>"
+ "<status>402</status>"
+ "</abort_task_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -536,9 +613,13 @@
set_client_state (CLIENT_NEW_TASK_COMMENT);
else
{
- SEND_TO_CLIENT ("<new_task_response>"
- "<status>402</status>"
- "</new_task_response>");
+ if (send_to_client ("<new_task_response>"
+ "<status>402</status>"
+ "</new_task_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -552,9 +633,13 @@
set_client_state (CLIENT_START_TASK_TASK_ID);
else
{
- SEND_TO_CLIENT ("<start_task_response>"
- "<status>402</status>"
- "</start_task_response>");
+ if (send_to_client ("<start_task_response>"
+ "<status>402</status>"
+ "</start_task_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -568,9 +653,13 @@
set_client_state (CLIENT_STATUS_TASK_ID);
else
{
- SEND_TO_CLIENT ("<status_response>"
- "<status>402</status>"
- "</status_response>");
+ if (send_to_client ("<status_response>"
+ "<status>402</status>"
+ "</status_response>"))
+ {
+ error_send_to_client (error);
+ return;
+ }
set_client_state (CLIENT_AUTHENTIC);
g_set_error (error,
G_MARKUP_ERROR,
@@ -590,11 +679,6 @@
}
return;
-
- send_to_client_fail:
- tracef (" SEND_TO_CLIENT out of space in to_client\n");
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
- "Manager out of space for reply to client.");
}
/**
@@ -608,18 +692,15 @@
static gint
send_requirement (gconstpointer element, /*@unused@*/ gconstpointer dummy)
{
+ gboolean fail;
gchar* text = g_markup_escape_text ((char*) element,
strlen ((char*) element));
gchar* msg = g_strdup_printf ("<need>%s</need>", text);
g_free (text);
- SEND_TO_CLIENT (msg);
-
+ fail = send_to_client (msg);
g_free (msg);
- return 1;
- send_to_client_fail:
- g_free (msg);
- return 0;
+ return fail ? 0 : 1;
}
/**
@@ -639,7 +720,11 @@
gchar* msg = g_strdup_printf ("<dependency><needer>%s</needer>",
key_text);
g_free (key_text);
- SEND_TO_CLIENT (msg);
+ if (send_to_client (msg))
+ {
+ g_free (msg);
+ return TRUE;
+ }
if (g_slist_find_custom ((GSList*) value, NULL, send_requirement))
{
@@ -647,13 +732,14 @@
return TRUE;
}
- SEND_TO_CLIENT ("</dependency>");
+ if (send_to_client ("</dependency>"))
+ {
+ g_free (msg);
+ return TRUE;
+ }
+
g_free (msg);
return FALSE;
-
- send_to_client_fail:
- g_free (msg);
- return TRUE;
}
/**
@@ -679,12 +765,13 @@
key_text, value_text);
g_free (key_text);
g_free (value_text);
- SEND_TO_CLIENT (msg);
+ if (send_to_client (msg))
+ {
+ g_free (msg);
+ return TRUE;
+ }
g_free (msg);
return FALSE;
- send_to_client_fail:
- g_free (msg);
- return TRUE;
}
/**
@@ -702,12 +789,13 @@
strlen ((char*) rule));
gchar* msg = g_strdup_printf ("<rule>%s</rule>", rule_text);
g_free (rule_text);
- SEND_TO_CLIENT (msg);
+ if (send_to_client (msg))
+ {
+ g_free (msg);
+ return TRUE;
+ }
g_free (msg);
return FALSE;
- send_to_client_fail:
- g_free (msg);
- return TRUE;
}
/**
@@ -789,7 +877,14 @@
"</messages>"
"</report>",
report_name);
- SEND_TO_CLIENT (msg);
+ if (send_to_client (msg))
+ {
+ g_free (msg);
+ while (index < count) { free (names[index++]); }
+ free (names);
+ g_free (dir_name);
+ return -4;
+ }
g_free (msg);
}
@@ -799,21 +894,33 @@
free (names);
g_free (dir_name);
return 0;
-
- send_to_client_fail:
- g_free (msg);
- while (index < count) { free (names[index++]); }
- free (names);
- g_free (dir_name);
- return -4;
}
/**
+ * @brief Send response message to client, returning on fail.
+ *
+ * Queue a message in \ref to_client with \ref send_to_client. On failure
+ * call \ref error_send_to_client on a GError* called "error" and do a return.
+ *
+ * @param[in] msg The message, a string.
+ */
+#define SEND_TO_CLIENT_OR_FAIL(msg) \
+ do \
+ { \
+ if (send_to_client (msg)) \
+ { \
+ error_send_to_client (error); \
+ return; \
+ } \
+ } \
+ while (0)
+
+/**
* @brief Handle the end of an OMP XML element.
*
* React to the end of an XML element according to the current value
* of \ref client_state, usually adjusting \ref client_state to indicate
- * the change (with \ref set_client_state). Call \ref SEND_TO_CLIENT to queue
+ * the change (with \ref set_client_state). Call \ref send_to_client to queue
* any responses for the client. Call the task utilities to adjust the
* tasks (for example \ref start_task, \ref stop_task, \ref set_task_parameter,
* \ref delete_task and \ref find_task).
@@ -839,35 +946,38 @@
break;
case CLIENT_ABORT_TASK:
- {
- unsigned int id;
- assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
- {
- task_t* task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT ("<abort_task_response>"
- "<status>407</status>"
- "</abort_task_response>");
- else if (stop_task (task))
- {
- /* to_server is full. */
- // FIX revert parsing for retry
- // process_omp_client_input must return -2
- abort ();
- }
- else
- SEND_TO_CLIENT ("<abort_task_response>"
- "<status>201</status>"
- "</abort_task_response>");
- }
- else
- SEND_TO_CLIENT ("<abort_task_response>"
- "<status>40x</status>"
- "</abort_task_response>");
- free_string_var (¤t_task_task_id);
- set_client_state (CLIENT_AUTHENTIC);
- }
+ if (current_task_task_id)
+ {
+ unsigned int id;
+ assert (current_client_task == NULL);
+ if (sscanf (current_task_task_id, "%u", &id) == 1)
+ {
+ task_t* task = find_task (id);
+ if (task == NULL)
+ SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
+ "<status>407</status>"
+ "</abort_task_response>");
+ else if (stop_task (task))
+ {
+ /* to_server is full. */
+ // FIX revert parsing for retry
+ // process_omp_client_input must return -2
+ abort ();
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
+ "<status>201</status>"
+ "</abort_task_response>");
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<abort_task_response>"
+ "<status>40x</status>"
+ "</abort_task_response>");
+ free_string_var (¤t_task_task_id);
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<status>50x</status>");
+ set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_ABORT_TASK_TASK_ID:
assert (strncasecmp ("TASK_ID", element_name, 7) == 0);
@@ -901,9 +1011,9 @@
}
else
{
- SEND_TO_CLIENT ("<authenticate_response>"
- "<status>403</status>"
- "</authenticate_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<authenticate_response>"
+ "<status>403</status>"
+ "</authenticate_response>");
free_credentials (¤t_credentials);
set_client_state (CLIENT_TOP);
}
@@ -927,53 +1037,69 @@
case CLIENT_GET_PREFERENCES:
if (server.preferences)
{
- SEND_TO_CLIENT ("<get_preferences_response><status>200</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_preferences_response>"
+ "<status>200</status>");
if (g_hash_table_find (server.preferences, send_preference, NULL))
- goto send_to_client_fail;
- SEND_TO_CLIENT ("</get_preferences_response>");
+ {
+ error_send_to_client (error);
+ return;
+ }
+ SEND_TO_CLIENT_OR_FAIL ("</get_preferences_response>");
}
else
- SEND_TO_CLIENT ("<get_preferences_response>"
- "<status>500</status>"
- "</get_preferences_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_preferences_response>"
+ "<status>500</status>"
+ "</get_preferences_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_GET_DEPENDENCIES:
if (server.plugins_dependencies)
{
- SEND_TO_CLIENT ("<get_dependencies_response><status>200</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_dependencies_response>"
+ "<status>200</status>");
if (g_hash_table_find (server.plugins_dependencies,
send_dependency,
NULL))
- goto send_to_client_fail;
- SEND_TO_CLIENT ("</get_dependencies_response>");
+ {
+ error_send_to_client (error);
+ return;
+ }
+ SEND_TO_CLIENT_OR_FAIL ("</get_dependencies_response>");
}
else
- SEND_TO_CLIENT ("<get_dependencies_response>"
- "<status>500</status>"
- "</get_dependencies_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_dependencies_response>"
+ "<status>500</status>"
+ "</get_dependencies_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_GET_NVT_FEED_ALL:
- SEND_TO_CLIENT ("<get_nvt_feed_all_response><status>200</status>");
- SEND_TO_CLIENT ("<nvt_count>2</nvt_count>");
- SEND_TO_CLIENT ("<feed_checksum>"
- "<algorithm>md5</algorithm>"
- "333"
- "</feed_checksum>");
- SEND_TO_CLIENT ("<nvt>"
- "<oid>1.3.6.1.4.1.25623.1.7.13005</oid>"
- "<name>FooBar 1.5 installed</name>"
- "<checksum><algorithm>md5</algorithm>222</checksum>"
- "</nvt>");
- SEND_TO_CLIENT ("<nvt>"
- "<oid>1.3.6.1.4.1.25623.1.7.13006</oid>"
- "<name>FooBar 2.1 XSS vulnerability</name>"
- "<checksum><algorithm>md5</algorithm>223</checksum>"
- "</nvt>");
- SEND_TO_CLIENT ("</get_nvt_feed_all_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_all_response>"
+ "<status>200</status>");
+ // FIX
+ SEND_TO_CLIENT_OR_FAIL ("<nvt_count>2</nvt_count>");
+ SEND_TO_CLIENT_OR_FAIL ("<feed_checksum>"
+ "<algorithm>md5</algorithm>"
+ "333"
+ "</feed_checksum>");
+ SEND_TO_CLIENT_OR_FAIL ("<nvt>"
+ "<oid>1.3.6.1.4.1.25623.1.7.13005</oid>"
+ "<name>FooBar 1.5 installed</name>"
+ "<checksum>"
+ "<algorithm>md5</algorithm>"
+ "222"
+ "</checksum>"
+ "</nvt>");
+ SEND_TO_CLIENT_OR_FAIL ("<nvt>"
+ "<oid>1.3.6.1.4.1.25623.1.7.13006</oid>"
+ "<name>FooBar 2.1 XSS vulnerability</name>"
+ "<checksum>"
+ "<algorithm>md5</algorithm>"
+ "223"
+ "</checksum>"
+ "</nvt>");
+ SEND_TO_CLIENT_OR_FAIL ("</get_nvt_feed_all_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
@@ -982,50 +1108,51 @@
#if 0
if (server.plugins_md5)
{
- SEND_TO_CLIENT ("<get_nvt_feed_checksum_response>"
- "<status>200</status>"
- "<algorithm>md5</algorithm>");
- SEND_TO_CLIENT (server.plugins_md5);
- SEND_TO_CLIENT ("</get_nvt_feed_checksum_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_checksum_response>"
+ "<status>200</status>"
+ "<algorithm>md5</algorithm>");
+ SEND_TO_CLIENT_OR_FAIL (server.plugins_md5);
+ SEND_TO_CLIENT_OR_FAIL ("</get_nvt_feed_checksum_response>");
}
else
- SEND_TO_CLIENT ("<get_nvt_feed_checksum_response>"
- "<status>500</status>"
- "</get_nvt_feed_checksum_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_checksum_response>"
+ "<status>500</status>"
+ "</get_nvt_feed_checksum_response>");
#else
- SEND_TO_CLIENT ("<get_nvt_feed_checksum_response>"
- "<status>200</status>"
- "<algorithm>md5</algorithm>");
- SEND_TO_CLIENT ("111");
- SEND_TO_CLIENT ("</get_nvt_feed_checksum_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_checksum_response>"
+ "<status>200</status>"
+ "<algorithm>md5</algorithm>");
+ SEND_TO_CLIENT_OR_FAIL ("111");
+ SEND_TO_CLIENT_OR_FAIL ("</get_nvt_feed_checksum_response>");
#endif
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_GET_NVT_FEED_DETAILS:
- SEND_TO_CLIENT ("<get_nvt_feed_details_response><status>200</status>");
- SEND_TO_CLIENT ("<nvt>"
- "<oid>1.3.6.1.4.1.25623.1.7.13005</oid>"
- "<cve>CVE-2008-4877</cve>"
- "<cve>CVE-2008-4881</cve>"
- "<bugtraq_id>12345</bugtraq_id>"
- "<filename>foobar_15_detect.nasl</filename>"
- "<description>This script detects whether FooBar 1.5 is installed.</description>"
- "</nvt>");
- SEND_TO_CLIENT ("<nvt>"
- "<oid>1.3.6.1.4.1.25623.1.7.13006</oid>"
- "<cve>CVE-2008-5142</cve>"
- "<bugtraq_id>12478</bugtraq_id>"
- "<filename>foobar_21_xss.nasl</filename>"
- "<description>This script detects whether the FooBar 2.1 XSS vulnerability is present.</description>"
- "</nvt>");
- SEND_TO_CLIENT ("</get_nvt_feed_details_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_nvt_feed_details_response><status>200</status>");
+ // FIX
+ SEND_TO_CLIENT_OR_FAIL ("<nvt>"
+ "<oid>1.3.6.1.4.1.25623.1.7.13005</oid>"
+ "<cve>CVE-2008-4877</cve>"
+ "<cve>CVE-2008-4881</cve>"
+ "<bugtraq_id>12345</bugtraq_id>"
+ "<filename>foobar_15_detect.nasl</filename>"
+ "<description>This script detects whether FooBar 1.5 is installed.</description>"
+ "</nvt>");
+ SEND_TO_CLIENT_OR_FAIL ("<nvt>"
+ "<oid>1.3.6.1.4.1.25623.1.7.13006</oid>"
+ "<cve>CVE-2008-5142</cve>"
+ "<bugtraq_id>12478</bugtraq_id>"
+ "<filename>foobar_21_xss.nasl</filename>"
+ "<description>This script detects whether the FooBar 2.1 XSS vulnerability is present.</description>"
+ "</nvt>");
+ SEND_TO_CLIENT_OR_FAIL ("</get_nvt_feed_details_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_DELETE_REPORT:
assert (strncasecmp ("DELETE_REPORT", element_name, 13) == 0);
- SEND_TO_CLIENT ("<delete_report_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<delete_report_response>");
if (current_task_task_id)
{
int ret = delete_report (current_task_task_id);
@@ -1033,24 +1160,25 @@
switch (ret)
{
case 0:
- SEND_TO_CLIENT ("<status>200</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<status>200</status>");
break;
case -1: /* Failed to find associated task. */
case -2: /* Report file missing. */
- SEND_TO_CLIENT ("<status>40x</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<status>40x</status>");
break;
case -3: /* Failed to read link. */
case -4: /* Failed to remove report. */
default:
free_string_var (¤t_task_task_id);
- SEND_TO_CLIENT ("<status>500</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<status>500</status>");
break;
}
}
else
// FIX could be a client error
- SEND_TO_CLIENT ("<status>50x</status>");
- SEND_TO_CLIENT ("</delete_report_response>");
+ // init to "" at ele start, then always server err
+ SEND_TO_CLIENT_OR_FAIL ("<status>50x</status>");
+ SEND_TO_CLIENT_OR_FAIL ("</delete_report_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_DELETE_REPORT_ID:
@@ -1060,7 +1188,8 @@
case CLIENT_GET_REPORT:
assert (strncasecmp ("GET_REPORT", element_name, 10) == 0);
- if (current_task_task_id && current_credentials.username)
+ if (current_task_task_id != NULL
+ && current_credentials.username != NULL)
{
gchar* name = g_build_filename (PREFIX
"/var/lib/openvas/mgr/users/",
@@ -1086,38 +1215,42 @@
{
if (content_error)
g_error_free (content_error);
- SEND_TO_CLIENT ("<get_report_response>"
- "<status>50x</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_report_response>"
+ "<status>50x</status>");
}
else
{
gchar* base64_content;
+ SEND_TO_CLIENT_OR_FAIL ("<get_report_response>"
+ "<status>200</status>"
+ "<report>");
base64_content = g_base64_encode ((guchar*) content,
content_length);
g_free (content);
- // FIX free base64_content if SEND_TO_CLIENT fail
- SEND_TO_CLIENT ("<get_report_response>"
- "<status>200</status>"
- "<report>");
- SEND_TO_CLIENT (base64_content);
+ if (send_to_client (base64_content))
+ {
+ g_free (base64_content);
+ error_send_to_client (error);
+ return;
+ }
g_free (base64_content);
- SEND_TO_CLIENT ("</report>");
+ SEND_TO_CLIENT_OR_FAIL ("</report>");
}
}
else
{
g_free (name);
- SEND_TO_CLIENT ("<get_report_response>"
- "<status>40x</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_report_response>"
+ "<status>40x</status>");
}
}
else
{
free_string_var (¤t_task_task_id);
- SEND_TO_CLIENT ("<get_report_response>"
- "<status>500</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_report_response>"
+ "<status>500</status>");
}
- SEND_TO_CLIENT ("</get_report_response>");
+ SEND_TO_CLIENT_OR_FAIL ("</get_report_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_GET_REPORT_ID:
@@ -1129,57 +1262,63 @@
if (server.rules)
{
int index;
- SEND_TO_CLIENT ("<get_rules_response><status>200</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_rules_response><status>200</status>");
for (index = 0; index < server.rules_size; index++)
if (send_rule (g_ptr_array_index (server.rules, index)))
- goto send_to_client_fail;
- SEND_TO_CLIENT ("</get_rules_response>");
+ {
+ error_send_to_client (error);
+ return;
+ }
+ SEND_TO_CLIENT_OR_FAIL ("</get_rules_response>");
}
else
- SEND_TO_CLIENT ("<get_rules_response>"
- "<status>500</status>"
- "</get_rules_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<get_rules_response>"
+ "<status>500</status>"
+ "</get_rules_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_VERSION:
- SEND_TO_CLIENT ("<omp_version_response>"
- "<status>200</status>"
- "<version><preferred/>1.0</version>"
- "</omp_version_response>");
+ SEND_TO_CLIENT_OR_FAIL ("<omp_version_response>"
+ "<status>200</status>"
+ "<version><preferred/>1.0</version>"
+ "</omp_version_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_DELETE_TASK:
- {
- unsigned int id;
- assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
- {
- task_t* task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT ("<delete_task_response>"
- "<status>407</status>"
- "</delete_task_response>");
- else if (delete_task (&task))
- {
- /* to_server is full. */
- // FIX revert parsing for retry
- // process_omp_client_input must return -2
- abort ();
- }
- else
- SEND_TO_CLIENT ("<delete_task_response>"
- "<status>201</status>"
- "</delete_task_response>");
- }
- else
- SEND_TO_CLIENT ("<delete_task_response>"
- "<status>40x</status>"
- "</delete_task_response>");
- free_string_var (¤t_task_task_id);
- set_client_state (CLIENT_AUTHENTIC);
- }
+ if (current_task_task_id)
+ {
+ unsigned int id;
+ assert (current_client_task == NULL);
+ if (sscanf (current_task_task_id, "%u", &id) == 1)
+ {
+ task_t* task = find_task (id);
+ if (task == NULL)
+ SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
+ "<status>407</status>"
+ "</delete_task_response>");
+ else if (delete_task (&task))
+ {
+ /* to_server is full. */
+ // FIX revert parsing for retry
+ // process_omp_client_input must return -2
+ abort ();
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
+ "<status>201</status>"
+ "</delete_task_response>");
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<delete_task_response>"
+ "<status>40x</status>"
+ "</delete_task_response>");
+ free_string_var (¤t_task_task_id);
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<status>50x</status>");
+ set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_DELETE_TASK_TASK_ID:
assert (strncasecmp ("TASK_ID", element_name, 7) == 0);
@@ -1187,9 +1326,9 @@
break;
case CLIENT_MODIFY_REPORT:
- if (current_task_task_id
- && modify_task_parameter
- && modify_task_value)
+ if (current_task_task_id != NULL
+ && modify_task_parameter != NULL
+ && modify_task_value != NULL)
{
int ret = set_report_parameter (current_task_task_id,
modify_task_parameter,
@@ -1200,17 +1339,17 @@
switch (ret)
{
case 0:
- SEND_TO_CLIENT ("<modify_report_response>"
- "<status>200</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<modify_report_response>"
+ "<status>200</status>");
break;
case -2: /* Parameter name error. */
- SEND_TO_CLIENT ("<modify_report_response>"
- "<status>40x</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<modify_report_response>"
+ "<status>40x</status>");
break;
case -3: /* Failed to write to disk. */
default:
- SEND_TO_CLIENT ("<modify_report_response>"
- "<status>50x</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<modify_report_response>"
+ "<status>50x</status>");
break;
}
}
@@ -1219,10 +1358,10 @@
free_string_var (&modify_task_parameter);
free_string_var (&modify_task_value);
free_string_var (¤t_task_task_id);
- SEND_TO_CLIENT ("<modify_report_response>"
- "<status>500</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<modify_report_response>"
+ "<status>500</status>");
}
- SEND_TO_CLIENT ("</modify_report_response>");
+ SEND_TO_CLIENT_OR_FAIL ("</modify_report_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_MODIFY_REPORT_PARAMETER:
@@ -1239,48 +1378,50 @@
break;
case CLIENT_MODIFY_TASK:
- {
- unsigned int id;
- assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
- {
- task_t* task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT ("<modify_task_response>"
- "<status>407</status>"
- "</modify_task_response>");
- else
- {
- // FIX check if param,value else respond fail
- int fail = set_task_parameter (task,
- modify_task_parameter,
- modify_task_value);
- free (modify_task_parameter);
- modify_task_parameter = NULL;
- if (fail)
- {
- free (modify_task_value);
- modify_task_value = NULL;
- SEND_TO_CLIENT ("<modify_task_response>"
+ if (current_task_task_id)
+ {
+ unsigned int id;
+ assert (current_client_task == NULL);
+ if (sscanf (current_task_task_id, "%u", &id) == 1)
+ {
+ task_t* task = find_task (id);
+ if (task == NULL)
+ SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
+ "<status>407</status>"
+ "</modify_task_response>");
+ else
+ {
+ // FIX check if param,value else respond fail
+ int fail = set_task_parameter (task,
+ modify_task_parameter,
+ modify_task_value);
+ free (modify_task_parameter);
+ if (fail)
+ {
+ free (modify_task_value);
+ modify_task_value = NULL;
+ SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
+ "<status>40x</status>"
+ "</modify_task_response>");
+ }
+ else
+ {
+ modify_task_value = NULL;
+ SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
+ "<status>201</status>"
+ "</modify_task_response>");
+ }
+ }
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<modify_task_response>"
"<status>40x</status>"
"</modify_task_response>");
- }
- else
- {
- modify_task_value = NULL;
- SEND_TO_CLIENT ("<modify_task_response>"
- "<status>201</status>"
- "</modify_task_response>");
- }
- }
- }
- else
- SEND_TO_CLIENT ("<modify_task_response>"
- "<status>40x</status>"
- "</modify_task_response>");
- free_string_var (¤t_task_task_id);
- set_client_state (CLIENT_AUTHENTIC);
- }
+ free_string_var (¤t_task_task_id);
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<status>50x</status>");
+ set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_MODIFY_TASK_PARAMETER:
assert (strncasecmp ("PARAMETER", element_name, 9) == 0);
@@ -1299,7 +1440,7 @@
{
gchar* msg;
assert (strncasecmp ("NEW_TASK", element_name, 7) == 0);
- assert (current_client_task);
+ assert (current_client_task != NULL);
// FIX if all rqrd fields given then ok, else respond fail
// FIX only here should the task be added to tasks
// eg on err half task could be saved (or saved with base64 file)
@@ -1308,9 +1449,13 @@
"<task_id>%u</task_id>"
"</new_task_response>",
current_client_task->id);
- // FIX free msg if fail
- SEND_TO_CLIENT (msg);
- free (msg);
+ if (send_to_client (msg))
+ {
+ g_free (msg);
+ error_send_to_client (error);
+ return;
+ }
+ g_free (msg);
current_client_task = NULL;
set_client_state (CLIENT_AUTHENTIC);
break;
@@ -1339,35 +1484,38 @@
break;
case CLIENT_START_TASK:
- {
- unsigned int id;
- assert (current_client_task == NULL);
- if (sscanf (current_task_task_id, "%u", &id) == 1)
- {
- task_t* task = find_task (id);
- if (task == NULL)
- SEND_TO_CLIENT ("<start_task_response>"
- "<status>407</status>"
- "</start_task_response>");
- else if (start_task (task))
- {
- /* to_server is full. */
- // FIX revert parsing for retry
- // process_omp_client_input must return -2
- abort ();
- }
- else
- SEND_TO_CLIENT ("<start_task_response>"
- "<status>201</status>"
- "</start_task_response>");
- }
- else
- SEND_TO_CLIENT ("<start_task_response>"
- "<status>40x</status>"
- "</start_task_response>");
- free_string_var (¤t_task_task_id);
- set_client_state (CLIENT_AUTHENTIC);
- }
+ if (current_task_task_id)
+ {
+ unsigned int id;
+ assert (current_client_task == NULL);
+ if (sscanf (current_task_task_id, "%u", &id) == 1)
+ {
+ task_t* task = find_task (id);
+ if (task == NULL)
+ SEND_TO_CLIENT_OR_FAIL ("<start_task_response>"
+ "<status>407</status>"
+ "</start_task_response>");
+ else if (start_task (task))
+ {
+ /* to_server is full. */
+ // FIX revert parsing for retry
+ // process_omp_client_input must return -2
+ abort ();
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<start_task_response>"
+ "<status>201</status>"
+ "</start_task_response>");
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<start_task_response>"
+ "<status>40x</status>"
+ "</start_task_response>");
+ free_string_var (¤t_task_task_id);
+ }
+ else
+ SEND_TO_CLIENT_OR_FAIL ("<status>50x</status>");
+ set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_START_TASK_TASK_ID:
assert (strncasecmp ("TASK_ID", element_name, 7) == 0);
@@ -1383,24 +1531,28 @@
{
task_t* task = find_task (id);
if (task == NULL)
- SEND_TO_CLIENT ("<status_response>"
- "<status>407</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<status_response>"
+ "<status>407</status>");
else
{
gchar* response;
- SEND_TO_CLIENT ("<status_response><status>200</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<status_response><status>200</status>");
response = g_strdup_printf ("<report_count>%u</report_count>",
task->report_count);
- // FIX free if fail
- SEND_TO_CLIENT (response);
+ if (send_to_client (response))
+ {
+ g_free (response);
+ error_send_to_client (error);
+ return;
+ }
g_free (response);
// FIX need to handle err cases before send status
(void) send_reports (task);
}
}
else
- SEND_TO_CLIENT ("<status_response>"
- "<status>40x</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<status_response>"
+ "<status>40x</status>");
free_string_var (¤t_task_task_id);
}
else
@@ -1408,11 +1560,15 @@
gchar* response;
task_t* index;
task_t* end;
- SEND_TO_CLIENT ("<status_response><status>200</status>");
+ SEND_TO_CLIENT_OR_FAIL ("<status_response><status>200</status>");
response = g_strdup_printf ("<task_count>%u</task_count>",
num_tasks);
- // FIX free response on fail
- SEND_TO_CLIENT (response);
+ if (send_to_client (response))
+ {
+ g_free (response);
+ error_send_to_client (error);
+ return;
+ }
g_free (response);
// FIX this is the only place that accesses "tasks" foreach_task?
index = tasks;
@@ -1452,13 +1608,18 @@
index->logs_size,
index->notes_size);
// FIX free line if RESPOND fails
- SEND_TO_CLIENT (line);
+ if (send_to_client (line))
+ {
+ g_free (line);
+ error_send_to_client (error);
+ return;
+ }
g_free (line);
}
index++;
}
}
- SEND_TO_CLIENT ("</status_response>");
+ SEND_TO_CLIENT_OR_FAIL ("</status_response>");
set_client_state (CLIENT_AUTHENTIC);
break;
case CLIENT_STATUS_TASK_ID:
@@ -1470,13 +1631,6 @@
assert (0);
break;
}
-
- return;
-
- send_to_client_fail:
- tracef (" SEND_TO_CLIENT out of space in to_client\n");
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
- "Manager out of space for reply to client.\n");
}
/**
@@ -1579,13 +1733,13 @@
// FIX probably should pass to process_omp_client_input
extern char from_client[];
-extern int from_client_start;
-extern int from_client_end;
+extern buffer_size_t from_client_start;
+extern buffer_size_t from_client_end;
/**
* @brief Initialise OMP library data.
*
- * This must run once, before the first call to \ref process_omp_client_input.
+ * This should run once, before the first call to \ref process_omp_client_input.
*/
void
init_omp_data ()
@@ -1596,6 +1750,7 @@
xml_parser.text = omp_xml_handle_text;
xml_parser.passthrough = NULL;
xml_parser.error = omp_xml_handle_error;
+ if (xml_context) g_free (xml_context);
xml_context = g_markup_parse_context_new (&xml_parser,
0,
NULL,
@@ -1611,7 +1766,7 @@
*
* The callback functions will queue any resulting server commands in
* \ref to_server (using \ref send_to_server) and any replies for
- * the client in \ref to_client (using \ref SEND_TO_CLIENT).
+ * the client in \ref to_client (using \ref send_to_client).
*
* @return 0 success, -1 error, -2 or -3 too little space in \ref to_client
* or \ref to_server.
@@ -1621,6 +1776,9 @@
{
gboolean success;
GError* error = NULL;
+
+ if (xml_context == NULL) return -1;
+
success = g_markup_parse_context_parse (xml_context,
from_client + from_client_start,
from_client_end - from_client_start,
Modified: trunk/openvas-manager/src/omp.h
===================================================================
--- trunk/openvas-manager/src/omp.h 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/omp.h 2009-04-08 13:17:43 UTC (rev 3061)
@@ -26,6 +26,7 @@
#ifndef OPENVAS_MANAGER_OMP_H
#define OPENVAS_MANAGER_OMP_H
+#include "types.h"
#include <sys/types.h>
/**
@@ -42,7 +43,7 @@
// FIX probably should be passed to process_omp_client_input/init_omp_data
// and defined in caller
extern char to_client[];
-extern size_t to_client_start;
-extern size_t to_client_end;
+extern buffer_size_t to_client_start;
+extern buffer_size_t to_client_end;
#endif
Modified: trunk/openvas-manager/src/ompd.c
===================================================================
--- trunk/openvas-manager/src/ompd.c 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/ompd.c 2009-04-08 13:17:43 UTC (rev 3061)
@@ -82,16 +82,16 @@
struct sockaddr_in server_address;
// FIX Should probably be passed into serve_omp.
-extern int from_buffer_size;
+extern buffer_size_t from_buffer_size;
// FIX mv these here when read_protocol sorted out in openvasmd.c
// FIX how to share these buffers with otpd.c?
extern char from_client[];
-extern int from_client_start;
-extern int from_client_end;
+extern buffer_size_t from_client_start;
+extern buffer_size_t from_client_end;
extern char from_server[];
-extern int from_server_start;
-extern int from_server_end;
+extern buffer_size_t from_server_start;
+extern buffer_size_t from_server_end;
/**
* @brief Read as much from the client as the \ref from_client buffer will hold.
@@ -112,7 +112,6 @@
count = gnutls_record_recv (*client_session,
from_client + from_client_end,
from_buffer_size - from_client_end);
- tracef (" c count: %i\n", count);
if (count < 0)
{
if (count == GNUTLS_E_AGAIN)
@@ -172,7 +171,6 @@
count = gnutls_record_recv (*server_session,
from_server + from_server_end,
from_buffer_size - from_server_end);
- tracef (" s count: %i\n", (int) count);
if (count < 0)
{
if (count == GNUTLS_E_AGAIN)
@@ -200,12 +198,13 @@
alert_name);
}
fprintf (stderr, "Failed to read from server.\n");
- gnutls_perror ((int) count);
+ gnutls_perror (count);
return -1;
}
if (count == 0)
/* End of file. */
return -3;
+ assert (count > 0);
from_server_end += count;
}
@@ -389,7 +388,7 @@
int client_socket, int* server_socket_addr)
{
int nfds;
- unsigned char lastfds;
+ uint8_t lastfds;
fd_set readfds, exceptfds, writefds;
int server_socket = *server_socket_addr;
/* True if processing of the client input is waiting for space in the
@@ -423,7 +422,8 @@
#if TRACE_TEXT
tracef ("<= client \"%.*s\"\n", from_client_end, from_client);
#else
- tracef ("<= client %i bytes\n", from_client_end - initial_start);
+ tracef ("<= client %" BUFFER_SIZE_T_FORMAT " bytes\n",
+ from_client_end);
#endif
#endif /* TRACE || LOG */
// FIX handle client_input_stalled
@@ -460,12 +460,12 @@
nfds = 1 + (client_socket > server_socket
? client_socket : server_socket);
- lastfds = '\0'; // FIX
+ lastfds = 0; // FIX
while (1)
{
int ret;
/* Setup for select. */
- unsigned char fds = '0'; /* What `select' is going to watch. */
+ uint8_t fds = 0; /* What `select' is going to watch. */
FD_ZERO (&exceptfds);
FD_ZERO (&readfds);
FD_ZERO (&writefds);
@@ -476,12 +476,12 @@
{
FD_SET (client_socket, &readfds);
fds |= FD_CLIENT_READ;
- if ((lastfds & FD_CLIENT_READ) == (unsigned char) 0)
+ if ((lastfds & FD_CLIENT_READ) == 0)
tracef (" client read on\n");
}
else
{
- if ((lastfds & FD_CLIENT_READ) != (unsigned char) 0)
+ if ((lastfds & FD_CLIENT_READ) > 0)
tracef (" client read off\n");
}
if ((server_init_state == SERVER_INIT_DONE
@@ -492,12 +492,12 @@
{
FD_SET (server_socket, &readfds);
fds |= FD_SERVER_READ;
- if ((lastfds & FD_SERVER_READ) == (unsigned char) 0)
+ if ((lastfds & FD_SERVER_READ) == 0)
tracef (" server read on\n");
}
else
{
- if ((lastfds & FD_SERVER_READ) != (unsigned char) 0)
+ if ((lastfds & FD_SERVER_READ) > 0)
tracef (" server read off\n");
}
if (to_client_start < to_client_end)
@@ -507,7 +507,7 @@
}
if (((server_init_state == SERVER_INIT_TOP
|| server_init_state == SERVER_INIT_DONE)
- && to_server_buffer_space ())
+ && to_server_buffer_space () > 0)
|| server_init_state == SERVER_INIT_CONNECT_INTR
|| server_init_state == SERVER_INIT_CONNECTED
|| server_init_state == SERVER_INIT_GOT_PASSWORD
@@ -540,10 +540,11 @@
return -1;
}
- if (fds & FD_CLIENT_READ && FD_ISSET (client_socket, &readfds))
+ if ((fds & FD_CLIENT_READ) == FD_CLIENT_READ
+ && FD_ISSET (client_socket, &readfds))
{
#if TRACE || LOG
- int initial_start = from_client_end;
+ buffer_size_t initial_start = from_client_end;
#endif
tracef (" FD_CLIENT_READ\n");
@@ -615,10 +616,11 @@
assert (0);
}
- if (fds & FD_SERVER_READ && FD_ISSET (server_socket, &readfds))
+ if ((fds & FD_SERVER_READ) == FD_SERVER_READ
+ && FD_ISSET (server_socket, &readfds))
{
#if TRACE || LOG
- int initial_start = from_server_end;
+ buffer_size_t initial_start = from_server_end;
#endif
tracef (" FD_SERVER_READ\n");
@@ -708,7 +710,7 @@
assert (0);
}
- if (fds & FD_SERVER_WRITE
+ if ((fds & FD_SERVER_WRITE) == FD_SERVER_WRITE
&& FD_ISSET (server_socket, &writefds))
{
/* Write as much as possible to the server. */
@@ -730,7 +732,7 @@
}
}
- if (fds & FD_CLIENT_WRITE
+ if ((fds & FD_CLIENT_WRITE) == FD_CLIENT_WRITE
&& FD_ISSET (client_socket, &writefds))
{
/* Write as much as possible to the client. */
Modified: trunk/openvas-manager/src/ompd.h
===================================================================
--- trunk/openvas-manager/src/ompd.h 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/ompd.h 2009-04-08 13:17:43 UTC (rev 3061)
@@ -26,6 +26,7 @@
#ifndef OPENVAS_MANAGER_OMPD_H
#define OPENVAS_MANAGER_OMPD_H
+#include "types.h"
#include <gnutls/gnutls.h>
int
@@ -33,11 +34,13 @@
gnutls_certificate_credentials_t*,
int, int*);
+/*@-exportlocal@*/
extern struct sockaddr_in server_address;
+/*@=exportlocal@*/
// FIX Temporarily, for omp.c SEND_TO_CLIENT.
extern char to_client[];
-extern size_t to_client_start;
-extern size_t to_client_end;
+extern buffer_size_t to_client_start;
+extern buffer_size_t to_client_end;
#endif
Modified: trunk/openvas-manager/src/openvasmd.c
===================================================================
--- trunk/openvas-manager/src/openvasmd.c 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/openvasmd.c 2009-04-08 13:17:43 UTC (rev 3061)
@@ -232,25 +232,26 @@
/**
* @brief Size of \ref from_client and \ref from_server data buffers, in bytes.
*/
-size_t from_buffer_size = FROM_BUFFER_SIZE;
+buffer_size_t from_buffer_size = FROM_BUFFER_SIZE;
// FIX just make these pntrs?
/**
* @brief The start of the data in the \ref from_client buffer.
*/
-size_t from_client_start = 0;
+buffer_size_t from_client_start = 0;
/**
* @brief The start of the data in the \ref from_server buffer.
*/
-size_t from_server_start = 0;
+buffer_size_t from_server_start = 0;
/**
* @brief The end of the data in the \ref from_client buffer.
*/
-size_t from_client_end = 0;
+buffer_size_t from_client_end = 0;
+
/**
* @brief The end of the data in the \ref from_server buffer.
*/
-size_t from_server_end = 0;
+buffer_size_t from_server_end = 0;
/* Checking protocol, forking, serving the client. */
@@ -268,7 +269,7 @@
{
/* Turn on blocking. */
// FIX get flags first
- if (fcntl (client_socket, F_SETFL, 0) == -1)
+ if (fcntl (client_socket, F_SETFL, 0L) == -1)
{
perror ("Failed to set client socket flag (read_protocol)");
return PROTOCOL_FAIL;
Modified: trunk/openvas-manager/src/otp.c
===================================================================
--- trunk/openvas-manager/src/otp.c 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/otp.c 2009-04-08 13:17:43 UTC (rev 3061)
@@ -39,6 +39,7 @@
#include "manage.h"
#include "string.h"
#include "tracef.h"
+#include "types.h"
#include <assert.h>
#include <errno.h>
@@ -59,7 +60,7 @@
#endif
// FIX Should probably be passed into process_otp_server_input.
-extern int from_buffer_size;
+extern buffer_size_t from_buffer_size;
/* Helper functions. */
@@ -102,6 +103,11 @@
} port_t;
#endif
+/*@shared@*/ static char* tcp_string = "tcp";
+/*@shared@*/ static char* udp_string = "tcp";
+/*@shared@*/ static char* other_string = "???";
+/*@shared@*/ static char* empty_string = "";
+
/**
* @brief Get the name of the protocol of a port.
*
@@ -109,15 +115,16 @@
*
* @return The name.
*/
-static char*
+/*@shared@*/
+static const char*
port_protocol_name (port_t* port)
{
switch (port->protocol)
{
- case PORT_PROTOCOL_TCP: return "tcp";
- case PORT_PROTOCOL_UDP: return "udp";
- case PORT_PROTOCOL_OTHER: return "???";
- default: assert (0); return "";
+ case PORT_PROTOCOL_TCP: return tcp_string;
+ case PORT_PROTOCOL_UDP: return udp_string;
+ case PORT_PROTOCOL_OTHER: return other_string;
+ default: assert (0); return empty_string;
}
}
@@ -130,7 +137,7 @@
static void
print_port (FILE* stream, port_t* port)
{
- fprintf (stream, "FIX (%d/%s)", port->number, port_protocol_name (port));
+ fprintf (stream, "FIX (%u/%s)", port->number, port_protocol_name (port));
}
@@ -152,7 +159,8 @@
/**
* @brief Current message during OTP SERVER message commands.
*/
-static /*@null@*/ message_t* current_message = NULL;
+/*@null@*/ /*@only@*/
+static message_t* current_message = NULL;
/**
* @brief Make a message.
@@ -162,13 +170,15 @@
*
* @return A pointer to the new message.
*/
+/*@only@*/
static message_t*
make_message (unsigned int number, const char* protocol)
+ /*@ensures isnull result->description, result->oid@*/
{
message_t* message;
tracef (" make_message %u %s\n", number, protocol);
- message = g_malloc (sizeof (message_t));
+ message = (message_t*) g_malloc (sizeof (message_t));
message->description = NULL;
message->oid = NULL;
@@ -234,8 +244,8 @@
*/
typedef struct
{
- FILE* stream; ///< Destination stream.
- char* type; ///< Type of message.
+ /*@temp@*/ FILE* stream; ///< Destination stream.
+ /*@temp@*/ char* type; ///< Type of message.
} message_data_t;
/**
@@ -433,7 +443,7 @@
* @param[in] message Message.
*/
static void
-append_debug_message (task_t* task, message_t* message)
+append_debug_message (task_t* task, /*@keep@*/ message_t* message)
{
g_ptr_array_add (task->debugs, (gpointer) message);
task->debugs_size++;
@@ -446,7 +456,7 @@
* @param[in] message Message.
*/
static void
-append_hole_message (task_t* task, message_t* message)
+append_hole_message (task_t* task, /*@keep@*/ message_t* message)
{
g_ptr_array_add (task->holes, (gpointer) message);
task->holes_size++;
@@ -459,7 +469,7 @@
* @param[in] message Message.
*/
static void
-append_info_message (task_t* task, message_t* message)
+append_info_message (task_t* task, /*@keep@*/ message_t* message)
{
g_ptr_array_add (task->infos, (gpointer) message);
task->infos_size++;
@@ -472,7 +482,7 @@
* @param[in] message Message.
*/
static void
-append_log_message (task_t* task, message_t* message)
+append_log_message (task_t* task, /*@keep@*/ message_t* message)
{
g_ptr_array_add (task->logs, (gpointer) message);
task->logs_size++;
@@ -485,7 +495,7 @@
* @param[in] message Message.
*/
static void
-append_note_message (task_t* task, message_t* message)
+append_note_message (task_t* task, /*@keep@*/ message_t* message)
{
g_ptr_array_add (task->notes, (gpointer) message);
task->notes_size++;
@@ -497,7 +507,8 @@
/**
* @brief The current server preference, during reading of server preferences.
*/
-static /*@null@*/ char* current_server_preference = NULL;
+/*@null@*/ /*@only@*/
+static char* current_server_preference = NULL;
/**
* @brief Create the server preferences.
@@ -522,7 +533,7 @@
* @param[in] value The value of the preference.
*/
static void
-add_server_preference (/*@only@*/ char* preference, /*@only@*/ char* value)
+add_server_preference (/*@keep@*/ char* preference, /*@keep@*/ char* value)
{
g_hash_table_insert (server.preferences, preference, value);
}
@@ -533,11 +544,13 @@
/**
* @brief The current server plugin, during reading of server plugin dependencies.
*/
+/*@only@*/
static char* current_server_plugin_dependency_name = NULL;
/**
* @brief The plugins required by the current server plugin.
*/
+/*@only@*/
static GSList* current_server_plugin_dependency_dependencies = NULL;
/**
@@ -564,9 +577,10 @@
* @param[in] requirements The plugins required by the plugin.
*/
static void
-add_server_plugins_dependency (char* name, GSList* requirements)
+add_server_plugins_dependency (/*@keep@*/ char* name,
+ /*@keep@*/ GSList* requirements)
{
- assert (server.plugins_dependencies);
+ assert (server.plugins_dependencies != NULL);
tracef (" server new dependency name: %s\n", name);
g_hash_table_insert (server.plugins_dependencies, name, requirements);
}
@@ -594,7 +608,7 @@
* make_server_plugins_dependencies.
*/
static void
-append_to_current_server_plugin_dependency (/*@only@*/ char* requirement)
+append_to_current_server_plugin_dependency (/*@keep@*/ char* requirement)
{
tracef (" server appending plugin requirement: %s\n", requirement);
current_server_plugin_dependency_dependencies
@@ -608,7 +622,7 @@
static void
finish_current_server_plugin_dependency ()
{
- assert (current_server_plugin_dependency_name);
+ assert (current_server_plugin_dependency_name != NULL);
add_server_plugins_dependency (current_server_plugin_dependency_name,
current_server_plugin_dependency_dependencies);
current_server_plugin_dependency_name = NULL;
@@ -625,9 +639,9 @@
* @param[in] dummy Dummy parameter, to please g_ptr_array_foreach.
*/
static void
-free_rule (void* rule, /*@unused@*/ void* dummy)
+free_rule (/*@only@*/ /*@out@*/ void* rule, /*@unused@*/ void* dummy)
{
- free (rule);
+ if (rule) free (rule);
}
/**
@@ -662,7 +676,7 @@
* @param[in] rule The rule.
*/
static void
-add_server_rule (/*@only@*/ char* rule)
+add_server_rule (/*@keep@*/ char* rule)
{
g_ptr_array_add (server.rules, rule);
server.rules_size++;
@@ -779,8 +793,8 @@
// FIX probably should pass to process_omp_client_input
extern char from_server[];
-extern int from_server_start;
-extern int from_server_end;
+extern buffer_size_t from_server_start;
+extern buffer_size_t from_server_end;
/**
* @brief Parse the final SERVER field of an OTP message.
@@ -821,11 +835,13 @@
parse_server_preference_value (char** messages)
{
char *value, *end, *match;
- assert (current_server_preference);
+ assert (current_server_preference != NULL);
end = *messages + from_server_end - from_server_start;
while (*messages < end && ((*messages)[0] == ' '))
{ (*messages)++; from_server_start++; }
- if ((match = memchr (*messages, '\n', from_server_end - from_server_start)))
+ if ((match = memchr (*messages,
+ (int) '\n',
+ from_server_end - from_server_start)))
{
match[0] = '\0';
value = g_strdup (*messages);
@@ -863,7 +879,9 @@
/* The rules list ends with "<|> SERVER". */
return -1;
/* There may be a rule ending in a semicolon. */
- if ((match = memchr (*messages, ';', from_server_end - from_server_start)))
+ if ((match = memchr (*messages,
+ (int) ';',
+ from_server_end - from_server_start)))
{
char* rule;
match[0] = '\0';
@@ -889,7 +907,7 @@
/* Look for the end of dependency marker: a newline that comes before
* the next <|>. */
char *separator, *end, *match, *input;
- int from_start, from_end;
+ buffer_size_t from_start, from_end;
separator = NULL;
/* Look for <|>. */
input = *messages;
@@ -899,7 +917,8 @@
&& (match = memchr (input, (int) '<', from_end - from_start))
!= NULL)
{
- if (((int) (match - input) - from_start + 1) < from_end
+ assert (match >= input);
+ if ((((match - input) + from_start + 1) < from_end)
&& (match[1] == '|')
&& (match[2] == '>'))
{
@@ -929,7 +948,6 @@
return separator == NULL;
}
-
/**
* @brief Parse the field following "SERVER <|>".
*
@@ -950,9 +968,9 @@
(int) '\n',
from_server_end - from_server_start)))
{
- char* newline;
- char* input;
- int from_start, from_end;
+ /*@dependent@*/ char* newline;
+ /*@dependent@*/ char* input;
+ buffer_size_t from_start, from_end;
match[0] = '\0';
// FIX is there ever whitespace before the newline?
while (*messages < end && ((*messages)[0] == ' '))
@@ -973,12 +991,13 @@
from_start = from_server_start;
from_end = from_server_end;
while (from_start < from_end
- && (match = memchr (input,
- (int) '<',
- from_end - from_start))
- != NULL)
+ && ((match = memchr (input,
+ (int) '<',
+ from_end - from_start))
+ != NULL))
{
- if ((((int) (match - input) - from_start + 1) < from_end)
+ assert (match >= input);
+ if ((((match - input) + from_start + 1) < from_end)
&& (match[1] == '|')
&& (match[2] == '>'))
{
@@ -1040,8 +1059,10 @@
#if TRACE
from_server[from_server_end] = '\0';
//tracef (" new from_server: %s\n", from_server);
- tracef (" new from_server_start: %i\n", from_server_start);
- tracef (" new from_server_end: %i\n", from_server_end);
+ tracef (" new from_server_start: %" BUFFER_SIZE_T_FORMAT "\n",
+ from_server_start);
+ tracef (" new from_server_end: %" BUFFER_SIZE_T_FORMAT "\n",
+ from_server_end);
#endif
}
return 0;
@@ -1064,10 +1085,10 @@
int
process_otp_server_input ()
{
- char* match = NULL;
- /*@shared@*/ char* messages = from_server + from_server_start;
- /*@shared@*/ char* input;
- int from_start, from_end;
+ /*@dependent@*/ char* match = NULL;
+ /*@dependent@*/ char* messages = from_server + from_server_start;
+ /*@dependent@*/ char* input;
+ buffer_size_t from_start, from_end;
//tracef (" consider %.*s\n", from_server_end - from_server_start, messages);
/* First, handle special server states where the input from the server
@@ -1205,9 +1226,13 @@
from_start = from_server_start;
from_end = from_server_end;
while (from_start < from_end
- && (match = memchr (input, '<', from_end - from_start)))
+ && ((match = memchr (input,
+ (int) '<',
+ from_end - from_start))
+ != NULL))
{
- if (((int) (match - input) - from_start + 1) < from_end
+ assert (match >= input);
+ if ((((match - input) + from_start + 1) < from_end)
&& (match[1] == '|')
&& (match[2] == '>'))
{
@@ -1432,7 +1457,7 @@
}
case SERVER_INFO_OID:
{
- if (current_message && current_server_task)
+ if (current_message != NULL && current_server_task != NULL)
{
char* oid = g_strdup (field);
set_message_oid (current_message, oid);
@@ -1498,7 +1523,7 @@
}
case SERVER_LOG_OID:
{
- if (current_message && current_server_task)
+ if (current_message != NULL && current_server_task != NULL)
{
char* oid = g_strdup (field);
set_message_oid (current_message, oid);
@@ -1564,7 +1589,7 @@
}
case SERVER_NOTE_OID:
{
- if (current_message && current_server_task)
+ if (current_message != NULL && current_server_task != NULL)
{
char* oid = g_strdup (field);
set_message_oid (current_message, oid);
@@ -1651,8 +1676,8 @@
if (current_server_task)
{
int number;
- char *name = g_newa (char, strlen (field));
- char *protocol = g_newa (char, strlen (field));
+ char *name = g_malloc0 (strlen (field));
+ char *protocol = g_malloc0 (strlen (field));
if (sscanf (field, "%s (%i/%[^)])",
name, &number, protocol)
@@ -1666,6 +1691,8 @@
append_task_open_port (current_server_task,
number,
protocol);
+ g_free (name);
+ g_free (protocol);
}
set_server_state (SERVER_DONE);
switch (parse_server_done (&messages))
Modified: trunk/openvas-manager/src/otp.h
===================================================================
--- trunk/openvas-manager/src/otp.h 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/otp.h 2009-04-08 13:17:43 UTC (rev 3061)
@@ -75,6 +75,8 @@
} server_t;
// FIX for omp.c access to server info (rules, prefs, ...)
+/*@-exportlocal@*/
extern server_t server;
+/*@=exportlocal@*/
#endif
Modified: trunk/openvas-manager/src/otpd.c
===================================================================
--- trunk/openvas-manager/src/otpd.c 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/otpd.c 2009-04-08 13:17:43 UTC (rev 3061)
@@ -37,6 +37,7 @@
* client and server.
*/
+#include "types.h"
#include "otpd.h"
#include "logf.h"
#include "tracef.h"
@@ -62,16 +63,16 @@
#define FD_SERVER_WRITE 8
// FIX Should probably be passed into serve_otp.
-extern size_t from_buffer_size;
+extern buffer_size_t from_buffer_size;
// FIX mv these here when read_protocol sorted out in openvasmd.c
// FIX how to share these buffers with ompd.c?
extern char from_client[];
-extern int from_client_start;
-extern int from_client_end;
+extern buffer_size_t from_client_start;
+extern buffer_size_t from_client_end;
extern char from_server[];
-extern int from_server_start;
-extern int from_server_end;
+extern buffer_size_t from_server_start;
+extern buffer_size_t from_server_end;
/**
* @brief Serve the OpenVAS Transfer Protocol (OTP).
@@ -103,7 +104,8 @@
#if TRACE_TEXT
tracef ("<= client \"%.*s\"\n", from_client_end, from_client);
#else
- tracef ("<= client %i bytes\n", from_client_end - initial_start);
+ tracef ("<= client %" BUFFER_SIZE_T_FORMAT " bytes\n",
+ from_client_end);
#endif
#endif /* TRACE || LOG */
@@ -164,10 +166,11 @@
return -1;
}
- if (fds & FD_CLIENT_READ && FD_ISSET (client_socket, &readfds))
+ if ((fds & FD_CLIENT_READ) == FD_CLIENT_READ
+ && FD_ISSET (client_socket, &readfds))
{
#if TRACE || LOG
- int initial_start = from_client_end;
+ buffer_size_t initial_start = from_client_end;
#endif
/* Read as much as possible from the client. */
while (from_client_end < from_buffer_size)
@@ -189,7 +192,7 @@
/* Return to select. TODO Rehandshake. */
break;
fprintf (stderr, "Failed to read from client.\n");
- gnutls_perror (count);
+ gnutls_perror ((int) count);
return -1;
}
if (count == 0)
@@ -217,7 +220,8 @@
#endif /* TRACE || LOG */
}
- if (fds & FD_SERVER_WRITE && FD_ISSET (server_socket, &writefds))
+ if ((fds & FD_SERVER_WRITE) == FD_SERVER_WRITE
+ && FD_ISSET (server_socket, &writefds))
{
int wrote_all = 1;
/* Write as much as possible to the server. */
@@ -243,11 +247,11 @@
/* Return to select. TODO Rehandshake. */
break;
fprintf (stderr, "Failed to write to server.\n");
- gnutls_perror (count);
+ gnutls_perror ((int) count);
return -1;
}
from_client_start += count;
- tracef ("=> server %i bytes\n", count);
+ tracef ("=> server %zi bytes\n", count);
}
if (wrote_all)
{
@@ -256,10 +260,11 @@
}
}
- if (fds & FD_SERVER_READ && FD_ISSET (server_socket, &readfds))
+ if ((fds & FD_SERVER_READ) == FD_SERVER_READ
+ && FD_ISSET (server_socket, &readfds))
{
#if TRACE
- int initial_start = from_server_end;
+ buffer_size_t initial_start = from_server_end;
#endif
/* Read as much as possible from the server. */
while (from_server_end < from_buffer_size)
@@ -290,7 +295,7 @@
gnutls_alert_get_name (alert));
}
fprintf (stderr, "Failed to read from server.\n");
- gnutls_perror (count);
+ gnutls_perror ((int) count);
return -1;
}
if (count == 0)
@@ -315,7 +320,8 @@
#endif /* TRACE */
}
- if (fds & FD_CLIENT_WRITE && FD_ISSET (client_socket, &writefds))
+ if ((fds & FD_CLIENT_WRITE) == FD_CLIENT_WRITE
+ && FD_ISSET (client_socket, &writefds))
{
int wrote_all = 1;
@@ -341,14 +347,14 @@
/* Return to select. TODO Rehandshake. */
break;
fprintf (stderr, "Failed to write to client.\n");
- gnutls_perror (count);
+ gnutls_perror ((int) count);
return -1;
}
logf ("=> %.*s\n",
from_server_end - from_server_start,
from_server + from_server_start);
from_server_start += count;
- tracef ("=> client %i bytes\n", count);
+ tracef ("=> client %zi bytes\n", count);
}
if (wrote_all)
{
Modified: trunk/openvas-manager/src/ovas-mngr-comm.c
===================================================================
--- trunk/openvas-manager/src/ovas-mngr-comm.c 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/ovas-mngr-comm.c 2009-04-08 13:17:43 UTC (rev 3061)
@@ -202,21 +202,39 @@
#if 1
/* Turn on blocking. */
// FIX get flags first
- if (fcntl (server_socket, F_SETFL, 0) == -1)
+ if (fcntl (server_socket, F_SETFL, 0L) == -1)
{
perror ("Failed to set server socket flag (end_session)");
return -1;
}
#endif
- gnutls_bye (server_session, GNUTLS_SHUT_RDWR);
+
+ while (1)
+ {
+ int ret = gnutls_bye (server_session, GNUTLS_SHUT_RDWR);
+ if (ret == GNUTLS_E_AGAIN) continue;
+ if (ret == GNUTLS_E_INTERRUPTED) continue;
+ if (ret)
+ {
+ fprintf (stderr, "Failed to gnutls_bye.\n");
+ gnutls_perror ((int) ret);
+ /* Carry on successfully anyway, as this often fails, perhaps
+ * because the server is closing the connection first. */
+ break;
+ }
+ }
+
gnutls_deinit (server_session);
+
gnutls_certificate_free_credentials (server_credentials);
+
if (shutdown (server_socket, SHUT_RDWR) == -1)
{
if (errno == ENOTCONN) return 0;
perror ("Failed to shutdown server socket");
return -1;
}
+
#if 0
if (close (server_socket) == -1)
{
@@ -224,6 +242,7 @@
return -1;
}
#endif
+
return 0;
}
@@ -235,7 +254,8 @@
unsigned int
to_server_buffer_space ()
{
- return to_server_end - to_server_start;
+ if (to_server_end < to_server_start) abort ();
+ return (unsigned int) (to_server_end - to_server_start);
}
/**
@@ -288,7 +308,8 @@
if (ret_len != (socklen_t) sizeof (ret))
{
fprintf (stderr, "Weird option length from getsockopt: %i.\n",
- ret_len);
+ /* socklen_t is an int, according to getsockopt(2). */
+ (int) ret_len);
return -1;
}
if (ret)
@@ -363,11 +384,11 @@
/* \todo Rehandshake. */
continue;
fprintf (stderr, "Failed to write to server.\n");
- gnutls_perror (count);
+ gnutls_perror ((int) count);
return -1;
}
point += count;
- tracef ("=> server (string) %i bytes\n", count);
+ tracef ("=> server (string) %zi bytes\n", count);
}
tracef ("=> server (string) done\n");
/* Wrote everything. */
@@ -404,11 +425,11 @@
/* \todo Rehandshake. */
continue;
fprintf (stderr, "Failed to write to server.\n");
- gnutls_perror (count);
+ gnutls_perror ((int) count);
return -1;
}
to_server_start += count;
- tracef ("=> server %i bytes\n", count);
+ tracef ("=> server %zi bytes\n", count);
}
tracef ("=> server done\n");
to_server_start = to_server_end = 0;
Modified: trunk/openvas-manager/src/splint.h
===================================================================
--- trunk/openvas-manager/src/splint.h 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/splint.h 2009-04-08 13:17:43 UTC (rev 3061)
@@ -33,6 +33,14 @@
/* GLib. */
+/*@only@*/
+gpointer
+g_malloc (gulong n_bytes);
+
+/*@only@*/
+gpointer
+g_malloc0 (gulong n_bytes);
+
void
g_free (/*@only@*/ /*@out@*/ /*@null@*/ gpointer mem);
@@ -48,6 +56,23 @@
gboolean free_segment);
void
+g_ptr_array_add (/*@only@*/ GPtrArray *array,
+ /*@keep@*/ gpointer data);
+
+/*@only@*/
+GSList*
+g_slist_append (/*@keep@*/ GSList* list, /*@keep@*/ gpointer data);
+
+// FIX these keeps depend on g_hash_table_new params
+void
+g_hash_table_insert (GHashTable *hash_table,
+ /*@keep@*/ gpointer key,
+ /*@keep@*/ gpointer value);
+
+void
+g_hash_table_destroy (/*@only@*/ GHashTable *hash_table);
+
+void
g_ptr_array_foreach (GPtrArray *array,
GFunc func,
/*@null@*/ gpointer user_data);
@@ -101,7 +126,7 @@
/* Standard functions. */
typedef /*@null@*/ struct dirent * dirent_pointer;
-typedef /*@out@*/ /*@null@*/ dirent_pointer* dirent_pointer_pointer;
+typedef /*@null@*/ dirent_pointer* dirent_pointer_pointer;
int
scandir (const char *dir, dirent_pointer_pointer *namelist,
Added: trunk/openvas-manager/src/types.h
===================================================================
--- trunk/openvas-manager/src/types.h 2009-04-08 11:57:03 UTC (rev 3060)
+++ trunk/openvas-manager/src/types.h 2009-04-08 13:17:43 UTC (rev 3061)
@@ -0,0 +1,33 @@
+/* OpenVAS Manager
+ * $Id$
+ * Description: Headers for OpenVAS Manager: types.
+ *
+ * Authors:
+ * Matthew Mundell <matt at mundell.ukfsn.org>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Intevation GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef OPENVAS_MANAGER_TYPES_H
+#define OPENVAS_MANAGER_TYPES_H
+
+#define BUFFER_SIZE_T_FORMAT "u"
+
+typedef unsigned int buffer_size_t;
+
+#endif /* !OPENVAS_MANAGER_TYPES_H */
More information about the Openvas-commits
mailing list