[Openvas-commits] r7362 - in trunk/openvas-administrator: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 20 08:03:48 CEST 2010


Author: felix
Date: 2010-04-20 08:03:46 +0200 (Tue, 20 Apr 2010)
New Revision: 7362

Modified:
   trunk/openvas-administrator/ChangeLog
   trunk/openvas-administrator/src/admin.c
Log:
* src/admin.c: Updated copyright, include new file utility module.
(check_is_dir, remove_recurse): Moved to
openvas-libraries/base/openvas_file module.
(openvas_admin_add_user): Moved code part regarding creation of rules
file to openvas-libraries/misc/openvas_auth module, call that new
function instead.
Updated calls to the functions that were moved to
openvas-libraries/base/openvas_file .


Modified: trunk/openvas-administrator/ChangeLog
===================================================================
--- trunk/openvas-administrator/ChangeLog	2010-04-20 05:57:41 UTC (rev 7361)
+++ trunk/openvas-administrator/ChangeLog	2010-04-20 06:03:46 UTC (rev 7362)
@@ -1,7 +1,18 @@
 2010-04-20  Felix Wolfsteller <felix.wolfsteller at greenbone.net>
 
-	* CMakeLists.txt, src/CMakeLists.txt: Lower cased cmake commands.
+	* src/admin.c: Updated copyright, include new file utility module.
+	(check_is_dir, remove_recurse): Moved to
+	openvas-libraries/base/openvas_file module.
+	(openvas_admin_add_user): Moved code part regarding creation of rules
+	file to openvas-libraries/misc/openvas_auth module, call that new
+	function instead.
+	Updated calls to the functions that were moved to
+	openvas-libraries/base/openvas_file .
 
+2010-04-20  Felix Wolfsteller <felix.wolfsteller at greenbone.net>
+
+	* CMakeLists.txt, src/CMakeLists.txt: Lowercased cmake commands.
+
 2010-04-15  Felix Wolfsteller <felix.wolfsteller at greenbone.net>
 
 	Moved code to openvas-libraries/misc/openvas_uuid module.

Modified: trunk/openvas-administrator/src/admin.c
===================================================================
--- trunk/openvas-administrator/src/admin.c	2010-04-20 05:57:41 UTC (rev 7361)
+++ trunk/openvas-administrator/src/admin.c	2010-04-20 06:03:46 UTC (rev 7362)
@@ -7,7 +7,7 @@
  * Michael Wiegand <michael.wiegand at intevation.de>
  *
  * Copyright:
- * Copyright (C) 2009 Greenbone Networks GmbH
+ * Copyright (C) 2009,2010 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 version 2,
@@ -49,6 +49,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
+#include <openvas/base/openvas_file.h>
 #include <openvas/base/settings.h>
 #include <openvas/openvas_auth.h>
 #include <openvas/openvas_uuid.h>
