[prev in list] [next in list] [prev in thread] [next in thread]
List: openvas-cvs
Subject: [Openvas-commits] r3221 - in trunk/openvas-config-manager: . src
From: scm-commit () wald ! intevation ! org
Date: 2009-04-30 10:13:29
Message-ID: 20090430101329.5801B4089F () pyrosoma ! intevation ! org
[Download RAW message or body]
Author: mwiegand
Date: 2009-04-30 12:13:28 +0200 (Thu, 30 Apr 2009)
New Revision: 3221
Modified:
trunk/openvas-config-manager/ChangeLog
trunk/openvas-config-manager/src/openvascd.c
Log:
Added preliminary support for removing users. This functionality is
currently not exposed pending the implementation of XML parsing.
* src/openvascd.c: (openvas_config_add_user) Free error pointer in the
correct place, don't attempt to free an empty error.
(openvas_config_remove_user) New. This function will remove a user from
the OpenVAS installation. (remove_recurse) New. Helper function to
recursively remove user directories. (check_is_dir) New. Helper function
to determine whether a file is a directory or not.
Modified: trunk/openvas-config-manager/ChangeLog
===================================================================
--- trunk/openvas-config-manager/ChangeLog 2009-04-30 08:39:15 UTC (rev 3220)
+++ trunk/openvas-config-manager/ChangeLog 2009-04-30 10:13:28 UTC (rev 3221)
@@ -1,3 +1,15 @@
+2009-04-30 Michael Wiegand <michael.wiegand@intevation.de>
+
+ Added preliminary support for removing users. This functionality is
+ currently not exposed pending the implementation of XML parsing.
+
+ * src/openvascd.c: (openvas_config_add_user) Free error pointer in the
+ correct place, don't attempt to free an empty error.
+ (openvas_config_remove_user) New. This function will remove a user from
+ the OpenVAS installation. (remove_recurse) New. Helper function to
+ recursively remove user directories. (check_is_dir) New. Helper function
+ to determine whether a file is a directory or not.
+
2009-04-29 Michael Wiegand <michael.wiegand@intevation.de>
* src/openvascd.c: Housekeeping commit. (openvas_config_list_users,
Modified: trunk/openvas-config-manager/src/openvascd.c
===================================================================
--- trunk/openvas-config-manager/src/openvascd.c 2009-04-30 08:39:15 UTC (rev 3220)
+++ trunk/openvas-config-manager/src/openvascd.c 2009-04-30 10:13:28 UTC (rev 3221)
@@ -84,6 +84,15 @@
gchar *
get_password_hashes (int, const gchar *);
+gboolean
+openvas_config_remove_user (gchar *, const gchar *);
+
+int
+remove_recurse (const gchar *);
+
+int
+check_is_dir (const char *);
+
/**
* @brief Convenience function to produce XML output from key/value pairs of
* preferences.
@@ -604,6 +613,7 @@
if (!g_file_set_contents (user_hash_file_name, hashes_out, -1, &error))
{
g_debug ("%s", error->message);
+ g_error_free (error);
return FALSE;
}
g_chmod (user_hash_file_name, 0600);
@@ -612,7 +622,6 @@
g_free (user_auth_dir_name);
g_free (user_rules_dir_name);
g_free (user_hash_file_name);
- g_error_free (error);
g_debug ("User %s created successfully!", name);
g_free (user_dir_name);
@@ -716,3 +725,122 @@
return hashes_out;
}
+
+/**
+ * @brief Removes an user from the OpenVAS installation.
+ *
+ * @param name The name of the user to be removed.
+ * @param directory The directory containing the user directories.
+ *
+ * @return TRUE if the user has been removed successfully, FALSE if not.
+ */
+gboolean
+openvas_config_remove_user (gchar * name, const gchar * directory)
+{
+ if (g_file_test (directory, G_FILE_TEST_EXISTS) &&
+ g_file_test (directory, G_FILE_TEST_IS_DIR))
+ {
+ gchar *user_dir_name = g_build_filename (directory, name, NULL);
+
+ 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)
+ {
+ return TRUE;
+ }
+ else
+ {
+ g_debug ("Failed to remove %s!", user_dir_name);
+ return FALSE;
+ }
+ }
+ else
+ {
+ g_debug ("User %s does not exist!", name);
+ return FALSE;
+ }
+ }
+ else
+ {
+ g_debug ("Could not find %s!", directory);
+ return FALSE;
+ }
+}
+
+/**
+ * @brief Recursively removes files and directories.
+ *
+ * This function will recursively call itself to delete a path and any
+ * contents of this path.
+ *
+ * @param 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.
+ */
+int
+remove_recurse (const gchar * pathname)
+{
+ if (check_is_dir (pathname) == 1)
+ {
+ GError *error = NULL;
+ GDir *directory = g_dir_open (pathname, 0, &error);
+
+ if (directory == NULL)
+ {
+ g_debug ("g_dir_open(%s) failed - %s\n", pathname, error->message);
+ g_error_free (error);
+ // errno should be set when we return -1 to maintain remove()
+ // compatibility.
+ return -1;
+ }
+ else
+ {
+ int ret = 0;
+ const gchar *entry = NULL;
+
+ while ((entry = g_dir_read_name (directory)) && (ret == 0))
+ {
+ ret = remove_recurse (g_build_filename (pathname, entry, NULL));
+ if (ret != 0)
+ {
+ g_debug ("Failed to remove %s from %s!", entry, pathname);
+ return ret;
+ }
+ }
+ }
+ }
+
+ return g_remove (pathname);
+}
+
+/**
+ * @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.
+ *
+ * @return 1 if parameter is directory, 0 if it is not, -1 if it does not
+ * exist or could not be accessed.
+ *
+ * \todo FIXME: handle symbolic links
+ * @TODO Move to other module.
+ */
+int
+check_is_dir (const char* name)
+{
+ struct stat sb;
+
+ if (stat(name, &sb))
+ {
+ return -1;
+ }
+ else
+ {
+ return (S_ISDIR(sb.st_mode));
+ }
+}
+
_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
http://lists.wald.intevation.org/mailman/listinfo/openvas-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic