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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue May 19 15:17:24 CEST 2009


Author: felix
Date: 2009-05-19 15:17:23 +0200 (Tue, 19 May 2009)
New Revision: 3427

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/nessus/context.c
Log:
Handle missing installers/packages on check on startup analog to
missing key files. Remove installer/packages if key files should be
deleted.

* nessus/context.c (verify_sshlogin_integrity): Check for 'missing'
installers/packages as well and recreate if user selects so.

* nessus/context.c (context_pickup_sshkeys): Remove installers/packages
if keys shall be deleted.

* nessus/context.c (context_delete_directory): Added doc and TODO,
minor reformatting.


Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-05-19 13:03:44 UTC (rev 3426)
+++ trunk/openvas-client/ChangeLog	2009-05-19 13:17:23 UTC (rev 3427)
@@ -1,5 +1,20 @@
 2009-05-19  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
+	Handle missing installers/packages on check on startup analog to
+	missing key files. Remove installer/packages if key files should be
+	deleted.
+	
+	* nessus/context.c (verify_sshlogin_integrity): Check for 'missing'
+	installers/packages as well and recreate if user selects so.
+
+	* nessus/context.c (context_pickup_sshkeys): Remove installers/packages
+	if keys shall be deleted.
+
+	* nessus/context.c (context_delete_directory): Added doc and TODO,
+	minor reformatting.
+
+2009-05-19  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
 	Remove installers / packages together with key files if an entry
 	is deleted via the OpenVAS LSC Credentials Manager.
 

Modified: trunk/openvas-client/nessus/context.c
===================================================================
--- trunk/openvas-client/nessus/context.c	2009-05-19 13:03:44 UTC (rev 3426)
+++ trunk/openvas-client/nessus/context.c	2009-05-19 13:17:23 UTC (rev 3427)
@@ -20,6 +20,8 @@
 
 #include "includes.h"
 #include "nessus_i18n.h"
+
+#include "file_utils.h"
 #include "nessus_plugin.h"
 #include "context.h"
 #include "preferences.h"
@@ -28,9 +30,15 @@
 #include "comm.h"
 #include "hash_table_file.h"
 #include "openvas_certificate_file.h"
+#include "openvas_lsc_user_deb.h"
+#include "openvas_lsc_user_makensis.h"
+#include "openvas_lsc_target_prep.h"
 #include "openvas_ssh_login.h"
 #include "openvas_ssh_key_create.h"
+#include "openvas_ssh_rpm.h"
 
+
+
 #ifdef USE_GTK
 #include <gtk/gtk.h>
 #endif /* USE_GTK */
@@ -254,6 +262,7 @@
   *child_ptr = next;
 }
 
