From 13656b27b5a765520c3f150d77cf00201ca3ffcc Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Wed, 11 Apr 2012 23:05:33 -0400 Subject: [PATCH] Fix DBUS_COOKIE_SHA1 authentication method When libdbus-1 moved to using monotonic time support for the DBUS_COOKIE_SHA1 authentication was broken, in particular interoperability with non-libdbus-1 implementations such as GDBus. The problem is that if monotonic clocks are available, _dbus_get_current_time() will not return the number of seconds since the Epoch as required by the D-Bus spec. If both peers are using libdbus-1 it's not a problem since both ends will use the wrong time and thus agree. However, if the other end is another implementation and following the spec it will not work. The fix is simple - just make libdbus-1 follow the spec and use number of seconds since the epoch. This problem was reported in bug 48580. https://bugs.freedesktop.org/show_bug.cgi?id=48580 Signed-off-by: David Zeuthen --- dbus/dbus-keyring.c | 6 +++--- dbus/dbus-sysdeps-unix.c | 21 +++++++++++++++++++++ dbus/dbus-sysdeps-win.c | 6 ++++++ dbus/dbus-sysdeps.h | 3 +++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/dbus/dbus-keyring.c b/dbus/dbus-keyring.c index 35e8d74..806e622 100644 --- a/dbus/dbus-keyring.c +++ b/dbus/dbus-keyring.c @@ -353,7 +353,7 @@ add_new_key (DBusKey **keys_p, goto out; } - _dbus_get_current_time (×tamp, NULL); + _dbus_get_current_time_real (×tamp, NULL); keys[n_keys-1].id = id; keys[n_keys-1].creation_time = timestamp; @@ -428,7 +428,7 @@ _dbus_keyring_reload (DBusKeyring *keyring, retval = FALSE; have_lock = FALSE; - _dbus_get_current_time (&now, NULL); + _dbus_get_current_time_real (&now, NULL); if (add_new) { @@ -908,7 +908,7 @@ find_recent_key (DBusKeyring *keyring) int i; long tv_sec, tv_usec; - _dbus_get_current_time (&tv_sec, &tv_usec); + _dbus_get_current_time_real (&tv_sec, &tv_usec); i = 0; while (i < keyring->n_keys) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 9fddca7..ad726d8 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -2625,6 +2625,27 @@ _dbus_get_current_time (long *tv_sec, } /** + * Get current time, as in gettimeofday(). Never uses the monotonic + * clock. + * + * @param tv_sec return location for number of seconds + * @param tv_usec return location for number of microseconds (thousandths) + */ +void +_dbus_get_current_time_real (long *tv_sec, + long *tv_usec) +{ + struct timeval t; + + gettimeofday (&t, NULL); + + if (tv_sec) + *tv_sec = t.tv_sec; + if (tv_usec) + *tv_usec = t.tv_usec; +} + +/** * Creates a directory; succeeds if the directory * is created or already existed. * diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index e30e92f..2964bbb 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -1901,6 +1901,12 @@ _dbus_get_current_time (long *tv_sec, *tv_usec = time64 % 1000000; } +void +_dbus_get_current_time_real (long *tv_sec, + long *tv_usec) +{ + return _dbus_get_current_time (tv_sec, tv_usec); +} /** * signal (SIGPIPE, SIG_IGN); diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index f8438f4..eeb6d3d 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -311,6 +311,9 @@ void _dbus_sleep_milliseconds (int milliseconds); void _dbus_get_current_time (long *tv_sec, long *tv_usec); +void _dbus_get_current_time_real (long *tv_sec, + long *tv_usec); + /** * directory interface */ -- 1.7.10