[Openvas-commits] r5363 - in trunk/openvas-scanner: . openvassd

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Oct 5 11:09:09 CEST 2009


Author: felix
Date: 2009-10-05 11:09:07 +0200 (Mon, 05 Oct 2009)
New Revision: 5363

Modified:
   trunk/openvas-scanner/ChangeLog
   trunk/openvas-scanner/openvassd/piic.c
   trunk/openvas-scanner/openvassd/pluginscheduler.c
   trunk/openvas-scanner/openvassd/plugs_req.c
   trunk/openvas-scanner/openvassd/save_kb.c
   trunk/openvas-scanner/openvassd/save_tests.c
   trunk/openvas-scanner/openvassd/utils.c
Log:
* openvassd/pluginscheduler.c, openvassd/plugs_req.c,
openvassd/save_kb.c, openvassd/save_tests.c, openvassd/utils.c,
openvassd/piic.c: Cosmetics, doc, todos added.

* ChangeLog: corrected with last entry.


Modified: trunk/openvas-scanner/ChangeLog
===================================================================
--- trunk/openvas-scanner/ChangeLog	2009-10-05 08:45:01 UTC (rev 5362)
+++ trunk/openvas-scanner/ChangeLog	2009-10-05 09:09:07 UTC (rev 5363)
@@ -1,3 +1,25 @@
+2009-10-05  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
+	* openvassd/pluginscheduler.c, openvassd/plugs_req.c,
+	openvassd/save_kb.c, openvassd/save_tests.c, openvassd/utils.c,
+	openvassd/piic.c: Cosmetics, doc, todos added.
+
+	* ChangeLog: corrected with last entry.
+
+2009-10-05  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
+	Towards removal of libopenvas.h.
+
+	* openvassd/utils.h, openvassd/users.c, openvassd/users.h,
+	openvassd/shared_socket.c, openvassd/save_kb.h, openvassd/rules.c,
+	openvassd/preferences.c, openvassd/plugs_req.h,, openvassd/plugs_hash.c,
+	openvassd/pluginscheduler.h, openvassd/pluginload.h,
+	openvassd/pluginload.c, openvassd/pluginlaunch.c, openvassd/parser.c,
+	openvassd/ntp_11.h, openvassd/ntp_11.c, openvassd/nes_plugins.c,
+	openvassd/nasl_plugins.c, openvassd/locks.c, openvassd/hosts.c,
+	openvassd/comm.h, openvassd/comm.c, cnvts/ssl_ciphers/ssl_ciphers.c:
+	Added/cleaned up includes.
+
 2009-09-28  Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
 
 	Post-release version bump.

Modified: trunk/openvas-scanner/openvassd/piic.c
===================================================================
--- trunk/openvas-scanner/openvassd/piic.c	2009-10-05 08:45:01 UTC (rev 5362)
+++ trunk/openvas-scanner/openvassd/piic.c	2009-10-05 09:09:07 UTC (rev 5363)
@@ -29,105 +29,118 @@
 
 
 #include <includes.h>
+
 #include "log.h"
 #include "save_kb.h"
 #include "utils.h"
 #include "piic.h"
 
-
-void kb_parse(int soc, struct arglist * globals, struct kb_item ** kb, char * buf, int msg )
+/**
+ * @brief Modifies the knowledge base or sends content of a kb item.
+ *
+ * If the knowledge base is going to be saved to disc, modify the entry on the
+ * file system, too.
+ *
+ * @param soc "Internal" socket to the child process that queries the kb or
+ *            requests modification.
+ * @param msg Explicitly handled if INTERNAL_COMM_KB_GET,
+ *            INTERNAL_COMM_KB_REPLACE (defined in plugutils.h)
+ */
+void
+kb_parse (int soc, struct arglist * globals, struct kb_item ** kb, char * buf,
+          int msg)
 {
- char * t;
- int type;
- char *c;
- int buf_len;
- char * copy;
- char * name;
- char * value;
- 
- if( buf == NULL || kb == NULL )
-  return;
+  char * t;
+  int type;
+  char *c;
+  int buf_len;
+  char * copy;
+  char * name;
+  char * value;
 
- if ( msg & INTERNAL_COMM_KB_GET )
- { 
-  struct kb_item * kitem = kb_item_get_single(kb, buf, 0);
+  if (buf == NULL || kb == NULL)
+    return;
 
-  if ( kitem == NULL )
-  {
-   internal_send(soc, NULL, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_ERROR);
-   return;
-  }
- 
-  if ( kitem->type == KB_TYPE_STR  )
-  {
-   internal_send(soc, kitem->v.v_str, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_SENDING_STR);
-   return;
-  }
-  else  if ( kitem->type == KB_TYPE_INT )
-  {
-   char buf[64];
-   snprintf(buf, sizeof(buf), "%d", kitem->v.v_int);
-   internal_send(soc, buf, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_SENDING_INT);
-  }
-  else 
-   internal_send(soc, NULL, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_ERROR);
-  return;	
- }
-  
- if ( buf[0] == '\0' ) 
+  if (msg & INTERNAL_COMM_KB_GET)
+    {
+      struct kb_item * kitem = kb_item_get_single (kb, buf, 0);
+
+      if (kitem == NULL)
+        {
+          internal_send (soc, NULL, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_ERROR);
+          return;
+        }
+
+      if (kitem->type == KB_TYPE_STR)
+        {
+          internal_send (soc, kitem->v.v_str, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_SENDING_STR);
+          return;
+        }
+      else if (kitem->type == KB_TYPE_INT)
+        {
+          char buf[64];
+          snprintf (buf, sizeof (buf), "%d", kitem->v.v_int);
+          internal_send (soc, buf, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_SENDING_INT);
+        }
+      else
+        internal_send (soc, NULL, INTERNAL_COMM_MSG_TYPE_KB|INTERNAL_COMM_KB_ERROR);
+
+      return;
+    }
+
+  if (buf[0] == '\0')
     return;
-    
- buf_len = strlen(buf);
-  
- if(buf[buf_len - 1]=='\n')
- 	buf[ buf_len - 1 ]='\0';
-	
- c = strrchr(buf, ';');
- if(c != NULL )
+
+  buf_len = strlen (buf);
+
+  if (buf[buf_len - 1] == '\n')
+    buf[buf_len - 1] = '\0';
+
+  c = strrchr (buf, ';');
+  if (c != NULL)
     c[0] = '\0';
-    
- t = strchr(buf, ' ');
- if( t == NULL )
+
+  t = strchr(buf, ' ');
+  if (t == NULL)
     return;
- 
- t[0] = '\0';
- type = atoi(buf);
- t[0] = ' ';
 
+  t[0] = '\0';
+  type = atoi (buf);
+  t[0] = ' ';
 
-  value = strchr(buf, '=');
-    
-  if( value == NULL )
-        return;
-        
+  value = strchr (buf, '=');
+
+  if (value == NULL)
+    return;
+
   value[0]='\0';
   value++;
-  
+
   name = t+1;
-  
-  if ( type == ARG_INT )
-  { 
-   int v = atoi(value);
-   if ( msg & INTERNAL_COMM_KB_REPLACE )
-   	kb_item_set_int(kb, name,v);
-    else
-	{
-   	kb_item_add_int(kb, name,v);
-   	if(save_kb(globals))save_kb_write_int(globals, arg_get_value(globals, "CURRENTLY_TESTED_HOST"), name,v);   
-	}
-  }
+
+  if (type == ARG_INT)
+    {
+      int v = atoi (value);
+      if (msg & INTERNAL_COMM_KB_REPLACE)
+        kb_item_set_int(kb, name,v);
+      else
+        {
+          kb_item_add_int(kb, name,v);
+          if (save_kb(globals))
+            save_kb_write_int (globals, arg_get_value (globals, "CURRENTLY_TESTED_HOST"), name,v);
+        }
+    }
   else
-  {
-   copy = rmslashes(value);
-   if ( msg & INTERNAL_COMM_KB_REPLACE )
-   	kb_item_set_str(kb, name, copy);
-   else
-	{
-   	kb_item_add_str(kb, name, copy);
-   	if(save_kb(globals))save_kb_write_str(globals, arg_get_value(globals, "CURRENTLY_TESTED_HOST"), name, copy);
-	}
-   efree(&copy);
-  }
+    {
+      copy = rmslashes (value);
+      if (msg & INTERNAL_COMM_KB_REPLACE)
+        kb_item_set_str (kb, name, copy);
+      else
+        {
+          kb_item_add_str (kb, name, copy);
+          if (save_kb (globals))
+            save_kb_write_str (globals, arg_get_value (globals, "CURRENTLY_TESTED_HOST"), name, copy);
+        }
+      efree (&copy);
+    }
 }