+
 /**
  * @brief Warns the user if a login is invalid (e.g. misses key file) and asks
  *        how to solve the situation.
@@ -270,45 +279,100 @@
                            GSList** removelist)
 {
   #ifdef USE_GTK
-  if (login && login->valid == FALSE)
+  // Check if something is missing
+  if (login)
     {
-      GtkWidget* dialog = gtk_message_dialog_new (NULL, 
-                            GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
-                            GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
-                            _("SSH Login '%s' misses files.\nDelete this account and all information or recreate the files?"),
-                             accountname);
-      gtk_dialog_add_buttons (GTK_DIALOG(dialog), _("Delete Account"), 12,
-                                                  _("Recreate Files"), 13, NULL);
+      gint response;
+      // Following will be true e.g. if makensis but no .exe found.
+      gboolean rpm_missing = FALSE;
+      gboolean deb_missing = FALSE;
+      gboolean exe_missing = FALSE;
+      gchar* packpath;
 
-      gtk_widget_show_all (dialog);
+      // Find out if a package/installer is missing but its possible to recreate
+      if (openvas_ssh_rpm_generator_found())
+        {
+          packpath = openvas_ssh_rpm_filename (login->name);
+          if (!check_is_file (packpath))
+              rpm_missing = TRUE;
 
-      int response = gtk_dialog_run (GTK_DIALOG(dialog));
+          g_free (packpath);
 
-      if (response == 12) // "Delete"
-        {
-          (*removelist) = g_slist_prepend ((*removelist), g_strdup(accountname));
+          packpath = openvas_lsc_user_deb_filename (login->name);
+          if (openvas_lsc_user_deb_alien_found() && !check_is_file (packpath))
+              deb_missing = TRUE;
+          g_free (packpath);
         }
-      else if (response == 13) // "Create new"
+
+      if (openvas_lsc_user_makensis_found())
         {
-          openvas_ssh_login* login = g_hash_table_lookup (Global->sshkeys, accountname);
-          openvas_ssh_key_create_unlink_files (login);
-          if (openvas_ssh_key_create (login) == FALSE)
-            show_warning (_("Recreation of SSH login '%s' failed.\nCheck your console and remove or repair this login manually."), accountname);
-          else
-            show_info (_("Recreation of SSH login '%s' successful."), accountname);
+          packpath = openvas_lsc_user_makensis_filename (login->name);
+          if (!check_is_file (packpath))
+            exe_missing = TRUE;
         }
-      else
+
+      // If some files are missing but can be recreated, let the user choose
+      if (rpm_missing || deb_missing || exe_missing || login->valid == FALSE)
         {
-          // Seems that dialog (or main-gui) was simply closed, do nothing.
-          // Put notification into the log message area.
+          GtkWidget* dialog = gtk_message_dialog_new (NULL, 
+                              GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+                              GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
+                              _("SSH Login '%s' misses files.\nDelete this account and all information or recreate the files?"),
+                              accountname);
+          gtk_dialog_add_buttons (GTK_DIALOG(dialog), _("Delete Account"), 12,
+                                                      _("Recreate Files"), 13, NULL);
+
+          gtk_widget_show_all (dialog);
+
+          response = gtk_dialog_run (GTK_DIALOG(dialog));
+
+          if (response == 12) // "Delete"
+            {
+              (*removelist) = g_slist_prepend ((*removelist), g_strdup(accountname));
+            }
+          else if (response == 13) // "Create new"
+            {
+              openvas_ssh_login* login = g_hash_table_lookup (Global->sshkeys, accountname);
+              // Recreate keys
+              if (login->valid == FALSE)
+                {
+                  openvas_ssh_key_create_unlink_files (login);
+                  if (openvas_ssh_key_create (login) == FALSE)
+                    show_warning (_("Recreation of SSH login '%s' failed.\nCheck your console and remove or repair this login manually."), accountname);
+                  else
+                    show_info (_("Recreation of SSH login '%s' successful."), accountname);
+                }
+              // Recreate nsis installer
+              if (exe_missing == TRUE)
+                {
+                  packpath = openvas_lsc_user_makensis_filename (login->name);
+                  openvas_lsc_user_makensis (login, packpath);
+                  g_free (packpath);
+                }
+              // Recreate rpm package
+              if (rpm_missing == TRUE)
+                {
+                  packpath = openvas_ssh_rpm_filename (login->name);
+                  openvas_ssh_rpm_create (login, packpath);
+                  g_free (packpath);
+                }
+              // Recreate deb package
+              if (deb_missing == TRUE)
+                {
+                  packpath = openvas_lsc_user_deb_filename (login->name);
+                  openvas_lsc_user_deb (login, packpath);
+                  g_free (packpath);
+                }
+            }
+          else // Seems that dialog (or main-gui) was simply closed, do nothing.
+            ;
+          gtk_widget_destroy (dialog);
         }
-
-      gtk_widget_destroy (dialog);
     }
   #else
-    if (login && login->valid == FALSE)
-      show_warning (_("SSH Login %s seems to miss files. (The GUI can help you to repair or delete it)"), login->name);
-  #endif
+  if (login && login->valid == FALSE)
+    show_warning (_("SSH Login %s seems to miss files. (The GUI can help you to repair or delete it)"), login->name);
+  #endif /* USE_GTK */
 }
 
 /**
@@ -338,12 +402,13 @@
   // Check if all logins are valid (files exist).
   g_hash_table_foreach (loginfos, (GHFunc) verify_sshlogin_integrity, &invalidkeylist);
 
-  // Remove the keys that the user wanted to destroy
+  // Remove the keys and other files that the user wanted to destroy
   if (invalidkeylist != NULL)
     {
       listit = invalidkeylist;
       while (listit != NULL)
         {
+          openvas_lsc_target_prep_remove (g_hash_table_lookup (Global->sshkeys, listit->data));
           openvas_ssh_key_create_undo (g_hash_table_lookup (Global->sshkeys, listit->data));
           free (listit->data);
           listit = listit->next;
@@ -662,7 +727,10 @@
   return context;
 }
 
-
+/**
+ * @brief Deletes a directory and (recursively) all its content.
+ * @TODO In the long run use function from file_utils module
+ */
 void
 context_delete_directory (const char* dir)
 {
@@ -685,8 +753,8 @@
 	context_delete_directory(path);
       else
 	if(unlink(path))
-	  show_error_and_wait(_("File %s couldn't be deleted: %s."),
-		path, strerror(errno));
+	  show_error_and_wait (_("File %s couldn't be deleted: %s."),
+                               path, strerror(errno));
       g_free(path);
     }
     closedir(odir);



More information about the Openvas-commits mailing list