Author: kroosec
Date: 2017-10-16 00:40:36 +0200 (Mon, 16 Oct 2017)
New Revision: 29863

Removed:
   trunk/openvas-scanner/misc/internal_com.h
Modified:
   trunk/openvas-scanner/COPYING
   trunk/openvas-scanner/ChangeLog
   trunk/openvas-scanner/misc/network.c
   trunk/openvas-scanner/misc/network.h
   trunk/openvas-scanner/misc/plugutils.c
   trunk/openvas-scanner/nasl/nasl_builtin_find_service.c
   trunk/openvas-scanner/src/attack.c
   trunk/openvas-scanner/src/hosts.c
   trunk/openvas-scanner/src/nasl_plugins.c
   trunk/openvas-scanner/src/ntp.c
   trunk/openvas-scanner/src/pluginlaunch.c
Log:
* COPYING: Remove internal_com.h entry.

* misc/internal_com.h: Remove file.

* misc/network.c (internal_send, internal_recv): Remove message type
handling.

* misc/network.h: Adjust function headers.

* misc/plugutils.c (plug_get_host_fqdn, proto_post_wrapped)
(plug_get_key): Adjust function calls.
(plug_fork_child): Send results through global_socket directly.

* nasl/nasl_builtin_find_service.c (fwd_data), src/attack.c
(comm_send_status, attack_host), src/hosts.c (forward),
src/nasl_plugins.c (nasl_thread), src/ntp.c (__ntp_timestamp_scan_host),
src/pluginlaunch.c (update_running_processes): Adjust function calls.

Modified: trunk/openvas-scanner/COPYING
===================================================================
--- trunk/openvas-scanner/COPYING       2017-10-15 22:40:34 UTC (rev 29862)
+++ trunk/openvas-scanner/COPYING       2017-10-15 22:40:36 UTC (rev 29863)
@@ -162,7 +162,6 @@
 misc/bpf_share.h: LGPL-2+
 misc/ftp_funcs.c: LGPL-2+
 misc/ftp_funcs.h: LGPL-2+
-misc/internal_com.h: GPL-2+
 misc/network.c: LGPL-2+
 misc/network.h: LGPL-2+
 misc/nvt_categories.h: LGPL-2+

Modified: trunk/openvas-scanner/ChangeLog
===================================================================
--- trunk/openvas-scanner/ChangeLog     2017-10-15 22:40:34 UTC (rev 29862)
+++ trunk/openvas-scanner/ChangeLog     2017-10-15 22:40:36 UTC (rev 29863)
@@ -1,5 +1,25 @@
 2017-10-13  Hani Benhabiles  <[email protected]>
 
+       * COPYING: Remove internal_com.h entry.
+
+       * misc/internal_com.h: Remove file.
+
+       * misc/network.c (internal_send, internal_recv): Remove message type
+       handling.
+
+       * misc/network.h: Adjust function headers.
+
+       * misc/plugutils.c (plug_get_host_fqdn, proto_post_wrapped)
+       (plug_get_key): Adjust function calls.
+       (plug_fork_child): Send results through global_socket directly.
+
+       * nasl/nasl_builtin_find_service.c (fwd_data), src/attack.c
+       (comm_send_status, attack_host), src/hosts.c (forward),
+       src/nasl_plugins.c (nasl_thread), src/ntp.c (__ntp_timestamp_scan_host),
+       src/pluginlaunch.c (update_running_processes): Adjust function calls.
+
+2017-10-13  Hani Benhabiles  <[email protected]>
+
        * src/pluginlaunch.c (plugin_launch): Adjust to set child processes to
        send scan results directly to main scan process instead of passing them
        through parent host process.

