[Openvas-commits] r5645 - in trunk/openvas-client: . openvas

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 20 13:53:31 CEST 2009


Author: felix
Date: 2009-10-20 13:53:27 +0200 (Tue, 20 Oct 2009)
New Revision: 5645

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/openvas/attack.c
   trunk/openvas-client/openvas/comm.c
   trunk/openvas-client/openvas/comm.h
Log:
* openvas/comm.c (omp_send_files, comm_omp_send_files): Refactored,
added todos.

* openvas/comm.h: Adjusted protos

* openvas/attack.c: Adjusted call refactored function.


Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-10-20 11:14:43 UTC (rev 5644)
+++ trunk/openvas-client/ChangeLog	2009-10-20 11:53:27 UTC (rev 5645)
@@ -1,5 +1,14 @@
 2009-10-20  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
+	* openvas/comm.c (omp_send_files, comm_omp_send_files): Refactored,
+	added todos.
+
+	* openvas/comm.h: Adjusted protos
+
+	* openvas/attack.c: Adjusted call refactored function.
+
+2009-10-20  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
 	Moved omp related functions to openvas-libraries/omp/omp.c module.
 
 	* openvas/comm.c (omp_get_nvt_all, omp_get_nvt_feed_checksum,

Modified: trunk/openvas-client/openvas/attack.c
===================================================================
--- trunk/openvas-client/openvas/attack.c	2009-10-20 11:14:43 UTC (rev 5644)
+++ trunk/openvas-client/openvas/attack.c	2009-10-20 11:53:27 UTC (rev 5645)
@@ -162,7 +162,7 @@
 
       /* Send files, in case they are newer. */
 
-      if (omp_send_files (context, socket, session) == FALSE)
+      if (comm_omp_send_files (context, socket, session) == FALSE)
         return 0;
 
       /* Start the task. */

Modified: trunk/openvas-client/openvas/comm.c
===================================================================
--- trunk/openvas-client/openvas/comm.c	2009-10-20 11:14:43 UTC (rev 5644)
+++ trunk/openvas-client/openvas/comm.c	2009-10-20 11:53:27 UTC (rev 5645)
@@ -67,7 +67,64 @@
 #endif /* USE_OMP */
 
 #ifdef USE_OMP
+
 /**
+ * @brief Sends a list of files to an omp server.
+ *
+ * This function will break on the first error and not continue sending if
+ * a problem occurred.
+ *
+ * @param[in]  session  Pointer to GnuTLS session to server.
+ * @param[in]  uuid     Tasks UUID.
+ * @param[in]  files    GSList, where data are pathes to files.
+ *
+ * @return 0 on success (also if list is empty), -1 if a file could not be
+ *         read, -2 if other error (e.g. bad server response).
+ *
+ * @todo If file content could not be read, somehow pass up the information,
+ *       _which_ file caused the problem.
+ * @todo Move to openvas-libraries/omp/omp.c
+ */
+int
+omp_send_files (gnutls_session_t session, const char* uuid, GSList* files)
+{
+  GSList* file = files;
+
+  while (file)
+    {
+      gchar *content;
+      gsize content_len;
+      GError *error;
+
+      if (file->data && strlen (file->data))
+        {
+          error = NULL;
+          g_file_get_contents (file->data, &content, &content_len, &error);
+          if (error)
+            {
+              g_error_free (error);
+              return -1;
+            }
+
+          if (omp_modify_task_file (&session,
+                                    uuid,
+                                    file->data,
+                                    content,
+                                    content_len))
+            {
+              g_free (content);
+              return -2;
+            }
+          g_free (content);
+        }
+
+      file = g_slist_next (file);
+    }
+
+  return 0;
+}
+
+/**
  * @brief Collects and then sends all the files that the server might need.
  *
  * Sends files that have been selected as a preference for an nvt and
@@ -81,7 +138,7 @@
  *         error message will be shown and the socket will be closed.
  */
 gboolean
-omp_send_files (struct context* context, int socket, gnutls_session_t session)
+comm_omp_send_files (struct context* context, int socket, gnutls_session_t session)
 {
   GSList *files = NULL;
   GSList *file = NULL;
@@ -117,45 +174,12 @@
         }
     }
 
-  /* Send the files. */
-  file = files;
-  while (file)
+  /* Send files, close connection if error. */
+  if (omp_send_files (session, prefs_get_string (context, "id"), files) != 0)
     {
-      gchar *content;
-      gsize content_len;
-      GError *error;
-
-      if (file->data && strlen (file->data))
-        {
-          error = NULL;
-          g_file_get_contents (file->data, &content, &content_len, &error);
-          if (error)
-            {
-              show_error (_("Error getting contents of '%s': %s"),
-                          file->data,
-                          error->message);
-              g_error_free (error);
-              openvas_server_close (socket, session);
-              success = FALSE;
-              break;
-            }
-
-          if (omp_modify_task_file (&session,
-                                    prefs_get_string (context, "id"),
-                                    file->data,
-                                    content,
-                                    content_len))
-            {
-              show_error (_("Failed to set file on task: '%s'"), file->data);
-              g_free (content);
-              openvas_server_close (socket, session);
-              success = FALSE;
-              break;
-            }
-          g_free (content);
-        }
-
-      file = g_slist_next (file);
+      success = FALSE;
+      show_error (_("Could not send file"));
+      openvas_server_close (socket, session);
     }
 
   /* Free list and content */

Modified: trunk/openvas-client/openvas/comm.h
===================================================================
--- trunk/openvas-client/openvas/comm.h	2009-10-20 11:14:43 UTC (rev 5644)
+++ trunk/openvas-client/openvas/comm.h	2009-10-20 11:53:27 UTC (rev 5645)
@@ -56,7 +56,7 @@
 GSList* send_ssh_credential_files (GSList* files_to_send);
 
 #ifdef USE_OMP
-gboolean omp_send_files (struct context* context, int socket, gnutls_session_t session);
+gboolean comm_omp_send_files (struct context* context, int socket, gnutls_session_t session);
 #endif
 
 #endif



More information about the Openvas-commits mailing list