'Machine ID' underspecified?

Thiago Macieira thiago at kde.org
Mon Dec 7 18:19:21 UTC 2020


On Monday, 7 December 2020 04:33:05 PST Simon McVittie wrote:
> With hindsight, the reference implementation's use of a ${prefix}-relative
> path for the machine ID is unwise: if you don't know ahead of time where
> dbus was installed, it makes interoperability impossible. More generally,
> a package that installs in a GNU-style configurable ${prefix} isn't really
> compatible with providing a "filesystem API". However, in practice dbus is
> nearly always an OS component installed into /usr, /var and /etc, so
> assuming /var/lib/dbus/machine-id is nearly always correct.
> 
> systemd and dbus will both try to populate both /etc/machine-id and
> /var/lib/dbus/machine-id with the same content, although if the two IDs
> already exist with different content, at least dbus (probably systemd too)
> will leave both intact.

QSysInfo also uses the D-Bus / systemd machine-id file and has a trick to deal 
with /usr/local. See [1]

    // The modern name on Linux is /etc/machine-id, but that path is
    // unlikely to exist on non-Linux (non-systemd) systems. The old
    // path is more than enough.
    static const char fullfilename[] = "/usr/local/var/lib/dbus/machine-id";
    const char *firstfilename = fullfilename + sizeof("/usr/local") - 1;
    int fd = qt_safe_open(firstfilename, O_RDONLY);
    if (fd == -1 && errno == ENOENT)
        fd = qt_safe_open(fullfilename, O_RDONLY);

This will find the machine-id installed on my Mac too, but that file disagrees 
with the sysctl, which in turn appears to disagree with the gethostuuid() 
function.

$ uname -rs
Darwin 19.6.0
$ cat /usr/local/var/lib/dbus/machine-id 
cf9cac9a2aeafe0c6df12d9b5d0d55e2
$ sysctl kern.uuid
kern.uuid: 9B5A7191-5B84-3990-8710-D9BD9273A8E5
$ /tmp/gethostuuid
87ed49ffc1815f1b9096bfab32e9880d

[1] https://code.woboq.org/qt5/qtbase/src/corelib/global/qglobal.cpp.html#3014

> > On Windows it appears to use a Windows API call GetCurrentHwProfileA to
> > get a GUID representing the 'hardware profile', and reformat it into the
> > UUID format D-Bus needs:
> > 
> > https://gitlab.freedesktop.org/dbus/dbus/-/blob/2ef39181cfe1443c3495007408
> > 55bf86f195f540/dbus/dbus-sysdeps-win.c#L2820> 
> I think the reformatting is essentially just removal of punctuation:
> Windows GUID {12340001-4980-1920-6788-123456789012} becomes D-Bus machine
> ID 12340001498019206788123456789012.

Hmm... I never thought to look at what libdbus-1 did for Windows. When I 
implemented QSysInfo::machineId, I used the registry ("SOFTWARE\\Microsoft
\\Cryptography\\MachineGuid"). I wonder if they're the same.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering





More information about the dbus mailing list