[Openvas-commits] r3398 - in trunk/openvas-client: . src/gui src/util

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon May 18 10:21:47 CEST 2009


Author: felix
Date: 2009-05-18 10:21:46 +0200 (Mon, 18 May 2009)
New Revision: 3398

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/src/gui/ssh_key_info_form.c
   trunk/openvas-client/src/gui/ssh_keys_dialog.c
   trunk/openvas-client/src/util/openvas_lsc_user_deb.c
   trunk/openvas-client/src/util/openvas_lsc_user_deb.h
   trunk/openvas-client/src/util/openvas_lsc_user_makensis.c
   trunk/openvas-client/src/util/openvas_lsc_user_makensis.h
   trunk/openvas-client/src/util/openvas_ssh_rpm.c
   trunk/openvas-client/src/util/openvas_ssh_rpm.h
Log:
Towards automatic generation of 'lsc user installer/packages'.
Therefore filenames for the generated installers/packages have to be
found and it has to be known if the tool to create the installer/package
is available.

* src/util/openvas_lsc_user_deb.c (execute_alien): Use --script
parameter when converting rpm to deb.

* src/util/openvas_lsc_user_deb.c (openvas_lsc_user_deb_alien_found):
New. Checks once for alien in path and returns whether it was found.

* src/util/openvas_lsc_user_makensis.c (execute_makensis): Included
return code of makensis in output to stdout.

* src/util/openvas_ssh_rpm.c (get_rpm_generator_path): Extracted.
Searches in install location and in tools folder for the rpm generator
script and returns its location if found.

* src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_create): Use new extracted
function get_rpm_generator_path, (debug) print the spawned command.

* src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_generator_found): New.
Checks once for existence of rpm generator script.

* src/util/openvas_lsc_user_deb.c (openvas_lsc_user_deb_filename),
src/util/openvas_lsc_user_deb.h,
src/util/openvas_lsc_makensis.c (openvas_lsc_makensis_filename)
src/util/openvas_lsc_makensis.h,
src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_filename),
src/util/openvas_ssh_rpm.h: New. Added functions and protos to create
and return filename of an installer/package.

* src/gui/ssh_key_info_form.c (typed_in_cb): When creating a new
account, now shows filenames for .exe, .rpm and .deb files as the
account name is typed in if the tools are available.

* src/gui/ssh_key_info_form.c (add_tooltips): Stub for function where
tooltips will be set.

* src/gui/ssh_key_info_form.c (ssh_key_info_form_create): Initialize
text to indicate that a tool could not be found - if so.

* src/gui/ssh_key_info_form.c (ssh_key_info_form_free): Free the new
text entries.

* src/gui/ssh_keys_dialog.c (ssh_keys_dialog_prompt_new): When account
is added, try to create the rpm, exe and deb installer/packages.