Deleted: trunk/openvas-scanner/misc/internal_com.h
===================================================================
--- trunk/openvas-scanner/misc/internal_com.h   2017-10-15 22:40:34 UTC (rev 
29862)
+++ trunk/openvas-scanner/misc/internal_com.h   2017-10-15 22:40:36 UTC (rev 
29863)
@@ -1,36 +0,0 @@
-/* OpenVAS Libraries
- * $Id$
- * Description: Defines for internal communication of scanner instances.
- *
- * Authors:
- * Jan-Oliver Wagner <[email protected]>
- *
- * Copyright:
- * Copyright (C) 2011 Greenbone Networks GmbH
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * 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 Street, Fifth Floor, Boston, MA  02110-1301,
- * USA.
- */
-
-#ifndef _INTERNAL_COM_H
-#define _INTERNAL_COM_H
-
-#define INTERNAL_COMM_MSG_TYPE_CTRL (1 << 16)
-#define INTERNAL_COMM_MSG_TYPE_DATA (1 << 18)
-
-#define INTERNAL_COMM_CTRL_FINISHED (1 << 0)
-#define INTERNAL_COMM_CTRL_ACK      (1 << 1)
-
-#endif /* not _INTERNAL_COM_H */

Modified: trunk/openvas-scanner/misc/network.c
===================================================================
--- trunk/openvas-scanner/misc/network.c        2017-10-15 22:40:34 UTC (rev 
29862)
+++ trunk/openvas-scanner/misc/network.c        2017-10-15 22:40:36 UTC (rev 
29863)
@@ -60,7 +60,6 @@
 #include "network.h"            /* for socket_close() */
 
 #include "plugutils.h"
-#include "internal_com.h" /* for INTERNAL_COMM_MSG_TYPE_CTRL */
 #include "support.h"
 
 #define TIMEOUT 20
@@ -2186,39 +2185,22 @@
  * the messages themselves.
  */
 int
-internal_send (int soc, char *data, int msg_type)
+internal_send (int soc, char *data)
 {
   int len;
   int e;
-  int ack;
 
   if (data == NULL)
     data = "";
 
-  e = os_send (soc, &msg_type, sizeof (msg_type), 0);
+  len = strlen (data);
+
+  e = os_send (soc, &len, sizeof (len), 0);
   if (e < 0)
     return -1;
-
-  if ((msg_type & INTERNAL_COMM_MSG_TYPE_CTRL) == 0)
-    {
-      len = strlen (data);
-
-      e = os_send (soc, &len, sizeof (len), 0);
-      if (e < 0)
-        return -1;
-      e = os_send (soc, data, len, 0);
-      if (e < 0)
-        return -1;
-    }
-
-  e = os_recv (soc, &ack, sizeof (ack), 0);
+  e = os_send (soc, data, len, 0);
   if (e < 0)
-    {
-      g_message ("internal_send->os_recv(%d): %s", soc,
-                 strerror (errno));
-      return -1;
-    }
-
+    return -1;
   return 0;
 }
 
@@ -2235,20 +2217,17 @@
  *                          set to NULL, and left untouched on failure or
  *                          zero-length messages.
  * @param[out]  data_sz     Size of the received message.
- * @param[out]  msg_type    Type of the message which was received.
  *
  * @retval Length of the received message on success (can be zero).
  * @retval Negative value on error.
  */
 int