-
-

Modified: trunk/openvas-scanner/openvassd/pluginscheduler.c
===================================================================
--- trunk/openvas-scanner/openvassd/pluginscheduler.c	2009-10-05 08:45:01 UTC (rev 5362)
+++ trunk/openvas-scanner/openvassd/pluginscheduler.c	2009-10-05 09:09:07 UTC (rev 5363)
@@ -104,10 +104,10 @@
  int i;
  if(h == NULL)
   return;
-  
+
  if(h->next != NULL)
   hash_link_destroy(h->next);
- 
+
  if( h->dependencies != NULL )
  {
   for(i=0;h->dependencies[i] != NULL;i++)
@@ -119,7 +119,7 @@
 
  efree(&h->dependencies_ptr);
  efree(&h->plugin);
- 
+
  if( h->ports != NULL )
  {
   for(i=0;h->ports[i] != NULL;i++)
@@ -128,14 +128,15 @@
   }
   efree(&h->ports);
  }
- 
+
  efree(&h);
 }
 
-static void hash_destroy(struct hash * h)
+static void
+hash_destroy (struct hash * h)
 {
  int i;
- 
+
  for(i=0;i<HASH_MAX;i++)
   {
   hash_link_destroy(h[i].next);
@@ -144,21 +145,22 @@
 }
 
 
-static int hash_add(struct hash * h, char * name, struct scheduler_plugin * plugin)
+static int
+hash_add (struct hash * h, char * name, struct scheduler_plugin * plugin)
 {
  struct hash * l = emalloc(sizeof(struct hash));
  unsigned int idx = mkhash(name);
  struct arglist * deps = plug_get_deps(plugin->arglist->value);
  struct arglist * ports = plug_get_required_ports(plugin->arglist->value);
  int num_deps = 0;
- 
+
  l->plugin = plugin;
  l->plugin->parent_hash = l;
  l->name   = name;
  l->next = h[idx].next;
  h[idx].next = l;
  l->dependencies_ptr = NULL;
- 
+
  if( deps == NULL )
   l->dependencies = NULL;
  else
@@ -166,7 +168,7 @@
   struct arglist * al = deps;
   int i = 0;
   while (al->next)
-  { 
+  {
    num_deps ++;
    al = al->next;
   }
@@ -179,7 +181,7 @@
    al = al->next;
   }
  }
- 
+
  if( ports == NULL )
   l->ports = NULL;
  else
@@ -192,7 +194,7 @@
     num_ports ++;
     al = al->next;
    }
-   
+
    l->ports = emalloc((num_ports + 1) * sizeof(char*));
    al = ports;
    while (al->next != NULL )
@@ -207,7 +209,8 @@
 
 
 
-static struct hash * _hash_get(struct hash * h, char * name)
+static struct hash *
+_hash_get (struct hash * h, char * name)
 {
  unsigned int idx = mkhash(name);
  struct hash * l = h[idx].next;
@@ -222,20 +225,22 @@
 }
 
 
-static struct hash ** hash_get_deps_ptr(struct hash * h, char * name)
+static struct hash **
+hash_get_deps_ptr (struct hash * h, char * name)
 {
  struct hash * l = _hash_get(h, name);
- 
+
  if( l == NULL )
   return NULL;
- 
+
  if( l->dependencies_ptr == NULL )
   return NULL;
- 
+
  return l->dependencies_ptr;
 }
 
-static void hash_fill_deps(struct hash * h, struct hash * l )
+static void
+hash_fill_deps (struct hash * h, struct hash * l )
 {
  int i, j = 0;
  if ( l->num_deps != 0 )
@@ -320,7 +325,7 @@
    pl->prev = NULL;
    sched->plist = pl;
   }
- } 
+ }
 }
 
 void scheduler_rm_running_ports(plugins_scheduler_t sched, struct scheduler_plugin * plugin)
@@ -328,18 +333,15 @@
  char ** ports; 
  int i;
 
- 
  ports = plugin->parent_hash->ports;
 
- 
  if( ports == NULL )
   return;
