[Openvas-commits] r5756 - in trunk/openvas-administrator: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Oct 29 15:32:26 CET 2009
Author: mattm
Date: 2009-10-29 15:32:25 +0100 (Thu, 29 Oct 2009)
New Revision: 5756
Modified:
trunk/openvas-administrator/ChangeLog
trunk/openvas-administrator/src/admin.c
trunk/openvas-administrator/src/oap.c
trunk/openvas-administrator/src/openvasad.c
trunk/openvas-administrator/src/splint.h
Log:
Cleanup after static analysis.
* src/splint.h: Include gnutls.h and uuid.h.
(g_malloc, g_malloc0): Update types.
(g_dir_read_name, g_dir_close, g_rand_new, g_rand_free, g_strfreev)
(g_key_file_free, g_slist_free, g_string_free, g_option_context_free): New
headers.
* src/oap.c: (oap_xml_handle_end_element): In CLIENT_GET_USERS use a temp
var to iterate over the list and free the list data.
* src/openvasad.c: Include splint.h. Move variable declarations to block
starts.
(main): Work around cpp string concatentation for splint. Free option
context. Free response. Exit with exit on special user fail, like other
cases.
* src/admin.c: Include splint.h. Move variable declarations to block
starts.
(print_preference, print_user, print_user_text) Free temporary string.
(remove_recurse): Free temporary filename.
(openvas_admin_list_users): Add note about freeing element data.
Modified: trunk/openvas-administrator/ChangeLog
===================================================================
--- trunk/openvas-administrator/ChangeLog 2009-10-29 11:52:09 UTC (rev 5755)
+++ trunk/openvas-administrator/ChangeLog 2009-10-29 14:32:25 UTC (rev 5756)
@@ -1,3 +1,28 @@
+2009-10-29 Matthew Mundell <matthew.mundell at intevation.de>
+
+ Cleanup after static analysis.
+
+ * src/splint.h: Include gnutls.h and uuid.h.
+ (g_malloc, g_malloc0): Update types.
+ (g_dir_read_name, g_dir_close, g_rand_new, g_rand_free, g_strfreev)
+ (g_key_file_free, g_slist_free, g_string_free, g_option_context_free): New
+ headers.
+
+ * src/oap.c: (oap_xml_handle_end_element): In CLIENT_GET_USERS use a temp
+ var to iterate over the list and free the list data.
+
+ * src/openvasad.c: Include splint.h. Move variable declarations to block
+ starts.
+ (main): Work around cpp string concatentation for splint. Free option
+ context. Free response. Exit with exit on special user fail, like other
+ cases.
+
+ * src/admin.c: Include splint.h. Move variable declarations to block
+ starts.
+ (print_preference, print_user, print_user_text) Free temporary string.
+ (remove_recurse): Free temporary filename.
+ (openvas_admin_list_users): Add note about freeing element data.
+
2009-10-26 Michael Wiegand <michael.wiegand at intevation.de>
Post release version bump.
Modified: trunk/openvas-administrator/src/admin.c
===================================================================
--- trunk/openvas-administrator/src/admin.c 2009-10-29 11:52:09 UTC (rev 5755)
+++ trunk/openvas-administrator/src/admin.c 2009-10-29 14:32:25 UTC (rev 5756)
@@ -44,6 +44,10 @@
#include <openvas/openvas_auth.h>
+#ifdef S_SPLINT_S
+#include "splint.h"
+#endif
+
#undef G_LOG_DOMAIN
/**
* @brief GLib log domain.
@@ -64,9 +68,11 @@
static void
print_preference (void * key, void * value, void * user_data)
{
- user_data = g_string_append ((GString *) user_data,
- g_markup_printf_escaped ("<preference name=\"%s\">%s</preference>",
- (gchar *) key, (gchar *) value));
+ gchar *xml;
+ xml = g_markup_printf_escaped ("<preference name=\"%s\">%s</preference>",
+ (gchar *) key, (gchar *) value);
+ g_string_append ((GString *) user_data, xml);
+ g_free (xml);
}
/**
@@ -79,9 +85,11 @@
static void
print_user (void * data, void * user_data)
{
- user_data = g_string_append ((GString *) user_data,
- g_markup_printf_escaped ("<user><name>%s</name><rules/></user>",
- (gchar *) data));
+ gchar *xml;
+ xml = g_markup_printf_escaped ("<user><name>%s</name><rules/></user>",
+ (gchar *) data);
+ g_string_append ((GString *) user_data, xml);
+ g_free (xml);
}
/**
@@ -94,8 +102,10 @@
static void
print_user_text (void * data, void * user_data)
{
- user_data = g_string_append ((GString *) user_data,
- g_markup_printf_escaped ("%s\n", (gchar *) data));
+ gchar *xml;
+ xml = g_markup_printf_escaped ("%s\n", (gchar *) data);
+ g_string_append ((GString *) user_data, xml);
+ g_free (xml);
}
/**
@@ -163,7 +173,9 @@
while ((entry = g_dir_read_name (directory)) && (ret == 0))
{
- ret = remove_recurse (g_build_filename (pathname, entry, NULL));
+ 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);
@@ -186,7 +198,8 @@
*
* @return A pointer to a GSList containing the names of the users or NULL if
* the directory could not be opened, did not exist or was not a directory.
- * The list should be freed with g_slist_free() when no longer needed.
+ * The list should be freed with g_slist_free when no longer needed. Each
+ * element of the list should be freed with g_free.
*/
GSList *
openvas_admin_list_users (const gchar * directory)
@@ -210,19 +223,22 @@
{
while ((entry_name = g_dir_read_name (users_dir)))
{
+ gchar *user_hash_filename;
+ gchar *user_dname_filename;
+
if (strcmp (entry_name, "om") == 0) continue;
- gchar *user_hash_filename = g_build_filename (directory, entry_name,
- "auth", "hash", NULL);
- gchar *user_dname_filename = g_build_filename (directory, entry_name,
- "auth", "dname", NULL);
+ user_hash_filename = g_build_filename (directory, entry_name,
+ "auth", "hash", NULL);
+ user_dname_filename = g_build_filename (directory, entry_name,
+ "auth", "dname", NULL);
if (g_file_test (user_hash_filename, G_FILE_TEST_EXISTS))
{
- users = g_slist_append (users, g_strdup(entry_name));
+ users = g_slist_append (users, g_strdup (entry_name));
}
else if (g_file_test (user_dname_filename, G_FILE_TEST_EXISTS))
{
- users = g_slist_append (users, g_strdup(entry_name));
+ users = g_slist_append (users, g_strdup (entry_name));
}
g_free (user_hash_filename);
g_free (user_dname_filename);
@@ -413,6 +429,7 @@
else
{
GError *error = NULL;
+ gchar *hashes_out;
gchar *user_auth_dir_name = g_build_filename (user_dir_name, "auth", NULL);
gchar *user_rules_file_name = g_build_filename (user_auth_dir_name, "rules", NULL);
@@ -442,7 +459,7 @@
return -1;
}
- gchar * hashes_out = get_password_hashes (GCRY_MD_MD5, password);
+ hashes_out = get_password_hashes (GCRY_MD_MD5, password);
if (!g_file_set_contents (user_hash_file_name, hashes_out, -1, &error))
{
Modified: trunk/openvas-administrator/src/oap.c
===================================================================
--- trunk/openvas-administrator/src/oap.c 2009-10-29 11:52:09 UTC (rev 5755)
+++ trunk/openvas-administrator/src/oap.c 2009-10-29 14:32:25 UTC (rev 5756)
@@ -1037,22 +1037,23 @@
case CLIENT_GET_USERS:
{
- GSList *users;
+ GSList *users, *user;
assert (strcasecmp ("GET_USERS", element_name) == 0);
SEND_TO_CLIENT_OR_FAIL ("<get_users_response"
" status=\"" STATUS_OK "\""
" status_text=\"" STATUS_OK_TEXT "\">");
- users = openvas_admin_list_users (users_dir);
- while (users)
+ user = users = openvas_admin_list_users (users_dir);
+ while (user)
{
SENDF_TO_CLIENT_OR_FAIL ("<user>"
"<name>%s</name>"
"<role>%s</role>"
"</user>",
- (gchar*) users->data,
- openvas_is_user_admin (users->data)
+ (gchar*) user->data,
+ openvas_is_user_admin (user->data)
? "Administrator" : "User");
- users = g_slist_next (users);
+ g_free (user->data);
+ user = g_slist_next (user);
}
g_slist_free (users);
SEND_TO_CLIENT_OR_FAIL ("</get_users_response>");
Modified: trunk/openvas-administrator/src/openvasad.c
===================================================================
--- trunk/openvas-administrator/src/openvasad.c 2009-10-29 11:52:09 UTC (rev 5755)
+++ trunk/openvas-administrator/src/openvasad.c 2009-10-29 14:32:25 UTC (rev 5756)
@@ -52,9 +52,11 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
+#ifndef S_SPLINT_S
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
+#endif
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
@@ -66,6 +68,10 @@
#include <openvas_auth.h>
#include <openvas/base/pidfile.h>
+#ifdef S_SPLINT_S
+#include "splint.h"
+#endif
+
/**
* @brief The name of this program.
*
@@ -241,10 +247,11 @@
accept_and_maybe_fork ()
{
/* Accept the client connection. */
+ pid_t pid;
struct sockaddr_in client_address;
- client_address.sin_family = AF_INET;
socklen_t size = sizeof (client_address);
int client_socket;
+ client_address.sin_family = AF_INET;
while ((client_socket = accept (administrator_socket,
(struct sockaddr *) &client_address,
&size))
@@ -264,12 +271,14 @@
#define FORK 1
#if FORK
/* Fork a child to serve the client. */
- pid_t pid = fork ();
+ pid = fork ();
switch (pid)
{
case 0:
/* Child. */
{
+ int ret;
+
#endif /* FORK */
// FIX get flags first
/* The socket must have O_NONBLOCK set, in case an "asynchronous
@@ -287,7 +296,7 @@
/* It's up to serve_client to openvas_server_free on
* client_socket. */
#if FORK
- int ret = serve_client (client_socket);
+ ret = serve_client (client_socket);
#else
serve_client (client_socket);
#endif
@@ -433,12 +442,14 @@
{ "rules-file", 0, 0, G_OPTION_ARG_FILENAME, &rules_file,
"File containing the rules for the user",
"<rules-file>" },
+#ifndef S_SPLINT_S
{ "users-dir", 0, 0, G_OPTION_ARG_FILENAME, &users_dir,
"Directory containing the OpenVAS user data (default: " OPENVAS_USERS_DIR ")",
"<users-dir>" },
{ "config-file", 0, 0, G_OPTION_ARG_FILENAME, &config_file,
"File containing the OpenVAS configuration (default: " OPENVAS_CONFIG_FILE ")",
"<config-file>" },
+#endif /* S_SPLINT_S */
{ NULL }
};
@@ -446,8 +457,10 @@
g_option_context_add_main_entries (option_context, option_entries, NULL);
if (!g_option_context_parse (option_context, &argc, &argv, &error))
{
+ g_option_context_free (option_context);
g_error ("%s\n\n", error->message);
}
+ g_option_context_free (option_context);
/* @todo Check that the options make sense, for example --name needs --command
* and --foreground excludes --name, etc. */
@@ -511,12 +524,14 @@
if (g_strcasecmp (command, "list_users") == 0)
{
GSList *user_list = openvas_admin_list_users (users_dir);
+ g_string_free (response, TRUE);
response = print_users_text (user_list);
g_slist_free (user_list);
}
else if (g_strcasecmp (command, "list_all_prefs") == 0)
{
GHashTable *all_prefs = openvas_admin_list_all_prefs (config_file);
+ g_string_free (response, TRUE);
response = print_preferences_xml (all_prefs);
g_hash_table_destroy (all_prefs);
}
@@ -620,7 +635,7 @@
if (strcmp (name, "om") == 0)
{
g_warning ("Attempt to set role of special \"om\" user.");
- return -1;
+ exit (EXIT_FAILURE);
}
if (openvas_set_user_role (name, role))
{
@@ -886,10 +901,11 @@
* want to communicate with anything else here, like the server?
*/
- int ret, nfds;
- fd_set readfds, exceptfds;
while (1)
{
+ int ret, nfds;
+ fd_set readfds, exceptfds;
+
FD_ZERO (&readfds);
FD_SET (administrator_socket, &readfds);
FD_ZERO (&exceptfds);
Modified: trunk/openvas-administrator/src/splint.h
===================================================================
--- trunk/openvas-administrator/src/splint.h 2009-10-29 11:52:09 UTC (rev 5755)
+++ trunk/openvas-administrator/src/splint.h 2009-10-29 14:32:25 UTC (rev 5756)
@@ -35,11 +35,11 @@
/*@only@*/
gpointer
-g_malloc (gulong n_bytes);
+g_malloc (gsize n_bytes);
/*@only@*/
gpointer
-g_malloc0 (gulong n_bytes);
+g_malloc0 (gsize n_bytes);
void
g_free (/*@only@*/ /*@out@*/ /*@null@*/ gpointer mem);
@@ -100,9 +100,38 @@
/*@notnull@*/ gchar*
g_build_filename (const gchar *first, ...);
+/*@dependent@*/ const gchar*
+g_dir_read_name (GDir *dir);
+
+/*@dependent@*/ const gchar*
+g_dir_close (/*@only@*/ /*@out@*/ GDir *dir);
+
+/*@only@*/ GRand*
+g_rand_new (void);
+
+void
+g_rand_free (/*@only@*/ /*@out@*/ GRand *);
+
+void
+g_strfreev (/*@only@*/ /*@out@*/ gchar **);
+
+void
+g_key_file_free (/*@only@*/ /*@out@*/ GKeyFile *);
+
+void
+g_slist_free (/*@only@*/ /*@out@*/ GSList *);
+
+void
+g_string_free (/*@only@*/ /*@out@*/ GString *, gboolean);
+
+void
+g_option_context_free (/*@only@*/ /*@out@*/ GOptionContext *);
+
/* UUIDS. */
+#include <ossp/uuid.h>
+
/*@shared@*/ char*
uuid_error (uuid_rc_t error);
@@ -119,6 +148,8 @@
/* GNUTLS. */
+#include <gnutls/gnutls.h>
+
/*@owned@*/ const char*
gnutls_alert_get_name (gnutls_alert_description_t alert);
More information about the Openvas-commits
mailing list