-internal_recv (int soc, char **data, int *data_sz, int *msg_type)
+internal_recv (int soc, char **data, int *data_sz)
 {
   int len = 0;
   int e;
   char *buf = NULL;
   int sz = 0;
-  int type;
-  int ack;
 
   if (*data != NULL)
     {
@@ -2256,37 +2235,23 @@
       return -1;
     }
 
-  e = os_recv (soc, &type, sizeof (type), 0);
-  if (e < 0)
+  e = os_recv (soc, &len, sizeof (len), 0);
+  if (e < 0 || len < 0)
     goto error;
 
-  if ((type & INTERNAL_COMM_MSG_TYPE_CTRL) == 0)
+  /* length == 0 is perfectly valid though */
+  if (len > 0)
     {
-      e = os_recv (soc, &len, sizeof (len), 0);
-      if (e < 0 || len < 0)
-        goto error;
+      sz = len + 1;
+      buf = g_malloc0 (sz);
 
-      /* length == 0 is perfectly valid though */
-      if (len > 0)
-        {
-          sz = len + 1;
-          buf = g_malloc0 (sz);
-
-          e = os_recv (soc, buf, len, 0);
-          if (e < 0)
-            goto error;
-        }
+      e = os_recv (soc, buf, len, 0);
+      if (e < 0)
+        goto error;
     }
 
   *data     = buf;
   *data_sz  = sz;
-  *msg_type = type;
-
-  ack = INTERNAL_COMM_MSG_TYPE_CTRL | INTERNAL_COMM_CTRL_ACK;
-  e = os_send (soc, &ack, sizeof (ack), 0);
-  if (e < 0)
-    goto error;
-
   return len;
 
 error:

Modified: trunk/openvas-scanner/misc/network.h
===================================================================
--- trunk/openvas-scanner/misc/network.h        2017-10-15 22:40:34 UTC (rev 
29862)
+++ trunk/openvas-scanner/misc/network.h        2017-10-15 22:40:36 UTC (rev 
29863)
@@ -115,8 +115,8 @@
 int os_send (int, void *, int, int);
 int os_recv (int, void *, int, int);
 
-int internal_send (int, char *, int);
-int internal_recv (int, char **, int *, int *);
+int internal_send (int, char *);
+int internal_recv (int, char **, int *);
 
 int fd_is_stream (int);
 

Modified: trunk/openvas-scanner/misc/plugutils.c
===================================================================
--- trunk/openvas-scanner/misc/plugutils.c      2017-10-15 22:40:34 UTC (rev 
29862)
+++ trunk/openvas-scanner/misc/plugutils.c      2017-10-15 22:40:36 UTC (rev 
29863)
@@ -48,7 +48,6 @@
 
 #include "network.h"
 #include "plugutils.h"
-#include "internal_com.h"
 
 
 #undef G_LOG_DOMAIN
@@ -61,7 +60,7 @@
 int global_nasl_debug = 0;
 
 static int
-plug_fork_child (struct scan_globals *, kb_t);
+plug_fork_child (kb_t);
 
 void
 plug_set_xref (struct script_infos *args, char *name, char *value)
@@ -217,7 +216,7 @@
     return hinfos->vhosts[0];
   for (i = 0; hinfos->vhosts[i]; i++)
     {
-      pid_t pid = plug_fork_child (args->globals, args->key);
+      pid_t pid = plug_fork_child (args->key);
 
       if (pid == 0)
         return hinfos->vhosts[i];
@@ -407,7 +406,7 @@
   soc = globals->global_socket;
   /* Convert to UTF-8 before sending to Manager. */
   data = g_convert (buffer, -1, "UTF-8", "ISO_8859-1", NULL, &length, NULL);
-  internal_send (soc, data, INTERNAL_COMM_MSG_TYPE_DATA);
+  internal_send (soc, data);
   g_free (data);
 
   g_free (buffer);
@@ -780,25 +779,15 @@
 }
 
 static int
-plug_fork_child (struct scan_globals *globals, kb_t kb)
+plug_fork_child (kb_t kb)
 {
-  int sockpair[2];
   pid_t pid;
 
-  socketpair (AF_UNIX, SOCK_STREAM, 0, sockpair);
   if ((pid = fork ()) == 0)
     {
-      int old;
-
       sig_term (_exit);
       kb_lnk_reset (kb);
       nvticache_reset ();
-      close (sockpair[0]);
-      old = globals->global_socket;
-      if (old > 0)
-        close (old);
-      globals->global_socket = sockpair[1];
-
       srand48 (getpid () + getppid () + time (NULL));
       return 0;
     }
@@ -809,48 +798,13 @@
     }
   else
     {
-      int e, status;
-
-      close (sockpair[1]);
       _plug_get_key_son = pid;
       sig_term (plug_get_key_sighand_term);
-      for (;;)
-        {
-          fd_set rd;
-          struct timeval tv;
-          int type;
-
-          do
-            {
-              tv.tv_sec = 0;
-              tv.tv_usec = 100000;
-              FD_ZERO (&rd);
-              FD_SET (sockpair[0], &rd);
-              e = select (sockpair[0] + 1, &rd, NULL, NULL, &tv);
-            }
-          while (e < 0 && errno == EINTR);
-
-          if (e > 0)
-            {
-              char *buf = NULL;
-              int bufsz = 0;
-
-              e = internal_recv (sockpair[0], &buf, &bufsz, &type);
-              if (e < 0 || (type & INTERNAL_COMM_MSG_TYPE_CTRL))
-                {
-                  waitpid (pid, &status, WNOHANG);
-                  _plug_get_key_son = 0;
-                  close (sockpair[0]);
-                  sig_term (_exit);
-                  g_free (buf); /* Left NULL on error, harmless */
-                  break;
-                }
-              else
-                internal_send (globals->global_socket, buf, type);
-
-              g_free (buf);
-            }
-        }
+      g_warning ("Started waiting for %d", pid);
+      waitpid (pid, NULL, 0);
+      g_warning ("Finished waiting for %d", pid);
+      _plug_get_key_son = 0;
+      sig_term (_exit);
     }
   return 1;
 }