- 
+
  for (i = 0 ; ports[i] != NULL ; i ++ )
  {
   struct plist * pl = pl_get(sched->plist, ports[i]);
- 
-	
+
   if( pl != NULL )
   {
    pl->occurences --;
@@ -347,7 +349,7 @@
    {
     if( pl->next != NULL )
      pl->next->prev = pl->prev;
-    
+
     if( pl->prev != NULL )
      pl->prev->next = pl->next;
     else
@@ -373,20 +375,19 @@
  char ** ports = hash_get_ports(sched->hash, plugin->arglist->name);
  int i;
  int score = 0;
- 
+
  if( ports == NULL ) 
   return 0;
- 
 
  for (i = 0; ports[i] != NULL; i ++)
  {
   struct plist * pl = pl_get(sched->plist, ports[i]);
   if(pl != NULL)
-  { 
+  {
    if(pl->occurences > score)
    	score = pl->occurences;
   }
- } 
+ }
  return score;
 }
 
@@ -408,7 +409,10 @@
 
 
 
-struct scheduler_plugin * plugin_next_unrun_dependencie(plugins_scheduler_t sched, struct hash ** dependencies_ptr, int already_in_dependencie)
+struct scheduler_plugin *
+plugin_next_unrun_dependencie (plugins_scheduler_t sched,
+                               struct hash ** dependencies_ptr,
+                               int already_in_dependencie)
 {
  int flag = 0;
  int counter = 0;
@@ -416,7 +420,7 @@
  
  if(dependencies_ptr == NULL)
   return NULL;
-  
+
  for(i=0;dependencies_ptr[i] != NULL;i++)
   {
    struct scheduler_plugin * plugin = dependencies_ptr[i]->plugin;
@@ -437,7 +441,7 @@
 	 ret = plugin_next_unrun_dependencie(sched, deps_ptr, 1);
 	 if(ret == NULL)
 		return plugin;
-	 else 
+	 else
 	 	if( ret == PLUG_RUNNING )
 			flag ++;
 		else
@@ -456,7 +460,7 @@
    }
   }
  }
-  
+
   if(flag == 0)
   	return NULL;
   else
@@ -468,7 +472,10 @@
 /*
  * Enables a plugin and its dependencies
  */
-static void enable_plugin_and_dependencies(plugins_scheduler_t shed, struct arglist * plugin, char * name, int silent)
+static void
+enable_plugin_and_dependencies (plugins_scheduler_t shed,
+                                struct arglist * plugin,
+                                char * name, int silent)
 {
  struct hash ** deps_ptr;
  int i;
@@ -486,7 +493,7 @@
   else
    plug_set_launch(plugin, LAUNCH_SILENT);
  }
- 
+
  if(deps_ptr != NULL)
  {
    for(i=0;deps_ptr[i] != NULL;i++)
@@ -506,17 +513,13 @@
  struct arglist * arg;
  int i;
  struct hash * l;
- 
- 
- 
- 
+
+
  if(plugins == NULL)
   return NULL;
- 
- 
- /*
-  * Fill our lists
-  */
+
+
+  /* Fill our lists */
   ret->hash = hash_init();
   arg = plugins;
   while(arg->next != NULL)
@@ -524,7 +527,7 @@
   struct scheduler_plugin * scheduler_plugin;
   struct list * dup;
   int category =  plug_get_category(arg->value);
-  
+
   scheduler_plugin = emalloc ( sizeof(struct scheduler_plugin) ) ;
   scheduler_plugin->arglist  = arg;
   scheduler_plugin->running_state  = PLUGIN_STATUS_UNRUN;
@@ -551,8 +554,8 @@
   hash_add(ret->hash, arg->name, scheduler_plugin);
   arg = arg->next;
   }
- 
- 
+
+
  for ( i = 0 ; i < HASH_MAX ; i ++ )
  {
   l = &ret->hash[i];
@@ -572,8 +575,8 @@
    arg = arg->next;
   }
  }
- 
- 
+
+
  /* Now, remove the plugins that won't be launched */
  for(i= ACT_FIRST ; i <= ACT_LAST ; i++)
  {
@@ -602,31 +605,30 @@
     l = l->next;
    }
   }
- 
+
  return ret;
 }
 
 
 
