From 067eb4c8f0cf251f9374db8c05b3b2adc1494346 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 28 Jul 2017 08:38:20 +0100 Subject: [PATCH 12/12] userdb: Respect $HOME for the home directory of our own uid This lets cooperating processes with the same value of $HOME interoperate for DBUS_COOKIE_SHA1 by reading and writing $HOME, even if their $HOME differs from the uid's "official" home directory according to getpwuid(). Out of paranoia, we only do this if the uid and the euid are equal, since if they were unequal the correct thing to do would be ambiguous. In particular, Debian autobuilders run as a user whose "official" home directory in /etc/passwd is "/nonexistent", as a mechanism to detect non-deterministic build processes that rely on the contents of the home directory. Until now, this meant we couldn't run dbus' build-time tests, because every test that used DBUS_COOKIE_SHA1 would fail in this environment. In the tests, set HOME as well as DBUS_TEST_HOMEDIR. We keep DBUS_TEST_HOMEDIR too, because Windows doesn't use HOME, only HOMEDRIVE and HOMEPATH. Bug-Debian: https://bugs.debian.org/630152 Signed-off-by: Simon McVittie --- dbus/dbus-sysdeps-unix.c | 3 ++- dbus/dbus-userdb.c | 10 ++++++++++ test/Makefile.am | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index bb059579..0146e555 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -4253,7 +4253,8 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory, static dbus_bool_t already_warned = FALSE; if (!already_warned) { - _dbus_warn ("Using your real home directory for testing, set DBUS_TEST_HOMEDIR to avoid"); + _dbus_warn ("Using %s for testing, set DBUS_TEST_HOMEDIR to avoid", + _dbus_string_get_const_data (&homedir)); already_warned = TRUE; } } diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c index 5d386faf..4c42b7dd 100644 --- a/dbus/dbus-userdb.c +++ b/dbus/dbus-userdb.c @@ -464,6 +464,16 @@ _dbus_homedir_from_uid (dbus_uid_t uid, DBusUserDatabase *db; const DBusUserInfo *info; + if (uid == _dbus_getuid () && uid == _dbus_geteuid ()) + { + const char *from_environment; + + from_environment = _dbus_getenv ("HOME"); + + if (from_environment != NULL) + return _dbus_string_append (homedir, from_environment); + } + /* FIXME: this can't distinguish ENOMEM from other errors */ if (!_dbus_user_database_lock_system ()) return FALSE; diff --git a/test/Makefile.am b/test/Makefile.am index af343708..7a8b649a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -246,6 +246,7 @@ installcheck_environment = \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \ export DBUS_TEST_UNINSTALLED=1; \ + export HOME=@abs_top_builddir@/dbus; \ ${NULL} # Tests in bus/config-parser.c rely on these specific values for XDG_* and @@ -267,6 +268,7 @@ AM_TESTS_ENVIRONMENT = \ export DBUS_TEST_EXEC=@abs_top_builddir@/test; \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ export DBUS_TEST_UNINSTALLED=1; \ + export HOME=@abs_top_builddir@/dbus; \ $(NULL) manual_authz_SOURCES = manual-authz.c -- 2.13.3