dbus-transport.c
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-transport.c DBusTransport object (internal to D-Bus implementation)
*
* Copyright (C) 2002, 2003 Red Hat Inc.
*
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <config.h>
#include "dbus-transport-protected.h"
#include "dbus-transport-unix.h"
#include "dbus-transport-socket.h"
#include "dbus-connection-internal.h"
#include "dbus-watch.h"
#include "dbus-auth.h"
#include "dbus-address.h"
#include "dbus-credentials.h"
#include "dbus-mainloop.h"
#include "dbus-message.h"
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-server-debug-pipe.h"
#endif
static void
live_messages_notify (DBusCounter *counter,
void *user_data)
{
DBusTransport *transport = user_data;
_dbus_connection_lock (transport->connection);
_dbus_transport_ref (transport);
#if 0
_dbus_verbose ("Size counter value is now %d\n",
(int) _dbus_counter_get_size_value (counter));
_dbus_verbose ("Unix FD counter value is now %d\n",
(int) _dbus_counter_get_unix_fd_value (counter));
#endif
/* disable or re-enable the read watch for the transport if
* required.
*/
if (transport->vtable->live_messages_changed)
{
(* transport->vtable->live_messages_changed) (transport);
}
_dbus_transport_unref (transport);
_dbus_connection_unlock (transport->connection);
}
dbus_bool_t
_dbus_transport_init_base (DBusTransport *transport,
const DBusTransportVTable *vtable,
const DBusString *server_guid,
const DBusString *address)
{
DBusMessageLoader *loader;
DBusAuth *auth;
DBusCounter *counter;
char *address_copy;
DBusCredentials *creds;
loader = _dbus_message_loader_new ();
if (loader == NULL)
return FALSE;
if (server_guid)
auth = _dbus_auth_server_new (server_guid);
else
auth = _dbus_auth_client_new ();
if (auth == NULL)
{
_dbus_message_loader_unref (loader);
return FALSE;
}
counter = _dbus_counter_new ();
if (counter == NULL)
{
_dbus_auth_unref (auth);
_dbus_message_loader_unref (loader);
return FALSE;
}
creds = _dbus_credentials_new ();
if (creds == NULL)
{
_dbus_counter_unref (counter);
_dbus_auth_unref (auth);
_dbus_message_loader_unref (loader);
return FALSE;
}
if (server_guid)
{
_dbus_assert (address == NULL);
address_copy = NULL;
}
else
{
_dbus_assert (address != NULL);
if (!_dbus_string_copy_data (address, &address_copy))
{
_dbus_credentials_unref (creds);
_dbus_counter_unref (counter);
_dbus_auth_unref (auth);
_dbus_message_loader_unref (loader);
return FALSE;
}
}
transport->refcount = 1;
transport->vtable = vtable;
transport->loader = loader;
transport->auth = auth;
transport->live_messages = counter;
transport->authenticated = FALSE;
transport->disconnected = FALSE;
transport->is_server = (server_guid != NULL);
transport->send_credentials_pending = !transport->is_server;
transport->receive_credentials_pending = transport->is_server;
transport->address = address_copy;
transport->unix_user_function = NULL;
transport->unix_user_data = NULL;
transport->free_unix_user_data = NULL;
transport->windows_user_function = NULL;
transport->windows_user_data = NULL;
transport->free_windows_user_data = NULL;
transport->expected_guid = NULL;
/* Try to default to something that won't totally hose the system,
* but doesn't impose too much of a limitation.
*/
transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
/* On Linux RLIMIT_NOFILE defaults to 1024, so allowing 4096 fds live
should be more than enough */
transport->max_live_messages_unix_fds = 4096;
/* credentials read from socket if any */
transport->credentials = creds;
_dbus_counter_set_notify (transport->live_messages,
transport->max_live_messages_size,
transport->max_live_messages_unix_fds,
live_messages_notify,
transport);
if (transport->address)
_dbus_verbose ("Initialized transport on address %s\n", transport->address);
return TRUE;
}
void
_dbus_transport_finalize_base (DBusTransport *transport)
{
if (!transport->disconnected)
_dbus_transport_disconnect (transport);
if (transport->free_unix_user_data != NULL)
(* transport->free_unix_user_data) (transport->unix_user_data);
if (transport->free_windows_user_data != NULL)
(* transport->free_windows_user_data) (transport->windows_user_data);
_dbus_message_loader_unref (transport->loader);
_dbus_auth_unref (transport->auth);
_dbus_counter_set_notify (transport->live_messages,
0, 0, NULL, NULL);
_dbus_counter_unref (transport->live_messages);
dbus_free (transport->address);
dbus_free (transport->expected_guid);
if (transport->credentials)
_dbus_credentials_unref (transport->credentials);
}
static DBusTransport*
check_address (const char *address, DBusError *error)
{
DBusAddressEntry **entries;
DBusTransport *transport = NULL;
int len, i;
_dbus_assert (address != NULL);
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!dbus_parse_address (address, &entries, &len, error))
return NULL; /* not a valid address */
for (i = 0; i < len; i++)
{
dbus_error_free (error);
transport = _dbus_transport_open (entries[i], error);
if (transport != NULL)
break;
}
dbus_address_entries_free (entries);
return transport;
}
static DBusTransport*
_dbus_transport_new_for_autolaunch (const char *scope, DBusError *error)
{
DBusString address;
DBusTransport *result = NULL;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (!_dbus_string_init (&address))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
if (!_dbus_get_autolaunch_address (scope, &address, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto out;
}
result = check_address (_dbus_string_get_const_data (&address), error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, result != NULL);
out:
_dbus_string_free (&address);
return result;
}
static DBusTransportOpenResult
_dbus_transport_open_autolaunch (DBusAddressEntry *entry,
DBusTransport **transport_p,
DBusError *error)
{
const char *method;
method = dbus_address_entry_get_method (entry);
_dbus_assert (method != NULL);
if (strcmp (method, "autolaunch") == 0)
{
const char *scope = dbus_address_entry_get_value (entry, "scope");
*transport_p = _dbus_transport_new_for_autolaunch (scope, error);
if (*transport_p == NULL)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
}
else
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return DBUS_TRANSPORT_OPEN_OK;
}
}
else
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
}
}
static const struct {
DBusTransportOpenResult (* func) (DBusAddressEntry *entry,
DBusTransport **transport_p,
DBusError *error);
} open_funcs[] = {
{ _dbus_transport_open_socket },
{ _dbus_transport_open_unix_socket },
#ifndef _WIN32
{ _dbus_transport_open_unixexec },
#endif
{ _dbus_transport_open_platform_specific },
{ _dbus_transport_open_autolaunch }
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
, { _dbus_transport_open_debug_pipe }
#endif
};
DBusTransport*
_dbus_transport_open (DBusAddressEntry *entry,
DBusError *error)
{
DBusTransport *transport;
const char *expected_guid_orig;
char *expected_guid;
int i;
DBusError tmp_error = DBUS_ERROR_INIT;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
transport = NULL;
expected_guid_orig = dbus_address_entry_get_value (entry, "guid");
expected_guid = _dbus_strdup (expected_guid_orig);
if (expected_guid_orig != NULL && expected_guid == NULL)
{
_DBUS_SET_OOM (error);
return NULL;
}
for (i = 0; i < (int) _DBUS_N_ELEMENTS (open_funcs); ++i)
{
DBusTransportOpenResult result;
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
result = (* open_funcs[i].func) (entry, &transport, &tmp_error);
switch (result)
{
case DBUS_TRANSPORT_OPEN_OK:
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
goto out;
break;
case DBUS_TRANSPORT_OPEN_NOT_HANDLED:
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
/* keep going through the loop of open funcs */
break;
case DBUS_TRANSPORT_OPEN_BAD_ADDRESS:
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
goto out;
break;
case DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT:
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
goto out;
break;
default:
_dbus_assert_not_reached ("invalid transport open result");
break;
}
}
out:
if (transport == NULL)
{
if (!dbus_error_is_set (&tmp_error))
_dbus_set_bad_address (&tmp_error,
NULL, NULL,
"Unknown address type (examples of valid types are \"tcp\" and on UNIX \"unix\")");
_DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
dbus_move_error(&tmp_error, error);
dbus_free (expected_guid);
}
else
{
_DBUS_ASSERT_ERROR_IS_CLEAR (&tmp_error);
/* In the case of autostart the initial guid is NULL
* and the autostart transport recursively calls
* _dbus_open_transport wich returns a transport
* with a guid. That guid is the definitive one.
*
* FIXME: if more transports are added they may have
* an effect on the expected_guid semantics (i.e.
* expected_guid and transport->expected_guid may
* both have values). This is very unlikely though
* we should either throw asserts here for those
* corner cases or refactor the code so it is
* clearer on what is expected and what is not
*/
if(expected_guid)
transport->expected_guid = expected_guid;
}
return transport;
}
DBusTransport *
_dbus_transport_ref (DBusTransport *transport)
{
_dbus_assert (transport->refcount > 0);
transport->refcount += 1;
return transport;
}
void
_dbus_transport_unref (DBusTransport *transport)
{
_dbus_assert (transport != NULL);
_dbus_assert (transport->refcount > 0);
transport->refcount -= 1;
if (transport->refcount == 0)
{
_dbus_verbose ("finalizing\n");
_dbus_assert (transport->vtable->finalize != NULL);
(* transport->vtable->finalize) (transport);
}
}
void
_dbus_transport_disconnect (DBusTransport *transport)
{
_dbus_verbose ("start\n");
_dbus_assert (transport->vtable->disconnect != NULL);
if (transport->disconnected)
return;
(* transport->vtable->disconnect) (transport);
transport->disconnected = TRUE;
_dbus_verbose ("end\n");
}
dbus_bool_t
_dbus_transport_get_is_connected (DBusTransport *transport)
{
return !transport->disconnected;
}
static dbus_bool_t
auth_via_unix_user_function (DBusTransport *transport)
{
DBusCredentials *auth_identity;
dbus_bool_t allow;
DBusConnection *connection;
DBusAllowUnixUserFunction unix_user_function;
void *unix_user_data;
dbus_uid_t uid;
/* Dropping the lock here probably isn't that safe. */
auth_identity = _dbus_auth_get_identity (transport->auth);
_dbus_assert (auth_identity != NULL);
connection = transport->connection;
unix_user_function = transport->unix_user_function;
unix_user_data = transport->unix_user_data;
uid = _dbus_credentials_get_unix_uid (auth_identity);
_dbus_verbose ("unlock\n");
_dbus_connection_unlock (connection);
allow = (* unix_user_function) (connection,
uid,
unix_user_data);
_dbus_verbose ("lock post unix user function\n");
_dbus_connection_lock (connection);
if (allow)
{
_dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", uid);
}
else
{
_dbus_verbose ("Client UID "DBUS_UID_FORMAT
" was rejected, disconnecting\n",
_dbus_credentials_get_unix_uid (auth_identity));
_dbus_transport_disconnect (transport);
}
return allow;
}
static dbus_bool_t
auth_via_windows_user_function (DBusTransport *transport)
{
DBusCredentials *auth_identity;
dbus_bool_t allow;
DBusConnection *connection;
DBusAllowWindowsUserFunction windows_user_function;
void *windows_user_data;
char *windows_sid;
/* Dropping the lock here probably isn't that safe. */
auth_identity = _dbus_auth_get_identity (transport->auth);
_dbus_assert (auth_identity != NULL);
connection = transport->connection;
windows_user_function = transport->windows_user_function;
windows_user_data = transport->unix_user_data;
windows_sid = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
if (windows_sid == NULL)
{
/* OOM */
return FALSE;
}
_dbus_verbose ("unlock\n");
_dbus_connection_unlock (connection);
allow = (* windows_user_function) (connection,
windows_sid,
windows_user_data);
_dbus_verbose ("lock post windows user function\n");
_dbus_connection_lock (connection);
if (allow)
{
_dbus_verbose ("Client SID '%s' authorized\n", windows_sid);
}
else
{
_dbus_verbose ("Client SID '%s' was rejected, disconnecting\n",
_dbus_credentials_get_windows_sid (auth_identity));
_dbus_transport_disconnect (transport);
}
return allow;
}
static dbus_bool_t
auth_via_default_rules (DBusTransport *transport)
{
DBusCredentials *auth_identity;
DBusCredentials *our_identity;
dbus_bool_t allow;
auth_identity = _dbus_auth_get_identity (transport->auth);
_dbus_assert (auth_identity != NULL);
/* By default, connection is allowed if the client is 1) root or 2)
* has the same UID as us or 3) anonymous is allowed.
*/
our_identity = _dbus_credentials_new_from_current_process ();
if (our_identity == NULL)
{
/* OOM */
return FALSE;
}
if (transport->allow_anonymous ||
_dbus_credentials_get_unix_uid (auth_identity) == 0 ||
_dbus_credentials_same_user (our_identity,
auth_identity))
{
if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
_dbus_verbose ("Client authorized as SID '%s'"
"matching our SID '%s'\n",
_dbus_credentials_get_windows_sid(auth_identity),
_dbus_credentials_get_windows_sid(our_identity));
else
_dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
" matching our UID "DBUS_UID_FORMAT"\n",
_dbus_credentials_get_unix_uid(auth_identity),
_dbus_credentials_get_unix_uid(our_identity));
/* We have authenticated! */
allow = TRUE;
}
else
{
if (_dbus_credentials_include(our_identity,DBUS_CREDENTIAL_WINDOWS_SID))
_dbus_verbose ("Client authorized as SID '%s'"
" but our SID is '%s', disconnecting\n",
(_dbus_credentials_get_windows_sid(auth_identity) ?
_dbus_credentials_get_windows_sid(auth_identity) : "<null>"),
(_dbus_credentials_get_windows_sid(our_identity) ?
_dbus_credentials_get_windows_sid(our_identity) : "<null>"));
else
_dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
" but our UID is "DBUS_UID_FORMAT", disconnecting\n",
_dbus_credentials_get_unix_uid(auth_identity),
_dbus_credentials_get_unix_uid(our_identity));
_dbus_transport_disconnect (transport);
allow = FALSE;
}
_dbus_credentials_unref (our_identity);
return allow;
}
dbus_bool_t
_dbus_transport_peek_is_authenticated (DBusTransport *transport)
{
return transport->authenticated;
}
dbus_bool_t
_dbus_transport_try_to_authenticate (DBusTransport *transport)
{
if (transport->authenticated)
return TRUE;
else
{
dbus_bool_t maybe_authenticated;
if (transport->disconnected)
return FALSE;
/* paranoia ref since we call user callbacks sometimes */
_dbus_connection_ref_unlocked (transport->connection);
maybe_authenticated =
(!(transport->send_credentials_pending ||
transport->receive_credentials_pending));
if (maybe_authenticated)
{
switch (_dbus_auth_do_work (transport->auth))
{
case DBUS_AUTH_STATE_AUTHENTICATED:
/* leave as maybe_authenticated */
break;
case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
case DBUS_AUTH_STATE_NEED_DISCONNECT:
maybe_authenticated = FALSE;
break;
case DBUS_AUTH_STATE_INVALID:
default:
_dbus_assert_not_reached ("invalid authentication state");
}
}
/* If we're the client, verify the GUID
*/
if (maybe_authenticated && !transport->is_server)
{
const char *server_guid;
server_guid = _dbus_auth_get_guid_from_server (transport->auth);
_dbus_assert (server_guid != NULL);
if (transport->expected_guid &&
strcmp (transport->expected_guid, server_guid) != 0)
{
_dbus_verbose ("Client expected GUID '%s' and we got '%s' from the server\n",
transport->expected_guid, server_guid);
_dbus_transport_disconnect (transport);
_dbus_connection_unref_unlocked (transport->connection);
return FALSE;
}
}
/* If we're the server, see if we want to allow this identity to proceed.
*/
if (maybe_authenticated && transport->is_server)
{
dbus_bool_t allow;
DBusCredentials *auth_identity;
auth_identity = _dbus_auth_get_identity (transport->auth);
_dbus_assert (auth_identity != NULL);
/* If we have an auth'd user and a user function, delegate
* deciding whether auth credentials are good enough to the
* app; otherwise, use our default decision process.
*/
if (transport->unix_user_function != NULL &&
_dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_UNIX_USER_ID))
{
allow = auth_via_unix_user_function (transport);
}
else if (transport->windows_user_function != NULL &&
_dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_WINDOWS_SID))
{
allow = auth_via_windows_user_function (transport);
}
else
{
allow = auth_via_default_rules (transport);
}
if (!allow)
maybe_authenticated = FALSE;
}
transport->authenticated = maybe_authenticated;
_dbus_connection_unref_unlocked (transport->connection);
return maybe_authenticated;
}
}
dbus_bool_t
_dbus_transport_get_is_anonymous (DBusTransport *transport)
{
DBusCredentials *auth_identity;
if (!transport->authenticated)
return TRUE;
auth_identity = _dbus_auth_get_identity (transport->auth);
if (_dbus_credentials_are_anonymous (auth_identity))
return TRUE;
else
return FALSE;
}
dbus_bool_t
_dbus_transport_can_pass_unix_fd(DBusTransport *transport)
{
return DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport);
}
const char*
_dbus_transport_get_address (DBusTransport *transport)
{
return transport->address;
}
const char*
_dbus_transport_get_server_id (DBusTransport *transport)
{
if (transport->is_server)
return NULL;
else if (transport->authenticated)
return _dbus_auth_get_guid_from_server (transport->auth);
else
return transport->expected_guid;
}
dbus_bool_t
_dbus_transport_handle_watch (DBusTransport *transport,
DBusWatch *watch,
unsigned int condition)
{
dbus_bool_t retval;
_dbus_assert (transport->vtable->handle_watch != NULL);
if (transport->disconnected)
return TRUE;
if (dbus_watch_get_socket (watch) < 0)
{
_dbus_warn_check_failed ("Tried to handle an invalidated watch; this watch should have been removed");
return TRUE;
}
_dbus_watch_sanitize_condition (watch, &condition);
_dbus_transport_ref (transport);
_dbus_watch_ref (watch);
retval = (* transport->vtable->handle_watch) (transport, watch, condition);
_dbus_watch_unref (watch);
_dbus_transport_unref (transport);
return retval;
}
dbus_bool_t
_dbus_transport_set_connection (DBusTransport *transport,
DBusConnection *connection)
{
_dbus_assert (transport->vtable->connection_set != NULL);
_dbus_assert (transport->connection == NULL);
transport->connection = connection;
_dbus_transport_ref (transport);
if (!(* transport->vtable->connection_set) (transport))
transport->connection = NULL;
_dbus_transport_unref (transport);
return transport->connection != NULL;
}
dbus_bool_t
_dbus_transport_get_socket_fd (DBusTransport *transport,
DBusSocket *fd_p)
{
dbus_bool_t retval;
if (transport->vtable->get_socket_fd == NULL)
return FALSE;
if (transport->disconnected)
return FALSE;
_dbus_transport_ref (transport);
retval = (* transport->vtable->get_socket_fd) (transport,
fd_p);
_dbus_transport_unref (transport);
return retval;
}
void
_dbus_transport_do_iteration (DBusTransport *transport,
unsigned int flags,
int timeout_milliseconds)
{
_dbus_assert (transport->vtable->do_iteration != NULL);
_dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",
flags, timeout_milliseconds, !transport->disconnected);
if ((flags & (DBUS_ITERATION_DO_WRITING |
DBUS_ITERATION_DO_READING)) == 0)
return; /* Nothing to do */
if (transport->disconnected)
return;
_dbus_transport_ref (transport);
(* transport->vtable->do_iteration) (transport, flags,
timeout_milliseconds);
_dbus_transport_unref (transport);
_dbus_verbose ("end\n");
}
static dbus_bool_t
recover_unused_bytes (DBusTransport *transport)
{
if (_dbus_auth_needs_decoding (transport->auth))
{
DBusString plaintext;
const DBusString *encoded;
DBusString *buffer;
int orig_len;
if (!_dbus_string_init (&plaintext))
goto nomem;
_dbus_auth_get_unused_bytes (transport->auth,
&encoded);
if (!_dbus_auth_decode_data (transport->auth,
encoded, &plaintext))
{
_dbus_string_free (&plaintext);
goto nomem;
}
_dbus_message_loader_get_buffer (transport->loader,
&buffer,
NULL,
NULL);
orig_len = _dbus_string_get_length (buffer);
if (!_dbus_string_move (&plaintext, 0, buffer,
orig_len))
{
_dbus_string_free (&plaintext);
goto nomem;
}
_dbus_verbose (" %d unused bytes sent to message loader\n",
_dbus_string_get_length (buffer) -
orig_len);
_dbus_message_loader_return_buffer (transport->loader,
buffer);
_dbus_auth_delete_unused_bytes (transport->auth);
_dbus_string_free (&plaintext);
}
else
{
const DBusString *bytes;
DBusString *buffer;
#ifdef DBUS_ENABLE_VERBOSE_MODE
int orig_len;
#endif
dbus_bool_t succeeded;
_dbus_message_loader_get_buffer (transport->loader,
&buffer,
NULL,
NULL);
#ifdef DBUS_ENABLE_VERBOSE_MODE
orig_len = _dbus_string_get_length (buffer);
#endif
_dbus_auth_get_unused_bytes (transport->auth,
&bytes);
succeeded = TRUE;
if (!_dbus_string_copy (bytes, 0, buffer, _dbus_string_get_length (buffer)))
succeeded = FALSE;
_dbus_verbose (" %d unused bytes sent to message loader\n",
_dbus_string_get_length (buffer) -
orig_len);
_dbus_message_loader_return_buffer (transport->loader,
buffer);
if (succeeded)
_dbus_auth_delete_unused_bytes (transport->auth);
else
goto nomem;
}
return TRUE;
nomem:
_dbus_verbose ("Not enough memory to transfer unused bytes from auth conversation\n");
return FALSE;
}
DBusDispatchStatus
_dbus_transport_get_dispatch_status (DBusTransport *transport)
{
if (_dbus_counter_get_size_value (transport->live_messages) >= transport->max_live_messages_size ||
_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_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_try_to_authenticate (transport))
return DBUS_DISPATCH_COMPLETE;
}
if (!transport->unused_bytes_recovered &&
!recover_unused_bytes (transport))
return DBUS_DISPATCH_NEED_MEMORY;
transport->unused_bytes_recovered = TRUE;
if (!_dbus_message_loader_queue_messages (transport->loader))
return DBUS_DISPATCH_NEED_MEMORY;
if (_dbus_message_loader_peek_message (transport->loader) != NULL)
return DBUS_DISPATCH_DATA_REMAINS;
else
return DBUS_DISPATCH_COMPLETE;
}
dbus_bool_t
_dbus_transport_queue_messages (DBusTransport *transport)
{
DBusDispatchStatus status;
#if 0
_dbus_verbose ("enter\n");
#endif
/* Queue any messages */
while ((status = _dbus_transport_get_dispatch_status (transport)) == DBUS_DISPATCH_DATA_REMAINS)
{
DBusMessage *message;
DBusList *link;
link = _dbus_message_loader_pop_message_link (transport->loader);
_dbus_assert (link != NULL);
message = link->data;
_dbus_verbose ("queueing received message %p\n", message);
if (!_dbus_message_add_counter (message, transport->live_messages))
{
_dbus_message_loader_putback_message_link (transport->loader,
link);
status = DBUS_DISPATCH_NEED_MEMORY;
break;
}
else
{
/* We didn't call the notify function when we added the counter, so
* catch up now. Since we have the connection's lock, it's desirable
* that we bypass the notify function and call this virtual method
* directly. */
if (transport->vtable->live_messages_changed)
(* transport->vtable->live_messages_changed) (transport);
/* pass ownership of link and message ref to connection */
_dbus_connection_queue_received_message_link (transport->connection,
link);
}
}
if (_dbus_message_loader_get_is_corrupted (transport->loader))
{
_dbus_verbose ("Corrupted message stream, disconnecting\n");
_dbus_transport_disconnect (transport);
}
return status != DBUS_DISPATCH_NEED_MEMORY;
}
void
_dbus_transport_set_max_message_size (DBusTransport *transport,
long size)
{
_dbus_message_loader_set_max_message_size (transport->loader, size);
}
void
_dbus_transport_set_max_message_unix_fds (DBusTransport *transport,
long n)
{
_dbus_message_loader_set_max_message_unix_fds (transport->loader, n);
}
long
_dbus_transport_get_max_message_size (DBusTransport *transport)
{
return _dbus_message_loader_get_max_message_size (transport->loader);
}
long
_dbus_transport_get_max_message_unix_fds (DBusTransport *transport)
{
return _dbus_message_loader_get_max_message_unix_fds (transport->loader);
}
void
_dbus_transport_set_max_received_size (DBusTransport *transport,
long size)
{
transport->max_live_messages_size = size;
_dbus_counter_set_notify (transport->live_messages,
transport->max_live_messages_size,
transport->max_live_messages_unix_fds,
live_messages_notify,
transport);
}
void
_dbus_transport_set_max_received_unix_fds (DBusTransport *transport,
long n)
{
transport->max_live_messages_unix_fds = n;
_dbus_counter_set_notify (transport->live_messages,
transport->max_live_messages_size,
transport->max_live_messages_unix_fds,
live_messages_notify,
transport);
}
long
_dbus_transport_get_max_received_size (DBusTransport *transport)
{
return transport->max_live_messages_size;
}
long
_dbus_transport_get_max_received_unix_fds (DBusTransport *transport)
{
return transport->max_live_messages_unix_fds;
}
dbus_bool_t
_dbus_transport_get_unix_user (DBusTransport *transport,
unsigned long *uid)
{
DBusCredentials *auth_identity;
*uid = _DBUS_INT32_MAX; /* better than some root or system user in
* case of bugs in the caller. Caller should
* never use this value on purpose, however.
*/
if (!transport->authenticated)
return FALSE;
auth_identity = _dbus_auth_get_identity (transport->auth);
if (_dbus_credentials_include (auth_identity,
DBUS_CREDENTIAL_UNIX_USER_ID))
{
*uid = _dbus_credentials_get_unix_uid (auth_identity);
return TRUE;
}
else
return FALSE;
}
dbus_bool_t
_dbus_transport_get_unix_process_id (DBusTransport *transport,
unsigned long *pid)
{
DBusCredentials *auth_identity;
*pid = DBUS_PID_UNSET; /* Caller should never use this value on purpose,
* but we set it to a safe number, INT_MAX,
* just to root out possible bugs in bad callers.
*/
if (!transport->authenticated)
return FALSE;
auth_identity = _dbus_auth_get_identity (transport->auth);
if (_dbus_credentials_include (auth_identity,
DBUS_CREDENTIAL_UNIX_PROCESS_ID))
{
*pid = _dbus_credentials_get_pid (auth_identity);
return TRUE;
}
else
return FALSE;
}
dbus_bool_t
_dbus_transport_get_adt_audit_session_data (DBusTransport *transport,
void **data,
int *data_size)
{
DBusCredentials *auth_identity;
*data = NULL;
*data_size = 0;
if (!transport->authenticated)
return FALSE;
auth_identity = _dbus_auth_get_identity (transport->auth);
if (_dbus_credentials_include (auth_identity,
DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID))
{
*data = (void *) _dbus_credentials_get_adt_audit_data (auth_identity);
*data_size = _dbus_credentials_get_adt_audit_data_size (auth_identity);
return TRUE;
}
else
return FALSE;
}
void
_dbus_transport_set_unix_user_function (DBusTransport *transport,
DBusAllowUnixUserFunction function,
void *data,
DBusFreeFunction free_data_function,
void **old_data,
DBusFreeFunction *old_free_data_function)
{
*old_data = transport->unix_user_data;
*old_free_data_function = transport->free_unix_user_data;
transport->unix_user_function = function;
transport->unix_user_data = data;
transport->free_unix_user_data = free_data_function;
}
dbus_bool_t
_dbus_transport_get_linux_security_label (DBusTransport *transport,
char **label_p)
{
DBusCredentials *auth_identity;
*label_p = NULL;
if (!transport->authenticated)
return FALSE;
auth_identity = _dbus_auth_get_identity (transport->auth);
if (_dbus_credentials_include (auth_identity,
DBUS_CREDENTIAL_LINUX_SECURITY_LABEL))
{
/* If no memory, we are supposed to return TRUE and set NULL */
*label_p = _dbus_strdup (_dbus_credentials_get_linux_security_label (auth_identity));
return TRUE;
}
else
{
return FALSE;
}
}
DBusCredentials *
_dbus_transport_get_credentials (DBusTransport *transport)
{
if (!transport->authenticated)
return FALSE;
return _dbus_auth_get_identity (transport->auth);
}
dbus_bool_t
_dbus_transport_get_windows_user (DBusTransport *transport,
char **windows_sid_p)
{
DBusCredentials *auth_identity;
*windows_sid_p = NULL;
if (!transport->authenticated)
return FALSE;
auth_identity = _dbus_auth_get_identity (transport->auth);
if (_dbus_credentials_include (auth_identity,
DBUS_CREDENTIAL_WINDOWS_SID))
{
/* If no memory, we are supposed to return TRUE and set NULL */
*windows_sid_p = _dbus_strdup (_dbus_credentials_get_windows_sid (auth_identity));
return TRUE;
}
else
return FALSE;
}
void
_dbus_transport_set_windows_user_function (DBusTransport *transport,
DBusAllowWindowsUserFunction function,
void *data,
DBusFreeFunction free_data_function,
void **old_data,
DBusFreeFunction *old_free_data_function)
{
*old_data = transport->windows_user_data;
*old_free_data_function = transport->free_windows_user_data;
transport->windows_user_function = function;
transport->windows_user_data = data;
transport->free_windows_user_data = free_data_function;
}
dbus_bool_t
_dbus_transport_set_auth_mechanisms (DBusTransport *transport,
const char **mechanisms)
{
return _dbus_auth_set_mechanisms (transport->auth, mechanisms);
}
void
_dbus_transport_set_allow_anonymous (DBusTransport *transport,
dbus_bool_t value)
{
transport->allow_anonymous = value != FALSE;
}
int
_dbus_transport_get_pending_fds_count (DBusTransport *transport)
{
return _dbus_message_loader_get_pending_fds_count (transport->loader);
}
void
_dbus_transport_set_pending_fds_function (DBusTransport *transport,
void (* callback) (void *),
void *data)
{
_dbus_message_loader_set_pending_fds_function (transport->loader,
callback, data);
}
#ifdef DBUS_ENABLE_STATS
void
_dbus_transport_get_stats (DBusTransport *transport,
dbus_uint32_t *queue_bytes,
dbus_uint32_t *queue_fds,
dbus_uint32_t *peak_queue_bytes,
dbus_uint32_t *peak_queue_fds)
{
if (queue_bytes != NULL)
*queue_bytes = _dbus_counter_get_size_value (transport->live_messages);
if (queue_fds != NULL)
*queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages);
if (peak_queue_bytes != NULL)
*peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages);
if (peak_queue_fds != NULL)
*peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages);
}
#endif /* DBUS_ENABLE_STATS */
_dbus_set_bad_address
void _dbus_set_bad_address(DBusError *error, const char *address_problem_type, const char *address_problem_field, const char *address_problem_other)
Sets DBUS_ERROR_BAD_ADDRESS.
Definition dbus-address.c:70
dbus_address_entries_free
void dbus_address_entries_free(DBusAddressEntry **entries)
Frees a NULL-terminated array of address entries.
Definition dbus-address.c:194
dbus_parse_address
dbus_bool_t dbus_parse_address(const char *address, DBusAddressEntry ***entry_result, int *array_len, DBusError *error)
Parses an address string of the form:
Definition dbus-address.c:368
dbus_address_entry_get_method
const char * dbus_address_entry_get_method(DBusAddressEntry *entry)
Returns the method string of an address entry.
Definition dbus-address.c:232
dbus_address_entry_get_value
const char * dbus_address_entry_get_value(DBusAddressEntry *entry, const char *key)
Returns a value from a key of an entry.
Definition dbus-address.c:249
_dbus_auth_do_work
DBusAuthState _dbus_auth_do_work(DBusAuth *auth)
Analyzes buffered input and moves the auth conversation forward, returning the new state of the auth ...
Definition dbus-auth.c:2548
_dbus_auth_get_identity
DBusCredentials * _dbus_auth_get_identity(DBusAuth *auth)
Gets the identity we authorized the client as.
Definition dbus-auth.c:2848
_dbus_auth_decode_data
dbus_bool_t _dbus_auth_decode_data(DBusAuth *auth, const DBusString *encoded, DBusString *plaintext)
Called post-authentication, decodes a block of bytes received from the peer.
Definition dbus-auth.c:2798
_dbus_auth_unref
void _dbus_auth_unref(DBusAuth *auth)
Decrements the refcount of an auth object.
Definition dbus-auth.c:2463
_dbus_auth_set_mechanisms
dbus_bool_t _dbus_auth_set_mechanisms(DBusAuth *auth, const char **mechanisms)
Sets an array of authentication mechanism names that we are willing to use.
Definition dbus-auth.c:2513
_dbus_auth_delete_unused_bytes
void _dbus_auth_delete_unused_bytes(DBusAuth *auth)
Gets rid of unused bytes returned by _dbus_auth_get_unused_bytes() after we've gotten them and succes...
Definition dbus-auth.c:2691
_dbus_auth_get_guid_from_server
const char * _dbus_auth_get_guid_from_server(DBusAuth *auth)
Gets the GUID from the server if we've authenticated; gets NULL otherwise.
Definition dbus-auth.c:2872
_dbus_auth_needs_decoding
dbus_bool_t _dbus_auth_needs_decoding(DBusAuth *auth)
Called post-authentication, indicates whether we need to decode the message stream with _dbus_auth_de...
Definition dbus-auth.c:2767
_dbus_auth_client_new
DBusAuth * _dbus_auth_client_new(void)
Creates a new auth conversation object for the client side.
Definition dbus-auth.c:2410
_dbus_auth_server_new
DBusAuth * _dbus_auth_server_new(const DBusString *guid)
Creates a new auth conversation object for the server side.
Definition dbus-auth.c:2364
_dbus_auth_get_unused_bytes
void _dbus_auth_get_unused_bytes(DBusAuth *auth, const DBusString **str)
Returns leftover bytes that were not used as part of the auth conversation.
Definition dbus-auth.c:2674
_dbus_connection_unlock
DBUS_PRIVATE_EXPORT void _dbus_connection_unlock(DBusConnection *connection)
Releases the connection lock.
Definition dbus-connection.c:403
_dbus_connection_lock
DBUS_PRIVATE_EXPORT void _dbus_connection_lock(DBusConnection *connection)
Acquires the connection lock.
Definition dbus-connection.c:392
_dbus_connection_unref_unlocked
DBUS_PRIVATE_EXPORT void _dbus_connection_unref_unlocked(DBusConnection *connection)
Decrements the reference count of a DBusConnection.
Definition dbus-connection.c:1447
_dbus_connection_queue_received_message_link
void _dbus_connection_queue_received_message_link(DBusConnection *connection, DBusList *link)
Adds a message-containing list link to the incoming message queue, taking ownership of the link and t...
Definition dbus-connection.c:484
_dbus_connection_ref_unlocked
DBUS_PRIVATE_EXPORT DBusConnection * _dbus_connection_ref_unlocked(DBusConnection *connection)
Increments the reference count of a DBusConnection.
Definition dbus-connection.c:1424
DBusAllowUnixUserFunction
dbus_bool_t(* DBusAllowUnixUserFunction)(DBusConnection *connection, unsigned long uid, void *data)
Called during authentication to check whether the given UNIX user ID is allowed to connect,...
Definition dbus-connection.h:146
DBusDispatchStatus
DBusDispatchStatus
Indicates the status of incoming data on a DBusConnection.
Definition dbus-connection.h:83
DBusAllowWindowsUserFunction
dbus_bool_t(* DBusAllowWindowsUserFunction)(DBusConnection *connection, const char *user_sid, void *data)
Called during authentication to check whether the given Windows user ID is allowed to connect,...
Definition dbus-connection.h:156
DBUS_DISPATCH_NEED_MEMORY
@ DBUS_DISPATCH_NEED_MEMORY
More memory is needed to continue.
Definition dbus-connection.h:86
DBUS_DISPATCH_COMPLETE
@ DBUS_DISPATCH_COMPLETE
All currently available data has been processed.
Definition dbus-connection.h:85
DBUS_DISPATCH_DATA_REMAINS
@ DBUS_DISPATCH_DATA_REMAINS
There is more data to potentially convert to messages.
Definition dbus-connection.h:84
_dbus_credentials_include
dbus_bool_t _dbus_credentials_include(DBusCredentials *credentials, DBusCredentialType type)
Checks whether the given credential is present.
Definition dbus-credentials.c:365
_dbus_credentials_same_user
dbus_bool_t _dbus_credentials_same_user(DBusCredentials *credentials, DBusCredentials *other_credentials)
Check whether the user-identifying credentials in two credentials objects are identical.
Definition dbus-credentials.c:747
_dbus_credentials_get_unix_uid
dbus_uid_t _dbus_credentials_get_unix_uid(DBusCredentials *credentials)
Gets the UNIX user ID in the credentials, or DBUS_UID_UNSET if the credentials object doesn't contain...
Definition dbus-credentials.c:440
_dbus_credentials_new_from_current_process
DBusCredentials * _dbus_credentials_new_from_current_process(void)
Creates a new object with the most important credentials (user ID and process ID) from the current pr...
Definition dbus-credentials.c:113
_dbus_credentials_new
DBusCredentials * _dbus_credentials_new(void)
Creates a new credentials object.
Definition dbus-credentials.c:86
_dbus_credentials_get_adt_audit_data
void * _dbus_credentials_get_adt_audit_data(DBusCredentials *credentials)
Gets the ADT audit data in the credentials, or NULL if the credentials object doesn't contain ADT aud...
Definition dbus-credentials.c:479
_dbus_credentials_get_linux_security_label
const char * _dbus_credentials_get_linux_security_label(DBusCredentials *credentials)
Gets the Linux security label (as used by LSMs) from the credentials, or NULL if the credentials obje...
Definition dbus-credentials.c:466
_dbus_credentials_unref
void _dbus_credentials_unref(DBusCredentials *credentials)
Decrement refcount on credentials.
Definition dbus-credentials.c:148
_dbus_credentials_get_pid
dbus_pid_t _dbus_credentials_get_pid(DBusCredentials *credentials)
Gets the UNIX process ID in the credentials, or DBUS_PID_UNSET if the credentials object doesn't cont...
Definition dbus-credentials.c:401
_dbus_credentials_get_adt_audit_data_size
dbus_int32_t _dbus_credentials_get_adt_audit_data_size(DBusCredentials *credentials)
Gets the ADT audit data size in the credentials, or 0 if the credentials object doesn't contain ADT a...
Definition dbus-credentials.c:492
_dbus_credentials_get_windows_sid
const char * _dbus_credentials_get_windows_sid(DBusCredentials *credentials)
Gets the Windows user SID in the credentials, or NULL if the credentials object doesn't contain a Win...
Definition dbus-credentials.c:453
_dbus_credentials_are_anonymous
dbus_bool_t _dbus_credentials_are_anonymous(DBusCredentials *credentials)
Checks whether a credentials object contains a user identity.
Definition dbus-credentials.c:558
DBUS_ERROR_INIT
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
Definition dbus-errors.h:64
dbus_move_error
void dbus_move_error(DBusError *src, DBusError *dest)
Moves an error src into dest, freeing src and overwriting dest.
Definition dbus-errors.c:281
dbus_set_error
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
Definition dbus-errors.c:356
dbus_error_free
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
Definition dbus-errors.c:213
dbus_error_is_set
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).
Definition dbus-errors.c:331
_dbus_assert_not_reached
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
Definition dbus-internals.h:164
_dbus_assert
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
Definition dbus-internals.h:153
_dbus_warn_check_failed
void _dbus_warn_check_failed(const char *format,...)
Prints a "critical" warning to stderr when an assertion fails; differs from _dbus_warn primarily in t...
Definition dbus-internals.c:310
_dbus_strdup
char * _dbus_strdup(const char *str)
Duplicates a string.
Definition dbus-internals.c:621
_DBUS_N_ELEMENTS
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
Definition dbus-internals.h:189
_DBUS_INT32_MAX
#define _DBUS_INT32_MAX
Maximum value of type "int32".
Definition dbus-internals.h:323
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
Definition dbus-macros.h:51
TRUE
#define TRUE
Expands to "1".
Definition dbus-macros.h:41
FALSE
#define FALSE
Expands to "0".
Definition dbus-macros.h:44
dbus_free
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition dbus-memory.c:710
DBusFreeFunction
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
Definition dbus-memory.h:65
_dbus_message_loader_set_max_message_size
void _dbus_message_loader_set_max_message_size(DBusMessageLoader *loader, long size)
Sets the maximum size message we allow.
Definition dbus-message.c:4843
_dbus_message_loader_get_is_corrupted
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_get_is_corrupted(DBusMessageLoader *loader)
Checks whether the loader is confused due to bad data.
Definition dbus-message.c:4814
_dbus_message_loader_unref
DBUS_PRIVATE_EXPORT void _dbus_message_loader_unref(DBusMessageLoader *loader)
Decrements the reference count of the loader and finalizes the loader when the count reaches zero.
Definition dbus-message.c:4239
_dbus_message_loader_set_pending_fds_function
void _dbus_message_loader_set_pending_fds_function(DBusMessageLoader *loader, void(*callback)(void *), void *data)
Register a function to be called whenever the number of pending file descriptors in the loader change...
Definition dbus-message.c:4922
_dbus_message_loader_putback_message_link
void _dbus_message_loader_putback_message_link(DBusMessageLoader *loader, DBusList *link)
Returns a popped message link, used to undo a pop.
Definition dbus-message.c:4798
_dbus_message_loader_get_pending_fds_count
int _dbus_message_loader_get_pending_fds_count(DBusMessageLoader *loader)
Return how many file descriptors are pending in the loader.
Definition dbus-message.c:4904
_dbus_message_loader_get_buffer
DBUS_PRIVATE_EXPORT void _dbus_message_loader_get_buffer(DBusMessageLoader *loader, DBusString **buffer, int *max_to_read, dbus_bool_t *may_read_unix_fds)
Gets the buffer to use for reading data from the network.
Definition dbus-message.c:4274
_dbus_message_add_counter
dbus_bool_t _dbus_message_add_counter(DBusMessage *message, DBusCounter *counter)
Adds a counter to be incremented immediately with the size/unix fds of this message,...
Definition dbus-message.c:376
_dbus_message_loader_peek_message
DBusMessage * _dbus_message_loader_peek_message(DBusMessageLoader *loader)
Peeks at first loaded message, returns NULL if no messages have been queued.
Definition dbus-message.c:4755
_dbus_message_loader_set_max_message_unix_fds
void _dbus_message_loader_set_max_message_unix_fds(DBusMessageLoader *loader, long n)
Sets the maximum unix fds per message we allow.
Definition dbus-message.c:4874
_dbus_message_loader_get_max_message_size
DBUS_PRIVATE_EXPORT long _dbus_message_loader_get_max_message_size(DBusMessageLoader *loader)
Gets the maximum allowed message size in bytes.
Definition dbus-message.c:4862
_dbus_message_loader_new
DBUS_PRIVATE_EXPORT DBusMessageLoader * _dbus_message_loader_new(void)
Creates a new message loader.
Definition dbus-message.c:4177
_dbus_message_loader_pop_message_link
DBusList * _dbus_message_loader_pop_message_link(DBusMessageLoader *loader)
Pops a loaded message inside a list link (passing ownership of the message and link to the caller).
Definition dbus-message.c:4786
_dbus_message_loader_queue_messages
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_message_loader_queue_messages(DBusMessageLoader *loader)
Converts buffered data into messages, if we have enough data.
Definition dbus-message.c:4692
_dbus_message_loader_return_buffer
DBUS_PRIVATE_EXPORT void _dbus_message_loader_return_buffer(DBusMessageLoader *loader, DBusString *buffer)
Returns a buffer obtained from _dbus_message_loader_get_buffer(), indicating to the loader how many b...
Definition dbus-message.c:4380
_dbus_message_loader_get_max_message_unix_fds
long _dbus_message_loader_get_max_message_unix_fds(DBusMessageLoader *loader)
Gets the maximum allowed number of unix fds per message.
Definition dbus-message.c:4893
DBUS_ERROR_NO_MEMORY
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
Definition dbus-protocol.h:363
_dbus_counter_set_notify
void _dbus_counter_set_notify(DBusCounter *counter, long size_guard_value, long unix_fd_guard_value, DBusCounterNotifyFunction function, void *user_data)
Sets the notify function for this counter; the notify function is called whenever the counter's value...
Definition dbus-resources.c:313
_dbus_counter_new
DBusCounter * _dbus_counter_new(void)
Creates a new DBusCounter.
Definition dbus-resources.c:91
_dbus_counter_get_unix_fd_value
long _dbus_counter_get_unix_fd_value(DBusCounter *counter)
Gets the current value of the unix fd counter.
Definition dbus-resources.c:292
_dbus_counter_unref
void _dbus_counter_unref(DBusCounter *counter)
Decrements refcount of the counter and possibly finalizes the counter.
Definition dbus-resources.c:138
_dbus_counter_get_size_value
long _dbus_counter_get_size_value(DBusCounter *counter)
Gets the current value of the size counter.
Definition dbus-resources.c:276
_dbus_string_init
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
Definition dbus-string.c:182
_dbus_string_copy
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that's copied to the d...
Definition dbus-string.c:1345
_dbus_string_free
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as _DBUS_STRING_IN...
Definition dbus-string.c:278
_dbus_string_copy_data
dbus_bool_t _dbus_string_copy_data(const DBusString *str, char **data_return)
Copies the data from the string into a char*.
Definition dbus-string.c:717
_dbus_string_move
dbus_bool_t _dbus_string_move(DBusString *source, int start, DBusString *dest, int insert_at)
Moves the end of one string into another string.
Definition dbus-string.c:1321
dbus_uid_t
unsigned long dbus_uid_t
A user ID.
Definition dbus-sysdeps.h:141
DBUS_PID_UNSET
#define DBUS_PID_UNSET
an invalid PID used to represent an uninitialized dbus_pid_t field
Definition dbus-sysdeps.h:146
DBUS_UID_FORMAT
#define DBUS_UID_FORMAT
an appropriate printf format for dbus_uid_t
Definition dbus-sysdeps.h:155
_dbus_get_autolaunch_address
dbus_bool_t _dbus_get_autolaunch_address(const char *scope, DBusString *address, DBusError *error)
Returns the address of a new session bus.
Definition dbus-sysdeps-unix.c:4299
_dbus_transport_open_socket
DBusTransportOpenResult _dbus_transport_open_socket(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens a TCP socket transport.
Definition dbus-transport-socket.c:1457
_dbus_transport_open_unix_socket
DBusTransportOpenResult _dbus_transport_open_unix_socket(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens a UNIX socket transport.
Definition dbus-transport-socket.c:1584
_dbus_transport_open_platform_specific
DBusTransportOpenResult _dbus_transport_open_platform_specific(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error)
Opens platform specific transport types.
Definition dbus-transport-win.c:52
_dbus_transport_set_max_message_size
void _dbus_transport_set_max_message_size(DBusTransport *transport, long size)
See dbus_connection_set_max_message_size().
Definition dbus-transport.c:1225
_dbus_transport_set_max_received_size
void _dbus_transport_set_max_received_size(DBusTransport *transport, long size)
See dbus_connection_set_max_received_size().
Definition dbus-transport.c:1275
_dbus_transport_get_dispatch_status
DBusDispatchStatus _dbus_transport_get_dispatch_status(DBusTransport *transport)
Reports our current dispatch status (whether there's buffered data to be queued as messages,...
Definition dbus-transport.c:1127
_dbus_transport_set_auth_mechanisms
dbus_bool_t _dbus_transport_set_auth_mechanisms(DBusTransport *transport, const char **mechanisms)
Sets the SASL authentication mechanisms supported by this transport.
Definition dbus-transport.c:1565
_dbus_transport_get_pending_fds_count
int _dbus_transport_get_pending_fds_count(DBusTransport *transport)
Return how many file descriptors are pending in the loader.
Definition dbus-transport.c:1590
_dbus_transport_get_adt_audit_session_data
dbus_bool_t _dbus_transport_get_adt_audit_session_data(DBusTransport *transport, void **data, int *data_size)
See dbus_connection_get_adt_audit_session_data().
Definition dbus-transport.c:1403
_dbus_transport_get_windows_user
dbus_bool_t _dbus_transport_get_windows_user(DBusTransport *transport, char **windows_sid_p)
See dbus_connection_get_windows_user().
Definition dbus-transport.c:1505
_dbus_transport_queue_messages
dbus_bool_t _dbus_transport_queue_messages(DBusTransport *transport)
Processes data we've read while handling a watch, potentially converting some of it to messages and q...
Definition dbus-transport.c:1166
_dbus_transport_get_socket_fd
dbus_bool_t _dbus_transport_get_socket_fd(DBusTransport *transport, DBusSocket *fd_p)
Get the socket file descriptor, if any.
Definition dbus-transport.c:969
_dbus_transport_get_address
const char * _dbus_transport_get_address(DBusTransport *transport)
Gets the address of a transport.
Definition dbus-transport.c:874
_dbus_transport_handle_watch
dbus_bool_t _dbus_transport_handle_watch(DBusTransport *transport, DBusWatch *watch, unsigned int condition)
Handles a watch by reading data, writing data, or disconnecting the transport, as appropriate for the...
Definition dbus-transport.c:907
_dbus_transport_ref
DBusTransport * _dbus_transport_ref(DBusTransport *transport)
Increments the reference count for the transport.
Definition dbus-transport.c:469
_dbus_transport_peek_is_authenticated
dbus_bool_t _dbus_transport_peek_is_authenticated(DBusTransport *transport)
Returns TRUE if we have been authenticated.
Definition dbus-transport.c:710
_dbus_transport_set_allow_anonymous
void _dbus_transport_set_allow_anonymous(DBusTransport *transport, dbus_bool_t value)
See dbus_connection_set_allow_anonymous().
Definition dbus-transport.c:1578
_dbus_transport_disconnect
void _dbus_transport_disconnect(DBusTransport *transport)
Closes our end of the connection to a remote application.
Definition dbus-transport.c:511
_dbus_transport_get_max_received_size
long _dbus_transport_get_max_received_size(DBusTransport *transport)
See dbus_connection_get_max_received_size().
Definition dbus-transport.c:1311
_dbus_transport_get_credentials
DBusCredentials * _dbus_transport_get_credentials(DBusTransport *transport)
If the transport has already been authenticated, return its credentials.
Definition dbus-transport.c:1489
_dbus_transport_set_connection
dbus_bool_t _dbus_transport_set_connection(DBusTransport *transport, DBusConnection *connection)
Sets the connection using this transport.
Definition dbus-transport.c:945
_dbus_transport_set_unix_user_function
void _dbus_transport_set_unix_user_function(DBusTransport *transport, DBusAllowUnixUserFunction function, void *data, DBusFreeFunction free_data_function, void **old_data, DBusFreeFunction *old_free_data_function)
See dbus_connection_set_unix_user_function().
Definition dbus-transport.c:1439
_dbus_transport_get_max_message_unix_fds
long _dbus_transport_get_max_message_unix_fds(DBusTransport *transport)
See dbus_connection_get_max_message_unix_fds().
Definition dbus-transport.c:1263
_dbus_transport_init_base
dbus_bool_t _dbus_transport_init_base(DBusTransport *transport, const DBusTransportVTable *vtable, const DBusString *server_guid, const DBusString *address)
Initializes the base class members of DBusTransport.
Definition dbus-transport.c:104
_dbus_transport_set_max_received_unix_fds
void _dbus_transport_set_max_received_unix_fds(DBusTransport *transport, long n)
See dbus_connection_set_max_received_unix_fds().
Definition dbus-transport.c:1293
_dbus_transport_unref
void _dbus_transport_unref(DBusTransport *transport)
Decrements the reference count for the transport.
Definition dbus-transport.c:486
_dbus_transport_can_pass_unix_fd
dbus_bool_t _dbus_transport_can_pass_unix_fd(DBusTransport *transport)
Returns TRUE if the transport supports sending unix fds.
Definition dbus-transport.c:861
_dbus_transport_try_to_authenticate
dbus_bool_t _dbus_transport_try_to_authenticate(DBusTransport *transport)
Returns TRUE if we have been authenticated.
Definition dbus-transport.c:733
_dbus_transport_do_iteration
void _dbus_transport_do_iteration(DBusTransport *transport, unsigned int flags, int timeout_milliseconds)
Performs a single poll()/select() on the transport's file descriptors and then reads/writes data as a...
Definition dbus-transport.c:1002
_dbus_transport_get_max_received_unix_fds
long _dbus_transport_get_max_received_unix_fds(DBusTransport *transport)
See dbus_connection_set_max_received_unix_fds().
Definition dbus-transport.c:1323
_dbus_transport_get_is_connected
dbus_bool_t _dbus_transport_get_is_connected(DBusTransport *transport)
Returns TRUE if the transport has not been disconnected.
Definition dbus-transport.c:536
_dbus_transport_set_max_message_unix_fds
void _dbus_transport_set_max_message_unix_fds(DBusTransport *transport, long n)
See dbus_connection_set_max_message_unix_fds().
Definition dbus-transport.c:1238
_dbus_transport_set_pending_fds_function
void _dbus_transport_set_pending_fds_function(DBusTransport *transport, void(*callback)(void *), void *data)
Register a function to be called whenever the number of pending file descriptors in the loader change...
Definition dbus-transport.c:1603
_dbus_transport_set_windows_user_function
void _dbus_transport_set_windows_user_function(DBusTransport *transport, DBusAllowWindowsUserFunction function, void *data, DBusFreeFunction free_data_function, void **old_data, DBusFreeFunction *old_free_data_function)
See dbus_connection_set_windows_user_function().
Definition dbus-transport.c:1541
_dbus_transport_get_max_message_size
long _dbus_transport_get_max_message_size(DBusTransport *transport)
See dbus_connection_get_max_message_size().
Definition dbus-transport.c:1251
_dbus_transport_get_unix_process_id
dbus_bool_t _dbus_transport_get_unix_process_id(DBusTransport *transport, unsigned long *pid)
See dbus_connection_get_unix_process_id().
Definition dbus-transport.c:1369
_dbus_transport_open
DBusTransport * _dbus_transport_open(DBusAddressEntry *entry, DBusError *error)
Try to open a new transport for the given address entry.
Definition dbus-transport.c:373
_dbus_transport_get_server_id
const char * _dbus_transport_get_server_id(DBusTransport *transport)
Gets the id of the server we are connected to (see dbus_server_get_id()).
Definition dbus-transport.c:887
_dbus_transport_get_is_anonymous
dbus_bool_t _dbus_transport_get_is_anonymous(DBusTransport *transport)
See dbus_connection_get_is_anonymous().
Definition dbus-transport.c:839
_dbus_transport_finalize_base
void _dbus_transport_finalize_base(DBusTransport *transport)
Finalizes base class members of DBusTransport.
Definition dbus-transport.c:218
_dbus_transport_get_unix_user
dbus_bool_t _dbus_transport_get_unix_user(DBusTransport *transport, unsigned long *uid)
See dbus_connection_get_unix_user().
Definition dbus-transport.c:1336
dbus_uint32_t
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
Definition dbus-arch-deps.h:45
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition dbus-types.h:37
_dbus_watch_sanitize_condition
void _dbus_watch_sanitize_condition(DBusWatch *watch, unsigned int *condition)
Sanitizes the given condition so that it only contains flags that the DBusWatch requested.
Definition dbus-watch.c:187
_dbus_watch_ref
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object.
Definition dbus-watch.c:126
_dbus_watch_unref
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
Definition dbus-watch.c:140
dbus_watch_get_socket
DBUS_EXPORT int dbus_watch_get_socket(DBusWatch *watch)
Returns a socket to be watched, on UNIX this will return -1 if our transport is not socket-based so d...
Definition dbus-watch.c:595
DBusAddressEntry
Internals of DBusAddressEntry.
Definition dbus-address.c:49
DBusAuth
Internal members of DBusAuth.
Definition dbus-auth.c:156
DBusConnection
Implementation details of DBusConnection.
Definition dbus-connection.c:259
DBusCounter
Internals of DBusCounter.
Definition dbus-resources.c:57
DBusCredentials
Definition dbus-credentials.c:60
DBusError
Object representing an exception.
Definition dbus-errors.h:51
DBusList
A node in a linked list.
Definition dbus-list.h:37
DBusList::data
void * data
Data stored at this element.
Definition dbus-list.h:40
DBusMessageLoader
Implementation details of DBusMessageLoader.
Definition dbus-message-private.h:63
DBusMessage
Internals of DBusMessage.
Definition dbus-message-private.h:102
DBusSocket
Socket interface.
Definition dbus-sysdeps.h:185
DBusString
Definition dbus-string.h:47
DBusTransportVTable
The virtual table that must be implemented to create a new kind of transport.
Definition dbus-transport-protected.h:44
DBusTransportVTable::get_socket_fd
dbus_bool_t(* get_socket_fd)(DBusTransport *transport, DBusSocket *fd_p)
Get socket file descriptor.
Definition dbus-transport-protected.h:71
DBusTransportVTable::disconnect
void(* disconnect)(DBusTransport *transport)
Disconnect this transport.
Definition dbus-transport-protected.h:55
DBusTransportVTable::live_messages_changed
void(* live_messages_changed)(DBusTransport *transport)
Outstanding messages counter changed.
Definition dbus-transport-protected.h:68
DBusTransportVTable::do_iteration
void(* do_iteration)(DBusTransport *transport, unsigned int flags, int timeout_milliseconds)
Called to do a single "iteration" (block on select/poll followed by reading or writing data).
Definition dbus-transport-protected.h:61
DBusTransportVTable::handle_watch
dbus_bool_t(* handle_watch)(DBusTransport *transport, DBusWatch *watch, unsigned int flags)
The handle_watch method handles reading/writing data as indicated by the flags.
Definition dbus-transport-protected.h:48
DBusTransportVTable::finalize
void(* finalize)(DBusTransport *transport)
The finalize method must free the transport.
Definition dbus-transport-protected.h:45
DBusTransportVTable::connection_set
dbus_bool_t(* connection_set)(DBusTransport *transport)
Called when transport->connection has been filled in.
Definition dbus-transport-protected.h:58
DBusTransport
Object representing a transport such as a socket.
Definition dbus-transport-protected.h:83
DBusTransport::authenticated
unsigned int authenticated
Cache of auth state; use _dbus_transport_peek_is_authenticated() to query value.
Definition dbus-transport-protected.h:116
DBusTransport::windows_user_function
DBusAllowWindowsUserFunction windows_user_function
Function for checking whether a user is authorized.
Definition dbus-transport-protected.h:110
DBusTransport::refcount
int refcount
Reference count.
Definition dbus-transport-protected.h:84
DBusTransport::max_live_messages_size
long max_live_messages_size
Max total size of received messages.
Definition dbus-transport-protected.h:96
DBusTransport::max_live_messages_unix_fds
long max_live_messages_unix_fds
Max total unix fds of received messages.
Definition dbus-transport-protected.h:97
DBusTransport::allow_anonymous
unsigned int allow_anonymous
TRUE if an anonymous client can connect
Definition dbus-transport-protected.h:121
DBusTransport::windows_user_data
void * windows_user_data
Data for windows_user_function.
Definition dbus-transport-protected.h:111
DBusTransport::is_server
unsigned int is_server
TRUE if on the server side
Definition dbus-transport-protected.h:119
DBusTransport::disconnected
unsigned int disconnected
TRUE if we are disconnected.
Definition dbus-transport-protected.h:115
DBusTransport::address
char * address
Address of the server we are connecting to (NULL for the server side of a transport).
Definition dbus-transport-protected.h:101
DBusTransport::unused_bytes_recovered
unsigned int unused_bytes_recovered
TRUE if we've recovered unused bytes from auth
Definition dbus-transport-protected.h:120
DBusTransport::vtable
const DBusTransportVTable * vtable
Virtual methods for this instance.
Definition dbus-transport-protected.h:86
DBusTransport::free_unix_user_data
DBusFreeFunction free_unix_user_data
Function to free unix_user_data.
Definition dbus-transport-protected.h:108
DBusTransport::send_credentials_pending
unsigned int send_credentials_pending
TRUE if we need to send credentials
Definition dbus-transport-protected.h:117
DBusTransport::unix_user_data
void * unix_user_data
Data for unix_user_function.
Definition dbus-transport-protected.h:106
DBusTransport::connection
DBusConnection * connection
Connection owning this transport.
Definition dbus-transport-protected.h:88
DBusTransport::receive_credentials_pending
unsigned int receive_credentials_pending
TRUE if we need to receive credentials
Definition dbus-transport-protected.h:118
DBusTransport::loader
DBusMessageLoader * loader
Message-loading buffer.
Definition dbus-transport-protected.h:90
DBusTransport::expected_guid
char * expected_guid
GUID we expect the server to have, NULL on server side or if we don't have an expectation.
Definition dbus-transport-protected.h:103
DBusTransport::free_windows_user_data
DBusFreeFunction free_windows_user_data
Function to free windows_user_data.
Definition dbus-transport-protected.h:113
DBusTransport::unix_user_function
DBusAllowUnixUserFunction unix_user_function
Function for checking whether a user is authorized.
Definition dbus-transport-protected.h:105
DBusTransport::credentials
DBusCredentials * credentials
Credentials of other end read from the socket.
Definition dbus-transport-protected.h:94
DBusTransport::auth
DBusAuth * auth
Authentication conversation.
Definition dbus-transport-protected.h:92
DBusTransport::live_messages
DBusCounter * live_messages
Counter for size/unix fds of all live messages.
Definition dbus-transport-protected.h:99
DBusWatch
Implementation of DBusWatch.
Definition dbus-watch.c:43