-struct scheduler_plugin * plugins_scheduler_next(plugins_scheduler_t h)
+struct scheduler_plugin *
+plugins_scheduler_next (plugins_scheduler_t h)
 {
- 
  struct list * l;
  int category;
  int running_category = ACT_LAST;
  int flag = 0;
- 
+
  if(h == NULL)
   return NULL;
- 
+
  for(category = ACT_FIRST;category<=ACT_LAST;category++)
  {
  l = h->list[category];
- 
+
  /*
   * Scanners (and DoS) must not be run in parallel
   */
-
  if((category == ACT_SCANNER) ||
     (category == ACT_KILL_HOST) ||
     (category == ACT_FLOOD) ||
@@ -634,25 +636,23 @@
     pluginlaunch_disable_parrallel_checks();
  else
     pluginlaunch_enable_parrallel_checks();
-  
-      
+
  while(l != NULL)
  {
    int state;
-  
+
   state = plugin_get_running_state(l->plugin);
- 
-  
+
   switch(state)
   {
    case PLUGIN_STATUS_UNRUN:
     {
     struct hash ** deps_ptr = l->plugin->parent_hash->dependencies_ptr;
-    
+
     if(deps_ptr != NULL)
     {
      struct scheduler_plugin * p = plugin_next_unrun_dependencie(h, deps_ptr, 0);
-     
+
      switch(GPOINTER_TO_SIZE(p))
      {
       case GPOINTER_TO_SIZE(NULL) :
@@ -706,8 +706,7 @@
 	  l->prev->next = l->next;
 	 else
 	  h->list[category] = l->next;
-	  
-	 
+
 	 if(l->next != NULL)
 	  l->next->prev = l->prev;
 
@@ -718,10 +717,10 @@
 	}
 	break;
     }
-  l = l->next; 
+  l = l->next;
   }
 
-  
+
   /* Could not find anything */
   if((category == ACT_SCANNER ||
      category == ACT_INIT || 
@@ -731,19 +730,20 @@
       flag = 0;
       category --;
      }
-     
+
    if(category + 1 >= ACT_DENIAL && flag && running_category < ACT_DENIAL)
-	{ 
-   	return PLUG_RUNNING;  
+	{
+   	return PLUG_RUNNING;
 	}
  }
- 
 
+
  return flag != 0 ? PLUG_RUNNING : NULL;
 }
 
 
-void list_destroy(struct list * list)
+void
+list_destroy (struct list * list)
 {
  while(list != NULL)
  {
@@ -754,7 +754,8 @@
 }
 
 
-void plugins_scheduler_free(plugins_scheduler_t sched)
+void
+plugins_scheduler_free (plugins_scheduler_t sched)
 {
  int i;
  hash_destroy(sched->hash);
@@ -762,6 +763,3 @@
  	list_destroy(sched->list[i]);	
  efree(&sched);
 }
-
-
-

Modified: trunk/openvas-scanner/openvassd/plugs_req.c
===================================================================
--- trunk/openvas-scanner/openvassd/plugs_req.c	2009-10-05 08:45:01 UTC (rev 5362)
+++ trunk/openvas-scanner/openvassd/plugs_req.c	2009-10-05 09:09:07 UTC (rev 5363)
@@ -27,8 +27,9 @@
 *
 */
 
- 
+
 #include <includes.h>
+
 #include "pluginscheduler.h"
 #include "plugs_req.h"
 
@@ -37,55 +38,48 @@
  		   Private Functions
 	
 ***********************************************************/
- 
+
 extern int kb_get_port_state_proto(struct kb_item **, struct arglist*, int, char*);
- 
+
 /*---------------------------------------------------------
 
   Returns whether a port in a port list is closed or not
  
  ----------------------------------------------------------*/
 static int
-get_closed_ports(kb, ports, preferences)
-   struct kb_item ** kb;
-   struct arglist * ports;
-   struct arglist * preferences;
+get_closed_ports (struct kb_item ** kb, struct arglist * ports,
+                  struct arglist * preferences)
 {
 
   if(ports == NULL)
    return -1;
-  
+
   while(ports->next != NULL)
   {
-   int iport = atoi(ports->name);			
+   int iport = atoi(ports->name);
    if(iport != 0)
    	{
       	if( kb_get_port_state_proto(kb, preferences, iport, "tcp") != 0 )
 		return iport;
 	}
-      else 
+      else
         {
-        
       	if( kb_item_get_int(kb, ports->name) > 0 )
 		return 1; /* should be the actual value indeed ! */
-	}   
+	}
     ports = ports->next;
   }
   return 0; /* found nothing */
 }
 
 
-/*-----------------------------------------------------------
-
-  Returns whether a port in a port list is closed or not
- 
- ------------------------------------------------------------*/
+/**
+ * @brief Returns whether a port in a port list is closed or not.
+ */
 static int
-get_closed_udp_ports(kb, ports, preferences)
-   struct kb_item ** kb;
-   struct arglist * ports;
-   struct arglist * preferences;
-{   
+get_closed_udp_ports (struct kb_item ** kb, struct arglist * ports,
+                      struct arglist * preferences)
+{
   if( ports == NULL )
   	return -1;
   else while( ports->next != NULL)
@@ -98,16 +92,11 @@
 }
 
 
-/*-----------------------------------------------------------
-            
-	     Returns the name of the first key
-	     which is not in <kb>
-	    
- -----------------------------------------------------------*/
-static char * 
-key_missing(kb, keys)
-  struct kb_item ** kb;
-  struct arglist * keys;
+/**
+ * @brief Returns the name of the first key which is not \ref kb.
+ */
+static char *
+key_missing (struct kb_item ** kb, struct arglist * keys)
 {
  if(kb == NULL || keys == NULL )
     return NULL;
@@ -123,14 +112,11 @@
  return NULL;
 }
 
-/*-----------------------------------------------------------
-            
-	    The opposite of the previous function
-	    
- -----------------------------------------------------------*/
-static char * key_present(kb, keys)
- struct kb_item ** kb;
- struct arglist * keys;
+/**
+ * @brief The opposite of the previous function (\ref key_missing).
+ */
+static char *
+key_present (struct kb_item ** kb, struct arglist * keys)
 {
  if( kb == NULL || keys == NULL )
     return NULL;
@@ -144,7 +130,7 @@
    }
  }
  return NULL;
-} 
+}
 
 /**********************************************************
  
@@ -155,24 +141,21 @@
 
 
 
-/*------------------------------------------------------
-
-  Returns <port> if the lists of the required ports between
-  plugin 1 and plugin 2 have at least one port in common
- 
- 
- ------------------------------------------------------*/
-struct arglist * 
-requirements_common_ports(plugin1, plugin2)
- struct scheduler_plugin * plugin1, *plugin2;
+/**
+ * @brief Returns \<port\> if the lists of the required ports between
+ * @brief plugin 1 and plugin 2 have at least one port in common.
+ */
+struct arglist *
+requirements_common_ports (struct scheduler_plugin * plugin1,
+                           struct scheduler_plugin * plugin1)
 {
  struct arglist * ret = NULL;
  struct arglist * req1;
  struct arglist * req2;
- 
- 
+
+
  if(!plugin1 || !plugin2) return 0;
- 
+
  req1 = plugin1->required_ports;
  if ( req1 == NULL )
 	return 0;
@@ -180,7 +163,7 @@
  req2 = plugin2->required_ports;
  if ( req2 == NULL )
 	return 0;
- 
+
  while(req1->next != NULL)
  {
   struct arglist * r = req2;
@@ -193,7 +176,7 @@
        if(!ret)ret = emalloc(sizeof(struct arglist));
        arg_add_value(ret, r->name, ARG_INT, 0,(void*)1);
        }
-   }  
+   }
    r = r->next;
   }
   req1 = req1->next;
@@ -215,25 +198,18 @@
                                struct scheduler_plugin * plugin)
 {
   if(key_missing(kb, plugin->mandatory_keys)) return 0;
-  
+
   return 1;
 }
 
-/*-------------------------------------------------------
-
-	Determine if the plugin requirements are
-	met.
-
-	Returns NULL is everything is ok, or else
-	returns an error message
-
----------------------------------------------------------*/
-
+/**
+ * @brief Determine if the plugin requirements are met.
+ *
+ * @return Returns NULL is everything is ok, else an error message.
+ */
 char *
