summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-auth-util.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2005-01-17 03:53:40 +0000
committerHavoc Pennington <hp@redhat.com>2005-01-17 03:53:40 +0000
commit7bf62e31a3c820852271768fafc04ba95c31a19f (patch)
tree660d6e210d04143773da2e86d3b3e8dae8be5cc0 /dbus/dbus-auth-util.c
parent4c1a2a760b67b4600db3e5b9c2ad0056b5cf32b6 (diff)
2005-01-16 Havoc Pennington <hp@redhat.com>
This is about it on what can be disabled/deleted from libdbus easily, back below 150K anyhow. Deeper cuts are more work than just turning the code off as I've done here. * dbus/dbus-marshal-basic.c (_dbus_pack_int32): we don't need the signed int convenience funcs * dbus/dbus-internals.c (_dbus_verbose_real): omit when not in verbose mode * dbus/dbus-string-util.c, dbus/dbus-string.c: more breaking things out of libdbus * dbus/dbus-sysdeps.c, dbus/dbus-sysdeps-util.c: same * dbus/dbus-hash.c: purge the TWO_STRINGS crap (well, make it tests-enabled-only, though it should probably be deleted) * dbus/dbus-message-util.c: same stuff * dbus/dbus-auth-util.c: same stuff
Diffstat (limited to 'dbus/dbus-auth-util.c')
-rw-r--r--dbus/dbus-auth-util.c169
1 files changed, 169 insertions, 0 deletions
diff --git a/dbus/dbus-auth-util.c b/dbus/dbus-auth-util.c
new file mode 100644
index 00000000..4d25cf0a
--- /dev/null
+++ b/dbus/dbus-auth-util.c
@@ -0,0 +1,169 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-auth-util.c Would be in dbus-auth.c, but only used for tests/bus
+ *
+ * Copyright (C) 2002, 2003, 2004 Red Hat Inc.
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#include "dbus-internals.h"
+#include "dbus-test.h"
+#include "dbus-auth.h"
+
+/**
+ * @addtogroup DBusAuth
+ * @{
+ */
+
+/** @} */
+
+#ifdef DBUS_BUILD_TESTS
+#include "dbus-test.h"
+#include "dbus-auth-script.h"
+#include <stdio.h>
+
+static dbus_bool_t
+process_test_subdir (const DBusString *test_base_dir,
+ const char *subdir)
+{
+ DBusString test_directory;
+ DBusString filename;
+ DBusDirIter *dir;
+ dbus_bool_t retval;
+ DBusError error;
+
+ retval = FALSE;
+ dir = NULL;
+
+ if (!_dbus_string_init (&test_directory))
+ _dbus_assert_not_reached ("didn't allocate test_directory\n");
+
+ _dbus_string_init_const (&filename, subdir);
+
+ if (!_dbus_string_copy (test_base_dir, 0,
+ &test_directory, 0))
+ _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
+
+ if (!_dbus_concat_dir_and_file (&test_directory, &filename))
+ _dbus_assert_not_reached ("couldn't allocate full path");
+
+ _dbus_string_free (&filename);
+ if (!_dbus_string_init (&filename))
+ _dbus_assert_not_reached ("didn't allocate filename string\n");
+
+ dbus_error_init (&error);
+ dir = _dbus_directory_open (&test_directory, &error);
+ if (dir == NULL)
+ {
+ _dbus_warn ("Could not open %s: %s\n",
+ _dbus_string_get_const_data (&test_directory),
+ error.message);
+ dbus_error_free (&error);
+ goto failed;
+ }
+
+ printf ("Testing %s:\n", subdir);
+
+ next:
+ while (_dbus_directory_get_next_file (dir, &filename, &error))
+ {
+ DBusString full_path;
+
+ if (!_dbus_string_init (&full_path))
+ _dbus_assert_not_reached ("couldn't init string");
+
+ if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
+ _dbus_assert_not_reached ("couldn't copy dir to full_path");
+
+ if (!_dbus_concat_dir_and_file (&full_path, &filename))
+ _dbus_assert_not_reached ("couldn't concat file to dir");
+
+ if (!_dbus_string_ends_with_c_str (&filename, ".auth-script"))
+ {
+ _dbus_verbose ("Skipping non-.auth-script file %s\n",
+ _dbus_string_get_const_data (&filename));
+ _dbus_string_free (&full_path);
+ goto next;
+ }
+
+ printf (" %s\n", _dbus_string_get_const_data (&filename));
+
+ if (!_dbus_auth_script_run (&full_path))
+ {
+ _dbus_string_free (&full_path);
+ goto failed;
+ }
+ else
+ _dbus_string_free (&full_path);
+ }
+
+ if (dbus_error_is_set (&error))
+ {
+ _dbus_warn ("Could not get next file in %s: %s\n",
+ _dbus_string_get_const_data (&test_directory), error.message);
+ dbus_error_free (&error);
+ goto failed;
+ }
+
+ retval = TRUE;
+
+ failed:
+
+ if (dir)
+ _dbus_directory_close (dir);
+ _dbus_string_free (&test_directory);
+ _dbus_string_free (&filename);
+
+ return retval;
+}
+
+static dbus_bool_t
+process_test_dirs (const char *test_data_dir)
+{
+ DBusString test_directory;
+ dbus_bool_t retval;
+
+ retval = FALSE;
+
+ _dbus_string_init_const (&test_directory, test_data_dir);
+
+ if (!process_test_subdir (&test_directory, "auth"))
+ goto failed;
+
+ retval = TRUE;
+
+ failed:
+
+ _dbus_string_free (&test_directory);
+
+ return retval;
+}
+
+dbus_bool_t
+_dbus_auth_test (const char *test_data_dir)
+{
+
+ if (test_data_dir == NULL)
+ return TRUE;
+
+ if (!process_test_dirs (test_data_dir))
+ return FALSE;
+
+ return TRUE;
+}
+
+#endif /* DBUS_BUILD_TESTS */