diff options
author | Alban Crequy <alban.crequy@collabora.co.uk> | 2012-05-29 11:37:12 +0000 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2012-05-29 16:03:32 +0200 |
commit | 74a16b8b4ea8b789d108422e815b2c79502fac04 (patch) | |
tree | 6199a797fcf79b77dd6597351a5565a2f905932a | |
parent | 165fea7341c46ea6038ce87de447df7541cddf04 (diff) | |
download | dbus-74a16b8b4ea8b789d108422e815b2c79502fac04.tar.gz |
Start a new proxy AF_BUS connection when proxying a legacy AF_UNIX connection
-rw-r--r-- | bus/bus.c | 46 | ||||
-rw-r--r-- | bus/bus.h | 1 | ||||
-rw-r--r-- | bus/connection.c | 36 | ||||
-rw-r--r-- | dbus/dbus-connection.c | 2 |
4 files changed, 79 insertions, 6 deletions
@@ -52,16 +52,20 @@ struct BusContext char *type; char *servicehelper; char *address; + + /* if we are in AF_BUS compat mode, contains the AF_BUS address */ + char *main_address; + char *pidfile; char *user; char *log_prefix; DBusLoop *loop; DBusList *servers; -#ifdef HAVE_AFBUS + /* One of the servers may be a AF_BUS server. We can have at most only one * AF_BUS server. */ DBusServer *main_afbus_server; -#endif + BusConnections *connections; BusActivation *activation; BusRegistry *registry; @@ -590,6 +594,7 @@ process_config_every_time (BusContext *context, DBusError *error) { DBusString full_address; + DBusString main_address; DBusList *link; DBusList **dirs; char *addr; @@ -609,6 +614,12 @@ process_config_every_time (BusContext *context, return FALSE; } + if (!_dbus_string_init (&main_address)) + { + BUS_SET_OOM (error); + return FALSE; + } + /* get our limits and timeout lengths */ bus_config_parser_get_limits (parser, &context->limits); @@ -645,6 +656,18 @@ process_config_every_time (BusContext *context, goto failed; } + if (dbus_server_is_afbus (link->data)) + { + /* There must be at most one AF_BUS server */ + _dbus_assert (_dbus_string_get_length (&main_address) == 0); + + if (!_dbus_string_append (&main_address, addr)) + { + BUS_SET_OOM (error); + goto failed; + } + } + dbus_free (addr); addr = NULL; @@ -652,7 +675,10 @@ process_config_every_time (BusContext *context, } if (is_reload) - dbus_free (context->address); + { + dbus_free (context->address); + dbus_free (context->main_address); + } if (!_dbus_string_copy_data (&full_address, &context->address)) { @@ -660,6 +686,12 @@ process_config_every_time (BusContext *context, goto failed; } + if (!_dbus_string_copy_data (&main_address, &context->main_address)) + { + BUS_SET_OOM (error); + goto failed; + } + /* get the service directories */ dirs = bus_config_parser_get_service_dirs (parser); @@ -700,6 +732,7 @@ process_config_every_time (BusContext *context, failed: _dbus_string_free (&full_address); + _dbus_string_free (&main_address); if (addr) dbus_free (addr); @@ -1167,6 +1200,7 @@ bus_context_unref (BusContext *context) dbus_free (context->log_prefix); dbus_free (context->type); dbus_free (context->address); + dbus_free (context->main_address); dbus_free (context->user); dbus_free (context->servicehelper); @@ -1202,6 +1236,12 @@ bus_context_get_address (BusContext *context) } const char* +bus_context_get_main_address (BusContext *context) +{ + return context->main_address; +} + +const char* bus_context_get_servicehelper (BusContext *context) { return context->servicehelper; @@ -88,6 +88,7 @@ dbus_bool_t bus_context_get_id (BusContext DBusString *uuid); const char* bus_context_get_type (BusContext *context); const char* bus_context_get_address (BusContext *context); +const char* bus_context_get_main_address (BusContext *context); const char* bus_context_get_servicehelper (BusContext *context); dbus_bool_t bus_context_get_systemd_activation (BusContext *context); BusRegistry* bus_context_get_registry (BusContext *context); diff --git a/bus/connection.c b/bus/connection.c index d69758c9..40392a49 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -34,6 +34,10 @@ #include <dbus/dbus-hash.h> #include <dbus/dbus-timeout.h> +#include <unistd.h> +#include <sys/types.h> /* See NOTES */ +#include <sys/socket.h> + /* Trim executed commands to this length; we want to keep logs readable */ #define MAX_LOG_COMMAND_LEN 50 @@ -94,6 +98,10 @@ typedef struct char *cached_loginfo_string; BusSELinuxID *selinux_id; + DBusConnection *proxy_connection; /**< If this is a compat connection, + proxy_connection is the proxy + connection to AF_BUS */ + long connection_tv_sec; /**< Time when we connected (seconds component) */ long connection_tv_usec; /**< Time when we connected (microsec component) */ int stamp; /**< connections->stamp last time we were traversed */ @@ -596,7 +604,9 @@ bus_connections_setup_connection (BusConnections *connections, BusConnectionData *d; dbus_bool_t retval; DBusError error; - + const char *main_address; + struct sockaddr_storage addr; + long addrlen = sizeof(addr); d = dbus_new0 (BusConnectionData, 1); @@ -622,8 +632,30 @@ bus_connections_setup_connection (BusConnections *connections, dbus_connection_set_route_peer_messages (connection, TRUE); retval = FALSE; - dbus_error_init (&error); + + /* If this connection is not AF_BUS, and we have a AF_BUS + * server, we are in compat mode and we need to setup a + * new connection */ + access("addrlen is ", addrlen); + memset (&addr, 0x5a5a5a5a, sizeof (addr)); + if (!dbus_connection_get_peer_address (connection, &addr, &addrlen) || + ((struct sockaddr *)&addr)->sa_family != AF_BUS) + { + main_address = bus_context_get_main_address (connections->context); + //access(main_address, addr.sa_family); + if (main_address) + { + d->proxy_connection = dbus_connection_open_private (main_address, + &error); + if (dbus_error_is_set (&error)) + { + dbus_error_free (&error); + goto out; + } + } + } + d->selinux_id = bus_selinux_init_connection_id (connection, &error); if (dbus_error_is_set (&error)) diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 35255618..5f3a459f 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -5460,7 +5460,7 @@ dbus_connection_get_peer_address (DBusConnection *connection, { dbus_bool_t res; int fd; - socklen_t _len; + socklen_t _len = *len; _dbus_return_val_if_fail (connection != NULL, FALSE); |