-requirements_plugin(kb, plugin, preferences)
- struct kb_item ** kb;
- struct scheduler_plugin * plugin;
- struct arglist * preferences;
+requirements_plugin (struct kb_item ** kb, struct scheduler_plugin * plugin,
+                     struct arglist * preferences)
 {
   static char error[64];
   char * missing;
@@ -244,14 +220,14 @@
   /*
    * Check wether the good ports are open
    */
-  error[sizeof(error) - 1] = '\0';  
+  error[sizeof(error) - 1] = '\0';
   tcp = plugin->required_ports;
   if(tcp != NULL && (get_closed_ports(kb, tcp , preferences)) == 0)
      {
       strncpy(error, "none of the required tcp ports are open", sizeof(error) - 1);
       return error;
      }
-      
+
    udp = plugin->required_udp_ports;
    if(udp != NULL && (get_closed_udp_ports(kb, udp , preferences)) == 0)
       {
@@ -271,7 +247,7 @@
      snprintf(error,sizeof(error), "because the key %s is missing", missing);
      return error;
   }
-  
+
   if (opti != NULL && (strcmp(opti, "required_keys") == 0 || atoi(opti) == 2))
      return NULL;
 

Modified: trunk/openvas-scanner/openvassd/save_kb.c
===================================================================
--- trunk/openvas-scanner/openvassd/save_kb.c	2009-10-05 08:45:01 UTC (rev 5362)
+++ trunk/openvas-scanner/openvassd/save_kb.c	2009-10-05 09:09:07 UTC (rev 5363)
@@ -33,7 +33,7 @@
  * This has not only importance for debugging, but could also allow differential
  * scans and information gain other than vulnerabilities of targets.
  * @see diff_scan
- * 
+ *
  * Knowledge base backups are (if the appropriate preferences are set) saved
  * under (PREFIX)var/lib/openvas/users/(USERNAME)/kbs/(HOSTNAME) ,
  * where strings in brackets have to be replaced by the respective value.
@@ -63,10 +63,10 @@
 			
 ===========================================================================*/
 /**
- * @brief Replaces slashes in name by underscores.
- * 
+ * @brief Replaces slashes in name by underscores (in-place).
+ *
  * @param name String in which slashes will be replaced by underscores.
- * 
+ *
  * @return Pointer to the parameter name string.
  */
 static char *
@@ -106,7 +106,7 @@
 {
  char *t;
  int ret = 0;
- 
+
  dir = estrdup(dir);
  t = strchr(dir+1, '/');
  while(t)
@@ -116,8 +116,7 @@
   t[0] = '/';
   t = strchr(t+1, '/');
  }
- 
- 
+
  if ((ret = mkdir(dir, 0700)) < 0) {
   if(errno != EEXIST)
     log_write("mkdir(%s) failed : %s\n", dir, strerror(errno));
@@ -130,7 +129,10 @@
 
 
 /**
- * From <hostname>, return /path/to/var/lib/openvas/<username>/kbs/<hostname> .
+ * @brief Returns file name where the kb for scan of a host can be saved/read
+ * @brief from.
+ *
+ * From \<hostname\>, return /path/to/var/lib/openvas/\<username\>/kbs/\<hostname\> .
  */
 static char*
 kb_fname (struct arglist* globals, char* hostname)
@@ -138,9 +140,10 @@
  gchar * dir = kb_dirname(globals);
  char * ret;
  char * hn = strdup(hostname);
- 
- hn = filter_odd_name(hn);
- 
+
+ hn = filter_odd_name (hn);
+
+ /** @todo use glibs *build_path functions */
  ret = emalloc(strlen(dir) + strlen(hn) + 2);
  sprintf(ret, "%s/%s", dir, hn);
  g_free (dir);
@@ -159,13 +162,13 @@
  char *ret;
  int i = 0;
  int len;
- 
+
  bzero(&st, sizeof(st));
  fstat(file, &st);
  len = (int)st.st_size;
  if ( len == 0 )
  	return NULL;
-	
+
  lseek(file, 0, SEEK_SET);
  ret = emalloc(len + 1);
  while(i < len )
@@ -181,11 +184,11 @@
 	return NULL;
      }
  }
- 
+
  lseek(file, len, SEEK_SET);
  return ret;
 }
- 
+
 static int
 save_kb_entry_present_already (struct arglist * globals, char * hostname,
                                char* name, char* value)
@@ -194,11 +197,11 @@
   int fd;
   char* req;
   int ret;
-   
+
   fd = GPOINTER_TO_SIZE(arg_get_value(globals, "save_kb"));
   if(fd <= 0)
    return -1;
- 
+
   buf = map_file(fd);
   if(buf)
   {
@@ -213,8 +216,8 @@
    return ret;
   }
  return -1;
-} 
- 
+}
+
 static int
 save_kb_rm_entry_value (struct arglist* globals, char* hostname, char* name,
                         char* value)
@@ -223,34 +226,34 @@
   char * t;
   int fd;
   char * req;
-  
-   
+
+
   fd = GPOINTER_TO_SIZE(arg_get_value(globals, "save_kb"));
   if(fd <= 0)
    return -1;