@@ -900,7 +854,7 @@
   res_list = res;
   while (res)
     {
-      pid_t pid = plug_fork_child (args->globals, kb);
+      pid_t pid = plug_fork_child (kb);
 
       if (pid == 0)
         {
@@ -929,8 +883,6 @@
       res = res->next;
     }
   kb_item_free (res_list);
-  internal_send (args->globals->global_socket, NULL,
-                 INTERNAL_COMM_MSG_TYPE_CTRL | INTERNAL_COMM_CTRL_FINISHED);
   exit (0);
 }
 

Modified: trunk/openvas-scanner/nasl/nasl_builtin_find_service.c
===================================================================
--- trunk/openvas-scanner/nasl/nasl_builtin_find_service.c      2017-10-15 
22:40:34 UTC (rev 29862)
+++ trunk/openvas-scanner/nasl/nasl_builtin_find_service.c      2017-10-15 
22:40:36 UTC (rev 29863)
@@ -2496,13 +2496,12 @@
   int e;
   char *buf = NULL;
   int bufsz = 0;
-  int type;
 
-  e = internal_recv (in, &buf, &bufsz, &type);
+  e = internal_recv (in, &buf, &bufsz);
   if (e <= 0)
     return -1;
 
-  internal_send (out, buf, type);
+  internal_send (out, buf);
   g_free (buf);
   return 0;
 }

Modified: trunk/openvas-scanner/src/attack.c
===================================================================
--- trunk/openvas-scanner/src/attack.c  2017-10-15 22:40:34 UTC (rev 29862)
+++ trunk/openvas-scanner/src/attack.c  2017-10-15 22:40:36 UTC (rev 29863)
@@ -46,7 +46,6 @@
 #include "../misc/network.h"        /* for auth_printf */
 #include "../misc/nvt_categories.h" /* for ACT_INIT */
 #include "../misc/pcap_openvas.h"   /* for v6_is_local_ip */
-#include "../misc/internal_com.h"
 #include "../misc/scanneraux.h"
 
 #include "attack.h"
@@ -126,7 +125,7 @@
             "SERVER <|> STATUS <|> %s <|> %d/%d <|> SERVER\n",
             hostname, curr, max);
 
-  internal_send (soc, buffer, INTERNAL_COMM_MSG_TYPE_DATA);
+  internal_send (soc, buffer);
 
   return 0;
 }
@@ -487,8 +486,7 @@
                      calculate the scan progress. */
                   comm_send_status(global_socket, hostname, 0, -1);
 #endif
-                  internal_send (global_socket, buffer,
-                                 INTERNAL_COMM_MSG_TYPE_DATA);
+                  internal_send (global_socket, buffer);
                   goto host_died;
                 }
               else if (e == ERR_CANT_FORK)

Modified: trunk/openvas-scanner/src/hosts.c
===================================================================
--- trunk/openvas-scanner/src/hosts.c   2017-10-15 22:40:34 UTC (rev 29862)
+++ trunk/openvas-scanner/src/hosts.c   2017-10-15 22:40:36 UTC (rev 29863)
@@ -33,7 +33,6 @@
 #include <glib.h>     /* for g_free() */
 
 #include "../misc/network.h"      /* for internal_recv */
