[gnome-control-center/wip/enterprise-login: 14/15] user-accounts: Add um_user_manager_cache_user()



commit 49b8995af06a3d2c26e1b359634e1beae60b6539
Author: Stef Walter <stefw gnome org>
Date:   Thu May 31 17:06:42 2012 +0200

    user-accounts: Add um_user_manager_cache_user()
    
    This calls the AccountsService.CacheUser() method to register
    a user that's not in /etc/passwd
    
    Depends on:
    
    https://bugs.freedesktop.org/show_bug.cgi?id=50770
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677548

 panels/user-accounts/um-user-manager.c |   69 +++++++++++++++++++++++++++++--
 panels/user-accounts/um-user-manager.h |   10 +++++
 2 files changed, 74 insertions(+), 5 deletions(-)
---
diff --git a/panels/user-accounts/um-user-manager.c b/panels/user-accounts/um-user-manager.c
index a9c629d..aff1469 100644
--- a/panels/user-accounts/um-user-manager.c
+++ b/panels/user-accounts/um-user-manager.c
@@ -427,10 +427,11 @@ async_user_op_data_free (gpointer d)
         g_free (data);
 }
 
+/* Used for both create_user and cache_user */
 static void
-create_user_done (GObject        *proxy,
-                  GAsyncResult   *r,
-                  gpointer        user_data)
+user_call_done (GObject        *proxy,
+                GAsyncResult   *r,
+                gpointer        user_data)
 {
         AsyncUserOpData *data = user_data;
         GSimpleAsyncResult *res;
@@ -455,7 +456,7 @@ create_user_done (GObject        *proxy,
                                                          UM_USER_MANAGER_ERROR_PERMISSION_DENIED,
                                                          "Not authorized");
                 }
-                if (g_dbus_error_is_remote_error (error) &&
+                else if (g_dbus_error_is_remote_error (error) &&
                     strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.UserExists") == 0) {
                         g_simple_async_result_set_error (res,
                                                          UM_USER_MANAGER_ERROR,
@@ -463,6 +464,14 @@ create_user_done (GObject        *proxy,
                                                          _("A user with name '%s' already exists."),
                                                          data->user_name);
                 }
+                else if (g_dbus_error_is_remote_error (error) &&
+                    strcmp (g_dbus_error_get_remote_error(error), "org.freedesktop.Accounts.Error.UserDoesNotExist") == 0) {
+                        g_simple_async_result_set_error (res,
+                                                         UM_USER_MANAGER_ERROR,
+                                                         UM_USER_MANAGER_ERROR_USER_DOES_NOT_EXIST,
+                                                         _("No user with the name '%s' exists."),
+                                                         data->user_name);
+                }
                 else {
                         g_simple_async_result_set_from_error (res, error);
                 }
@@ -535,7 +544,57 @@ um_user_manager_create_user (UmUserManager       *manager,
                            G_DBUS_CALL_FLAGS_NONE,
                            -1,
                            cancellable,
-                           create_user_done,
+                           user_call_done,
+                           data);
+}
+
+gboolean
+um_user_manager_cache_user_finish (UmUserManager       *manager,
+                                   GAsyncResult        *result,
+                                   UmUser             **user,
+                                   GError             **error)
+{
+        gchar *path;
+        GSimpleAsyncResult *res;
+
+        res = G_SIMPLE_ASYNC_RESULT (result);
+
+        *user = NULL;
+
+        if (g_simple_async_result_propagate_error (res, error)) {
+                return FALSE;
+        }
+
+        path = g_simple_async_result_get_op_res_gpointer (res);
+        *user = g_hash_table_lookup (manager->user_by_object_path, path);
+
+        return TRUE;
+}
+
+void
+um_user_manager_cache_user (UmUserManager       *manager,
+                            const char          *user_name,
+                            GCancellable        *cancellable,
+                            GAsyncReadyCallback  done,
+                            gpointer             done_data,
+                            GDestroyNotify       destroy)
+{
+        AsyncUserOpData *data;
+
+        data = g_new0 (AsyncUserOpData, 1);
+        data->manager = g_object_ref (manager);
+        data->user_name = g_strdup (user_name);
+        data->callback = done;
+        data->data = done_data;
+        data->destroy = destroy;
+
+        g_dbus_proxy_call (manager->proxy,
+                           "CacheUser",
+                           g_variant_new ("(s)", user_name),
+                           G_DBUS_CALL_FLAGS_NONE,
+                           -1,
+                           cancellable,
+                           user_call_done,
                            data);
 }
 
diff --git a/panels/user-accounts/um-user-manager.h b/panels/user-accounts/um-user-manager.h
index c47ecb5..ebd9ce4 100644
--- a/panels/user-accounts/um-user-manager.h
+++ b/panels/user-accounts/um-user-manager.h
@@ -96,6 +96,16 @@ gboolean           um_user_manager_create_user_finish    (UmUserManager       *m
                                                           GAsyncResult        *result,
                                                           UmUser             **user,
                                                           GError             **error);
+void               um_user_manager_cache_user            (UmUserManager       *manager,
+                                                          const char          *user_name,
+                                                          GCancellable        *cancellable,
+                                                          GAsyncReadyCallback  done,
+                                                          gpointer             user_data,
+                                                          GDestroyNotify       destroy);
+gboolean           um_user_manager_cache_user_finish     (UmUserManager       *manager,
+                                                          GAsyncResult        *result,
+                                                          UmUser             **user,
+                                                          GError             **error);
 void               um_user_manager_delete_user           (UmUserManager       *manager,
                                                           UmUser              *user,
                                                           gboolean             remove_files,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]