From 1ff6851a1a8dcb89f6cb4097b765167b0949a982 Mon Sep 17 00:00:00 2001 From: startx2017 Date: Mon, 26 Mar 2018 10:46:09 -0400 Subject: dbus.c --- src/firejail/dbus.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/firejail/dbus.c (limited to 'src') diff --git a/src/firejail/dbus.c b/src/firejail/dbus.c new file mode 100644 index 000000000..eee3e2a35 --- /dev/null +++ b/src/firejail/dbus.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014-2018 Firejail Authors + * + * This file is part of firejail project + * + * 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 "firejail.h" + +void dbus_session_disable(void) { + char *path; + if (asprintf(&path, "/run/user/%d/bus", getuid()) == -1) + errExit("asprintf"); + char *env_var; + if (asprintf(&env_var, "DBUS_SESSION_BUS_ADDRESS=unix:path=%s", path) == -1) + errExit("asprintf"); + + // set a new environment variable: DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user//bus + if (setenv("DBUS_SESSION_BUS_ADDRESS", env_var, 1) == -1) { + fprintf(stderr, "Error: cannot modify DBUS_SESSION_BUS_ADDRESS required by --nodbus\n"); + exit(1); + } + + // blacklist the path + disable_file_or_dir(path); + free(path); + free(env_var); + + // look for a possible abstract unix socket + + // --net=none + if (arg_nonetwork) + return; + + // --net=eth0 + if (any_bridge_configured()) + return; + + // --protocol=unix +#ifdef HAVE_SECCOMP + if (cfg.protocol && !strstr(cfg.protocol, "unix")) + return; +#endif + + fwarning("An abstract unix socket for session D-BUS might still be available. Use --net or remove unix from --protocol set.\n"); +} -- cgit v1.2.3-70-g09d2