-#include "../misc/internal_com.h" /* for INTERNAL_COMM_MSG_TYPE_CTRL */
 
 #include "utils.h" /* for data_left() */
 #include "hosts.h" /* for hosts_new() */
@@ -72,24 +71,11 @@
   char *buf = NULL;
   int bufsz = 0;
   int len;
-  int type;
 
-  if (internal_recv (in, &buf, &bufsz, &type) < 0)
+  if (internal_recv (in, &buf, &bufsz) < 0)
     return -1;
 
-  if (type & INTERNAL_COMM_MSG_TYPE_CTRL)
-    {
-      errno = type & ~INTERNAL_COMM_MSG_TYPE_CTRL;
-      return -1;
-    }
-  else if ((type & INTERNAL_COMM_MSG_TYPE_DATA) == 0)
-    {
-      g_debug ("hosts.c:forward(): bad msg type (%d)\n", type);
-      return -1;
-    }
-
   len = strlen (buf);
-
   if (out > 0)
     {
       int n;

Modified: trunk/openvas-scanner/src/nasl_plugins.c
===================================================================
--- trunk/openvas-scanner/src/nasl_plugins.c    2017-10-15 22:40:34 UTC (rev 
29862)
+++ trunk/openvas-scanner/src/nasl_plugins.c    2017-10-15 22:40:36 UTC (rev 
29863)
@@ -47,7 +47,6 @@
 
 #include "../misc/network.h"    /* for internal_send */
 #include "../misc/plugutils.h"     /* for plug_set_launch */
-#include "../misc/internal_com.h"  /* for INTERNAL_COMM_CTRL_FINISHED */
 
 #include "../nasl/nasl.h"
 
@@ -212,6 +211,4 @@
     }
 
   exec_nasl_script (args, name, nargs->oid, nasl_mode);
-  internal_send (nargs->soc, NULL,
-                 INTERNAL_COMM_MSG_TYPE_CTRL | INTERNAL_COMM_CTRL_FINISHED);
 }

Modified: trunk/openvas-scanner/src/ntp.c
===================================================================
--- trunk/openvas-scanner/src/ntp.c     2017-10-15 22:40:34 UTC (rev 29862)
+++ trunk/openvas-scanner/src/ntp.c     2017-10-15 22:40:36 UTC (rev 29863)
@@ -34,7 +34,6 @@
 #include <gvm/base/prefs.h>         /* for prefs_set() */
 
 #include "../misc/network.h"    /* for recv_line */
-#include "../misc/internal_com.h" /* for INTERNAL_COMM_MSG_TYPE_DATA */
 
 #include "ntp.h"
 #include "otp.h"
@@ -416,7 +415,7 @@
             "SERVER <|> TIME <|> %s <|> %s <|> %s <|> SERVER\n", msg, host,
             timestr);
 
-  internal_send (soc, buf, INTERNAL_COMM_MSG_TYPE_DATA);
+  internal_send (soc, buf);
 
   return 0;
 }

Modified: trunk/openvas-scanner/src/pluginlaunch.c
===================================================================
--- trunk/openvas-scanner/src/pluginlaunch.c    2017-10-15 22:40:34 UTC (rev 
29862)
+++ trunk/openvas-scanner/src/pluginlaunch.c    2017-10-15 22:40:36 UTC (rev 
29863)
@@ -39,7 +39,6 @@
 
 #include "../misc/network.h"    /* for internal_send */
 #include "../misc/nvt_categories.h"  /* for ACT_SCANNER */
-#include "../misc/internal_com.h"  /* for INTERNAL_COMM_MSG_TYPE_DATA */
 
 #include "pluginload.h"
 #include "utils.h"
@@ -126,8 +125,7 @@
                           " <|> NVT timed out after %d seconds."
                           " <|> %s <|> SERVER\n",
                           hostname, processes[i].timeout, oid ?: "0");
-                  internal_send (processes[i].upstream_soc,
-                                 msg, INTERNAL_COMM_MSG_TYPE_DATA);
+                  internal_send (processes[i].upstream_soc, msg);
                   g_free (msg);
 
                   terminate_process (processes[i].pid);

_______________________________________________
Openvas-commits mailing list
[email protected]
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits

Reply via email to