When trying to connect to the system bus from a setuid application, D-Bus throws back the following error:

Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

After some debugging, I found that the problem is a bug in the D-Bus EXTERNAL authentication method: the library sends the real UID while the daemon checks the effective UID, which of course doesn't work at all in setuid applications.

I filed a bug report in the Freedesktop Bugzilla and provideda patch which is yet to be merged.

In the meantime, if you need to use D-Bus in a setuid application, the following code might help:

DBusConnection *my_dbus_bus_get(DBusBusType type, DBusError *error)
{
DBusConnection *bus = NULL;

if (!(bus = dbus_bus_get(type, error)))
{
/* The connection to the BUS failed, we now check
* if we are running as setuid. */
uid_t ruid;
uid_t euid;

if (!(euid = geteuid()) && (ruid = getuid()))
{
/* In that case, we temporary change our
* real uid to the effective uid and try again */
dbus_error_free(error);
setreuid(euid, euid);
bus = dbus_bus_get(type, error);
setreuid(ruid, euid);
}
}
return bus;
}

This workaround is a function you'll have to call instead of the regular dbus_bus_get(). In case the connection fails and it's running on a setuid application, it will change the real UID to match the effective UID so the authentication process will succeed, make a connection to D-Bus and restore everything back.