From 0e5457995ad18167d3df76a805843145de2f028e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 1 May 2019 11:47:57 +0100 Subject: [PATCH] run: Make D-Bus session bus default to $XDG_RUNTIME_DIR/bus This matches what's now implemented in libdbus, GDBus and sd-bus. If $DBUS_SESSION_BUS_ADDRESS is unset, check whether $XDG_RUNTIME_DIR/bus is a socket owned by Flatpak's uid; if it is, use it. Signed-off-by: Simon McVittie Closes: #2874 Approved by: alexlarsson --- common/flatpak-run.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/common/flatpak-run.c b/common/flatpak-run.c index 36b1c437..3bcd9359 100644 --- a/common/flatpak-run.c +++ b/common/flatpak-run.c @@ -578,15 +578,28 @@ flatpak_run_add_session_dbus_args (FlatpakBwrap *app_bwrap, unrestricted = (context->sockets & FLATPAK_CONTEXT_SOCKET_SESSION_BUS) != 0; - if (dbus_address == NULL) - return FALSE; + if (dbus_address != NULL) + { + dbus_session_socket = extract_unix_path_from_dbus_address (dbus_address); + } + else + { + g_autofree char *user_runtime_dir = flatpak_get_real_xdg_runtime_dir (); + struct stat statbuf; + + dbus_session_socket = g_build_filename (user_runtime_dir, "bus", NULL); + + if (stat (dbus_session_socket, &statbuf) < 0 + || (statbuf.st_mode & S_IFMT) != S_IFSOCK + || statbuf.st_uid != getuid ()) + return FALSE; + } if (unrestricted) g_debug ("Allowing session-dbus access"); no_proxy = (flags & FLATPAK_RUN_FLAG_NO_SESSION_BUS_PROXY) != 0; - dbus_session_socket = extract_unix_path_from_dbus_address (dbus_address); if (dbus_session_socket != NULL && unrestricted) { flatpak_bwrap_add_args (app_bwrap,