* src/gui/ssh_keys_dialog.c (ssh_keys_dialog_create_exe_click,
ssh_keys_dialog_create_rpm_click, ssh_keys_dialog_show): Removed buttons
to manually create rpm and exe installer/package and associated callback
functions.


Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/ChangeLog	2009-05-18 08:21:46 UTC (rev 3398)
@@ -1,3 +1,58 @@
+2009-05-18  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
+	Towards automatic generation of 'lsc user installer/packages'.
+	Therefore filenames for the generated installers/packages have to be
+	found and it has to be known if the tool to create the installer/package
+	is available.
+	
+	* src/util/openvas_lsc_user_deb.c (execute_alien): Use --script
+	parameter when converting rpm to deb.
+	
+	* src/util/openvas_lsc_user_deb.c (openvas_lsc_user_deb_alien_found):
+	New. Checks once for alien in path and returns whether it was found.
+	
+	* src/util/openvas_lsc_user_makensis.c (execute_makensis): Included
+	return code of makensis in output to stdout.
+	
+	* src/util/openvas_ssh_rpm.c (get_rpm_generator_path): Extracted.
+	Searches in install location and in tools folder for the rpm generator
+	script and returns its location if found.
+	
+	* src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_create): Use new extracted
+	function get_rpm_generator_path, (debug) print the spawned command.
+	
+	* src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_generator_found): New.
+	Checks once for existence of rpm generator script.
+	
+	* src/util/openvas_lsc_user_deb.c (openvas_lsc_user_deb_filename),
+	src/util/openvas_lsc_user_deb.h,
+	src/util/openvas_lsc_makensis.c (openvas_lsc_makensis_filename)
+	src/util/openvas_lsc_makensis.h,
+	src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_filename),
+	src/util/openvas_ssh_rpm.h: New. Added functions and protos to create
+	and return filename of an installer/package.
+
+	* src/gui/ssh_key_info_form.c (typed_in_cb): When creating a new
+	account, now shows filenames for .exe, .rpm and .deb files as the
+	account name is typed in if the tools are available.
+	
+	* src/gui/ssh_key_info_form.c (add_tooltips): Stub for function where
+	tooltips will be set.
+	
+	* src/gui/ssh_key_info_form.c (ssh_key_info_form_create): Initialize
+	text to indicate that a tool could not be found - if so.
+	
+	* src/gui/ssh_key_info_form.c (ssh_key_info_form_free): Free the new
+	text entries.
+	
+	* src/gui/ssh_keys_dialog.c (ssh_keys_dialog_prompt_new): When account
+	is added, try to create the rpm, exe and deb installer/packages.
+	
+	* src/gui/ssh_keys_dialog.c (ssh_keys_dialog_create_exe_click,
+	ssh_keys_dialog_create_rpm_click, ssh_keys_dialog_show): Removed buttons
+	to manually create rpm and exe installer/package and associated callback
+	functions.
+
 2009-05-15  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
 	Added stub for module openvas_lsc_user_deb that will create deb packages

Modified: trunk/openvas-client/src/gui/ssh_key_info_form.c
===================================================================
--- trunk/openvas-client/src/gui/ssh_key_info_form.c	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/gui/ssh_key_info_form.c	2009-05-18 08:21:46 UTC (rev 3398)
@@ -40,12 +40,15 @@
 #include <gtk/gtk.h>
 #include "context.h" /* for check_is_file */
 #include "error_dlg.h"
+#include "openvas_lsc_user_deb.h" /* for openvas_lsc_user_deb_alien_found () */
+#include "openvas_lsc_user_makensis.h" /* for openvas_lsc_user_makensis_found () */
+#include "openvas_ssh_rpm.h" /* for openvas_lsc_rpm_generator_found () */
 #include "openvas_ssh_login.h"
 #include "preferences.h"
 #include "ssh_key_info_form.h"
 
 /**
- * Chars used with g_strcanon to produce valid file paths.
+ * @brief Chars used with g_strcanon to produce valid file paths.
  */
 #define LEGAL_FILENAME_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYZ1234567890_./"
 
