From 77c3f5484f8f6b35b71c518ac191f7ad13bc9673 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT service" Date: Tue, 10 Jul 2012 10:18:10 +0200 Subject: [PATCH 2/4] Removed silly dbus-based account lookup --- src/accounts.c | 203 +------------------------------------------------------- src/accounts.h | 2 - 2 files changed, 2 insertions(+), 203 deletions(-) diff --git a/src/accounts.c b/src/accounts.c index e974c54..599c414 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -23,9 +23,6 @@ struct UserPrivate /* Name of user */ gchar *name; - /* Accounts interface proxy */ - GDBusProxy *proxy; - /* User ID */ uid_t uid; @@ -53,79 +50,6 @@ struct UserPrivate G_DEFINE_TYPE (User, user, G_TYPE_OBJECT); -/* Connection to AccountsService */ -static GDBusProxy *accounts_service_proxy = NULL; -static gboolean have_accounts_service_proxy = FALSE; - -static gboolean -call_method (GDBusProxy *proxy, const gchar *method, GVariant *args, - const gchar *expected, GVariant **result) -{ - GVariant *answer; - GError *error = NULL; - - if (!proxy) - return FALSE; - - answer = g_dbus_proxy_call_sync (proxy, - method, - args, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - if (error) - g_warning ("Could not call %s: %s", method, error->message); - g_clear_error (&error); - - if (!answer) - return FALSE; - - if (!g_variant_is_of_type (answer, G_VARIANT_TYPE (expected))) - { - g_warning ("Unexpected response from %s: %s", - method, g_variant_get_type_string (answer)); - g_variant_unref (answer); - return FALSE; - } - - if (result) - *result = answer; - else - g_variant_unref (answer); - - return TRUE; -} - -static gboolean -get_property (GDBusProxy *proxy, const gchar *property, - const gchar *expected, GVariant **result) -{ - GVariant *answer; - - answer = g_dbus_proxy_get_cached_property (proxy, property); - - if (!answer) - { - g_warning ("Could not get accounts property %s", property); - return FALSE; - } - - if (!g_variant_is_of_type (answer, G_VARIANT_TYPE (expected))) - { - g_warning ("Unexpected accounts property type for %s: %s", - property, g_variant_get_type_string (answer)); - g_variant_unref (answer); - return FALSE; - } - - if (result) - *result = answer; - else - g_variant_unref (answer); - return TRUE; -} - static void save_string_to_dmrc (const gchar *username, const gchar *group, const gchar *key, const gchar *value) @@ -153,83 +77,6 @@ get_string_from_dmrc (const gchar *username, const gchar *group, return value; } -static GDBusProxy * -get_accounts_service_proxy () -{ - GError *error = NULL; - - if (have_accounts_service_proxy) - return accounts_service_proxy; - - have_accounts_service_proxy = TRUE; - accounts_service_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - "org.freedesktop.Accounts", - "/org/freedesktop/Accounts", - "org.freedesktop.Accounts", - NULL, &error); - if (error) - g_warning ("Could not get accounts proxy: %s", error->message); - g_clear_error (&error); - - if (accounts_service_proxy) - { - gchar *name; - name = g_dbus_proxy_get_name_owner (accounts_service_proxy); - if (!name) - { - g_debug ("org.freedesktop.Accounts does not exist, falling back to passwd file"); - g_object_unref (accounts_service_proxy); - accounts_service_proxy = NULL; - } - g_free (name); - } - - return accounts_service_proxy; -} - -static GDBusProxy * -get_accounts_proxy_for_user (const gchar *user) -{ - GDBusProxy *proxy; - GError *error = NULL; - GVariant *result; - gboolean success; - gchar *user_path = NULL; - - g_return_val_if_fail (user != NULL, NULL); - - proxy = get_accounts_service_proxy (); - if (!proxy) - return NULL; - - success = call_method (proxy, "FindUserByName", g_variant_new ("(s)", user), "(o)", &result); - - if (!success) - return NULL; - - g_variant_get (result, "(o)", &user_path); - g_variant_unref (result); - - if (!user_path) - return NULL; - - proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - "org.freedesktop.Accounts", - user_path, - "org.freedesktop.Accounts.User", - NULL, &error); - if (error) - g_warning ("Could not get accounts user proxy: %s", error->message); - g_clear_error (&error); - g_free (user_path); - - return proxy; -} - static User * user_from_passwd (struct passwd *user_info) { @@ -242,7 +89,6 @@ user_from_passwd (struct passwd *user_info) user->priv->gecos = g_strdup (user_info->pw_gecos); user->priv->home_directory = g_strdup (user_info->pw_dir); user->priv->shell = g_strdup (user_info->pw_shell); - user->priv->proxy = get_accounts_proxy_for_user (user->priv->name); return user; } @@ -332,44 +178,17 @@ user_get_shell (User *user) return user->priv->shell; } -const gchar * -user_get_locale (User *user) -{ - g_return_val_if_fail (user != NULL, NULL); - - g_free (user->priv->locale); - if (user->priv->proxy) - user->priv->locale = NULL; - else - user->priv->locale = get_string_from_dmrc (user->priv->name, "Desktop", "Language"); - - /* Treat a blank locale as unset */ - if (g_strcmp0 (user->priv->locale, "") == 0) - { - g_free (user->priv->locale); - user->priv->locale = NULL; - } - - return user->priv->locale; -} - void user_set_language (User *user, const gchar *language) { g_return_if_fail (user != NULL); - - if (user->priv->proxy) - call_method (user->priv->proxy, "SetLanguage", g_variant_new ("(s)", language), "()", NULL); - else - save_string_to_dmrc (user->priv->name, "Desktop", "Language", language); + save_string_to_dmrc (user->priv->name, "Desktop", "Language", language); } void user_set_xsession (User *user, const gchar *xsession) { g_return_if_fail (user != NULL); - - call_method (user->priv->proxy, "SetXSession", g_variant_new ("(s)", xsession), "()", NULL); save_string_to_dmrc (user->priv->name, "Desktop", "Session", xsession); } @@ -381,18 +200,7 @@ user_get_xsession (User *user) g_return_val_if_fail (user != NULL, NULL); g_free (user->priv->xsession); - if (user->priv->proxy) - { - if (get_property (user->priv->proxy, "XSession", "s", &result)) - { - g_variant_get (result, "s", &user->priv->xsession); - g_variant_unref (result); - } - else - user->priv->xsession = NULL; - } - else - user->priv->xsession = get_string_from_dmrc (user->priv->name, "Desktop", "Session"); + user->priv->xsession = get_string_from_dmrc (user->priv->name, "Desktop", "Session"); if (g_strcmp0 (user->priv->xsession, "") == 0) { @@ -415,13 +223,6 @@ user_dispose (GObject *object) User *self; self = USER (object); - - if (self->priv->proxy) - { - g_object_unref (self->priv->proxy); - self->priv->proxy = NULL; - } - G_OBJECT_CLASS (user_parent_class)->dispose (object); } diff --git a/src/accounts.h b/src/accounts.h index 8bd5247..4ffd4fe 100644 --- a/src/accounts.h +++ b/src/accounts.h @@ -58,8 +58,6 @@ const gchar *user_get_xsession (User *user); void user_set_xsession (User *user, const gchar *session); -const gchar *user_get_locale (User *user); - void user_set_language (User *user, const gchar *language); G_END_DECLS -- 1.7.9.5