package/dbus: incorrect session bus configuration file containing builder environment

### Check-list

- [x] I did not find the issue in the existing issues
- [x] I can reproduce the issue with unmodified Buildroot from [this
      repository](https://gitlab.com/buildroot.org/buildroot), not from a
      fork somewhere else
- [x] I can reproduce the issue on the latest commit of the branch I'm using:
    - [x] master
- [x] I can reproduce the issue after running `make clean; make`
- [x] I attached a **minimal** defconfig file that can reproduce the
      issue (`make BR2_DEFCONFIG=$(pwd)/issue_defconfig savedefconfig`)
      [issue_defconfig](/uploads/2b444462432b744b03df51e46e9b9999/issue_defconfig)
      (I guess, it could be smaller: we do not need most of it, just dbus for x86_64)

What I did

  • Buildroot commit sha1: 2024.08-1489-gd7deecbce2
  • Distribution of the build machine: NAME="Linux Mint" VERSION="22 (Wilma)"

Here, describe what you did:

  • $TMPDIR=~/ehehe
  • the commands you ran:
    $ mkdir ~/ehehe
    $ export TMPDIR=~/ehehe
    $ make pc_x86_64_efi_defconfig
    $ make

What happens

buildroot/output/target/usr/share/dbus-1/session.conf contains unix:tmpdir=/home/user/ehehe


What was expected

buildroot/output/target/usr/share/dbus-1/session.conf contains unix:tmpdir=/tmp


Extra information

Correct /usr/share/dbus-1/session.conf in resulting image is needed for dbus session bus to work. If it contains a wrong tmpdir path, work over a session bus is inoperable (as opening connections needs a valid path for temporary files to be created).

Leaking builder's details (such as environment or possible paths) to a target image does not look good as well (for reproducibility or security). The description for reproduction is silly, but it is based on a real life bug encountered when building on a specialized builder, configured to have separate TMPDIR for different builds (to run multiple builds at once without clashing in /tmp).

As for the root of the problem, currently used dbus-1.14.10 contains the following in CMakeLists.txt:

#### Find socket directories
set(DBUS_SESSION_SOCKET_DIR "" CACHE STRING "Default directory for session socket")
if(UNIX)
    if (CMAKE_CROSSCOMPILING)
        if (NOT DBUS_SESSION_SOCKET_DIR)
            message(FATAL_ERROR "cannot autodetect session socket directory "
                    "when crosscompiling, pass -DDBUS_SESSION_SOCKET_DIR=...")
        endif()
    elseif(NOT $ENV{TMPDIR} STREQUAL "")
        set(DBUS_SESSION_SOCKET_DIR $ENV{TMPDIR})
    elseif(NOT $ENV{TEMP} STREQUAL "")
        set(DBUS_SESSION_SOCKET_DIR $ENV{TEMP})
    elseif(NOT $ENV{TMP} STREQUAL "")
        set(DBUS_SESSION_SOCKET_DIR $ENV{TMP})
    else()
        set(DBUS_SESSION_SOCKET_DIR /tmp)
    endif()
endif()

I guess, DBUS_SESSION_SOCKET_DIR for target dbus build should be provided with tempdir of the resulting image (/tmp? Or may be the configured value for target tempdir, if there is one?). May be CMAKE_CROSSCOMPILING should be detected as well (as target package is being in fact cross-compiled)?