From efd24605727ee979b35053397463246456cf0ed0 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 10 Sep 2009 16:26:01 -0500 Subject: work in progress --- src/users-service-dbus.c | 379 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 379 insertions(+) create mode 100644 src/users-service-dbus.c (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c new file mode 100644 index 0000000..95b0f49 --- /dev/null +++ b/src/users-service-dbus.c @@ -0,0 +1,379 @@ +/* + * Copyright 2009 Canonical Ltd. + * + * Authors: + * Cody Russell + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "dbus-shared-names.h" +#include "users-service-dbus.h" +#include "users-service-client.h" + +static void users_service_dbus_class_init (UsersServiceDbusClass *klass); +static void users_service_dbus_init (UsersServiceDbus *self); +static void users_service_dbus_dispose (GObject *object); +static void users_service_dbus_finalize (GObject *object); +static gboolean _users_service_server_count_users (UsersServiceDbus *service, + gint *count, + GError **error); +static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, + GArray **list, + GError **error); +static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, + const gint64 uid, + gchar **username, + gchar **real_name, + gchar **shell, + char **icon_url, + GError **error); +static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, + const GArray *uids, + GPtrArray **user_info, + GError **error); +static void users_loaded (DBusGProxy *proxy, + gpointer user_data); +static void user_added (DBusGProxy *proxy, + guint uid, + gpointer user_data); +static void user_removed (DBusGProxy *proxy, + guint uid, + gpointer user_data); + +#include "users-service-server.h" + +/* Private */ +typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate; + +struct _UsersServiceDbusPrivate +{ + GList *users; + gint count; + + DBusGConnection *session_bus; + DBusGConnection *system_bus; + DBusGProxy *dbus_proxy_session; + DBusGProxy *dbus_proxy_system; +}; + +#define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) + +/* Signals */ +enum { + USERS_LOADED, + USER_ADDED, + USER_REMOVED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +/* GObject Boilerplate */ +G_DEFINE_TYPE (UsersServiceDbus, users_service_dbus, G_TYPE_OBJECT); + +static void +users_service_dbus_class_init (UsersServiceDbusClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (UsersServiceDbusPrivate)); + + object_class->dispose = users_service_dbus_dispose; + object_class->finalize = users_service_dbus_finalize; + + signals[USERS_LOADED] = g_signal_new ("users-loaded", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, users_loaded), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[USER_ADDED] = g_signal_new ("user-added", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, user_added), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, G_TYPE_INT); + + signals[USER_REMOVED] = g_signal_new ("user-removed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, user_removed), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, G_TYPE_INT); + + dbus_g_object_type_install_info (USERS_SERVICE_DBUS_TYPE, &dbus_glib__users_service_server_object_info); +} + +static void +users_service_dbus_init (UsersServiceDbus *self) +{ + GError *error = NULL; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + priv->users = NULL; + priv->count = 0; + + /* Get the buses */ + priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_error ("Unable to get session bus: %s", error->message); + g_error_free (error); + + return; + } + + priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (error != NULL) { + g_error("Unable to get system bus: %s", error->message); + g_error_free(error); + + return; + } + + dbus_g_connection_register_g_object (priv->session_bus, + INDICATOR_USERS_SERVICE_DBUS_OBJECT, + G_OBJECT (self)); + + /* Set up the DBUS service proxies */ + priv->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (priv->session_bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + g_error ("Unable to get dbus proxy on session bus: %s", error->message); + g_error_free (error); + + return; + } + + priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS, + &error); + if (error != NULL) { + g_error ("Unable to get dbus proxy on system bus: %s", error->message); + g_error_free (error); + + return; + } + + dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + "UsersLoaded", + G_CALLBACK (users_loaded), + self, + NULL); + + dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + "UserAdded", + G_CALLBACK (user_added), + self, + NULL); + + dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + "UserRemoved", + G_CALLBACK (user_removed), + self, + NULL); +} + +static void +users_service_dbus_dispose (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->dispose (object); +} + +static void +users_service_dbus_finalize (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); +} + +static void +users_loaded (DBusGProxy *proxy, + gpointer user_data) +{ + UsersServiceDbus *service; + UsersServiceDbusPrivate *priv; + GError *error = NULL; + GArray *uids; + GPtrArray *users_info; + gint count; + int i; + + service = (UsersServiceDbus *)user_data; + priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + + if (!org_gnome_DisplayManager_UserManager_count_users (proxy, + &count, + &error)) + { + g_warning ("failed to retrieve user count: %s", error->message); + g_error_free (error); + + return; + } + + priv->count = count; + + if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy, + &uids, + &error)) + { + g_warning ("failed to retrieve user list: %s", error->message); + g_error_free (error); + + return; + } + + if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy, + uids, + &users_info, + &error)) + { + g_warning ("failed to retrieve user info: %s", error->message); + g_error_free (error); + + return; + } + + for (i = 0; i < users_info->len; i++) + { + UserData *data = g_ptr_array_index (users_info, i); + + priv->users = g_list_prepend (priv->users, data); + } +} + +gint +users_service_dbus_get_user_count (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->count; +} + +GList * +users_service_dbus_get_user_list (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->users; +} + +static void +user_added (DBusGProxy *proxy, + guint uid, + gpointer user_data) +{ + UsersServiceDbus *service = (UsersServiceDbus *)user_data; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + UserData *user = g_new0 (UserData, 1); + GError *error = NULL; + + priv->count++; + + if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy, + uid, + &user->user_name, + &user->real_name, + &user->shell, + &user->icon_url, + &error)) + { + g_warning ("unable to retrieve user info: %s", error->message); + g_error_free (error); + + g_free (user); + + return; + } + + user->uid = uid; + + priv->users = g_list_prepend (priv->users, user); + + g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); +} + +static void +user_removed (DBusGProxy *proxy, + guint uid, + gpointer user_data) +{ + UsersServiceDbus *service = (UsersServiceDbus *)user_data; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GList *l; + + priv->count--; + + for (l = priv->users; l != NULL; l = g_list_next (l)) + { + UserData *user = (UserData *)l->data; + + if (user->uid == uid) + { + priv->users = g_list_remove (priv->users, l->data); + g_signal_emit (G_OBJECT (service), signals[USER_REMOVED], 0, user, TRUE); + } + } +} + +static gboolean +_users_service_server_count_users (UsersServiceDbus *service, + gint *uids, + GError **error) +{ + return TRUE; +} + +static gboolean +_users_service_server_get_user_list (UsersServiceDbus *service, + GArray **list, + GError **error) +{ + return TRUE; +} + +static gboolean +_users_service_server_get_user_info (UsersServiceDbus *service, + const gint64 uid, + gchar **username, + gchar **real_name, + gchar **shell, + char **icon_url, + GError **error) +{ + return TRUE; +} + +static gboolean +_users_service_server_get_users_info (UsersServiceDbus *service, + const GArray *uids, + GPtrArray **user_info, + GError **error) +{ + return TRUE; +} -- cgit v1.2.3 From 91c2993398771ca1ff5a65003c681724291d9e2f Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 14:52:45 -0500 Subject: dbus fu updates --- src/users-service-dbus.c | 221 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 173 insertions(+), 48 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 95b0f49..ce22e6f 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -26,36 +26,44 @@ #include "dbus-shared-names.h" #include "users-service-dbus.h" #include "users-service-client.h" - -static void users_service_dbus_class_init (UsersServiceDbusClass *klass); -static void users_service_dbus_init (UsersServiceDbus *self); -static void users_service_dbus_dispose (GObject *object); -static void users_service_dbus_finalize (GObject *object); -static gboolean _users_service_server_count_users (UsersServiceDbus *service, - gint *count, - GError **error); -static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, - GArray **list, - GError **error); -static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, - const gint64 uid, - gchar **username, - gchar **real_name, - gchar **shell, - char **icon_url, - GError **error); -static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, - const GArray *uids, - GPtrArray **user_info, - GError **error); -static void users_loaded (DBusGProxy *proxy, - gpointer user_data); -static void user_added (DBusGProxy *proxy, - guint uid, - gpointer user_data); -static void user_removed (DBusGProxy *proxy, - guint uid, - gpointer user_data); +#include "users-service-marshal.h" + +static void users_service_dbus_class_init (UsersServiceDbusClass *klass); +static void users_service_dbus_init (UsersServiceDbus *self); +static void users_service_dbus_dispose (GObject *object); +static void users_service_dbus_finalize (GObject *object); +static gboolean _users_service_server_count_users (UsersServiceDbus *service, + gint *count, + GError **error); +static gboolean _users_service_server_get_users_loaded (UsersServiceDbus *self, + gboolean *is_loaded, + GError **error); +static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, + GArray **list, + GError **error); +static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, + const gint64 uid, + gchar **username, + gchar **real_name, + gchar **shell, + gint *login_count, + gchar **icon_url, + GError **error); +static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, + const GArray *uids, + GPtrArray **user_info, + GError **error); +static void users_loaded (DBusGProxy *proxy, + gpointer user_data); +static void user_added (DBusGProxy *proxy, + guint uid, + gpointer user_data); +static void user_removed (DBusGProxy *proxy, + guint uid, + gpointer user_data); +static void user_updated (DBusGProxy *proxy, + guint uid, + gpointer user_data); #include "users-service-server.h" @@ -71,6 +79,9 @@ struct _UsersServiceDbusPrivate DBusGConnection *system_bus; DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; + DBusGProxy *gdm_proxy; + + gchar *error; }; #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) @@ -80,6 +91,7 @@ enum { USERS_LOADED, USER_ADDED, USER_REMOVED, + USER_UPDATED, LAST_SIGNAL }; @@ -111,16 +123,24 @@ users_service_dbus_class_init (UsersServiceDbusClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (UsersServiceDbusClass, user_added), NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + _users_service_marshal_VOID__INT64, + G_TYPE_NONE, 1, G_TYPE_INT64); signals[USER_REMOVED] = g_signal_new ("user-removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (UsersServiceDbusClass, user_removed), NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + _users_service_marshal_VOID__INT64, + G_TYPE_NONE, 1, G_TYPE_INT64); + + signals[USER_UPDATED] = g_signal_new ("user-updated", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UsersServiceDbusClass, user_updated), + NULL, NULL, + _users_service_marshal_VOID__INT64, + G_TYPE_NONE, 1, G_TYPE_INT64); dbus_g_object_type_install_info (USERS_SERVICE_DBUS_TYPE, &dbus_glib__users_service_server_object_info); } @@ -140,6 +160,8 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get session bus: %s", error->message); g_error_free (error); + priv->error = g_strdup ("Failed to get session bus"); + return; } @@ -148,6 +170,8 @@ users_service_dbus_init (UsersServiceDbus *self) g_error("Unable to get system bus: %s", error->message); g_error_free(error); + priv->error = g_strdup ("Failed to get system bus"); + return; } @@ -161,42 +185,89 @@ users_service_dbus_init (UsersServiceDbus *self) DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &error); - if (error != NULL) { - g_error ("Unable to get dbus proxy on session bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get dbus proxy on session bus: %s", error->message); + g_error_free (error); - return; - } + priv->error = g_strdup ("Failed to get session proxy"); + + return; + } priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &error); - if (error != NULL) { - g_error ("Unable to get dbus proxy on system bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get dbus proxy on system bus: %s", error->message); + g_error_free (error); - return; - } + priv->error = g_strdup ("Failed to get system proxy"); + + return; + } + + priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, // XXX ? + "org.gnome.DisplayManager", + "/org/gnome/DisplayManager/UserManager", + "org.gnome.DisplayManager.UserManager", + &error); + + if (error != NULL) + { + g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); + g_error_free (error); + + priv->error = g_strdup_printf ("Unable to get DisplayManager proxy: %s", error->message); + } + + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UsersLoaded", + G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UserAdded", + G_TYPE_UINT64, + G_TYPE_INVALID); + + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UserRemoved", + G_TYPE_UINT64, + G_TYPE_INVALID); + + dbus_g_proxy_add_signal (priv->gdm_proxy, + "UserUpdated", + G_TYPE_UINT64, + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal (priv->gdm_proxy, "UsersLoaded", G_CALLBACK (users_loaded), self, NULL); - dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + dbus_g_proxy_connect_signal (priv->gdm_proxy, "UserAdded", G_CALLBACK (user_added), self, NULL); - dbus_g_proxy_connect_signal (priv->dbus_proxy_system, + dbus_g_proxy_connect_signal (priv->gdm_proxy, "UserRemoved", G_CALLBACK (user_removed), self, NULL); + + dbus_g_proxy_connect_signal (priv->gdm_proxy, + "UserUpdated", + G_CALLBACK (user_updated), + self, + NULL); + + users_loaded (priv->gdm_proxy, self); } static void @@ -231,6 +302,7 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user count: %s", error->message); + priv->error = g_strdup_printf ("Failed to retrieve user count: %s", error->message); g_error_free (error); return; @@ -243,6 +315,8 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user list: %s", error->message); + priv->error = g_strdup_printf ("Failed to retrieve user list: %s", error->message); + g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; @@ -254,6 +328,8 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user info: %s", error->message); + priv->error = g_strdup_printf ("Failed to get user info: %s", error->message); + g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; @@ -261,7 +337,13 @@ users_loaded (DBusGProxy *proxy, for (i = 0; i < users_info->len; i++) { - UserData *data = g_ptr_array_index (users_info, i); + UserData *data; + + g_print (" -> setting up user %d\n", i); + + data = g_ptr_array_index (users_info, i); + + g_print (" * user_name: %s\n", data->user_name); priv->users = g_list_prepend (priv->users, data); } @@ -280,6 +362,11 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + g_print ("users_service_dbus_get_user_list()\n"); + + if (!priv->users) + g_print ("users_service_dbus_get_user_list(): priv->users is NULL\n"); + return priv->users; } @@ -300,6 +387,7 @@ user_added (DBusGProxy *proxy, &user->user_name, &user->real_name, &user->shell, + &user->login_count, &user->icon_url, &error)) { @@ -341,6 +429,26 @@ user_removed (DBusGProxy *proxy, } } +static void +user_updated (DBusGProxy *proxy, + guint uid, + gpointer user_data) +{ + UsersServiceDbus *service = (UsersServiceDbus *)user_data; + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GList *l; + + for (l = priv->users; l != NULL; l = g_list_next (l)) + { + UserData *user = (UserData *)l->data; + + if (user->uid == uid) + { + // XXX - update user data + } + } +} + static gboolean _users_service_server_count_users (UsersServiceDbus *service, gint *uids, @@ -357,12 +465,21 @@ _users_service_server_get_user_list (UsersServiceDbus *service, return TRUE; } +static gboolean +_users_service_server_get_users_loaded (UsersServiceDbus *self, + gboolean *is_loaded, + GError **error) +{ + return TRUE; +} + static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, const gint64 uid, gchar **username, gchar **real_name, gchar **shell, + gint *login_count, char **icon_url, GError **error) { @@ -377,3 +494,11 @@ _users_service_server_get_users_info (UsersServiceDbus *service, { return TRUE; } + +gchar * +users_service_dbus_get_error (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->error; +} -- cgit v1.2.3 From 15e2e5192dce211e3d6d8f4dfa0bf1690ca3a77d Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 15:42:19 -0500 Subject: register marshallers --- src/users-service-dbus.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index ce22e6f..18a1b2a 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -224,23 +224,28 @@ users_service_dbus_init (UsersServiceDbus *self) priv->error = g_strdup_printf ("Unable to get DisplayManager proxy: %s", error->message); } + dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, + G_TYPE_NONE, + G_TYPE_INT64, + G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->gdm_proxy, "UsersLoaded", G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->gdm_proxy, "UserAdded", - G_TYPE_UINT64, + G_TYPE_INT64, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->gdm_proxy, "UserRemoved", - G_TYPE_UINT64, + G_TYPE_INT64, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->gdm_proxy, "UserUpdated", - G_TYPE_UINT64, + G_TYPE_INT64, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->gdm_proxy, -- cgit v1.2.3 From c4ff339c7576c83000b1a3695918d70e0124c098 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 16:57:01 -0500 Subject: fix dbus fu --- src/users-service-dbus.c | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 18a1b2a..e044fe8 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -80,8 +80,6 @@ struct _UsersServiceDbusPrivate DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; - - gchar *error; }; #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) @@ -160,8 +158,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get session bus: %s", error->message); g_error_free (error); - priv->error = g_strdup ("Failed to get session bus"); - return; } @@ -170,8 +166,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error("Unable to get system bus: %s", error->message); g_error_free(error); - priv->error = g_strdup ("Failed to get system bus"); - return; } @@ -190,8 +184,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get dbus proxy on session bus: %s", error->message); g_error_free (error); - priv->error = g_strdup ("Failed to get session proxy"); - return; } @@ -205,12 +197,10 @@ users_service_dbus_init (UsersServiceDbus *self) g_error ("Unable to get dbus proxy on system bus: %s", error->message); g_error_free (error); - priv->error = g_strdup ("Failed to get system proxy"); - return; } - priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, // XXX ? + priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.gnome.DisplayManager", "/org/gnome/DisplayManager/UserManager", "org.gnome.DisplayManager.UserManager", @@ -220,8 +210,6 @@ users_service_dbus_init (UsersServiceDbus *self) { g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); g_error_free (error); - - priv->error = g_strdup_printf ("Unable to get DisplayManager proxy: %s", error->message); } dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, @@ -294,8 +282,8 @@ users_loaded (DBusGProxy *proxy, UsersServiceDbus *service; UsersServiceDbusPrivate *priv; GError *error = NULL; - GArray *uids; - GPtrArray *users_info; + GArray *uids = NULL; + GPtrArray *users_info = NULL; gint count; int i; @@ -307,7 +295,6 @@ users_loaded (DBusGProxy *proxy, &error)) { g_warning ("failed to retrieve user count: %s", error->message); - priv->error = g_strdup_printf ("Failed to retrieve user count: %s", error->message); g_error_free (error); return; @@ -315,26 +302,26 @@ users_loaded (DBusGProxy *proxy, priv->count = count; + uids = g_array_new (FALSE, FALSE, sizeof (gint64)); + if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy, &uids, &error)) { g_warning ("failed to retrieve user list: %s", error->message); - priv->error = g_strdup_printf ("Failed to retrieve user list: %s", error->message); - g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; } + users_info = g_ptr_array_new (); + if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy, uids, &users_info, &error)) { g_warning ("failed to retrieve user info: %s", error->message); - priv->error = g_strdup_printf ("Failed to get user info: %s", error->message); - g_print ("priv->error == %s\n", priv->error); g_error_free (error); return; @@ -342,13 +329,19 @@ users_loaded (DBusGProxy *proxy, for (i = 0; i < users_info->len; i++) { + GValueArray *values; UserData *data; - g_print (" -> setting up user %d\n", i); + values = g_ptr_array_index (users_info, i); - data = g_ptr_array_index (users_info, i); + data = g_new0 (UserData, 1); - g_print (" * user_name: %s\n", data->user_name); + data->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); + data->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); + data->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); + data->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); + data->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); + data->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); priv->users = g_list_prepend (priv->users, data); } @@ -499,11 +492,3 @@ _users_service_server_get_users_info (UsersServiceDbus *service, { return TRUE; } - -gchar * -users_service_dbus_get_error (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - return priv->error; -} -- cgit v1.2.3 From 0e5b24c9c86750f4ce10f9a53846da049caeb179 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 16:58:03 -0500 Subject: cleanup --- src/users-service-dbus.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index e044fe8..8685105 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -360,11 +360,6 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - g_print ("users_service_dbus_get_user_list()\n"); - - if (!priv->users) - g_print ("users_service_dbus_get_user_list(): priv->users is NULL\n"); - return priv->users; } -- cgit v1.2.3 From de28377d3ad3797516826f287f554dfefb7fdb47 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Sep 2009 17:31:31 -0500 Subject: some refactoring --- src/users-service-dbus.c | 89 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 30 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 8685105..acc3f7d 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -53,6 +53,9 @@ static gboolean _users_service_server_get_users_info (UsersServiceDbus *servi const GArray *uids, GPtrArray **user_info, GError **error); +static void create_session_proxy (UsersServiceDbus *self); +static void create_system_proxy (UsersServiceDbus *self); +static void create_gdm_proxy (UsersServiceDbus *self); static void users_loaded (DBusGProxy *proxy, gpointer user_data); static void user_added (DBusGProxy *proxy, @@ -154,26 +157,57 @@ users_service_dbus_init (UsersServiceDbus *self) /* Get the buses */ priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (error != NULL) { - g_error ("Unable to get session bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get session bus: %s", error->message); + g_error_free (error); - return; - } + return; + } priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (error != NULL) { - g_error("Unable to get system bus: %s", error->message); - g_error_free(error); + if (error != NULL) + { + g_error("Unable to get system bus: %s", error->message); + g_error_free(error); - return; - } + return; + } dbus_g_connection_register_g_object (priv->session_bus, INDICATOR_USERS_SERVICE_DBUS_OBJECT, G_OBJECT (self)); - /* Set up the DBUS service proxies */ + dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, + G_TYPE_NONE, + G_TYPE_INT64, + G_TYPE_INVALID); + + create_session_proxy (self); + create_system_proxy (self); + create_gdm_proxy (self); + + users_loaded (priv->gdm_proxy, self); +} + +static void +users_service_dbus_dispose (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->dispose (object); +} + +static void +users_service_dbus_finalize (GObject *object) +{ + G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); +} + +static void +create_session_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + priv->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (priv->session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, @@ -186,6 +220,13 @@ users_service_dbus_init (UsersServiceDbus *self) return; } +} + +static void +create_system_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, DBUS_SERVICE_DBUS, @@ -199,6 +240,13 @@ users_service_dbus_init (UsersServiceDbus *self) return; } +} + +static void +create_gdm_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; priv->gdm_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.gnome.DisplayManager", @@ -212,11 +260,6 @@ users_service_dbus_init (UsersServiceDbus *self) g_error_free (error); } - dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, - G_TYPE_NONE, - G_TYPE_INT64, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->gdm_proxy, "UsersLoaded", G_TYPE_INVALID); @@ -259,20 +302,6 @@ users_service_dbus_init (UsersServiceDbus *self) G_CALLBACK (user_updated), self, NULL); - - users_loaded (priv->gdm_proxy, self); -} - -static void -users_service_dbus_dispose (GObject *object) -{ - G_OBJECT_CLASS (users_service_dbus_parent_class)->dispose (object); -} - -static void -users_service_dbus_finalize (GObject *object) -{ - G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); } static void -- cgit v1.2.3 From 541259b2cb86b7393232f59e4f61366e52fe5cea Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 10:01:58 -0500 Subject: ck fu --- src/users-service-dbus.c | 458 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 417 insertions(+), 41 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index acc3f7d..b9e9391 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -21,6 +21,10 @@ #include "config.h" #endif +#include +#include +#include + #include #include "dbus-shared-names.h" @@ -56,6 +60,10 @@ static gboolean _users_service_server_get_users_info (UsersServiceDbus *servi static void create_session_proxy (UsersServiceDbus *self); static void create_system_proxy (UsersServiceDbus *self); static void create_gdm_proxy (UsersServiceDbus *self); +static void create_seat_proxy (UsersServiceDbus *self); +static void create_ck_proxy (UsersServiceDbus *self); +static void create_cksession_proxy (UsersServiceDbus *self); +static gchar *get_seat (UsersServiceDbus *service); static void users_loaded (DBusGProxy *proxy, gpointer user_data); static void user_added (DBusGProxy *proxy, @@ -67,6 +75,16 @@ static void user_removed (DBusGProxy *proxy static void user_updated (DBusGProxy *proxy, guint uid, gpointer user_data); +static void seat_proxy_session_added (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service); +static void seat_proxy_session_removed (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service); +static gboolean maybe_add_session_for_user (UsersServiceDbus *service, + UserData *user, + const gchar *ssid); +static gchar * get_seat_internal (UsersServiceDbus *self); #include "users-service-server.h" @@ -75,14 +93,23 @@ typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate; struct _UsersServiceDbusPrivate { - GList *users; - gint count; + GHashTable *users; + gint count; + gchar *seat; + gchar *ssid; DBusGConnection *session_bus; DBusGConnection *system_bus; + DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; + DBusGProxy *ck_proxy; + DBusGProxy *seat_proxy; + DBusGProxy *session_proxy; + + GHashTable *exclusions; + GHashTable *sessions; }; #define USERS_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), USERS_SERVICE_DBUS_TYPE, UsersServiceDbusPrivate)) @@ -174,6 +201,16 @@ users_service_dbus_init (UsersServiceDbus *self) return; } + priv->exclusions = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + NULL); + + priv->users = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + NULL); + dbus_g_connection_register_g_object (priv->session_bus, INDICATOR_USERS_SERVICE_DBUS_OBJECT, G_OBJECT (self)); @@ -186,6 +223,8 @@ users_service_dbus_init (UsersServiceDbus *self) create_session_proxy (self); create_system_proxy (self); create_gdm_proxy (self); + create_seat_proxy (self); + create_ck_proxy (self); users_loaded (priv->gdm_proxy, self); } @@ -233,12 +272,16 @@ create_system_proxy (UsersServiceDbus *self) DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &error); - if (error != NULL) + + if (!priv->dbus_proxy_system) { - g_error ("Unable to get dbus proxy on system bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get dbus proxy on system bus: %s", error->message); + g_error_free (error); - return; + return; + } } } @@ -254,10 +297,15 @@ create_gdm_proxy (UsersServiceDbus *self) "org.gnome.DisplayManager.UserManager", &error); - if (error != NULL) + if (!priv->gdm_proxy) { - g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); - g_error_free (error); + if (error != NULL) + { + g_error ("Unable to get DisplayManager proxy on system bus: %s", error->message); + g_error_free (error); + } + + return; } dbus_g_proxy_add_signal (priv->gdm_proxy, @@ -304,6 +352,329 @@ create_gdm_proxy (UsersServiceDbus *self) NULL); } +static void +create_ck_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + priv->ck_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager"); + + if (!priv->ck_proxy) + { + g_warning ("Failed to setup ConsoleKit proxy."); + return; + } +} + +static void +create_seat_proxy (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + + priv->seat = get_seat (self); + if (priv->seat == NULL) + { + return; + } + + priv->seat_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, + "org.freedesktop.ConsoleKit", + priv->seat, + "org.freedesktop.ConsoleKit.Seat", + &error); + + if (!priv->seat_proxy) + { + if (error != NULL) + { + g_warning ("Failed to connect to the ConsoleKit seat: %s", error->message); + g_error_free (error); + } + + return; + } + + dbus_g_proxy_add_signal (priv->seat_proxy, + "SessionAdded", + DBUS_TYPE_G_OBJECT_PATH, + G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->seat_proxy, + "SessionRemoved", + DBUS_TYPE_G_OBJECT_PATH, + G_TYPE_INVALID); + + dbus_g_proxy_connect_signal (priv->seat_proxy, + "SessionAdded", + G_CALLBACK (seat_proxy_session_added), + self, + NULL); + dbus_g_proxy_connect_signal (priv->seat_proxy, + "SessionRemoved", + G_CALLBACK (seat_proxy_session_removed), + self, + NULL); +} + +static void +create_cksession_proxy (UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + + priv->session_proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.ConsoleKit", + priv->ssid, + "org.freedesktop.ConsoleKit.Session"); + + if (!priv->session_proxy) + { + g_warning ("Failed to connect to ConsoleKit session"); + return; + } +} + +static gchar * +get_seat (UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GError *error = NULL; + gchar *ssid = NULL; + gchar *seat; + + if (!dbus_g_proxy_call (priv->ck_proxy, + "GetCurrentSession", + &error, + G_TYPE_INVALID, + DBUS_TYPE_G_OBJECT_PATH, + &ssid, + G_TYPE_INVALID)) + { + if (error) + { + g_debug ("Failed to get session: %s", error->message); + g_error_free (error); + } + + if (ssid) + g_free (ssid); + + return NULL; + } + + priv->ssid = ssid; + create_cksession_proxy (service); + + if (ssid) + g_free (ssid); + + seat = get_seat_internal (service); + + return seat; +} + +static gchar * +get_seat_internal (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + gchar *seat; + + if (!dbus_g_proxy_call (priv->session_proxy, + "GetSeatId", + &error, + G_TYPE_INVALID, + DBUS_TYPE_G_OBJECT_PATH, &seat, + G_TYPE_INVALID)) + { + if (error) + { + g_debug ("Failed to identify the current seat: %s", error->message); + } + } + + return seat; +} + +static gboolean +get_uid_from_session_id (UsersServiceDbus *service, + const gchar *session_id, + uid_t *uidp) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GError *error; + guint uid; + + if (dbus_g_proxy_call (priv->session_proxy, + "GetUnixUser", + &error, + G_TYPE_INVALID, + G_TYPE_UINT, &uid, + G_TYPE_INVALID)) + { + if (error) + { + g_warning ("Failed to get the session: %s", error->message); + g_error_free (error); + } + + return FALSE; + } + + if (uidp != NULL) + { + *uidp = (uid_t)uid; + } + + return TRUE; +} + +static gint +session_compare (const gchar *a, + const gchar *b) +{ + if (a == NULL) + return 1; + else if (b == NULL) + return -1; + + return strcmp (a, b); +} + +static gboolean +maybe_add_session_for_user (UsersServiceDbus *service, + UserData *user, + const gchar *ssid) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + GError *error = NULL; + gchar *seat = NULL; + gchar *xdisplay = NULL; + GList *l; + + seat = get_seat_internal (service); + if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0) + return FALSE; + + if (!dbus_g_proxy_call (priv->session_proxy, + "GetX11Display", + &error, + G_TYPE_INVALID, + G_TYPE_STRING, &xdisplay, + G_TYPE_INVALID)) + { + if (error) + { + g_debug ("Failed to get X11 display: %s", error->message); + g_error_free (error); + } + + return FALSE; + } + + if (!xdisplay || xdisplay[0] == '\0') + return FALSE; + + if (g_hash_table_lookup (priv->exclusions, user->user_name)) + return FALSE; + + g_hash_table_insert (priv->sessions, + g_strdup (ssid), + g_strdup (user->user_name)); + + l = g_list_find_custom (user->sessions, ssid, (GCompareFunc)session_compare); + if (l == NULL) + { + g_debug ("Adding session %s", ssid); + + user->sessions = g_list_prepend (user->sessions, g_strdup (ssid)); + } + else + { + g_debug ("User %s already has session %s", user->user_name, ssid); + } + + return TRUE; +} + +static void +seat_proxy_session_added (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + uid_t uid; + gboolean res; + struct passwd *pwent; + UserData *user; + + if (!get_uid_from_session_id (service, session_id, &uid)) + { + g_warning ("Failed to lookup user for session"); + return; + } + + errno = 0; + pwent = getpwuid (uid); + if (!pwent) + { + g_warning ("Failed to lookup user id %d: %s", (int)uid, g_strerror (errno)); + return; + } + + if (g_hash_table_lookup (priv->exclusions, pwent->pw_name)) + { + g_debug ("Excluding user %s", pwent->pw_name); + return; + } + + user = g_hash_table_lookup (priv->users, pwent->pw_name); + if (!user) + { + return; + } + + res = maybe_add_session_for_user (service, user, session_id); +} + +static void +seat_proxy_session_removed (DBusGProxy *seat_proxy, + const gchar *session_id, + UsersServiceDbus *service) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + UserData *user; + gchar *username; + GList *l; + + username = g_hash_table_lookup (priv->sessions, session_id); + if (!username) + return; + + user = g_hash_table_lookup (priv->users, username); + if (!user) + return; + + //_user_remove_session (user, session_id); + + l = g_list_find_custom (user->sessions, + session_id, + (GCompareFunc)session_compare); + if (l) + { + g_debug ("Removing session %s", session_id); + + g_free (l->data); + user->sessions = g_list_delete_link (user->sessions, l); + } + else + { + g_debug ("Session not found: %s", session_id); + } +} + static void users_loaded (DBusGProxy *proxy, gpointer user_data) @@ -359,20 +730,22 @@ users_loaded (DBusGProxy *proxy, for (i = 0; i < users_info->len; i++) { GValueArray *values; - UserData *data; + UserData *user; values = g_ptr_array_index (users_info, i); - data = g_new0 (UserData, 1); + user = g_new0 (UserData, 1); - data->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); - data->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); - data->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); - data->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); - data->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); - data->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); + user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); + user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); + user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); + user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); + user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); + user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); - priv->users = g_list_prepend (priv->users, data); + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); } } @@ -389,7 +762,7 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - return priv->users; + return g_hash_table_get_values (priv->users); } static void @@ -423,11 +796,21 @@ user_added (DBusGProxy *proxy, user->uid = uid; - priv->users = g_list_prepend (priv->users, user); + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); } +static gboolean +compare_users_by_uid (gpointer key, + gpointer value, + gpointer user_data) +{ + return (GPOINTER_TO_UINT (value) == GPOINTER_TO_UINT (user_data)); +} + static void user_removed (DBusGProxy *proxy, guint uid, @@ -435,20 +818,16 @@ user_removed (DBusGProxy *proxy, { UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - GList *l; + UserData *user; - priv->count--; + user = g_hash_table_find (priv->users, + compare_users_by_uid, + GUINT_TO_POINTER (uid)); - for (l = priv->users; l != NULL; l = g_list_next (l)) - { - UserData *user = (UserData *)l->data; + g_hash_table_remove (priv->users, + user->user_name); - if (user->uid == uid) - { - priv->users = g_list_remove (priv->users, l->data); - g_signal_emit (G_OBJECT (service), signals[USER_REMOVED], 0, user, TRUE); - } - } + priv->count--; } static void @@ -456,19 +835,16 @@ user_updated (DBusGProxy *proxy, guint uid, gpointer user_data) { +#if 0 + // XXX - TODO UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - GList *l; + UserData *user; - for (l = priv->users; l != NULL; l = g_list_next (l)) - { - UserData *user = (UserData *)l->data; - - if (user->uid == uid) - { - // XXX - update user data - } - } + user = g_hash_table_find (priv->users, + compare_users_by_uid, + GUINT_TO_POINTER (uid)); +#endif } static gboolean -- cgit v1.2.3 From a3ca139c3e39765da2a295b1d7261268f94f020b Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 12:40:16 -0500 Subject: user activation wip --- src/users-service-dbus.c | 154 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 142 insertions(+), 12 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index b9e9391..593ef83 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -26,6 +26,8 @@ #include #include +#include +#include #include "dbus-shared-names.h" #include "users-service-dbus.h" @@ -81,7 +83,7 @@ static void seat_proxy_session_added (DBusGProxy *seat_ static void seat_proxy_session_removed (DBusGProxy *seat_proxy, const gchar *session_id, UsersServiceDbus *service); -static gboolean maybe_add_session_for_user (UsersServiceDbus *service, +static gboolean do_add_session (UsersServiceDbus *service, UserData *user, const gchar *ssid); static gchar * get_seat_internal (UsersServiceDbus *self); @@ -464,12 +466,11 @@ get_seat (UsersServiceDbus *service) return NULL; } + g_print ("get_seat(): ssid is %s\n", ssid); + priv->ssid = ssid; create_cksession_proxy (service); - if (ssid) - g_free (ssid); - seat = get_seat_internal (service); return seat; @@ -495,13 +496,15 @@ get_seat_internal (UsersServiceDbus *self) } } + g_print ("get_seat_internal: %s\n", seat); + return seat; } static gboolean -get_uid_from_session_id (UsersServiceDbus *service, - const gchar *session_id, - uid_t *uidp) +get_unix_user (UsersServiceDbus *service, + const gchar *session_id, + uid_t *uidp) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); GError *error; @@ -543,10 +546,65 @@ session_compare (const gchar *a, return strcmp (a, b); } +static gchar * +get_session_for_user (UsersServiceDbus *service, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); + gboolean can_activate; + GError *error = NULL; + GList *l; + + if (!priv->seat_proxy) + create_seat_proxy (service); + + if (priv->seat == NULL || priv->seat[0] == '\0') + { + return NULL; + } + + if (!dbus_g_proxy_call (priv->seat_proxy, + "CanActivateSessions", + &error, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, &can_activate, + G_TYPE_INVALID)) + { + g_warning ("Failed to determine if seat can activate sessions: %s", error->message); + g_error_free (error); + + return NULL; + } + + if (!can_activate) { + return NULL; + } + + if (!user->sessions || g_list_length (user->sessions) == 0) + { + return NULL; + } + + for (l = user->sessions; l != NULL; l = l->next) + { + const char *ssid; + + ssid = l->data; + + /* FIXME: better way to choose? */ + if (ssid != NULL) + { + return g_strdup (ssid); + } + } + + return NULL; +} + static gboolean -maybe_add_session_for_user (UsersServiceDbus *service, - UserData *user, - const gchar *ssid) +do_add_session (UsersServiceDbus *service, + UserData *user, + const gchar *ssid) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); GError *error = NULL; @@ -577,6 +635,8 @@ maybe_add_session_for_user (UsersServiceDbus *service, if (!xdisplay || xdisplay[0] == '\0') return FALSE; + g_print ("xdisplay is %s\n", xdisplay); + if (g_hash_table_lookup (priv->exclusions, user->user_name)) return FALSE; @@ -610,7 +670,7 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, struct passwd *pwent; UserData *user; - if (!get_uid_from_session_id (service, session_id, &uid)) + if (!get_unix_user (service, session_id, &uid)) { g_warning ("Failed to lookup user for session"); return; @@ -636,7 +696,7 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, return; } - res = maybe_add_session_for_user (service, user, session_id); + res = do_add_session (service, user, session_id); } static void @@ -765,6 +825,76 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) return g_hash_table_get_values (priv->users); } +gboolean +users_service_dbus_activate_user_session (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusError error; + gchar *ssid; + + dbus_error_init (&error); + + if (!priv->seat) + priv->seat = get_seat (self); + + ssid = get_session_for_user (self, user); + + g_print ("users_service_dbus_activate_user_session...\n"); + g_print ("seat is %s\n", priv->seat); + g_print ("ssid is %s\n", ssid); + + if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + priv->seat, + "org.freedesktop.ConsoleKit.Seat", + "ActivateSession"))) + { + g_warning ("failed to create new message"); + return FALSE; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_OBJECT_PATH, + &ssid, + DBUS_TYPE_INVALID)) + { + g_warning ("failed to append args"); + return FALSE; + } + + if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), + message, + -1, + &error))) + { + g_warning ("send_with_reply_and_block failed"); + + if (dbus_error_is_set (&error)) + { + g_warning ("Unable to activate session: %s", error.message); + dbus_error_free (&error); + + return FALSE; + } + } + + g_print ("freeing shit up..\n"); + + if (message) + { + dbus_message_unref (message); + } + + if (reply) + { + dbus_message_unref (reply); + } + + return TRUE; +} + static void user_added (DBusGProxy *proxy, guint uid, -- cgit v1.2.3 From 9a12a13ccda5cbcce28f6913fd29bd47a61c6762 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 13:49:17 -0500 Subject: session adding --- src/users-service-dbus.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 593ef83..d369833 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -181,6 +181,8 @@ users_service_dbus_init (UsersServiceDbus *self) GError *error = NULL; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + g_print ("INIT\n"); + priv->users = NULL; priv->count = 0; @@ -225,8 +227,8 @@ users_service_dbus_init (UsersServiceDbus *self) create_session_proxy (self); create_system_proxy (self); create_gdm_proxy (self); - create_seat_proxy (self); create_ck_proxy (self); + create_seat_proxy (self); users_loaded (priv->gdm_proxy, self); } @@ -377,12 +379,16 @@ create_seat_proxy (UsersServiceDbus *self) UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); GError *error = NULL; + g_print ("create_seat_proxy ()\n"); + priv->seat = get_seat (self); if (priv->seat == NULL) { + g_print (" ** no priv->seat, returning\n"); return; } + g_print ("setup priv->seat_proxy...\n"); priv->seat_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.freedesktop.ConsoleKit", priv->seat, @@ -391,6 +397,8 @@ create_seat_proxy (UsersServiceDbus *self) if (!priv->seat_proxy) { + g_print ("some error...\n"); + if (error != NULL) { g_warning ("Failed to connect to the ConsoleKit seat: %s", error->message); @@ -400,10 +408,12 @@ create_seat_proxy (UsersServiceDbus *self) return; } + g_print ("... SessionAdded\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); + g_print ("... SessionRemoved\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionRemoved", DBUS_TYPE_G_OBJECT_PATH, @@ -577,11 +587,13 @@ get_session_for_user (UsersServiceDbus *service, } if (!can_activate) { + g_warning ("Can't activate sessions"); return NULL; } if (!user->sessions || g_list_length (user->sessions) == 0) { + g_print (" *** no user sessions\n"); return NULL; } @@ -594,6 +606,7 @@ get_session_for_user (UsersServiceDbus *service, /* FIXME: better way to choose? */ if (ssid != NULL) { + g_print (" ==== ssid is %s\n", ssid); return g_strdup (ssid); } } @@ -612,7 +625,10 @@ do_add_session (UsersServiceDbus *service, gchar *xdisplay = NULL; GList *l; + g_print ("DO_ADD_SESSION (ssid is %s)\n", ssid); + seat = get_seat_internal (service); + g_print (" *** seat is %s\n", seat); if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0) return FALSE; @@ -659,6 +675,44 @@ do_add_session (UsersServiceDbus *service, return TRUE; } +static void +add_sessions_for_user (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error; + GPtrArray *sessions; + int i; + + error = NULL; + if (!dbus_g_proxy_call (priv->ck_proxy, + "GetSessionsForUnixUser", + &error, + G_TYPE_UINT, user->uid, + G_TYPE_INVALID, + dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), + &sessions, + G_TYPE_INVALID)) + { + g_debug ("Failed to find sessions for user: %s", error->message); + g_error_free (error); + + return; + } + + for (i = 0; i < sessions->len; i++) + { + char *ssid; + + ssid = g_ptr_array_index (sessions, i); + do_add_session (self, user, ssid); + } + + g_ptr_array_foreach (sessions, (GFunc)g_free, NULL); + g_ptr_array_free (sessions, TRUE); +} + + static void seat_proxy_session_added (DBusGProxy *seat_proxy, const gchar *session_id, @@ -787,6 +841,9 @@ users_loaded (DBusGProxy *proxy, return; } + g_print ("***************\n"); + g_print ("*** users_info->len is %d\n", users_info->len); + for (i = 0; i < users_info->len; i++) { GValueArray *values; @@ -803,9 +860,15 @@ users_loaded (DBusGProxy *proxy, user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); + g_print ("*** username is %s\n", user->user_name); + g_hash_table_insert (priv->users, g_strdup (user->user_name), user); + + g_print (" ... adding sessions for %s\n", user->user_name); + add_sessions_for_user (service, user); + g_print ("***************\n"); } } -- cgit v1.2.3 From 3de7117e82eb5d0b39fd17532852f27dcd555dfe Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 17:09:07 -0500 Subject: cleanups and more session fu --- src/users-service-dbus.c | 300 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 247 insertions(+), 53 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index d369833..15da3d2 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -180,8 +180,31 @@ users_service_dbus_init (UsersServiceDbus *self) { GError *error = NULL; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - g_print ("INIT\n"); + gint i = 0; + const gchar *excludes[] = + { "bin", + "root", /* excludes taken from gdm */ + "daemon", + "adm", + "lp", + "sync", + "shutdown", + "halt", + "mail", + "news", + "uucp", + "operator", + "nobody", + "nobody4", + "noaccess", + "gdm", + "postgres", + "pvm", + "rpm", + "nfsnobody", + "pcap", + NULL + }; priv->users = NULL; priv->count = 0; @@ -199,7 +222,7 @@ users_service_dbus_init (UsersServiceDbus *self) priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error != NULL) { - g_error("Unable to get system bus: %s", error->message); + g_error ("Unable to get system bus: %s", error->message); g_error_free(error); return; @@ -210,6 +233,18 @@ users_service_dbus_init (UsersServiceDbus *self) g_free, NULL); + for (i = 0; excludes[i] != NULL; i++) + { + g_hash_table_insert (priv->exclusions, + g_strdup (excludes [i]), + GUINT_TO_POINTER (TRUE)); + } + + priv->sessions = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); + priv->users = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, @@ -368,7 +403,7 @@ create_ck_proxy (UsersServiceDbus *self) if (!priv->ck_proxy) { - g_warning ("Failed to setup ConsoleKit proxy."); + g_warning ("Failed to get ConsoleKit proxy."); return; } } @@ -379,16 +414,12 @@ create_seat_proxy (UsersServiceDbus *self) UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); GError *error = NULL; - g_print ("create_seat_proxy ()\n"); - priv->seat = get_seat (self); if (priv->seat == NULL) { - g_print (" ** no priv->seat, returning\n"); return; } - g_print ("setup priv->seat_proxy...\n"); priv->seat_proxy = dbus_g_proxy_new_for_name_owner (priv->system_bus, "org.freedesktop.ConsoleKit", priv->seat, @@ -397,8 +428,6 @@ create_seat_proxy (UsersServiceDbus *self) if (!priv->seat_proxy) { - g_print ("some error...\n"); - if (error != NULL) { g_warning ("Failed to connect to the ConsoleKit seat: %s", error->message); @@ -408,12 +437,10 @@ create_seat_proxy (UsersServiceDbus *self) return; } - g_print ("... SessionAdded\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - g_print ("... SessionRemoved\n"); dbus_g_proxy_add_signal (priv->seat_proxy, "SessionRemoved", DBUS_TYPE_G_OBJECT_PATH, @@ -443,7 +470,7 @@ create_cksession_proxy (UsersServiceDbus *service) if (!priv->session_proxy) { - g_warning ("Failed to connect to ConsoleKit session"); + g_warning ("Failed to get ConsoleKit session proxy"); return; } } @@ -466,7 +493,7 @@ get_seat (UsersServiceDbus *service) { if (error) { - g_debug ("Failed to get session: %s", error->message); + g_debug ("Failed to call GetCurrentSession: %s", error->message); g_error_free (error); } @@ -476,8 +503,6 @@ get_seat (UsersServiceDbus *service) return NULL; } - g_print ("get_seat(): ssid is %s\n", ssid); - priv->ssid = ssid; create_cksession_proxy (service); @@ -491,7 +516,7 @@ get_seat_internal (UsersServiceDbus *self) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); GError *error = NULL; - gchar *seat; + gchar *seat = NULL; if (!dbus_g_proxy_call (priv->session_proxy, "GetSeatId", @@ -502,12 +527,12 @@ get_seat_internal (UsersServiceDbus *self) { if (error) { - g_debug ("Failed to identify the current seat: %s", error->message); + g_debug ("Failed to call GetSeatId: %s", error->message); + + return NULL; } } - g_print ("get_seat_internal: %s\n", seat); - return seat; } @@ -517,7 +542,7 @@ get_unix_user (UsersServiceDbus *service, uid_t *uidp) { UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - GError *error; + GError *error = NULL; guint uid; if (dbus_g_proxy_call (priv->session_proxy, @@ -529,7 +554,7 @@ get_unix_user (UsersServiceDbus *service, { if (error) { - g_warning ("Failed to get the session: %s", error->message); + g_warning ("Failed to call GetUnixUser: %s", error->message); g_error_free (error); } @@ -586,14 +611,13 @@ get_session_for_user (UsersServiceDbus *service, return NULL; } - if (!can_activate) { - g_warning ("Can't activate sessions"); - return NULL; - } + if (!can_activate) + { + return NULL; + } if (!user->sessions || g_list_length (user->sessions) == 0) { - g_print (" *** no user sessions\n"); return NULL; } @@ -603,10 +627,8 @@ get_session_for_user (UsersServiceDbus *service, ssid = l->data; - /* FIXME: better way to choose? */ - if (ssid != NULL) + if (ssid) { - g_print (" ==== ssid is %s\n", ssid); return g_strdup (ssid); } } @@ -625,10 +647,8 @@ do_add_session (UsersServiceDbus *service, gchar *xdisplay = NULL; GList *l; - g_print ("DO_ADD_SESSION (ssid is %s)\n", ssid); - seat = get_seat_internal (service); - g_print (" *** seat is %s\n", seat); + if (!seat || !priv->seat || strcmp (seat, priv->seat) != 0) return FALSE; @@ -641,7 +661,7 @@ do_add_session (UsersServiceDbus *service, { if (error) { - g_debug ("Failed to get X11 display: %s", error->message); + g_debug ("Failed to call GetX11Display: %s", error->message); g_error_free (error); } @@ -651,8 +671,6 @@ do_add_session (UsersServiceDbus *service, if (!xdisplay || xdisplay[0] == '\0') return FALSE; - g_print ("xdisplay is %s\n", xdisplay); - if (g_hash_table_lookup (priv->exclusions, user->user_name)) return FALSE; @@ -694,7 +712,7 @@ add_sessions_for_user (UsersServiceDbus *self, &sessions, G_TYPE_INVALID)) { - g_debug ("Failed to find sessions for user: %s", error->message); + g_debug ("Failed to call GetSessionsForUnixUser: %s", error->message); g_error_free (error); return; @@ -771,7 +789,7 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, if (!user) return; - //_user_remove_session (user, session_id); + // remove_session_from_user (user, session_id); ?? l = g_list_find_custom (user->sessions, session_id, @@ -841,9 +859,6 @@ users_loaded (DBusGProxy *proxy, return; } - g_print ("***************\n"); - g_print ("*** users_info->len is %d\n", users_info->len); - for (i = 0; i < users_info->len; i++) { GValueArray *values; @@ -860,15 +875,11 @@ users_loaded (DBusGProxy *proxy, user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); - g_print ("*** username is %s\n", user->user_name); - g_hash_table_insert (priv->users, g_strdup (user->user_name), user); - g_print (" ... adding sessions for %s\n", user->user_name); add_sessions_for_user (service, user); - g_print ("***************\n"); } } @@ -888,6 +899,192 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) return g_hash_table_get_values (priv->users); } +static gboolean +session_is_login_window (UsersServiceDbus *self, + const char *ssid) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusGProxy *proxy = NULL; + GError *error = NULL; + char *type = NULL; + + if (!(proxy = dbus_g_proxy_new_for_name (priv->system_bus, + "org.freedesktop.ConsoleKit", + ssid, + "org.freedesktop.ConsoleKit.Session"))) + { + g_warning ("Failed to get ConsoleKit proxy"); + + return FALSE; + } + + if (!dbus_g_proxy_call (proxy, + "GetSessionType", + &error, + G_TYPE_INVALID, + G_TYPE_STRING, &type, + G_TYPE_INVALID)) + { + g_warning ("Can't call GetSessionType: %s", error->message); + g_error_free (error); + + if (proxy) + g_object_unref (proxy); + + return FALSE; + } + + if (proxy) + g_object_unref (proxy); + + return (type && type[0] != '\0' && strcmp (type, "LoginWindow") == 0); +} + +static char * +get_login_session (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + gboolean can_activate; + GError *error = NULL; + GPtrArray *sessions = NULL; + char *ssid = NULL; + int i; + + if (!priv->seat || priv->seat[0] == '\0') + { + return NULL; + } + + if (!dbus_g_proxy_call (priv->seat_proxy, + "CanActivateSessions", + &error, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, &can_activate, + G_TYPE_INVALID)) + { + g_warning ("Failed to call CanActivateSessions: %s", error->message); + g_error_free (error); + + return NULL; + } + + if (!can_activate) + { + return NULL; + } + + error = NULL; + if (!dbus_g_proxy_call (priv->seat_proxy, + "GetSessions", + &error, + G_TYPE_INVALID, + dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &sessions, + G_TYPE_INVALID)) + { + g_warning ("Failed to call GetSessions: %s", error->message); + g_error_free (error); + + return NULL; + } + + for (i = 0; i < sessions->len; i++) + { + char *s = g_ptr_array_index (sessions, i); + + if (session_is_login_window (self, s)) + { + ssid = g_strdup (s); + break; + } + } + + g_ptr_array_foreach (sessions, (GFunc)g_free, NULL); + g_ptr_array_free (sessions, TRUE); + + return ssid; +} + +static gboolean +activate_user_session (UsersServiceDbus *self, + const char *seat, + const char *ssid) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusError error; + + if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + seat, + "org.freedesktop.ConsoleKit.Seat", + "ActivateSession"))) + { + return FALSE; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_OBJECT_PATH, &ssid, + DBUS_TYPE_INVALID)) + { + return FALSE; + } + + dbus_error_init (&error); + if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), + message, + -1, + &error))) + { + if (dbus_error_is_set (&error)) + { + g_warning ("Can't activate session: %s", error.message); + dbus_error_free (&error); + + return FALSE; + } + } + + if (message) + { + dbus_message_unref (message); + } + + if (reply) + { + dbus_message_unref (reply); + } + + return TRUE; +} + +gboolean +start_new_user_session (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + GError *error = NULL; + char *ssid; + + ssid = get_login_session (self); + if (ssid) + { + if (!activate_user_session (self, priv->seat, ssid)) + { + return FALSE; + } + } + + if (!g_spawn_command_line_async ("gdmflexiserver -s", &error)) + { + g_warning ("Failed to start new login session: %s", error->message); + g_error_free (error); + + return FALSE; + } + + return TRUE; +} + gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self, UserData *user) @@ -905,9 +1102,10 @@ users_service_dbus_activate_user_session (UsersServiceDbus *self, ssid = get_session_for_user (self, user); - g_print ("users_service_dbus_activate_user_session...\n"); - g_print ("seat is %s\n", priv->seat); - g_print ("ssid is %s\n", ssid); + if (!ssid) + { + return start_new_user_session (self, user); + } if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", priv->seat, @@ -932,19 +1130,15 @@ users_service_dbus_activate_user_session (UsersServiceDbus *self, -1, &error))) { - g_warning ("send_with_reply_and_block failed"); - if (dbus_error_is_set (&error)) { - g_warning ("Unable to activate session: %s", error.message); + g_warning ("Failed to send message: %s", error.message); dbus_error_free (&error); return FALSE; } } - g_print ("freeing shit up..\n"); - if (message) { dbus_message_unref (message); -- cgit v1.2.3 From 8888a1aa1b4ca13be5028561f4b0adf21d392719 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 18:00:35 -0500 Subject: move stuff around --- src/users-service-dbus.c | 166 +++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 83 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 15da3d2..fac689d 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -883,22 +883,6 @@ users_loaded (DBusGProxy *proxy, } } -gint -users_service_dbus_get_user_count (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - return priv->count; -} - -GList * -users_service_dbus_get_user_list (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - - return g_hash_table_get_values (priv->users); -} - static gboolean session_is_login_window (UsersServiceDbus *self, const char *ssid) @@ -1085,73 +1069,6 @@ start_new_user_session (UsersServiceDbus *self, return TRUE; } -gboolean -users_service_dbus_activate_user_session (UsersServiceDbus *self, - UserData *user) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - DBusMessage *message = NULL; - DBusMessage *reply = NULL; - DBusError error; - gchar *ssid; - - dbus_error_init (&error); - - if (!priv->seat) - priv->seat = get_seat (self); - - ssid = get_session_for_user (self, user); - - if (!ssid) - { - return start_new_user_session (self, user); - } - - if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", - priv->seat, - "org.freedesktop.ConsoleKit.Seat", - "ActivateSession"))) - { - g_warning ("failed to create new message"); - return FALSE; - } - - if (!dbus_message_append_args (message, - DBUS_TYPE_OBJECT_PATH, - &ssid, - DBUS_TYPE_INVALID)) - { - g_warning ("failed to append args"); - return FALSE; - } - - if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), - message, - -1, - &error))) - { - if (dbus_error_is_set (&error)) - { - g_warning ("Failed to send message: %s", error.message); - dbus_error_free (&error); - - return FALSE; - } - } - - if (message) - { - dbus_message_unref (message); - } - - if (reply) - { - dbus_message_unref (reply); - } - - return TRUE; -} - static void user_added (DBusGProxy *proxy, guint uid, @@ -1279,3 +1196,86 @@ _users_service_server_get_users_info (UsersServiceDbus *service, { return TRUE; } + +gint +users_service_dbus_get_user_count (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return priv->count; +} + +GList * +users_service_dbus_get_user_list (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + return g_hash_table_get_values (priv->users); +} + +gboolean +users_service_dbus_activate_user_session (UsersServiceDbus *self, + UserData *user) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusError error; + gchar *ssid; + + dbus_error_init (&error); + + if (!priv->seat) + priv->seat = get_seat (self); + + ssid = get_session_for_user (self, user); + + if (!ssid) + { + return start_new_user_session (self, user); + } + + if (!(message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + priv->seat, + "org.freedesktop.ConsoleKit.Seat", + "ActivateSession"))) + { + g_warning ("failed to create new message"); + return FALSE; + } + + if (!dbus_message_append_args (message, + DBUS_TYPE_OBJECT_PATH, + &ssid, + DBUS_TYPE_INVALID)) + { + g_warning ("failed to append args"); + return FALSE; + } + + if (!(reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (priv->system_bus), + message, + -1, + &error))) + { + if (dbus_error_is_set (&error)) + { + g_warning ("Failed to send message: %s", error.message); + dbus_error_free (&error); + + return FALSE; + } + } + + if (message) + { + dbus_message_unref (message); + } + + if (reply) + { + dbus_message_unref (reply); + } + + return TRUE; +} -- cgit v1.2.3 From cbcbcc64d025aae5b3fa6d1a9b4a8839a95842f6 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 18:05:39 -0500 Subject: add todo comment --- src/users-service-dbus.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index fac689d..937ce30 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -1213,6 +1213,17 @@ users_service_dbus_get_user_list (UsersServiceDbus *self) return g_hash_table_get_values (priv->users); } +/* + * XXX - TODO: Right now we switch to a session that another user + * already has open, but if there are no open sessions + * for this user we go to the login screen and the + * user at the seat must select a user and enter a + * password. This kind of defeats the purpose of + * actually selecting a username, since selecting any + * user will do the same thing here. We need to change + * it so you only need to enter a password for the + * specified user. + */ gboolean users_service_dbus_activate_user_session (UsersServiceDbus *self, UserData *user) -- cgit v1.2.3 From 61d73835f3f9b4bc1970587e172f228c3474bdb1 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 19:12:14 -0500 Subject: cleanup --- src/users-service-dbus.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 937ce30..bcd5a03 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -789,8 +789,6 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, if (!user) return; - // remove_session_from_user (user, session_id); ?? - l = g_list_find_custom (user->sessions, session_id, (GCompareFunc)session_compare); -- cgit v1.2.3 From fec2a3548f53572ed24ee675c5f16e65dd35a299 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:05:38 -0500 Subject: don't need to dbus_g_object_type_install_info() --- src/users-service-dbus.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index bcd5a03..261c4c7 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -171,8 +171,6 @@ users_service_dbus_class_init (UsersServiceDbusClass *klass) NULL, NULL, _users_service_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64); - - dbus_g_object_type_install_info (USERS_SERVICE_DBUS_TYPE, &dbus_glib__users_service_server_object_info); } static void -- cgit v1.2.3 From d9caa21356ea1b220018f37163e1ede65a37c945 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:08:05 -0500 Subject: remove unnecessary stuff --- src/users-service-dbus.c | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 261c4c7..649bbbf 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -178,31 +178,6 @@ users_service_dbus_init (UsersServiceDbus *self) { GError *error = NULL; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - gint i = 0; - const gchar *excludes[] = - { "bin", - "root", /* excludes taken from gdm */ - "daemon", - "adm", - "lp", - "sync", - "shutdown", - "halt", - "mail", - "news", - "uucp", - "operator", - "nobody", - "nobody4", - "noaccess", - "gdm", - "postgres", - "pvm", - "rpm", - "nfsnobody", - "pcap", - NULL - }; priv->users = NULL; priv->count = 0; @@ -226,18 +201,6 @@ users_service_dbus_init (UsersServiceDbus *self) return; } - priv->exclusions = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - NULL); - - for (i = 0; excludes[i] != NULL; i++) - { - g_hash_table_insert (priv->exclusions, - g_strdup (excludes [i]), - GUINT_TO_POINTER (TRUE)); - } - priv->sessions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, @@ -669,9 +632,6 @@ do_add_session (UsersServiceDbus *service, if (!xdisplay || xdisplay[0] == '\0') return FALSE; - if (g_hash_table_lookup (priv->exclusions, user->user_name)) - return FALSE; - g_hash_table_insert (priv->sessions, g_strdup (ssid), g_strdup (user->user_name)); @@ -754,12 +714,6 @@ seat_proxy_session_added (DBusGProxy *seat_proxy, return; } - if (g_hash_table_lookup (priv->exclusions, pwent->pw_name)) - { - g_debug ("Excluding user %s", pwent->pw_name); - return; - } - user = g_hash_table_lookup (priv->users, pwent->pw_name); if (!user) { -- cgit v1.2.3 From 7fa88e1e36df5efdf8c7d6d7b874d4e4e92a1d28 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:10:31 -0500 Subject: remove session proxy fu --- src/users-service-dbus.c | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 649bbbf..0ae0170 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -59,7 +59,6 @@ static gboolean _users_service_server_get_users_info (UsersServiceDbus *servi const GArray *uids, GPtrArray **user_info, GError **error); -static void create_session_proxy (UsersServiceDbus *self); static void create_system_proxy (UsersServiceDbus *self); static void create_gdm_proxy (UsersServiceDbus *self); static void create_seat_proxy (UsersServiceDbus *self); @@ -100,10 +99,8 @@ struct _UsersServiceDbusPrivate gchar *seat; gchar *ssid; - DBusGConnection *session_bus; DBusGConnection *system_bus; - DBusGProxy *dbus_proxy_session; DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; DBusGProxy *ck_proxy; @@ -182,16 +179,7 @@ users_service_dbus_init (UsersServiceDbus *self) priv->users = NULL; priv->count = 0; - /* Get the buses */ - priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (error != NULL) - { - g_error ("Unable to get session bus: %s", error->message); - g_error_free (error); - - return; - } - + /* Get the system bus */ priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error != NULL) { @@ -211,16 +199,11 @@ users_service_dbus_init (UsersServiceDbus *self) g_free, NULL); - dbus_g_connection_register_g_object (priv->session_bus, - INDICATOR_USERS_SERVICE_DBUS_OBJECT, - G_OBJECT (self)); - dbus_g_object_register_marshaller (_users_service_marshal_VOID__INT64, G_TYPE_NONE, G_TYPE_INT64, G_TYPE_INVALID); - create_session_proxy (self); create_system_proxy (self); create_gdm_proxy (self); create_ck_proxy (self); @@ -241,26 +224,6 @@ users_service_dbus_finalize (GObject *object) G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); } -static void -create_session_proxy (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - GError *error = NULL; - - priv->dbus_proxy_session = dbus_g_proxy_new_for_name_owner (priv->session_bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - &error); - if (error != NULL) - { - g_error ("Unable to get dbus proxy on session bus: %s", error->message); - g_error_free (error); - - return; - } -} - static void create_system_proxy (UsersServiceDbus *self) { -- cgit v1.2.3 From c608393d5e0650f348fc39769531cb0a1e7c95a0 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:15:56 -0500 Subject: remove the server code --- src/users-service-dbus.c | 69 ------------------------------------------------ 1 file changed, 69 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 0ae0170..5a9b874 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -38,27 +38,6 @@ static void users_service_dbus_class_init (UsersServiceDbusClass *k static void users_service_dbus_init (UsersServiceDbus *self); static void users_service_dbus_dispose (GObject *object); static void users_service_dbus_finalize (GObject *object); -static gboolean _users_service_server_count_users (UsersServiceDbus *service, - gint *count, - GError **error); -static gboolean _users_service_server_get_users_loaded (UsersServiceDbus *self, - gboolean *is_loaded, - GError **error); -static gboolean _users_service_server_get_user_list (UsersServiceDbus *service, - GArray **list, - GError **error); -static gboolean _users_service_server_get_user_info (UsersServiceDbus *service, - const gint64 uid, - gchar **username, - gchar **real_name, - gchar **shell, - gint *login_count, - gchar **icon_url, - GError **error); -static gboolean _users_service_server_get_users_info (UsersServiceDbus *service, - const GArray *uids, - GPtrArray **user_info, - GError **error); static void create_system_proxy (UsersServiceDbus *self); static void create_gdm_proxy (UsersServiceDbus *self); static void create_seat_proxy (UsersServiceDbus *self); @@ -87,8 +66,6 @@ static gboolean do_add_session (UsersServiceDbus *servi const gchar *ssid); static gchar * get_seat_internal (UsersServiceDbus *self); -#include "users-service-server.h" - /* Private */ typedef struct _UsersServiceDbusPrivate UsersServiceDbusPrivate; @@ -1064,52 +1041,6 @@ user_updated (DBusGProxy *proxy, #endif } -static gboolean -_users_service_server_count_users (UsersServiceDbus *service, - gint *uids, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_user_list (UsersServiceDbus *service, - GArray **list, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_users_loaded (UsersServiceDbus *self, - gboolean *is_loaded, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_user_info (UsersServiceDbus *service, - const gint64 uid, - gchar **username, - gchar **real_name, - gchar **shell, - gint *login_count, - char **icon_url, - GError **error) -{ - return TRUE; -} - -static gboolean -_users_service_server_get_users_info (UsersServiceDbus *service, - const GArray *uids, - GPtrArray **user_info, - GError **error) -{ - return TRUE; -} - gint users_service_dbus_get_user_count (UsersServiceDbus *self) { -- cgit v1.2.3 From f8e0ff04840fe4842c5c3ebeef396b530d6f1995 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:18:51 -0500 Subject: remove system proxy --- src/users-service-dbus.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 5a9b874..499182b 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -34,11 +34,10 @@ #include "users-service-client.h" #include "users-service-marshal.h" -static void users_service_dbus_class_init (UsersServiceDbusClass *klass); -static void users_service_dbus_init (UsersServiceDbus *self); -static void users_service_dbus_dispose (GObject *object); -static void users_service_dbus_finalize (GObject *object); -static void create_system_proxy (UsersServiceDbus *self); +static void users_service_dbus_class_init (UsersServiceDbusClass *klass); +static void users_service_dbus_init (UsersServiceDbus *self); +static void users_service_dbus_dispose (GObject *object); +static void users_service_dbus_finalize (GObject *object); static void create_gdm_proxy (UsersServiceDbus *self); static void create_seat_proxy (UsersServiceDbus *self); static void create_ck_proxy (UsersServiceDbus *self); @@ -78,7 +77,6 @@ struct _UsersServiceDbusPrivate DBusGConnection *system_bus; - DBusGProxy *dbus_proxy_system; DBusGProxy *gdm_proxy; DBusGProxy *ck_proxy; DBusGProxy *seat_proxy; @@ -181,7 +179,6 @@ users_service_dbus_init (UsersServiceDbus *self) G_TYPE_INT64, G_TYPE_INVALID); - create_system_proxy (self); create_gdm_proxy (self); create_ck_proxy (self); create_seat_proxy (self); @@ -201,30 +198,6 @@ users_service_dbus_finalize (GObject *object) G_OBJECT_CLASS (users_service_dbus_parent_class)->finalize (object); } -static void -create_system_proxy (UsersServiceDbus *self) -{ - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); - GError *error = NULL; - - priv->dbus_proxy_system = dbus_g_proxy_new_for_name_owner (priv->system_bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - &error); - - if (!priv->dbus_proxy_system) - { - if (error != NULL) - { - g_error ("Unable to get dbus proxy on system bus: %s", error->message); - g_error_free (error); - - return; - } - } -} - static void create_gdm_proxy (UsersServiceDbus *self) { -- cgit v1.2.3 From 2bb61203e78626f51bdbfbc8fb1440a046bab7be Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:21:21 -0500 Subject: use g_strcmp0 --- src/users-service-dbus.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 499182b..96f5cd5 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -443,18 +443,6 @@ get_unix_user (UsersServiceDbus *service, return TRUE; } -static gint -session_compare (const gchar *a, - const gchar *b) -{ - if (a == NULL) - return 1; - else if (b == NULL) - return -1; - - return strcmp (a, b); -} - static gchar * get_session_for_user (UsersServiceDbus *service, UserData *user) @@ -549,7 +537,7 @@ do_add_session (UsersServiceDbus *service, g_strdup (ssid), g_strdup (user->user_name)); - l = g_list_find_custom (user->sessions, ssid, (GCompareFunc)session_compare); + l = g_list_find_custom (user->sessions, ssid, (GCompareFunc)g_strcmp0); if (l == NULL) { g_debug ("Adding session %s", ssid); @@ -656,7 +644,7 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, l = g_list_find_custom (user->sessions, session_id, - (GCompareFunc)session_compare); + (GCompareFunc)g_strcmp0); if (l) { g_debug ("Removing session %s", session_id); -- cgit v1.2.3 From 3427b4a7054aa66f1aaa20aed56ad445aecd5ec4 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Wed, 23 Sep 2009 23:30:48 -0500 Subject: expose users_service_dbus_can_activate_session() --- src/users-service-dbus.c | 61 +++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 26 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 96f5cd5..6051e4e 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -447,33 +447,9 @@ static gchar * get_session_for_user (UsersServiceDbus *service, UserData *user) { - UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); - gboolean can_activate; - GError *error = NULL; - GList *l; - - if (!priv->seat_proxy) - create_seat_proxy (service); - - if (priv->seat == NULL || priv->seat[0] == '\0') - { - return NULL; - } - - if (!dbus_g_proxy_call (priv->seat_proxy, - "CanActivateSessions", - &error, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &can_activate, - G_TYPE_INVALID)) - { - g_warning ("Failed to determine if seat can activate sessions: %s", error->message); - g_error_free (error); - - return NULL; - } + GList *l; - if (!can_activate) + if (!users_service_dbus_can_activate_session (service)) { return NULL; } @@ -1095,3 +1071,36 @@ users_service_dbus_activate_user_session (UsersServiceDbus *self, return TRUE; } + +gboolean +users_service_dbus_can_activate_session (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + gboolean can_activate = FALSE; + GError *error = NULL; + + if (!priv->seat_proxy) + { + create_seat_proxy (self); + } + + if (!priv->seat || priv->seat[0] == '\0') + { + return FALSE; + } + + if (!dbus_g_proxy_call (priv->seat_proxy, + "CanActivateSessions", + &error, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, &can_activate, + G_TYPE_INVALID)) + { + g_warning ("Failed to determine if seat can activate sessions: %s", error->message); + g_error_free (error); + + return FALSE; + } + + return can_activate; +} -- cgit v1.2.3 From 7f7ed7fe0e23a4d4f044fda7cc201f4e474a6e17 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Thu, 24 Sep 2009 01:21:50 -0500 Subject: don't load all the users unless needed --- src/users-service-dbus.c | 197 ++++++++++++++++++++++++++++------------------- 1 file changed, 119 insertions(+), 78 deletions(-) (limited to 'src/users-service-dbus.c') diff --git a/src/users-service-dbus.c b/src/users-service-dbus.c index 6051e4e..018469c 100644 --- a/src/users-service-dbus.c +++ b/src/users-service-dbus.c @@ -634,6 +634,73 @@ seat_proxy_session_removed (DBusGProxy *seat_proxy, } } +static void +sync_users (UsersServiceDbus *self) +{ + UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (self); + + if (g_hash_table_size (priv->users) > 0) + { + return; + } + + if (priv->count > MINIMUM_USERS && priv->count < MAXIMUM_USERS) + { + GArray *uids = NULL; + GPtrArray *users_info = NULL; + GError *error = NULL; + gint i; + + uids = g_array_new (FALSE, FALSE, sizeof (gint64)); + + if (!org_gnome_DisplayManager_UserManager_get_user_list (priv->gdm_proxy, + &uids, + &error)) + { + g_warning ("failed to retrieve user list: %s", error->message); + g_error_free (error); + + return; + } + + users_info = g_ptr_array_new (); + + if (!org_gnome_DisplayManager_UserManager_get_users_info (priv->gdm_proxy, + uids, + &users_info, + &error)) + { + g_warning ("failed to retrieve user info: %s", error->message); + g_error_free (error); + + return; + } + + for (i = 0; i < users_info->len; i++) + { + GValueArray *values; + UserData *user; + + values = g_ptr_array_index (users_info, i); + + user = g_new0 (UserData, 1); + + user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); + user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); + user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); + user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); + user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); + user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); + + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); + + add_sessions_for_user (self, user); + } + } +} + static void users_loaded (DBusGProxy *proxy, gpointer user_data) @@ -641,10 +708,7 @@ users_loaded (DBusGProxy *proxy, UsersServiceDbus *service; UsersServiceDbusPrivate *priv; GError *error = NULL; - GArray *uids = NULL; - GPtrArray *users_info = NULL; gint count; - int i; service = (UsersServiceDbus *)user_data; priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); @@ -661,53 +725,7 @@ users_loaded (DBusGProxy *proxy, priv->count = count; - uids = g_array_new (FALSE, FALSE, sizeof (gint64)); - - if (!org_gnome_DisplayManager_UserManager_get_user_list (proxy, - &uids, - &error)) - { - g_warning ("failed to retrieve user list: %s", error->message); - g_error_free (error); - - return; - } - - users_info = g_ptr_array_new (); - - if (!org_gnome_DisplayManager_UserManager_get_users_info (proxy, - uids, - &users_info, - &error)) - { - g_warning ("failed to retrieve user info: %s", error->message); - g_error_free (error); - - return; - } - - for (i = 0; i < users_info->len; i++) - { - GValueArray *values; - UserData *user; - - values = g_ptr_array_index (users_info, i); - - user = g_new0 (UserData, 1); - - user->uid = g_value_get_int64 (g_value_array_get_nth (values, 0)); - user->user_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 1))); - user->real_name = g_strdup (g_value_get_string (g_value_array_get_nth (values, 2))); - user->shell = g_strdup (g_value_get_string (g_value_array_get_nth (values, 3))); - user->login_count = g_value_get_int (g_value_array_get_nth (values, 4)); - user->icon_url = g_strdup (g_value_get_string (g_value_array_get_nth (values, 5))); - - g_hash_table_insert (priv->users, - g_strdup (user->user_name), - user); - - add_sessions_for_user (service, user); - } + sync_users (service); } static gboolean @@ -908,30 +926,40 @@ user_added (DBusGProxy *proxy, priv->count++; - if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy, - uid, - &user->user_name, - &user->real_name, - &user->shell, - &user->login_count, - &user->icon_url, - &error)) + if (priv->count < MAXIMUM_USERS) { - g_warning ("unable to retrieve user info: %s", error->message); - g_error_free (error); - - g_free (user); - - return; + if ((priv->count - g_hash_table_size (priv->users)) > 1) + { + sync_users (service); + } + else + { + if (!org_gnome_DisplayManager_UserManager_get_user_info (proxy, + uid, + &user->user_name, + &user->real_name, + &user->shell, + &user->login_count, + &user->icon_url, + &error)) + { + g_warning ("unable to retrieve user info: %s", error->message); + g_error_free (error); + + g_free (user); + + return; + } + + user->uid = uid; + + g_hash_table_insert (priv->users, + g_strdup (user->user_name), + user); + + g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); + } } - - user->uid = uid; - - g_hash_table_insert (priv->users, - g_strdup (user->user_name), - user); - - g_signal_emit (G_OBJECT (service), signals[USER_ADDED], 0, user, TRUE); } static gboolean @@ -950,15 +978,28 @@ user_removed (DBusGProxy *proxy, UsersServiceDbus *service = (UsersServiceDbus *)user_data; UsersServiceDbusPrivate *priv = USERS_SERVICE_DBUS_GET_PRIVATE (service); UserData *user; + gint size; - user = g_hash_table_find (priv->users, - compare_users_by_uid, - GUINT_TO_POINTER (uid)); - - g_hash_table_remove (priv->users, - user->user_name); + size = g_hash_table_size (priv->users); priv->count--; + + if (size == 0 || (size - priv->count) > 1) + { + sync_users (service); + } + else + { + user = g_hash_table_find (priv->users, + compare_users_by_uid, + GUINT_TO_POINTER (uid)); + + if (user != NULL) + { + g_hash_table_remove (priv->users, + user->user_name); + } + } } static void -- cgit v1.2.3