-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-userdb-util.c Would be in dbus-userdb.c, but not used in libdbus
*
* Copyright (C) 2003, 2004, 2005 Red Hat, Inc.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#include <config.h>
#define DBUS_USERDB_INCLUDES_PRIVATE 1
#include "dbus-userdb.h"
#include "dbus-test.h"
#include "dbus-protocol.h"
#include <string.h>
+#if HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
+#endif
+
/**
* @addtogroup DBusInternalsUtils
* @{
DBusUserDatabase *db;
const DBusUserInfo *info;
- dbus_bool_t result = FALSE;
+ dbus_bool_t result = FALSE;
+
+#ifdef HAVE_SYSTEMD
+ if (sd_booted () > 0)
+ {
+ int r;
+
+ /* Check whether this user is logged in on at least one physical
+ seat */
+ r = sd_uid_get_seats (uid, 0, NULL);
+ if (r < 0)
+ {
+ dbus_set_error (error, _dbus_error_from_errno (-r),
+ "Failed to determine seats of user \"" DBUS_UID_FORMAT "\": %s",
+ uid,
+ _dbus_strerror (-r));
+ return FALSE;
+ }
+
+ return (r > 0);
+ }
+#endif
#ifdef HAVE_CONSOLE_OWNER_FILE
gid = n;
}
-#ifdef DBUS_ENABLE_USER_CACHE
+#ifdef DBUS_ENABLE_USERDB_CACHE
if (gid != DBUS_GID_UNSET)
- info = _dbus_hash_table_lookup_ulong (db->groups, gid);
+ info = _dbus_hash_table_lookup_uintptr (db->groups, gid);
else
info = _dbus_hash_table_lookup_string (db->groups_by_name,
_dbus_string_get_const_data (groupname));
gid = DBUS_GID_UNSET;
groupname = NULL;
- if (!_dbus_hash_table_insert_ulong (db->groups, info->gid, info))
+ if (!_dbus_hash_table_insert_uintptr (db->groups, info->gid, info))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_group_info_free_allocated (info);
info->groupname,
info))
{
- _dbus_hash_table_remove_ulong (db->groups, info->gid);
+ _dbus_hash_table_remove_uintptr (db->groups, info->gid);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
dbus_uid_t uid;
unsigned long *group_ids;
int n_group_ids, i;
+ DBusError error;
- if (!_dbus_append_desired_identity (&username))
+ if (!_dbus_username_from_current_process (&username))
_dbus_assert_not_reached ("didn't get username");
if (!_dbus_homedir_from_current_process (&homedir))
printf(" %ld", group_ids[i]);
printf ("\n");
-
+
+ dbus_error_init (&error);
+ printf ("Is Console user: %i\n",
+ _dbus_is_console_user (uid, &error));
+ printf ("Invocation was OK: %s\n", error.message ? error.message : "yes");
+ dbus_error_free (&error);
+ printf ("Is Console user 4711: %i\n",
+ _dbus_is_console_user (4711, &error));
+ printf ("Invocation was OK: %s\n", error.message ? error.message : "yes");
+ dbus_error_free (&error);
+
dbus_free (group_ids);
return TRUE;