Created-by: Kimmo Hämäläinen Comments-by: Guillem Jover Index: b/dbus/dbus-sysdeps-util-unix.c =================================================================== --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -389,6 +390,8 @@ _dbus_change_to_daemon_user (const char } #endif /* HAVE_LIBAUDIT */ +/* XXX: maemo */ +#if 0 /* setgroups() only works if we are a privileged process, * so we don't return error on failure; the only possible * failure is that we don't have perms to do it. @@ -400,6 +403,25 @@ _dbus_change_to_daemon_user (const char _dbus_warn ("Failed to drop supplementary groups: %s\n", _dbus_strerror (errno)); +#endif + + struct passwd *pw = getpwuid (uid); + if (pw == NULL) + { + dbus_set_error (error, _dbus_error_from_errno (errno), + "getpwuid () for UID '%d' failed: %s", uid, + _dbus_strerror (errno)); + return FALSE; + } + + if (initgroups (pw->pw_name, pw->pw_gid) < 0) + { + dbus_set_error (error, _dbus_error_from_errno (errno), + "initgroups () failed: %s", + _dbus_strerror (errno)); + return FALSE; + } + /* Set GID first, or the setuid may remove our permission * to change the GID */