summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Shaw <joeshaw@novell.com>2003-02-18 22:51:35 +0000
committerJoe Shaw <joeshaw@novell.com>2003-02-18 22:51:35 +0000
commit9ada6e2cad0d623fb578f349790a0c62297d2394 (patch)
tree2925acc28c0d15a6bb8bc78909502035847476b8
parent9e1b2fe28e0f8ef49221113634d8d591d106820d (diff)
2003-02-18 Joe Shaw <joe@assbarn.com>
* dbus/dbus-auth.c (handle_server_data_stupid_test_mech): Just get credentials from our currently running process. (get_word): Fix a buglet where we were copying the entire length instead of relative to our position. * dbus/dbus-hash.c (_dbus_hash_test): Don't try to allocate the keys on the stack... it's 640k of data. * dbus/dbus-sysdeps.c (_dbus_read_credentials_unix_socket): Always read the credentials byte off the socket, even if we don't have SO_PEERCRED. (_dbus_poll): Implement poll() using select() for systems which don't have it. * glib/test-dbus-glib.c (main): Print out an error if no parameters are given. * test/data/auth/fallback.auth-script: Added. Tests that a client can fallback to a secondary auth mechanism if the first fails.
-rw-r--r--AUTHORS3
-rw-r--r--ChangeLog22
-rw-r--r--dbus/dbus-auth.c4
-rw-r--r--dbus/dbus-hash.c90
-rw-r--r--dbus/dbus-sysdeps.c62
-rw-r--r--glib/test-dbus-glib.c7
-rw-r--r--test/data/auth/fallback.auth-script21
7 files changed, 165 insertions, 44 deletions
diff --git a/AUTHORS b/AUTHORS
index 2433009c..649a1703 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -2,4 +2,5 @@ Anders Carlsson <andersca@codefactory.se>
Alex Larsson <alexl@redhat.com>
Havoc Pennington <hp@redhat.com>
Harri Porten <porten@kde.org>
-Zack Rusin <zack@kde.org> \ No newline at end of file
+Zack Rusin <zack@kde.org>
+Joe Shaw <joe@assbarn.com> \ No newline at end of file
diff --git a/ChangeLog b/ChangeLog
index 7a0b1f11..7e41a82e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2003-02-18 Joe Shaw <joe@assbarn.com>
+
+ * dbus/dbus-auth.c (handle_server_data_stupid_test_mech): Just get
+ credentials from our currently running process.
+ (get_word): Fix a buglet where we were copying the entire length
+ instead of relative to our position.
+
+ * dbus/dbus-hash.c (_dbus_hash_test): Don't try to allocate the
+ keys on the stack... it's 640k of data.
+
+ * dbus/dbus-sysdeps.c (_dbus_read_credentials_unix_socket): Always
+ read the credentials byte off the socket, even if we don't have
+ SO_PEERCRED.
+ (_dbus_poll): Implement poll() using select() for systems which
+ don't have it.
+
+ * glib/test-dbus-glib.c (main): Print out an error if no
+ parameters are given.
+
+ * test/data/auth/fallback.auth-script: Added. Tests that a client
+ can fallback to a secondary auth mechanism if the first fails.
+
2003-02-18 Havoc Pennington <hp@pobox.com>
* AUTHORS: add Alex
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c
index dca83ba3..c4e1c5e8 100644
--- a/dbus/dbus-auth.c
+++ b/dbus/dbus-auth.c
@@ -321,6 +321,8 @@ handle_server_data_stupid_test_mech (DBusAuth *auth,
"OK\r\n"))
return FALSE;
+ _dbus_credentials_from_current_process (&auth->authorized_identity);
+
auth->authenticated_pending_begin = TRUE;
return TRUE;
@@ -799,7 +801,7 @@ get_word (const DBusString *str,
if (i > *start)
{
- if (!_dbus_string_copy_len (str, *start, i, word, 0))
+ if (!_dbus_string_copy_len (str, *start, i - *start, word, 0))
return FALSE;
*start = i;
diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c
index d7791d2a..a53c5020 100644
--- a/dbus/dbus-hash.c
+++ b/dbus/dbus-hash.c
@@ -1318,7 +1318,20 @@ _dbus_hash_test (void)
DBusHashTable *table2;
DBusHashIter iter;
#define N_HASH_KEYS 5000
- char keys[N_HASH_KEYS][128];
+ char **keys;
+ dbus_bool_t ret = FALSE;
+
+ keys = dbus_new (char *, N_HASH_KEYS);
+ if (keys == NULL)
+ _dbus_assert_not_reached ("no memory");
+
+ for (i = 0; i < N_HASH_KEYS; i++)
+ {
+ keys[i] = dbus_malloc (128);
+
+ if (keys[i] == NULL)
+ _dbus_assert_not_reached ("no memory");
+ }
printf ("Computing test hash keys...\n");
i = 0;
@@ -1332,12 +1345,12 @@ _dbus_hash_test (void)
table1 = _dbus_hash_table_new (DBUS_HASH_STRING,
dbus_free, dbus_free);
if (table1 == NULL)
- return FALSE;
+ goto out;
table2 = _dbus_hash_table_new (DBUS_HASH_INT,
NULL, dbus_free);
if (table2 == NULL)
- return FALSE;
+ goto out;
/* Insert and remove a bunch of stuff, counting the table in between
* to be sure it's not broken and that iteration works
@@ -1350,22 +1363,22 @@ _dbus_hash_test (void)
key = _dbus_strdup (keys[i]);
if (key == NULL)
- return FALSE;
+ goto out;
value = _dbus_strdup ("Value!");
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_table_insert_string (table1,
key, value))
- return FALSE;
+ goto out;
value = _dbus_strdup (keys[i]);
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_table_insert_int (table2,
i, value))
- return FALSE;
+ goto out;
_dbus_assert (count_entries (table1) == i + 1);
_dbus_assert (count_entries (table2) == i + 1);
@@ -1410,12 +1423,12 @@ _dbus_hash_test (void)
table1 = _dbus_hash_table_new (DBUS_HASH_STRING,
dbus_free, dbus_free);
if (table1 == NULL)
- return FALSE;
+ goto out;
table2 = _dbus_hash_table_new (DBUS_HASH_INT,
NULL, dbus_free);
if (table2 == NULL)
- return FALSE;
+ goto out;
i = 0;
while (i < 5000)
@@ -1425,22 +1438,22 @@ _dbus_hash_test (void)
key = _dbus_strdup (keys[i]);
if (key == NULL)
- return FALSE;
+ goto out;
value = _dbus_strdup ("Value!");
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_table_insert_string (table1,
key, value))
- return FALSE;
+ goto out;
value = _dbus_strdup (keys[i]);
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_table_insert_int (table2,
i, value))
- return FALSE;
+ goto out;
_dbus_assert (count_entries (table1) == i + 1);
_dbus_assert (count_entries (table2) == i + 1);
@@ -1461,7 +1474,7 @@ _dbus_hash_test (void)
value = _dbus_strdup ("Different value!");
if (value == NULL)
- return FALSE;
+ goto out;
_dbus_hash_iter_set_value (&iter, value);
@@ -1489,7 +1502,7 @@ _dbus_hash_test (void)
value = _dbus_strdup ("Different value!");
if (value == NULL)
- return FALSE;
+ goto out;
_dbus_hash_iter_set_value (&iter, value);
@@ -1516,15 +1529,15 @@ _dbus_hash_test (void)
key = _dbus_strdup (keys[i]);
if (key == NULL)
- return FALSE;
+ goto out;
value = _dbus_strdup ("Value!");
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_table_insert_string (table1,
key, value))
- return FALSE;
+ goto out;
++i;
}
@@ -1537,20 +1550,20 @@ _dbus_hash_test (void)
key = _dbus_strdup (keys[i]);
if (key == NULL)
- return FALSE;
+ goto out;
value = _dbus_strdup ("Value!");
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_table_remove_string (table1, keys[i]))
- return FALSE;
+ goto out;
if (!_dbus_hash_table_insert_string (table1,
key, value))
- return FALSE;
+ goto out;
if (!_dbus_hash_table_remove_string (table1, keys[i]))
- return FALSE;
+ goto out;
_dbus_assert (_dbus_hash_table_get_n_entries (table1) == i);
@@ -1568,12 +1581,12 @@ _dbus_hash_test (void)
table1 = _dbus_hash_table_new (DBUS_HASH_STRING,
dbus_free, dbus_free);
if (table1 == NULL)
- return FALSE;
+ goto out;
table2 = _dbus_hash_table_new (DBUS_HASH_INT,
NULL, dbus_free);
if (table2 == NULL)
- return FALSE;
+ goto out;
i = 0;
while (i < 3000)
@@ -1583,24 +1596,24 @@ _dbus_hash_test (void)
key = _dbus_strdup (keys[i]);
if (key == NULL)
- return FALSE;
+ goto out;
value = _dbus_strdup ("Value!");
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_iter_lookup (table1,
key, TRUE, &iter))
- return FALSE;
+ goto out;
_dbus_assert (_dbus_hash_iter_get_value (&iter) == NULL);
_dbus_hash_iter_set_value (&iter, value);
value = _dbus_strdup (keys[i]);
if (value == NULL)
- return FALSE;
+ goto out;
if (!_dbus_hash_iter_lookup (table2,
_DBUS_INT_TO_POINTER (i), TRUE, &iter))
- return FALSE;
+ goto out;
_dbus_assert (_dbus_hash_iter_get_value (&iter) == NULL);
_dbus_hash_iter_set_value (&iter, value);
@@ -1608,7 +1621,7 @@ _dbus_hash_test (void)
_dbus_assert (count_entries (table2) == i + 1);
if (!_dbus_hash_iter_lookup (table1, keys[i], FALSE, &iter))
- return FALSE;
+ goto out;
value = _dbus_hash_iter_get_value (&iter);
_dbus_assert (value != NULL);
@@ -1621,7 +1634,7 @@ _dbus_hash_test (void)
;
if (!_dbus_hash_iter_lookup (table2, _DBUS_INT_TO_POINTER (i), FALSE, &iter))
- return FALSE;
+ goto out;
value = _dbus_hash_iter_get_value (&iter);
_dbus_assert (value != NULL);
@@ -1656,8 +1669,15 @@ _dbus_hash_test (void)
_dbus_hash_table_unref (table1);
_dbus_hash_table_unref (table2);
+ ret = TRUE;
+
+ out:
+ for (i = 0; i < N_HASH_KEYS; i++)
+ dbus_free (keys[i]);
+
+ dbus_free (keys);
- return TRUE;
+ return ret;
}
#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index 1308a6ba..f76c6bd0 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -503,9 +503,9 @@ _dbus_read_credentials_unix_socket (int client_fd,
credentials->uid = -1;
credentials->gid = -1;
-#ifdef SO_PEERCRED
if (read_credentials_byte (client_fd, result))
{
+#ifdef SO_PEERCRED
struct ucred cr;
int cr_len = sizeof (cr);
@@ -525,15 +525,14 @@ _dbus_read_credentials_unix_socket (int client_fd,
_dbus_verbose ("Failed to getsockopt() credentials, returned len %d/%d: %s\n",
cr_len, (int) sizeof (cr), _dbus_strerror (errno));
}
+#else /* !SO_PEERCRED */
+ _dbus_verbose ("Socket credentials not supported on this OS\n");
+#endif
return TRUE;
}
else
return FALSE;
-#else /* !SO_PEERCRED */
- _dbus_verbose ("Socket credentials not supported on this OS\n");
- return TRUE;
-#endif
}
/**
@@ -1052,8 +1051,57 @@ _dbus_poll (DBusPollFD *fds,
return -1;
}
#else /* ! HAVE_POLL */
- _dbus_warn ("need to implement select() fallback for systems with no poll()\n");
- return -1;
+
+ fd_set read_set, write_set, err_set;
+ int max_fd;
+ int i;
+ struct timeval tv;
+ int ready;
+
+ FD_ZERO (&read_set);
+ FD_ZERO (&write_set);
+ FD_ZERO (&err_set);
+
+ for (i = 0; i < n_fds; i++)
+ {
+ DBusPollFD f = fds[i];
+
+ if (f.events & _DBUS_POLLIN)
+ FD_SET (f.fd, &read_set);
+
+ if (f.events & _DBUS_POLLOUT)
+ FD_SET (f.fd, &write_set);
+
+ FD_SET (f.fd, &err_set);
+
+ max_fd = MAX (max_fd, f.fd);
+ }
+
+ tv.tv_sec = timeout_milliseconds / 1000;
+ tv.tv_usec = (timeout_milliseconds % 1000) * 1000;
+
+ ready = select (max_fd + 1, &read_set, &write_set, &err_set, &tv);
+
+ if (ready > 0)
+ {
+ for (i = 0; i < n_fds; i++)
+ {
+ DBusPollFD f = fds[i];
+
+ f.revents = 0;
+
+ if (FD_ISSET (f.fd, &read_set))
+ f.revents |= _DBUS_POLLIN;
+
+ if (FD_ISSET (f.fd, &write_set))
+ f.revents |= _DBUS_POLLOUT;
+
+ if (FD_ISSET (f.fd, &err_set))
+ f.revents |= _DBUS_POLLERR;
+ }
+ }
+
+ return ready;
#endif
}
diff --git a/glib/test-dbus-glib.c b/glib/test-dbus-glib.c
index 085e856c..b1ca2d3c 100644
--- a/glib/test-dbus-glib.c
+++ b/glib/test-dbus-glib.c
@@ -1,3 +1,4 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
#include "dbus-glib.h"
#include <stdio.h>
@@ -10,6 +11,12 @@ main (int argc, char **argv)
GMainLoop *loop;
+ if (argc < 2)
+ {
+ fprintf (stderr, "Give the server address as an argument\n");
+ return 1;
+ }
+
loop = g_main_loop_new (NULL, FALSE);
connection = dbus_connection_open (argv[1], &result);
diff --git a/test/data/auth/fallback.auth-script b/test/data/auth/fallback.auth-script
new file mode 100644
index 00000000..1b8c40f5
--- /dev/null
+++ b/test/data/auth/fallback.auth-script
@@ -0,0 +1,21 @@
+## this tests that a client can fallback to a secondary auth mech
+
+CLIENT
+
+## Will try EXTERNAL by default first without first calling AUTH alone.
+
+EXPECT_COMMAND AUTH
+SEND 'REJECTED EXTERNAL DBUS_STUPID_TEST_MECH'
+
+## Will try EXTERNAL again.
+
+EXPECT_COMMAND AUTH
+SEND 'REJECTED EXTERNAL DBUS_STUPID_TEST_MECH'
+
+## And this time we get DBUS_STUPID_TEST_MECH.
+
+EXPECT_COMMAND AUTH
+SEND 'OK'
+
+EXPECT_COMMAND BEGIN
+EXPECT_STATE AUTHENTICATED