@@ -139,22 +142,63 @@
 name_typed_in_cb(GtkEntry *entry, ssh_key_info_form* form)
 {
   const char* name   = gtk_entry_get_text(entry);
-  
+
   char* home         = prefs_get_nessushome();
-  
-  char* pubkey_path  = g_strdup_printf("%s/.openvas/.ssh/%s.pub", home, name);
-  char* privkey_path = g_strdup_printf("%s/.openvas/.ssh/%s.p8",  home, name);
 
+  gchar* pubkey_path  = g_strdup_printf("%s/.openvas/.ssh/%s.pub", home, name);
+  gchar* privkey_path = g_strdup_printf("%s/.openvas/.ssh/%s.p8",  home, name);
+
   // Instead of using g_strcanon, g_build_filename () could be used.
-  gtk_entry_set_text(GTK_ENTRY(form->public_key_path), 
+  gtk_entry_set_text(GTK_ENTRY(form->public_key_path),
                      g_strcanon( pubkey_path, LEGAL_FILENAME_CHARS, '_'));
   gtk_entry_set_text(GTK_ENTRY(form->private_key_path),
                      g_strcanon( privkey_path, LEGAL_FILENAME_CHARS, '_'));
-  
-  efree(&pubkey_path);
-  efree(&privkey_path);
+
+  if (openvas_lsc_user_deb_alien_found() == TRUE)
+    {
+      gchar* deb_path     = g_strdup_printf("%s/.openvas/.ssh/%s.deb",  home, name);
+      gtk_entry_set_text (GTK_ENTRY(form->deb_location),
+                          g_strcanon (deb_path, LEGAL_FILENAME_CHARS, '_'));
+      g_free (deb_path);
+    }
+
+  if (openvas_ssh_rpm_generator_found() == TRUE)
+  {
+    gchar* rpm_path     = g_strdup_printf("%s/.openvas/.ssh/%s.rpm",  home, name);
+    gtk_entry_set_text (GTK_ENTRY(form->rpm_location),
+                      g_strcanon (rpm_path, LEGAL_FILENAME_CHARS, '_'));
+    g_free (rpm_path);
+  }
+
+  if (openvas_lsc_user_makensis_found() == TRUE)
+    {
+      gchar* exe_path     = g_strdup_printf("%s/.openvas/.ssh/%s.exe",  home, name);
+      gtk_entry_set_text (GTK_ENTRY(form->exe_location),
+                          g_strcanon (exe_path, LEGAL_FILENAME_CHARS, '_'));
+      g_free (exe_path);
+    }
+
+  g_free (pubkey_path);
+  g_free (privkey_path);
 }
 
+/**
+ * @brief Adds tooltips to all text entries.
+ * @param form The form to set tooltips to.
+ */
+static void
+add_tooltips (ssh_key_info_form* form)
+{
+  GtkTooltips* form_tips;
+  form_tips = gtk_tooltips_new ();
+  gtk_tooltips_set_tip (GTK_TOOLTIPS (form_tips), form->name,
+                          _("Name for this account."),
+                          _("Name for this account."));
+  gtk_tooltips_set_tip (GTK_TOOLTIPS (form_tips), form->username,
+                          _("The local username of this account."),
+                          _("The local username of this account."));
+  /** @TODO tooltips for all entries! */
+}
 
 /**
  * @brief Initializes a ssh_key_info_form.
@@ -204,16 +248,25 @@
   
   form->comment = gtk_entry_new();
   gtk_entry_set_text(GTK_ENTRY(form->comment), "");
-  
+
   form->rpm_location = gtk_entry_new ();
-  gtk_entry_set_text(GTK_ENTRY (form->rpm_location), "");
-  
+  if (openvas_ssh_rpm_generator_found () == TRUE)
+    gtk_entry_set_text(GTK_ENTRY (form->rpm_location), "");
+  else
+    gtk_entry_set_text(GTK_ENTRY (form->rpm_location), "rpm generator script not found");
+
   form->deb_location = gtk_entry_new ();
-  gtk_entry_set_text(GTK_ENTRY (form->deb_location), "");
-  
+  if (openvas_lsc_user_deb_alien_found() == TRUE && openvas_ssh_rpm_generator_found () == TRUE)
+    gtk_entry_set_text (GTK_ENTRY (form->deb_location), "");
+  else
+    gtk_entry_set_text (GTK_ENTRY (form->deb_location), _("alien or rpm not found in path"));
+
   form->exe_location = gtk_entry_new ();
-  gtk_entry_set_text(GTK_ENTRY (form->exe_location), "");
-  
+  if (openvas_lsc_user_makensis_found() == TRUE)
+    gtk_entry_set_text(GTK_ENTRY (form->exe_location), "");
+  else
+    gtk_entry_set_text(GTK_ENTRY (form->exe_location), _("makensis not found in path"));
+
   /* Setup layouting table */
   int row = 1;
   int col = 1;
@@ -291,15 +344,9 @@
   gtk_table_attach_defaults(GTK_TABLE(table), label, col, col+1, row, row+1);
   col++;
   gtk_table_attach_defaults(GTK_TABLE(table), form->exe_location, col, col+1, row, row+1);
-  
-  /** @TODO Set up tool tips like
-    GtkTooltips* button_bar_tips;
-    button_bar_tips = gtk_tooltips_new ();
-    gtk_tooltips_set_tip (GTK_TOOLTIPS (button_bar_tips), form->deb_location,
-                          _("Location of deb package.\n To generate deb packages you need to have rpm and alien installed."),
-                          _("Location of deb package"));
-  */
-  
+
+  add_tooltips (form);
+
   return form;
 }
 
@@ -404,6 +451,12 @@
     gtk_widget_destroy(form->ssh_key_passphrase);
   if(form->comment)
     gtk_widget_destroy(form->comment);
+  if (form->rpm_location)
+    gtk_widget_destroy(form->rpm_location);
+  if (form->deb_location)
+    gtk_widget_destroy(form->deb_location);
+  if (form->exe_location)
+    gtk_widget_destroy(form->exe_location);
   efree(&form);
 }
 

