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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed May 13 12:23:16 CEST 2009


Author: felix
Date: 2009-05-13 12:23:15 +0200 (Wed, 13 May 2009)
New Revision: 3355

Modified:
   trunk/openvas-client/ChangeLog
   trunk/openvas-client/src/util/openvas_ssh_rpm.c
Log:
Few cleanups in rpm export function.

* src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_create): Slightly better
error handling and cleanup, corrected memory allocation, using
file_utils module function instead of context_remove_directory.


Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog	2009-05-13 10:10:04 UTC (rev 3354)
+++ trunk/openvas-client/ChangeLog	2009-05-13 10:23:15 UTC (rev 3355)
@@ -1,5 +1,13 @@
 2009-05-13  Felix Wolfsteller <felix.wolfsteller at intevation.de>
 
+	Few cleanups in rpm export function.
+
+	* src/util/openvas_ssh_rpm.c (openvas_ssh_rpm_create): Slightly better
+	error handling and cleanup, corrected memory allocation, using
+	file_utils module function instead of context_remove_directory.
+
+2009-05-13  Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
 	Better wording and catching the case where credentials export
 	functionality is attempted to be used before any credentials
 	were created.

Modified: trunk/openvas-client/src/util/openvas_ssh_rpm.c
===================================================================
--- trunk/openvas-client/src/util/openvas_ssh_rpm.c	2009-05-13 10:10:04 UTC (rev 3354)
+++ trunk/openvas-client/src/util/openvas_ssh_rpm.c	2009-05-13 10:23:15 UTC (rev 3355)
@@ -86,6 +86,7 @@
   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). */
@@ -142,7 +143,7 @@
 
   // Next, execute create-rpm script
   printf ("--- RPM-builder: Attempt RPM build\n");
-  cmd = (gchar **) g_malloc (4 * sizeof (gchar *));
+  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");
@@ -163,8 +164,7 @@
     {
       show_error(_("Error (%d) creating the rpm with.\n"
                    "For further information consult your shell."), exit_status, cmd);
-      /** @TODO clean up, free mem */
-      return FALSE;
+      success =  FALSE;
     }
 
   g_free (cmd[0]);
@@ -176,7 +176,7 @@
   g_free (pubkey_basename);
   g_free (new_pubkey_filename);
   g_free (oltap_path);
-  printf ("--- RPM-builder: finished happily.\n");
+  printf ("--- RPM-builder: returned %d.\n", exit_status);
 
   // e.g. RPMS/noarch/openvas-lsc-target-example_user-0.5-1.noarch.rpm
   gchar* rpmfile = g_strconcat ("openvas-lsc-target-",
@@ -184,23 +184,22 @@
   rpm_path = g_build_filename (tmpdir, rpmfile, NULL);
 
   // Move that file
-  if (file_utils_move_file(rpm_path, to_filename) == FALSE)
+  if (file_utils_move_file(rpm_path, to_filename) == FALSE && success == TRUE)
     {
       show_error(_("RPM- File %s couldn't be moved to %s.\nFile will be deleted."),
                      rpm_path, to_filename);
-      g_free (rpm_path);
-      g_free (tmpdir);
-      g_free (rpmfile);
-      /** @TODO Clean up */
-      return FALSE;
+      success = FALSE;
     }
 
   // Now remove the copy of the public key and the temporary directory
-  /** @TODO Implement return value for context_delete_directory, refactor. */
-  context_delete_directory (tmpdir);
+  if (file_utils_rmdir_rf (tmpdir) != 0 && success == TRUE)
+    {
+      show_error (_("Temporary directory (%s) which contains private information could not be deleted."), tmpdir);
+    }
 
   g_free (tmpdir);
   g_free (rpm_path);
   g_free (rpmfile);
+
   return TRUE;
 }



More information about the Openvas-commits mailing list