From 01af5ff4101e540a6456bca01d56272e701bea78 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 4 Jan 2003 07:28:54 +0000 Subject: 2003-01-04 Havoc Pennington * test/watch.c (error_handler): make it safe if the error handler is called multiple times (if we s/error handler/disconnect handler/ we should just guarantee it's called only once) * dbus/dbus-transport.c (_dbus_transport_disconnect): call the error handler on disconnect (it's quite possible we should just change the error handler to a "disconnect handler," I'm not sure we have any other meaningful errors) * configure.in: check for getpwnam_r * dbus/dbus-transport.c, dbus/dbus-transport-unix.c, dbus/dbus-auth.c: add credentials support, add EXTERNAL auth mechanism as in SASL spec, using socket credentials * dbus/dbus-sysdeps.c (_dbus_read_credentials_unix_socket): new function (_dbus_send_credentials_unix_socket): new function * dbus/dbus-sysdeps.c (_dbus_accept_unix_socket): rename just dbus_accept() (_dbus_write): only check errno if <0 returned (_dbus_write_two): ditto --- dbus/dbus-transport-unix.c | 62 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'dbus/dbus-transport-unix.c') diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c index dd0c6833..ba1528c4 100644 --- a/dbus/dbus-transport-unix.c +++ b/dbus/dbus-transport-unix.c @@ -123,7 +123,8 @@ check_write_watch (DBusTransport *transport) if (_dbus_transport_get_is_authenticated (transport)) need_write_watch = transport->messages_need_sending; else - need_write_watch = _dbus_auth_do_work (transport->auth) == DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND; + need_write_watch = transport->send_credentials_pending || + _dbus_auth_do_work (transport->auth) == DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND; if (transport->disconnected) need_write_watch = FALSE; @@ -390,16 +391,71 @@ recover_unused_bytes (DBusTransport *transport) do_io_error (transport); } +static void +exchange_credentials (DBusTransport *transport, + dbus_bool_t do_reading, + dbus_bool_t do_writing) +{ + DBusTransportUnix *unix_transport = (DBusTransportUnix*) transport; + + if (do_writing && transport->send_credentials_pending) + { + if (_dbus_send_credentials_unix_socket (unix_transport->fd, + NULL)) + { + transport->send_credentials_pending = FALSE; + } + else + { + _dbus_verbose ("Failed to write credentials\n"); + do_io_error (transport); + } + } + + if (do_reading && transport->receive_credentials_pending) + { + if (_dbus_read_credentials_unix_socket (unix_transport->fd, + &transport->credentials, + NULL)) + { + transport->receive_credentials_pending = FALSE; + } + else + { + _dbus_verbose ("Failed to read credentials\n"); + do_io_error (transport); + } + } + + if (!(transport->send_credentials_pending || + transport->receive_credentials_pending)) + { + _dbus_auth_set_credentials (transport->auth, + &transport->credentials); + } +} + static void do_authentication (DBusTransport *transport, dbus_bool_t do_reading, dbus_bool_t do_writing) -{ +{ _dbus_transport_ref (transport); while (!_dbus_transport_get_is_authenticated (transport) && _dbus_transport_get_is_connected (transport)) { + exchange_credentials (transport, do_reading, do_writing); + + if (transport->send_credentials_pending || + transport->receive_credentials_pending) + { + _dbus_verbose ("send_credentials_pending = %d receive_credentials_pending = %d\n", + transport->send_credentials_pending, + transport->receive_credentials_pending); + goto out; + } + switch (_dbus_auth_do_work (transport->auth)) { case DBUS_AUTH_STATE_WAITING_FOR_INPUT: @@ -963,7 +1019,7 @@ _dbus_transport_new_for_domain_socket (const char *path, close (fd); fd = -1; } - + return transport; } -- cgit