Modified: trunk/openvas-client/src/gui/ssh_keys_dialog.c
===================================================================
--- trunk/openvas-client/src/gui/ssh_keys_dialog.c	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/gui/ssh_keys_dialog.c	2009-05-18 08:21:46 UTC (rev 3398)
@@ -44,6 +44,7 @@
 #include "preferences.h"
 #include "nvt_pref_sshlogin.h"
 #include "ssh_keys_dialog.h"
+#include "openvas_lsc_user_deb.h"
 #include "openvas_lsc_user_makensis.h"
 #include "openvas_ssh_key_create.h"
 #include "openvas_ssh_rpm.h"
@@ -162,6 +163,8 @@
       openvas_ssh_login* login = g_hash_table_lookup(Global->sshkeys,  selected_account);
       // Remove files and entry in Context->sshkeys hash map
       openvas_ssh_key_create_undo (login);
+      /** @TODO remove installers */
+
       // Save the file so that the removed login is not listed anymore and will
       // not appear next time.
       char* loginsfile = g_build_filename(prefs_get_nessushome(), ".openvas", ".ssh", ".logins", NULL);
@@ -243,6 +246,27 @@
       openvas_ssh_login_file_write (Global->sshkeys, loginsfile);
       g_free (loginsfile);
 
+      // Attempt to create rpm, deb and exe
+      if (openvas_ssh_rpm_generator_found() == TRUE)
+        {
+          gchar* filename = openvas_ssh_rpm_filename (loginfo);
+          // Check return value
+          openvas_ssh_rpm_create (loginfo, filename);
+          g_free (filename);
+        }
+      if (openvas_lsc_user_makensis_found() == TRUE)
+        {
+          gchar* filename = openvas_lsc_user_makensis_filename (loginfo);
+          openvas_lsc_user_makensis (loginfo, filename);
+          g_free (filename);
+        }
+      if (openvas_lsc_user_deb_alien_found() == TRUE)
+        {
+          gchar* filename = openvas_lsc_user_deb_filename (loginfo);
+          openvas_lsc_user_deb (loginfo, filename);
+          g_free (filename);
+        }
+
       ssh_keys_dialog_add_key (NULL, loginfo, notebook);
       nvt_pref_sshlogin_update_all_comboboxes (Global, loginfo->name);
       break;
@@ -254,112 +278,8 @@
    gtk_widget_destroy(dialog);
 }
 
