diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-08-23 00:43:02 +0200 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2013-08-23 00:45:11 +0200 |
commit | 36bb2125d1dbca0ee30fbe29090c4a6a7be37854 (patch) | |
tree | 9d1c3d9c0c1ba305666d6a0aed8e689bab946fc1 /dbus/dbus-transport.c | |
parent | 1809c7ad2a72b7186bbff0180aaae72337055829 (diff) | |
download | dbus-36bb2125d1dbca0ee30fbe29090c4a6a7be37854.tar.gz |
Fix confusion between "is it authenticated?" and "try to authenticate"
Historically, _dbus_transport_get_is_authenticated() has had the
side-effect of trying to advance the authentication state machine (if
there's enough buffered input to do so). This seems an inappropriate
activity for what looks like a simple getter.
Split it into _dbus_transport_try_to_authenticate (which does what it
always used to do) and _dbus_transport_peek_is_authenticated (which
is the simple getter version).
To minimize the difference in behaviour for the stable branch of D-Bus,
I've only used _dbus_transport_peek_is_authenticated where it was used
in an assertion, which should clearly not have side effects (and I've
checked that the asserting function cannot be called until both
authentication and authorization have completed). Replacing most of the
calls to get_is_authenticated with try_to_authenticate is a possible
piece of future work.
Based on patches from Cosimo Alfarano, who noticed this
assertion-with-side-effects.
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
https://bugs.freedesktop.org/show_bug.cgi?id=39720
Reviewed-by: Cosimo Alfarano <cosimo.alfarano@collabora.com>
Diffstat (limited to 'dbus/dbus-transport.c')
-rw-r--r-- | dbus/dbus-transport.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index 47437f21..e68a9f03 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -686,10 +686,33 @@ auth_via_default_rules (DBusTransport *transport) return allow; } +/** + * Returns #TRUE if we have been authenticated. It will return #TRUE even if + * the transport is now disconnected, but was ever authenticated before + * disconnecting. + * + * This replaces the older _dbus_transport_get_is_authenticated() which + * had side-effects. + * + * @param transport the transport + * @returns whether we're authenticated + */ +dbus_bool_t +_dbus_transport_peek_is_authenticated (DBusTransport *transport) +{ + return transport->authenticated; +} /** - * Returns #TRUE if we have been authenticated. Will return #TRUE - * even if the transport is disconnected. + * Returns #TRUE if we have been authenticated. It will return #TRUE even if + * the transport is now disconnected, but was ever authenticated before + * disconnecting. + * + * If we have not finished authenticating, but we have enough buffered input + * to finish the job, then this function will do so before it returns. + * + * This used to be called _dbus_transport_get_is_authenticated(), but that + * name seems inappropriate for a function with side-effects. * * @todo we drop connection->mutex when calling the unix_user_function, * and windows_user_function, which may not be safe really. @@ -698,7 +721,7 @@ auth_via_default_rules (DBusTransport *transport) * @returns whether we're authenticated */ dbus_bool_t -_dbus_transport_get_is_authenticated (DBusTransport *transport) +_dbus_transport_try_to_authenticate (DBusTransport *transport) { if (transport->authenticated) return TRUE; @@ -1085,12 +1108,12 @@ _dbus_transport_get_dispatch_status (DBusTransport *transport) _dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds) return DBUS_DISPATCH_COMPLETE; /* complete for now */ - if (!_dbus_transport_get_is_authenticated (transport)) + if (!_dbus_transport_try_to_authenticate (transport)) { if (_dbus_auth_do_work (transport->auth) == DBUS_AUTH_STATE_WAITING_FOR_MEMORY) return DBUS_DISPATCH_NEED_MEMORY; - else if (!_dbus_transport_get_is_authenticated (transport)) + else if (!_dbus_transport_try_to_authenticate (transport)) return DBUS_DISPATCH_COMPLETE; } |