[Openvas-commits] r3274 - in trunk/openvas-manager: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 8 10:21:32 CEST 2009


Author: mattm
Date: 2009-05-08 10:21:31 +0200 (Fri, 08 May 2009)
New Revision: 3274

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/src/manage.c
   trunk/openvas-manager/src/ovas-mngr-comm.c
   trunk/openvas-manager/src/ovas-mngr-comm.h
Log:
	* src/ovas-mngr-comm.c (sendf_to_server): New function.

	* src/ovas-mngr-comm.h (sendf_to_server): New header.

	* src/manage.c (task_preference): New function.
	(start_task): Use RC file targets instead of hardcoded target.
	(stop_task): Send STOP_WHOLE_TEST instead of STOP_ATTACK.


Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog	2009-05-07 16:03:35 UTC (rev 3273)
+++ trunk/openvas-manager/ChangeLog	2009-05-08 08:21:31 UTC (rev 3274)
@@ -1,3 +1,13 @@
+2009-05-08  Matthew Mundell <matt at mundell.ukfsn.org>
+
+	* src/ovas-mngr-comm.c (sendf_to_server): New function.
+
+	* src/ovas-mngr-comm.h (sendf_to_server): New header.
+
+	* src/manage.c (task_preference): New function.
+	(start_task): Use RC file targets instead of hardcoded target.
+	(stop_task): Send STOP_WHOLE_TEST instead of STOP_ATTACK.
+
 2009-05-07  Michael Wiegand <michael.wiegand at intevation.de>
 
 	* CMakeLists.txt: Added initial support for creating source and binary

Modified: trunk/openvas-manager/src/manage.c
===================================================================
--- trunk/openvas-manager/src/manage.c	2009-05-07 16:03:35 UTC (rev 3273)
+++ trunk/openvas-manager/src/manage.c	2009-05-08 08:21:31 UTC (rev 3274)
@@ -607,6 +607,52 @@
   return 0;
 }
 
+static char*
+task_preference (task_t task, const char* name)
+{
+  const char* desc = task_description (task);
+  const char* seek;
+  while ((seek = strchr (desc, '\n')))
+    {
+      char* eq = seek
+                 ? memchr (desc, '=', seek - desc)
+                 : strchr (desc, '=');
+      if (eq)
+        {
+#if 0
+          tracef ("found: %.*s\n",
+                  seek ? seek - desc : strlen (seek),
+                  desc);
+#endif
+          if (strncmp (desc, name, eq - desc - 1) == 0)
+            return g_strndup (eq + 1, seek ? seek - eq + 1 : strlen (seek));
+        }
+      else if ((seek ? seek - desc > 7 : 1)
+               && strncmp (desc, "begin(", 6) == 0)
+        {
+          /* Read over the section. */
+          desc = seek;
+          while ((seek = strchr (desc, '\n')))
+            {
+              if ((seek ? seek - desc > 5 : 1)
+                  && strncmp (desc, "end(", 4))
+                {
+                  break;
+                }
+#if 0
+              tracef ("skip: %.*s\n",
+                      seek ? seek - desc : strlen (seek),
+                      desc);
+#endif
+              desc = seek + 1;
+            }
+        }
+      if (seek == NULL) break;
+      desc = seek + 1;
+    }
+  return NULL;
+}
+
 /**
  * @brief Start a task.
  *
@@ -619,6 +665,9 @@
 int
 start_task (task_t task)
 {
+  char* targets;
+  int fail;
+
   tracef ("   start task %u\n", task_id (task));
 
   // FIX atomic
@@ -660,16 +709,12 @@
 #endif
   if (send_to_server ("<|> CLIENT\n")) return -1;
 
-#if 0
-  char* targets = task_preference (task, "targets");
-  if (send_to_server ("CLIENT <|> LONG_ATTACK <|>\n%d\n%s\n",
-                      strlen (targets),
-                      targets))
-    return -1;
-#else
-  if (send_to_server ("CLIENT <|> LONG_ATTACK <|>\n3\ndik\n"))
-    return -1;
-#endif
+  targets = task_preference (task, "targets");
+  fail = sendf_to_server ("CLIENT <|> LONG_ATTACK <|>\n%d\n%s\n",
+                          strlen (targets),
+                          targets);
+  free (targets);
+  if (fail) return -1;
 
   set_task_run_status (task, TASK_STATUS_REQUESTED);
 
@@ -704,8 +749,7 @@
   if (run_status == TASK_STATUS_REQUESTED
       || run_status == TASK_STATUS_RUNNING)
     {
-      // FIX dik
-      if (send_to_server ("CLIENT <|> STOP_ATTACK <|> dik <|> CLIENT\n"))
+      if (send_to_server ("CLIENT <|> STOP_WHOLE_TEST <|> CLIENT\n"))
         return -1;
       // FIX TASK_STATUS_STOP_REQUESTED?
       set_task_run_status (task, TASK_STATUS_DONE);

Modified: trunk/openvas-manager/src/ovas-mngr-comm.c
===================================================================
--- trunk/openvas-manager/src/ovas-mngr-comm.c	2009-05-07 16:03:35 UTC (rev 3273)
+++ trunk/openvas-manager/src/ovas-mngr-comm.c	2009-05-08 08:21:31 UTC (rev 3274)
@@ -263,7 +263,7 @@
  *
  * @param[in]  msg  The message, a string.
  *
- * @return 0 for success, for any other values a failure happened.
+ * @return 0 for success, any other value for failure.
  */
 int
 send_to_server (char * msg)
@@ -279,6 +279,25 @@
 }
 
 /**
+ * @brief Format and send a message to the server.
+ *
+ * @param[in]  format  printf-style format string for message.
+ *
+ * @return 0 for success, any other value for failure.
+ */
+int
+sendf_to_server (const char* format, ...)
+{
+  va_list args;
+  va_start (args, format);
+  gchar* msg = g_strdup_vprintf (format, args);
+  int ret = send_to_server (msg);
+  g_free (msg);
+  va_end (args);
+  return ret;
+}
+
+/**
  * @brief Connect to the server.
  *
  * @param[in]  server_socket   Socket to connect to server.

Modified: trunk/openvas-manager/src/ovas-mngr-comm.h
===================================================================
--- trunk/openvas-manager/src/ovas-mngr-comm.h	2009-05-07 16:03:35 UTC (rev 3273)
+++ trunk/openvas-manager/src/ovas-mngr-comm.h	2009-05-08 08:21:31 UTC (rev 3274)
@@ -53,6 +53,9 @@
 send_to_server (char *);
 
 int
+sendf_to_server (const char*, ...);
+
+int
 connect_to_server (int, struct sockaddr_in*, gnutls_session_t*, gboolean);
 
 int



More information about the Openvas-commits mailing list