-/**
- * @brief Attempts building ms installer package (exe) that installs the
- * @brief selected user in an ms windows environment.
- */
-static void
-ssh_keys_dialog_create_exe_click (GtkWidget* parent, GtkWidget* notebook)
-{
-  /** @TODO Following code duplicate of create_rpm_ click, refactor. */
-  const char* selected_account = listnotebook_get_selected (notebook);
-  if (selected_account == NULL || !strcmp(selected_account, STR_NO_LOGINS_YET))
-    {
-      show_info (_("No credentials selected to create installer for."));
-      return;
-    }
-  openvas_ssh_login* login = g_hash_table_lookup(Global->sshkeys, selected_account);
-  GtkWidget* file_chooser;
-  gchar* filename;
 
-  if (login == NULL)
-    {
-      show_error (_("Cannot find credentials to create installer for."));
-      return;
-    }
-
-  file_chooser = gtk_file_chooser_dialog_new (_("Export to"),
-                                              NULL,//GTK_WINDOW(arg_get_value(MainDialog, "WINDOW")),
-                                              GTK_FILE_CHOOSER_ACTION_SAVE,
-                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                              GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-                                              NULL);
-  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (file_chooser), TRUE);
-  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (file_chooser), g_build_filename ("installuser.exe", NULL) );
-
-  if (gtk_dialog_run (GTK_DIALOG (file_chooser)) != GTK_RESPONSE_ACCEPT)
-    {
-      gtk_widget_destroy (file_chooser);
-      // NTBD
-      return;
-    }
-
-  filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser));
-
-  if (openvas_lsc_user_makensis_found ())
-    {
-      if (openvas_lsc_user_makensis (login, filename) == FALSE)
-        show_error (_("Creation of a user-install-executable failed."));
-      else
-        show_info (_("Creation of a user-install-executable successful."));
-    }
-  else
-    show_info (_("To use this function you need to have nsis (http://nsis.sourceforge.net/) installed.\n"));
-
-  gtk_widget_destroy (file_chooser);
-}
-
 /**
- * @brief Attempts building RPM packages that install a public key.
- */
-static void
-ssh_keys_dialog_create_rpm_click (GtkWidget* parent, GtkWidget* notebook)
-{
-  const char* selected_account = listnotebook_get_selected (notebook);
-  if (selected_account == NULL || !strcmp(selected_account, STR_NO_LOGINS_YET))
-    {
-      show_info (_("No credentials selected to create RPM for."));
-      return;
-    }
-  openvas_ssh_login* login = g_hash_table_lookup(Global->sshkeys, selected_account);
-  GtkWidget* file_chooser;
-  gchar* filename;
-
-  if (login == NULL)
-    {
-      show_error (_("Cannot find credentials to create RPM for."));
-      return;
-    }
-
-  file_chooser = gtk_file_chooser_dialog_new (_("Export to"),
-                                              NULL,//GTK_WINDOW(arg_get_value(MainDialog, "WINDOW")),
-                                              GTK_FILE_CHOOSER_ACTION_SAVE,
-                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                              GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-                                              NULL);
-  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (file_chooser), TRUE);
-  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (file_chooser), g_build_filename ("rpm.rpm", NULL) );
-
-  if (gtk_dialog_run (GTK_DIALOG (file_chooser)) != GTK_RESPONSE_ACCEPT)
-    {
-      gtk_widget_destroy (file_chooser);
-      // NTBD
-      return;
-    }
-
-  filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser));
-
-  if (openvas_ssh_rpm_create (login, filename) == TRUE)
-    show_info (_("RPM Creation succeeded.\n"));
-  else
-    show_error (_("RPM Creation failed\n"));
-
-  g_free (filename);
-  gtk_widget_destroy (file_chooser);
-}
-
-
-/**
  * @brief Shows the OpenVAS LSC Credentials Management Dialog.
  */
 void
@@ -410,14 +330,6 @@
   GtkWidget* button_new = gtk_button_new_with_label(_("Create a new keypair"));
   gtk_box_pack_start (GTK_BOX(buttonbox), button_new, TRUE, TRUE, 5);
 
-  // RPM generation
-  GtkWidget* button_rpm = gtk_button_new_with_label(_("Create RPM"));
-  gtk_box_pack_start (GTK_BOX(buttonbox), button_rpm, TRUE, TRUE, 5);
-
-  // MS Windows installer via nsis
-  GtkWidget* button_exe = gtk_button_new_with_label(_("Create EXE"));
-  gtk_box_pack_start (GTK_BOX(buttonbox), button_exe, TRUE, TRUE, 5);
-
   // Close dialog button
   gtk_dialog_add_buttons (GTK_DIALOG(win), GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
 
@@ -426,10 +338,6 @@
                     (GtkSignalFunc) ssh_keys_dialog_prompt_new, key_notebook);
   g_signal_connect (button_del, "clicked", 
                     (GtkSignalFunc) ssh_keys_dialog_delete_login, key_notebook);
-  g_signal_connect (button_rpm, "clicked",
-                    (GtkSignalFunc) ssh_keys_dialog_create_rpm_click, key_notebook);
-  g_signal_connect (button_exe, "clicked",
-                    (GtkSignalFunc) ssh_keys_dialog_create_exe_click, key_notebook);
   g_signal_connect_swapped (win, "response", G_CALLBACK (gtk_widget_destroy),
                             win);
 

Modified: trunk/openvas-client/src/util/openvas_lsc_user_deb.c
===================================================================
--- trunk/openvas-client/src/util/openvas_lsc_user_deb.c	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/util/openvas_lsc_user_deb.c	2009-05-18 08:21:46 UTC (rev 3398)
@@ -54,7 +54,8 @@
 #include "includes.h" /* For stdio (function: remove) */
 #include "preferences.h" /* For prefs_get_nessushome */
 #include "context.h" /* For check_is_dir (!) and context_remove_directory (!): @TODO */
