-#ifdef DBUS_AUTHENTICATION
-/* return value is whether we successfully read any new data. */
-static dbus_bool_t
-read_data_into_auth (DBusTransport *transport,
- dbus_bool_t *oom)
-{
- DBusTransportKdbus *socket_transport = (DBusTransportKdbus*) transport;
- DBusString *buffer;
- int bytes_read;
- int *fds, n_fds;
-
- *oom = FALSE;
-
- _dbus_auth_get_buffer (transport->auth, &buffer);
-
- bytes_read = kdbus_read_message(socket_transport, buffer, fds, &n_fds);
-
- _dbus_auth_return_buffer (transport->auth, buffer,
- bytes_read > 0 ? bytes_read : 0);
-
- if (bytes_read > 0)
- {
- _dbus_verbose (" read %d bytes in auth phase\n", bytes_read);
- return TRUE;
- }
- else if (bytes_read < 0)
- {
- /* EINTR already handled for us */
-
- if (_dbus_get_is_errno_enomem ())
- {
- *oom = TRUE;
- }
- else if (_dbus_get_is_errno_eagain_or_ewouldblock ())
- ; /* do nothing, just return FALSE below */
- else
- {
- _dbus_verbose ("Error reading from remote app: %s\n",
- _dbus_strerror_from_errno ());
- do_io_error (transport);
- }
-
- return FALSE;
- }
- else
- {
- _dbus_assert (bytes_read == 0);
-
- _dbus_verbose ("Disconnected from remote app\n");
- do_io_error (transport);
-
- return FALSE;
- }
-}
-
-static int kdbus_send_auth (DBusTransport *transport, const DBusString *buffer)
-{
- int len;
- int bytes_written = -1;
- struct kdbus_msg *msg;
- struct kdbus_item *item;
-
- len = _dbus_string_get_length (buffer);
-// data = _dbus_string_get_const_data_len (buffer, 0, len);
-
- msg = kdbus_init_msg(NULL, 1, 0, FALSE, 0, (DBusTransportKdbus*)transport);
- item = msg->items;
- MSG_ITEM_BUILD_VEC(_dbus_string_get_const_data_len (buffer, 0, len), len);
-
- again:
- if(ioctl(((DBusTransportKdbus*)transport)->fd, KDBUS_CMD_MSG_SEND, msg))
- {
- if(errno == EINTR)
- goto again;
- _dbus_verbose ("Error writing auth: %d, %m\n", errno);
- }
- else
- bytes_written = len;
-
- return bytes_written;
-}
-
-/* Return value is whether we successfully wrote any bytes */
-static dbus_bool_t
-write_data_from_auth (DBusTransport *transport)
-{
-// DBusTransportKdbus *socket_transport = (DBusTransportSocket*) transport;
- int bytes_written;
- const DBusString *buffer;
-
- if (!_dbus_auth_get_bytes_to_send (transport->auth,
- &buffer))
- return FALSE;
-
- bytes_written = kdbus_send_auth (transport, buffer);
-
- if (bytes_written > 0)
- {
- _dbus_auth_bytes_sent (transport->auth, bytes_written);
- return TRUE;
- }
- else if (bytes_written < 0)
- {
- /* EINTR already handled for us */
-
- if (_dbus_get_is_errno_eagain_or_ewouldblock ())
- ;
- else
- {
- _dbus_verbose ("Error writing to remote app: %s\n",
- _dbus_strerror_from_errno ());
- do_io_error (transport);
- }
- }
-
- return FALSE;
-}
-
-/* FALSE on OOM */
-static dbus_bool_t
-exchange_credentials (DBusTransport *transport,
- dbus_bool_t do_reading,
- dbus_bool_t do_writing)
-{
- DBusTransportKdbus *socket_transport = (DBusTransportKdbus*) transport;
- DBusError error = DBUS_ERROR_INIT;
-
- _dbus_verbose ("exchange_credentials: do_reading = %d, do_writing = %d\n",
- do_reading, do_writing);
-
- if (do_writing && transport->send_credentials_pending)
- {
- if (_dbus_send_credentials_socket (socket_transport->fd,
- &error))
- {
- transport->send_credentials_pending = FALSE;
- }
- else
- {
- _dbus_verbose ("Failed to write credentials: %s\n", error.message);
- dbus_error_free (&error);
- do_io_error (transport);
- }
- }
-
- if (do_reading && transport->receive_credentials_pending)
- {
- /* FIXME this can fail due to IO error _or_ OOM, broken
- * (somewhat tricky to fix since the OOM error can be set after
- * we already read the credentials byte, so basically we need to
- * separate reading the byte and storing it in the
- * transport->credentials). Does not really matter for now
- * because storing in credentials never actually fails on unix.
- */
- if (_dbus_read_credentials_socket (socket_transport->fd,
- transport->credentials,
- &error))
- {
- transport->receive_credentials_pending = FALSE;
- }
- else
- {
- _dbus_verbose ("Failed to read credentials %s\n", error.message);
- dbus_error_free (&error);
- do_io_error (transport);
- }
- }
-
- if (!(transport->send_credentials_pending ||
- transport->receive_credentials_pending))
- {
- if (!_dbus_auth_set_credentials (transport->auth,
- transport->credentials))
- return FALSE;
- }
-
- return TRUE;
-}
-