-  
+
   buf = map_file(fd);
   if(buf)
   {
    if(value)
-   { 
+   {
     req = emalloc(strlen(name) + strlen(value) + 2);
     sprintf(req, "%s=%s", name, value);
    }
-   else 
+   else
     req = estrdup(name);
-    
+
    t = strstr(buf, req);
    if(t)
    {
     char * end;
-       
+
      while(t[0] != '\n')
      {
        if(t == buf)break;
        else t--;
      }
-       
+
      if(t[0] == '\n')t++;
      end = strchr(t, '\n');
      t[0] = '\0';
@@ -263,18 +266,18 @@
        {
         log_write("lseek() failed - %s\n", strerror(errno));
        }
-       
+
      if((ftruncate(fd, 0))<0)
        {
         log_write("ftruncate() failed - %s\n", strerror(errno));
        }
-       
-      
+
+
      if(write(fd, buf, strlen(buf)) < 0)
        {
         log_write("write() failed - %s\n", strerror(errno));
        }
-     
+
      if(end){
        	if((write(fd, end, strlen(end)))<0)
 	  log_write("write() failed - %s\n", strerror(errno));
@@ -288,85 +291,90 @@
 }
 
 static int
-save_kb_rm_entry(globals, hostname, name)
- struct arglist * globals;
- char * hostname;
- char * name;
+save_kb_rm_entry (struct arglist * globals, char * hostname, char * name)
 {
  return save_kb_rm_entry_value(globals, hostname, name, NULL);
 }
- 
+
 /**
- * Write data
+ * @brief Writes an entry to a knowledge base file.
  *
- * We want to avoid duplicates for :
+ * The entry will look like:
+ * 1254307384 1 Banner/22=SSH-2.0-OpenSSH_5.1p1 Debian-5\r\n
+ * where the first value is a timestamp, the second item is the \ref type,
+ * and the string before the equalsign in the third item is the key for the
+ * knowledge base and the rest the value for that key.
  *
- * 	Successful/...
- *	SentData/...
- *	Launched/...
+ * Duplicates for keys starting with:
+ *   Successful/...
+ *   SentData/...
+ *   Launched/...
+ * are not created (existing values are removed first).
+ * Any items starting with /tmp/, NIDS/ or Settings/ are not written to the file
+ * but rather ignored.
  *
- * Ignores any items starting with /tmp/, NIDS/ or Settings/
+ * @param name Key of the kb-item.
+ * @return -1 if invalid file handle to write to or any parameter is NULL, 0
+ *         otherwise.
  */
 static int
 save_kb_write (struct arglist * globals, char* hostname, char* name,
                char* value, int type)
 {
- int fd;
- char * str;
- int e;
- struct timeval now;
+  int fd;
+  char * str;
+  int e;
+  struct timeval now;
 
- if(!globals  ||
-    !hostname || 
-    !name     || 
-    !value)
- 	return -1;
-	
- fd = GPOINTER_TO_SIZE(arg_get_value(globals, "save_kb"));
- if(fd <= 0)
-  {
-  log_write("user %s : Can not find KB fd for %s\n", (char*)arg_get_value(globals, "user"), hostname);
-  return -1;
-  }
- 
+  if (!globals || !hostname || !name || !value)
+    return -1;
 
- /*
-  * Don't save temporary KB entries
-  */
- if(!strncmp(name, "/tmp/", 4) ||
-    !strncmp(name, "NIDS/", 5) ||
-    !strncmp(name, "Settings/", 9))
-   	return 0;
+  fd = GPOINTER_TO_SIZE (arg_get_value(globals, "save_kb"));
+  if (fd <= 0)
+    {
+      log_write ("user %s : Can not find KB fd for %s\n",
+                 (char*) arg_get_value (globals, "user"), hostname);
+      return -1;
+    }
 
- /* Don't save sensitive information */
- if (strncmp(name, "Secret/", 7) == 0)
-   return 0;
+  /* Skip temporary KB entries */
+  if (!strncmp (name, "/tmp/", 4) ||
+      !strncmp (name, "NIDS/", 5) ||
+      !strncmp (name, "Settings/", 9))
+    return 0;
 
- /*
-  * Avoid duplicates for these families
-  */
- if(!strncmp(name, "Success/", strlen("Success/"))   ||
-    !strncmp(name, "Launched/", strlen("Launched/")) ||
-    !strncmp(name, "SentData/", strlen("SentData/")))
+  /* Don't save sensitive information */
+  if (strncmp (name, "Secret/", 7) == 0)
+    return 0;
+
+  /* Avoid duplicates for these families */
+  if (!strncmp (name, "Success/", strlen ("Success/"))   ||
+      !strncmp (name, "Launched/", strlen ("Launched/")) ||
+      !strncmp (name, "SentData/", strlen ("SentData/")))
     {
-     save_kb_rm_entry(globals, hostname, name);
+      save_kb_rm_entry (globals, hostname, name);
     }
- 
- if(save_kb_entry_present_already(globals, hostname, name, value))
- {
-  save_kb_rm_entry_value(globals, hostname, name, value);
- }
-   
- str = emalloc(strlen(name) + strlen(value) + 25);
- gettimeofday(&now, NULL);
- sprintf(str, "%ld %d %s=%s\n", (long)now.tv_sec, type, name, value);
- e = write(fd, str, strlen(str));
- if(e < 0)
- {
-  log_write("user %s : write kb error - %s\n", (char*)arg_get_value(globals, "user"), strerror(errno));
- }
- efree(&str);
- return 0;
+
+  if (save_kb_entry_present_already (globals, hostname, name, value))
+    {
+      save_kb_rm_entry_value (globals, hostname, name, value);
+    }
+
+  str = emalloc (strlen (name) + strlen (value) + 25);
+  gettimeofday (&now, NULL);
+  sprintf (str, "%ld %d %s=%s\n", (long) now.tv_sec, type, name, value);
+
+  /** @todo Fix a bug (most probably race condition). Although following write
+   * call does return > 0, sometimes the content never reaches the file,
+   * especially for big amount of data in value (e.g. big file contents) */
+  e = write (fd, str, strlen (str));
+  if (e < 0)
+    {
+      log_write ("user %s : write kb error - %s\n",
+                (char*) arg_get_value (globals, "user"), strerror (errno));
+   }
+  efree (&str);
+  return 0;
 }
 
 
@@ -378,8 +386,8 @@
 
 /**
  * @brief Initialize a new KB that will be saved.
- * 
- * The indexes of all the opened KB are in a hashlist in 
+ *
+ * The indices of all the opened KB are in a hashlist in 
  * globals, saved under the name "save_kb". This makes no sense
  * at this time, as the test of each host is done in a separate
  * process, but this allows us to regroup easily these in
@@ -399,9 +407,9 @@
  dir = kb_dirname(globals);
  kb_mkdir(dir);
  efree(&dir);
- 
+
  fname = kb_fname(globals, hostname);
- 
+
  if(file_locked(fname))
  {
   efree(&fname);
@@ -440,17 +448,16 @@
 }
 
 /**
- * Returns <1> if we already saved a KB for this host,
- * less than <max_age> seconds ago. If <max_age> is
- * equal to zero, then the age is not taken in account
- * (returns true if a knowledge base exists)
+ * @return 1 if we already saved a KB for this host, less than \<max_age\>
+ *         seconds ago. If \<max_age\> equals zero, then the age is not taken in
+ *         account (returns true if a knowledge base exists).
  */
 int
 save_kb_exists (struct arglist * globals, char * hostname)
 {
  char * fname = kb_fname(globals, hostname);
  FILE *f;
- 
+
  if(file_locked(fname))
  {
   efree(&fname);
@@ -467,12 +474,12 @@
 
 
 int
-save_kb_write_str (struct arglist * globals, char * hostname, char* name, 
+save_kb_write_str (struct arglist * globals, char * hostname, char* name,
                    char* value)
 {
  char * newvalue  = addslashes(value);
  int e;
- 
+
  e = save_kb_write(globals, hostname, name, newvalue, ARG_STRING);
  efree(&newvalue);
  return e;
@@ -502,11 +509,11 @@
  char * fname = kb_fname(globals, hostname);
  char * bakname;
  int fd;
- 
+
  bakname = emalloc(strlen(fname) + 5);
  strcat(bakname, fname);
  strcat(bakname, ".bak");
- 
+
  unlink(fname);
  if((fd = open(bakname, O_RDONLY)) >= 0)
  {
@@ -525,27 +532,26 @@
  char * fname = kb_fname(globals, hostname);
  char * newname = NULL;
  int fd_src = -1, fd_dst = -1;
- 
- 
+
  if(file_locked(fname))
   {
    log_write("%s is locked\n", fname);
    goto failed1;
   }
- 
+
  file_lock(fname);
- 
+
  newname = emalloc(strlen(fname) + 5);
  strcat(newname, fname);
  strcat(newname, ".bak");
- 
+
  if((fd_src = open(fname, O_RDONLY)) >= 0)
  {
   char buf[4096];
   int n;
   fd_dst = open(newname, O_WRONLY|O_CREAT|O_TRUNC, 0640);
   if(fd_dst < 0)
-  { 
+  {
    log_write("save_kb_backup failed : %s", strerror(errno));
    close(fd_src);
    goto failed;
@@ -565,13 +571,13 @@
      goto failed;
      }
      m+=e;
-    } 
+    }
     bzero(buf, sizeof(buf));
    }
   }
-  else 
+  else
     log_write("save_kb_backup failed : %s\n", strerror(errno));
-    
+
   close(fd_src);
   close(fd_dst);
   efree(&newname);
@@ -580,7 +586,7 @@
   return 0;
 failed:
   file_unlock(fname);
-failed1:  
+failed1:
   efree(&fname);
   efree(&newname);
   return -1;
@@ -602,7 +608,7 @@
  struct kb_item ** kb;
  char buf[4096];
  long max_age = save_kb_max_age(globals);
- 
+
  if(file_locked(fname))
  {
   efree(&fname);
@@ -617,52 +623,55 @@
   }
  bzero(buf, sizeof(buf));
  fgets(buf, sizeof(buf) - 1, f);
- 
+
  kb  = kb_new();
- /*
-  * Ignore the date
-  */
- bzero(buf, sizeof(buf)); 
- 
+
+ /* Ignore the date */
+ bzero(buf, sizeof(buf));
+
  while(fgets(buf, sizeof(buf) - 1, f))
  {
   int type;
   char * name, * value, *t;
   struct timeval then, now;
-  
+
   buf[strlen(buf)-1]='\0'; /* chomp(buf) */
   t = strchr(buf, ' ');
-  if(!t)continue;
-  
+  if (!t)
+    continue;
+
   t[0] = '\0';
-  
+
   then.tv_sec = atol(buf);
   t[0] = ' ';t++;
   type = atoi(t);
   t = strchr(t, ' ');
-  if(!t)
-	  continue;
+  if (!t)
+    continue;
+
   t[0] = ' ';t++;
   name = t;
   t = strchr(name, '=');
-  if(!t)continue;
+  if (!t)
+    continue;
+
   t[0] = '\0';
   name = strdup(name);
   t[0] = ' ';
   t++;
   value = strdup(t);
-  
+
   if(strcmp(name, "Host/dead") && strncmp(name, "/tmp/", 4) &&
      strcmp(name, "Host/ping_failed"))
   {
    gettimeofday(&now, NULL);
    if(now.tv_sec - then.tv_sec > max_age)
    {
-    /* 
+    /*
     log_write("discarding %s because it's too old\n",
     		name,
     		(now.tv_sec - then.tv_sec));
-     */		
+     */
    }
    else
    {
@@ -681,7 +690,7 @@
   bzero(buf, sizeof(buf));
  }
  fclose(f);
- 
+
  /*
   * Re-open the file
   */
@@ -707,26 +716,29 @@
 
 /**
  * @return 1 if the user wants us the save the knowledge base.
+ * @todo This operation is possibly executed often (with every kb modification).
+ *       Evaluate wether the preference can change during a scan, consider the
+ *       use of a static variable.
  */
 int
 save_kb (struct arglist * globals)
 {
- struct arglist * preferences;
- char * value;
- 
- if(!globals)
+  struct arglist * preferences;
+  char * value;
+
+  if (!globals)
+    return 0;
+
+  preferences = arg_get_value (globals, "preferences");
+  if (!preferences)
+    return 0;
+
+  value = arg_get_value (preferences, "save_knowledge_base");
+
+  if (value && !strcmp (value, "yes"))
+    return 1;
+
   return 0;
-  
- preferences = arg_get_value(globals, "preferences");
- if(!preferences)
-  return 0;
-  
- value = arg_get_value(preferences, "save_knowledge_base");
- 
- if(value && !strcmp(value, "yes"))
-  return 1;
- 
- return 0;
 }
 
 /**
@@ -737,11 +749,11 @@
 {
  struct arglist * preferences = arg_get_value(globals, "preferences");
  char * value;
- 
+
  value = arg_get_value(preferences, "only_test_hosts_whose_kb_we_have");
  if(value && !strcmp(value, "yes"))
   return 1;
- 
+
  return 0;
 }
 
@@ -753,11 +765,11 @@
 {
  struct arglist * preferences = arg_get_value(globals, "preferences");
  char * value;
- 
+
  value = arg_get_value(preferences, "only_test_hosts_whose_kb_we_dont_have");
  if(value && !strcmp(value, "yes"))
   return 1;
- 
+
  return 0;
 }
 
@@ -769,11 +781,11 @@
 {
  struct arglist * preferences = arg_get_value(globals, "preferences");
  char * value;
- 
+
  value = arg_get_value(preferences, "kb_restore");
  if(value && !strcmp(value, "yes"))
   return 1;
- 
+
  return 0;
 }
 
@@ -806,7 +818,7 @@
 	break;
   /* ACT_SETTINGS and ACT_INIT should always be executed */
  }
- 
+
  if(name)
  {
   value = arg_get_value(preferences, name);

Modified: trunk/openvas-scanner/openvassd/save_tests.c
===================================================================
--- trunk/openvas-scanner/openvassd/save_tests.c	2009-10-05 08:45:01 UTC (rev 5362)
+++ trunk/openvas-scanner/openvassd/save_tests.c	2009-10-05 09:09:07 UTC (rev 5363)
@@ -173,7 +173,7 @@
  asctime = emalloc(2048); 
  t = time(NULL);
  lt = localtime(&t);
- 
+
  /*
   * Session id : <year><month><day>-<hour><minute><second>
   */
@@ -182,10 +182,10 @@
  dir = session_dirname(globals);
  session_mkdir(dir);
  efree(&dir);
- 
+
  index_fname = session_fname(globals, asctime, "index");
  data_fname  = session_fname(globals, asctime, "data");
- 
+
  index = open(index_fname, O_CREAT|O_WRONLY|O_EXCL, 0600);
  file_lock(index_fname);
  if(index < 0)
@@ -198,7 +198,7 @@
  {
   struct arglist * prefs = arg_get_value(globals, "preferences");
   char * target = arg_get_value(prefs, "TARGET");
-  
+
   log_write("user %s : session will be saved as %s", user, index_fname);
   if(arg_get_value(globals, "save_tests_index"))
   {
@@ -206,7 +206,7 @@
   }
   else
    arg_add_value(globals, "save_tests_index", ARG_INT, sizeof(gpointer), GSIZE_TO_POINTER(index));
- 
+
   if(arg_get_value(globals, "save_tests_index_fname"))
   {
    char * s = arg_get_value(globals, "save_tests_index_fname");
@@ -223,7 +223,7 @@
   write(index, target, strlen(target));
   write(index, "\n", 1);
  }
- 
+
  data = open(data_fname, O_CREAT|O_WRONLY|O_EXCL, 0600);
  file_lock(data_fname);
  if(data <  0)
@@ -454,20 +454,17 @@
 		session);
   return -1;
   }
- 
+
  stat(index, &st);
  len = (int)st.st_size;
- 
- /*
-  * Get the first line of our file, which contains the 
-  * list of hosts to test
-  */
+
+ /* Get the first line of our file, which contains the list of hosts to test */
  buf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
  t = buf;
  while(t[length] && t[length]!='\n')length++;
  munmap(buf, len);
  close(fd);
- 
+
  target = emalloc(length+3);
  f = fopen(index, "r");
  fgets(target, length+2, f);
@@ -476,10 +473,8 @@
  buf = emalloc(4096);
  tested = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
- /*
-  * Populate our harglst with the names of the
-  * hosts that have been completely tested
-  */
+ /* Populate our hashtable with the names of the hosts that have been completely
+  * tested */
  while(fgets(buf, 4095, f))
  {
   if (buf[strlen(buf)-1] == '\n')
@@ -491,9 +486,7 @@
  efree(&buf);
  fclose(f);
 
- /*
-  * Set the global variables accordingly
-  */
+ /* Set the global variables accordingly */
   if(arg_get_value(globals, "TESTED_HOSTS")) 
   arg_set_value(globals, "TESTED_HOSTS", -1, tested);
  else

Modified: trunk/openvas-scanner/openvassd/utils.c
===================================================================
--- trunk/openvas-scanner/openvassd/utils.c	2009-10-05 08:45:01 UTC (rev 5362)
+++ trunk/openvas-scanner/openvassd/utils.c	2009-10-05 09:09:07 UTC (rev 5363)
@@ -26,8 +26,9 @@
 *
 *
 */
- 
+
 #include <includes.h>
+
 #include "log.h"
 #include "ntp.h"
 #include "auth.h"
@@ -203,32 +204,29 @@
 
 
 /**
- * Returns the number of plugins that will be launched
+ * @brief Returns the number of plugins that will be launched.
  */
-int 
-get_active_plugins_number(plugins)
- struct arglist *  plugins;
+int
+get_active_plugins_number (struct arglist *  plugins)
 {
   int num = 0;
-  
+
   if(plugins != NULL)
    while(plugins->next != NULL)
    {
-    if(plug_get_launch(plugins->value) != LAUNCH_DISABLED )num++;
+    if (plug_get_launch(plugins->value) != LAUNCH_DISABLED)
+      num++;
     plugins = plugins->next;
    }
-   
-   
+
  return num;
 }
 
 
 
 
-void 
-plugins_set_ntp_caps(plugins, caps)
- struct arglist * plugins;
- ntp_caps* caps;
+void
+plugins_set_ntp_caps (struct arglist * plugins, ntp_caps* caps)
 {
  if(!caps || !plugins)return;
  while(plugins->next)
@@ -238,7 +236,7 @@
    v = plugins->value;
   else 
    v = NULL;
-  
+
   if( v != NULL ){
 	struct ntp_caps * old = arg_get_value(v, "NTP_CAPS");
 	if ( old != NULL )
@@ -257,19 +255,18 @@
 
 
 int
-is_symlink(name)
- char * name;
+is_symlink (char * name)
 {
  struct stat sb;
  if(stat(name, &sb))return(0);
  return(S_ISLNK(sb.st_mode));
 }
 
-void check_symlink(name)
- char * name;
+void
+check_symlink (char * name)
 {
- if(is_symlink(name))
- { 
+ if (is_symlink(name))
+ {
   fprintf(stderr, "The file %s is a symlink -- can't continue\n", name);
   DO_EXIT(0);
  }
@@ -280,9 +277,8 @@
  * to a space delimited lists of hosts
  * in one string and returns it.
  */
-char * 
-hosts_arglist_to_string(hosts)
- struct arglist * hosts;
+char *
+hosts_arglist_to_string (struct arglist * hosts)
 {
  int num_hosts = 0;
  struct arglist * start = hosts;
@@ -296,12 +292,12 @@
     hosts_len+=strlen(hosts->value);
   }
   hosts = hosts->next;
- }       
-  
+ }
+
  ret = emalloc(hosts_len + 2 * num_hosts + 1);
- 
+
  hosts = start;
- 
+
  while(hosts && hosts->next) {
   if(hosts->value){
    strcat(ret, hosts->value);
@@ -310,7 +306,7 @@
   hosts = hosts->next;
  }
 return(ret);
-} 
+}
 
 /*-----------------------------------------------------------------
 
@@ -318,8 +314,9 @@
 		
 -------------------------------------------------------------------*/
 
+/** @todo use glib functions to create the path */
 void
-create_pid_file()
+create_pid_file ()
 {
  FILE * f;
  char * fname = malloc(strlen(OPENVASSD_PIDDIR) + strlen("/openvassd.pid") + 1);
@@ -338,8 +335,9 @@
  free(fname);
 }
 
+/** @todo use glib functions to create the path */
 void
-delete_pid_file()
+delete_pid_file ()
 {
  char * fname = malloc(strlen(OPENVASSD_PIDDIR) + strlen("/openvassd.pid") + 1);
  strcpy(fname, OPENVASSD_PIDDIR);
@@ -371,7 +369,7 @@
  fd = open(ret, O_RDONLY);
  }
   while (fd >= 0);
-  
+
  return ret;
 }
 
@@ -381,19 +379,17 @@
 /**
  * Determines if a process is alive - as reliably as we can
  */
-int 
-process_alive(pid)
- pid_t pid;
+int
+process_alive (pid_t pid)
 {
- int i, ret;
- if( pid == 0 ) 
+  int i, ret;
+  if (pid == 0)
   return 0;
- 
- for(i=0,ret=1;(i<10) && (ret > 0);i++)
-   ret = waitpid(pid, NULL, WNOHANG);
-   
-   
- return kill(pid, 0) == 0;
+
+  for (i = 0,ret = 1;(i < 10) && (ret > 0) ; i++)
+   ret = waitpid (pid, NULL, WNOHANG);
+
+  return kill (pid, 0) == 0;
 }
 
 



More information about the Openvas-commits mailing list