-#include "openvas_lsc_user_makensis.h"
+#include "openvas_lsc_user_deb.h"
+#include "openvas_ssh_rpm.h" /* for openvas_ssh_rpm_filename */
 
 /**
  * @brief Execute alien to create a deb packages from an rpm package.
@@ -66,11 +67,12 @@
   gchar** cmd;
   gint exit_status;
 
-  cmd = (gchar **) g_malloc (3 * sizeof (gchar *));
+  cmd = (gchar **) g_malloc (4 * sizeof (gchar *));
 
   cmd[0] = g_strdup ("alien");
-  cmd[1] = g_strdup (rpmfile);
-  cmd[2] = NULL;
+  cmd[1] = g_strdup ("--scripts");
+  cmd[2] = g_strdup (rpmfile);
+  cmd[3] = NULL;
   printf ("--- executing alien.\n");
   if (g_spawn_sync (".",
                     cmd,
@@ -127,18 +129,51 @@
 }
 
 /**
+ * @brief Returns the path to debian package 'installer' for a given
+ * @brief openvas_ssh_login.
+ *
+ * Installers will be placed to or read from this location. It equals the path
+ * to the public key but with a different file extension (.rpm).
+ *
+ * @return Path to installer for given openvas_ssh_login, has to be freed using
+ *         g_free, NULL in case of errors.
+ */
+gchar*
+openvas_lsc_user_deb_filename (const openvas_ssh_login* loginfo)
+{
+  if (   loginfo == NULL || loginfo->public_key_path == NULL
+      || strrchr(loginfo->public_key_path, '.') == NULL)
+    return NULL;
+
+  // Exchange file extensions
+  gchar* loc = g_strdup (loginfo->public_key_path);
+  g_strlcpy (strrchr(loc, '.') + 1, "deb", 4);
+  return loc;
+}
+
+
+/**
  * @brief Attempts creation of a deb packages from an rpm package.
  * 
  * @param loginfo openvas_ssh_login struct to create rpm for.
  * 
  * @return TRUE if successful, FALSE otherwise.
+ * @TODO Test (and likely correct) behaviour.
  */
 gboolean
 openvas_lsc_user_deb (openvas_ssh_login* loginfo, const gchar* to_filename)
 {
   gboolean success   = FALSE;
-  
-  /** @TODO execute_alien */
+  gchar* debfilename = g_strdup_printf ("openvas-lsc-target-%s_0.5-2_all.deb", loginfo->username);
+  gchar* rpmfile = openvas_ssh_rpm_filename (loginfo);
 
+  openvas_lsc_user_deb_alien_found ();
+
+  execute_alien (rpmfile);
+  file_utils_move_file (debfilename, to_filename);
+
+  g_free (debfilename);
+  g_free (rpmfile);
+
   return success;
 }

Modified: trunk/openvas-client/src/util/openvas_lsc_user_deb.h
===================================================================
--- trunk/openvas-client/src/util/openvas_lsc_user_deb.h	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/util/openvas_lsc_user_deb.h	2009-05-18 08:21:46 UTC (rev 3398)
@@ -42,6 +42,8 @@
 gboolean openvas_lsc_user_deb (openvas_ssh_login* loginfo,
                                const gchar* to_filename);
 
+gchar* openvas_lsc_user_deb_filename (const openvas_ssh_login* loginfo);
+
 gboolean openvas_lsc_user_deb_alien_found ();
 
 #endif /* _OPENVAS_LSC_USER_DEB_H */

Modified: trunk/openvas-client/src/util/openvas_lsc_user_makensis.c
===================================================================
--- trunk/openvas-client/src/util/openvas_lsc_user_makensis.c	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/util/openvas_lsc_user_makensis.c	2009-05-18 08:21:46 UTC (rev 3398)
@@ -91,6 +91,7 @@
   return tmpdir;
 }
 
