diff options
author | Joe Shaw <joeshaw@novell.com> | 2003-02-18 22:51:35 +0000 |
---|---|---|
committer | Joe Shaw <joeshaw@novell.com> | 2003-02-18 22:51:35 +0000 |
commit | 9ada6e2cad0d623fb578f349790a0c62297d2394 (patch) | |
tree | 2925acc28c0d15a6bb8bc78909502035847476b8 /dbus | |
parent | 9e1b2fe28e0f8ef49221113634d8d591d106820d (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.
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-auth.c | 4 | ||||
-rw-r--r-- | dbus/dbus-hash.c | 90 | ||||
-rw-r--r-- | dbus/dbus-sysdeps.c | 62 |
3 files changed, 113 insertions, 43 deletions
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 } |