@@ -139,89 +140,6 @@
 }
 
 /**
- * @brief Checks whether a file is a directory or not.
- *
- * This is a replacement for the g_file_test functionality which is reported
- * to be unreliable under certain circumstances, for example if this
- * application and glib are compiled with a different libc.
- *
- * @todo FIXME: handle symbolic links
- * @todo Move to libs?
- *
- * @param[in]  name  Name of file or directory.
- *
- * @return 1 if parameter is directory, 0 if it is not, -1 if it does not
- *         exist or could not be accessed.
- */
-static int
-check_is_dir (const char* name)
-{
-  struct stat sb;
-
-  if (stat (name, &sb))
-    {
-      return -1;
-    }
-  else
-    {
-      return (S_ISDIR (sb.st_mode));
-    }
-}
-
-/**
- * @brief Recursively removes files and directories.
- *
- * This function will recursively call itself to delete a path and any
- * contents of this path.
- *
- * @todo Move to libs?
- *
- * @param[in]  pathname  The name of the file to be deleted from the filesystem.
- *
- * @return 0 if the name was successfully deleted, -1 if an error occurred.
- *         Please note that errno is currently not guaranteed to contain the correct
- *         value if -1 is returned.
- */
-static int
-remove_recurse (const gchar * pathname)
-{
-  /** @todo Set errno when we return -1 to maintain remove() compatibility. */
-  if (check_is_dir (pathname) == 1)
-    {
-      GError *error = NULL;
-      GDir *directory = g_dir_open (pathname, 0, &error);
-
-      if (directory == NULL)
-        {
-          g_warning ("g_dir_open(%s) failed - %s\n", pathname, error->message);
-          g_error_free (error);
-          return -1;
-        }
-      else
-        {
-          int ret = 0;
-          const gchar *entry = NULL;
-
-          while ((entry = g_dir_read_name (directory)) && (ret == 0))
-            {
-              gchar *entry_path = g_build_filename (pathname, entry, NULL);
-              ret = remove_recurse (entry_path);
-              g_free (entry_path);
-              if (ret != 0)
-                {
-                  g_warning ("Failed to remove %s from %s!", entry, pathname);
-                  g_dir_close (directory);
-                  return ret;
-                }
-            }
-          g_dir_close (directory);
-        }
-    }
-
-  return g_remove (pathname);
-}
-
-/**
  * @brief Descending strcmp.
  *
  * @param[in]  one  First string.
@@ -314,6 +232,7 @@
     }
 }
 
+/** @todo Use openvas-libraries/misc/openvas_auth module funcitonality */
 /**
  * @brief Get access information for a user.
  *
@@ -486,9 +405,8 @@
   if (g_file_test (directory, G_FILE_TEST_IS_DIR))
     {
       GError *error = NULL;
-      gchar *user_dir_name, *user_auth_dir_name, *user_rules_file_name;
+      gchar *user_dir_name, *user_auth_dir_name;
       gchar *user_hash_file_name, *hashes_out, *uuid_file_name, *contents;
-      GString *rules;
       char *uuid;
 
       user_dir_name = g_build_filename (directory, name, NULL);
@@ -517,7 +435,7 @@
       if (g_mkdir (user_auth_dir_name, 0700))
         {
           g_warning ("Could not create %s!", user_auth_dir_name);
-          if (remove_recurse (user_dir_name))
+          if (openvas_file_remove_recurse (user_dir_name))
             g_warning ("Could not remove %s while trying to revert changes!",
                        user_dir_name);
           g_warning ("Failed to set up user directories for user %s", name);
@@ -545,7 +463,7 @@
         {
           g_warning ("Failed to store UUID: %s", error->message);
           g_error_free (error);
-          if (remove_recurse (user_dir_name))
+          if (openvas_file_remove_recurse (user_dir_name))
             g_warning ("Could not remove %s while trying to revert changes!",
                        user_dir_name);
           free (contents);
@@ -570,7 +488,7 @@
         {
           g_warning ("%s", error->message);
           g_error_free (error);
-          if (remove_recurse (user_dir_name))
+          if (openvas_file_remove_recurse (user_dir_name))
             g_warning ("Could not remove %s while trying to revert changes!",
                        user_dir_name);
           g_free (hashes_out);
@@ -585,68 +503,13 @@
 
       /* Create rules according to hosts. */
 
-      rules = g_string_new (RULES_HEADER);
-      if (hosts && strlen (hosts))
-        {
-          gchar **split = g_strsplit (hosts, ",", 0);
+      openvas_auth_store_user_rules (hosts, hosts_allow);
 
-          /** @todo Do better format checking on hosts. */
-
-          if (hosts_allow)
-            {
-              gchar **host;
-              g_string_append_printf (rules, "# allow %s\n", hosts);
-              for (host = split; *host; host++)
-                g_string_append_printf (rules,
-                                        "accept %s\n",
-                                        g_strstrip (*host));
-              g_string_append (rules, "default deny\n");
-            }
-          else
-            {
-              gchar **host;
-              g_string_append_printf (rules, "# deny %s\n", hosts);
-              for (host = split; *host; host++)
-                g_string_append_printf (rules,
-                                        "deny %s\n",
-                                        g_strstrip (*host));
-              g_string_append (rules, "default accept\n");
-            }
-
-          g_strfreev (split);
-        }
-
-      /* Put the rules in auth/rules. */
-
-      user_rules_file_name = g_build_filename (user_auth_dir_name,
-                                               "rules",
-                                               NULL);
-      g_free (user_auth_dir_name);
-      if (!g_file_set_contents (user_rules_file_name,
-                                rules->str,
-                                -1,
-                                &error))
-        {
-          g_warning ("%s", error->message);
-          g_error_free (error);
-          if (remove_recurse (user_dir_name))
-            g_warning ("Could not remove %s while trying to revert changes!",
-                       user_dir_name);
-          g_string_free (rules, TRUE);
-          g_free (user_dir_name);
-          g_free (user_rules_file_name);
-          return -1;
-        }
-      g_string_free (rules, TRUE);
-      g_chmod (user_rules_file_name, 0600);
-      g_free (user_rules_file_name);
-      g_free (user_dir_name);
-
       /* Set the role of the user. */
 
       if (openvas_set_user_role (name, role))
         {
-          if (remove_recurse (user_dir_name))
+          if (openvas_file_remove_recurse (user_dir_name))
             g_warning ("Could not remove %s while trying to revert changes!",
                        user_dir_name);
           return -1;
@@ -687,7 +550,7 @@
       if (g_file_test (user_dir_name, G_FILE_TEST_EXISTS) &&
           g_file_test (user_dir_name, G_FILE_TEST_IS_DIR))
         {
-          if (remove_recurse (user_dir_name) == 0)
+          if (openvas_file_remove_recurse (user_dir_name) == 0)
             {
               g_free (user_dir_name);
               return 0;



More information about the Openvas-commits mailing list