+
 /**
  * @brief Writes a nsi file to be used with the 'Nullsoft scriptable installer
  * @brief system'.
@@ -226,7 +227,7 @@
   g_free (cmd[2]);
   g_free (cmd);
 
-  printf ("--- makensis finished happily.\n");
+  printf ("--- makensis returned %d.\n", exit_status);
   return (exit_status == 0);
 }
 
@@ -247,6 +248,28 @@
 }
 
 /**
+ * @brief Returns the path to installer for a given openvas_ssh_login.
+ *
+ * Installers will be placed to or read from this location. It equals the path
+ * to the public key but with a different file extension (.rpm).
+ *
+ * @return Path to installer for given openvas_ssh_login, has to be freed using
+ *         g_free, NULL in case of errors.
+ */
+gchar*
+openvas_lsc_user_makensis_filename (const openvas_ssh_login* loginfo)
+{
+  if (   loginfo == NULL || loginfo->public_key_path == NULL
+      || strrchr(loginfo->public_key_path, '.') == NULL)
+    return NULL;
+
+  // Exchange file extensions
+  gchar* loc = g_strdup (loginfo->public_key_path);
+  g_strlcpy (strrchr(loc, '.') + 1, "exe", 4);
+  return loc;
+}
+
+/**
  * @brief Attempts creation of RPM packages to install a users public key file.
  * 
  * @param loginfo openvas_ssh_login struct to create rpm for.

Modified: trunk/openvas-client/src/util/openvas_lsc_user_makensis.h
===================================================================
--- trunk/openvas-client/src/util/openvas_lsc_user_makensis.h	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/util/openvas_lsc_user_makensis.h	2009-05-18 08:21:46 UTC (rev 3398)
@@ -43,6 +43,8 @@
 gboolean openvas_lsc_user_makensis (openvas_ssh_login* loginfo,
                                     const gchar* to_filename);
 
+gchar* openvas_lsc_user_makensis_filename (const openvas_ssh_login* loginfo);
+
 gboolean openvas_lsc_user_makensis_found ();
 
 #endif /* _OPENVAS_LSC_NSI_EXPORT_H */

Modified: trunk/openvas-client/src/util/openvas_ssh_rpm.c
===================================================================
--- trunk/openvas-client/src/util/openvas_ssh_rpm.c	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/util/openvas_ssh_rpm.c	2009-05-18 08:21:46 UTC (rev 3398)
@@ -42,6 +42,7 @@
 #include "includes.h" /* For stdio (function: remove) */
 #include "preferences.h" /* For prefs_get_nessushome */
 #include "context.h" /* For check_is_dir (!) and context_remove_directory (!): @TODO */
+#include "openvas_ssh_rpm.h"
 
 /**
  * @brief Creates a temporary directory to place copy of key and as working
@@ -67,6 +68,92 @@
 }
 
 /**
+ * @brief Returns the path to the directory where the rpm generator
+ * @brief ("openvas-ssh-client-rpm-creator.sh") is located.
+ * 
+ * The search will be performed just once.
+ * 
+ * @return Path to the directory with the rpm generator or NULL (shall not be
+ *         freed!).
+ */
+static gchar*
+get_rpm_generator_path ()
+{
+  static gchar* rpm_generator_path = NULL;
+
+  if (rpm_generator_path == NULL)
+    {
+      // Search in two location 
+      gchar* path_exec = g_build_filename (OPENVASCLIENT_LSCRPMGEN_DIR, "openvas-ssh-client-rpm-creator.sh", NULL);
+      if (check_is_file (path_exec) == 0)
+        {
+          g_free (path_exec);
+          path_exec = g_build_filename ("tools", "openvas-ssh-client-rpm-creator.sh", NULL);
+          if (check_is_file (path_exec) == 0)
+            {
+              // Could not be found at all
+               g_free (path_exec);
+            }
+          else
+            g_free (path_exec);
+            rpm_generator_path = g_strdup ("tools");
+        }
+      else
+        rpm_generator_path = g_strdup (OPENVASCLIENT_LSCRPMGEN_DIR);
+    }
+
+  return rpm_generator_path;
+}
+
+
+/**
+ * @brief Returns the path to rpm package 'installer' for a given
+ * @brief openvas_ssh_login.
+ *
+ * Installers will be placed to or read from this location. It equals the path
+ * to the public key but with a different file extension (.rpm).
+ *
+ * @return Path to installer for given openvas_ssh_login, has to be freed using
+ *         g_free, NULL in case of errors.
+ */
+gchar*
+openvas_ssh_rpm_filename (const openvas_ssh_login* loginfo)
+{
+  if (   loginfo == NULL || loginfo->public_key_path == NULL
+      || strrchr(loginfo->public_key_path, '.') == NULL)
+    return NULL;
+
+  // Exchange file extensions
+  gchar* loc = g_strdup (loginfo->public_key_path);
+  g_strlcpy (strrchr(loc, '.') + 1, "rpm", 4);
+  return loc;
+}
+
+/**
+ * @brief Returns whether the rpm generator script was found.
+ * 
+ * The search will be performed only once.
+ * 
+ * @return TRUE if the script was found, FALSE otherwise.
+ */
+gboolean
+openvas_ssh_rpm_generator_found ()
+{
+  static gboolean searched = FALSE;
+  static gboolean found    = FALSE;
+
+  if (searched == FALSE)
+    {
+      searched = TRUE;
+      gchar* rpmgen_path = get_rpm_generator_path ();
+      if (rpmgen_path != NULL)
+        found = TRUE;
+    }
+
+  return found;
+}
+
+/**
  * @brief Attempts creation of RPM packages to install a users public key file.
  * 
  * @param loginfo openvas_ssh_login struct to create rpm for.
@@ -84,39 +171,11 @@
   gchar* new_pubkey_filename = NULL;
   gchar* pubkey_basename = NULL;
   gchar** cmd;
-  gchar* path_exec = NULL;
   gchar* tmpdir = NULL;
   gboolean success = TRUE;
 
-  /** Path to the lsc preparation rpm generator script (currently defined via
-   * src/util/Makefile). */
-  oltap_path = g_strdup (OPENVASCLIENT_LSCRPMGEN_DIR);
+  oltap_path = get_rpm_generator_path ();
 
