diff --git a/dbus/dbus-bus.h b/dbus/dbus-bus.h index 02a9571..6509b5f 100644 --- a/dbus/dbus-bus.h +++ b/dbus/dbus-bus.h @@ -88,6 +88,9 @@ void dbus_bus_remove_match (DBusConnection *connection, const char *rule, DBusError *error); +DBUS_EXPORT +void dbus_setup_session_address (const char *addr); + /** @} */ DBUS_END_DECLS diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index b4ecc96..d50dc84 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3654,6 +3654,22 @@ _dbus_lookup_session_address_launchd (DBusString *address, DBusError *error) #endif /** + * Sets up the custom session bus address. + * + * This function is tend to be used by setuid/setgid + * programs to explicitly set up the desired bus address. + * To avoid security violations the address should be first + * carefully checked. + */ + +static const char *custom_session_address = NULL; +void +dbus_setup_session_address(const char *addr) +{ + custom_session_address = addr; +} + +/** * Determines the address of the session bus by querying a * platform-specific method. * @@ -3681,11 +3697,17 @@ _dbus_lookup_session_address (dbus_bool_t *supported, *supported = TRUE; return _dbus_lookup_session_address_launchd (address, error); #else - /* On non-Mac Unix platforms, if the session address isn't already - * set in DBUS_SESSION_BUS_ADDRESS environment variable, we punt and - * fall back to the autolaunch: global default; see - * init_session_address in dbus/dbus-bus.c. */ - *supported = FALSE; + if (!custom_session_address) + *supported = FALSE; + else + { + *supported = TRUE; + if (!_dbus_string_append (address, custom_session_address)) + { + _DBUS_SET_OOM (error); + return FALSE; + } + } return TRUE; #endif }