-  path_exec = g_build_filename (oltap_path, "openvas-ssh-client-rpm-creator.sh", NULL);
-
-  // Find executable
-  if (check_is_file (path_exec) == 0)
-    {
-      g_free (path_exec);
-      path_exec = g_build_filename ("tools", "openvas-ssh-client-rpm-creator.sh", NULL);
-      if (check_is_file (path_exec) == 0)
-        {
-          // Could not be found at all
-          show_error ("The RPM generator script could not be neither found "
-                        "in %s nor in %s\n", oltap_path, "tools");
-          g_free (path_exec);
-          g_free (oltap_path);
-          return FALSE;
-        }
-      // Found "local" (in tools)
-      show_warning ("The RPM generator script could not be found in %s.\n"
-                    "However a local version in 'tools' was found and will be "
-                    "used.", oltap_path);
-      g_free (oltap_path);
-      oltap_path = g_strdup ("tools");
-    }
-  g_free (path_exec);
-
   // First, create a temporary directory
   printf ("--- RPM-builder: create temporary directory\n");
   tmpdir = create_tmp_dir();
@@ -144,12 +203,12 @@
   // Next, execute create-rpm script
   printf ("--- RPM-builder: Attempt RPM build\n");
   cmd = (gchar **) g_malloc (5 * sizeof (gchar *));
-  // --target (and remove later)
   cmd[0] = g_strdup ("./openvas-ssh-client-rpm-creator.sh");
   cmd[1] = g_strdup ("--target");
   cmd[2] = g_strdup (tmpdir);
   cmd[3] = g_build_filename (tmpdir, pubkey_basename, NULL);
   cmd[4] = NULL;
+  printf ("Spawning in %s: %s %s %s %s\n", oltap_path, cmd[0], cmd[1], cmd[2], cmd[3]);
   if (g_spawn_sync (oltap_path,
                     cmd,
                     NULL, // env
@@ -201,5 +260,5 @@
   g_free (rpm_path);
   g_free (rpmfile);
 
-  return TRUE;
+  return success;
 }

Modified: trunk/openvas-client/src/util/openvas_ssh_rpm.h
===================================================================
--- trunk/openvas-client/src/util/openvas_ssh_rpm.h	2009-05-18 07:48:30 UTC (rev 3397)
+++ trunk/openvas-client/src/util/openvas_ssh_rpm.h	2009-05-18 08:21:46 UTC (rev 3398)
@@ -43,4 +43,8 @@
 gboolean openvas_ssh_rpm_create (openvas_ssh_login* loginfo,
                                  const gchar* to_filename);
 
+gchar* openvas_ssh_rpm_filename (const openvas_ssh_login* loginfo);
+
+gboolean openvas_ssh_rpm_generator_found ();
+
 #endif



More information about the Openvas-commits mailing list