[accounts-dialog] Adapt to streamlined privileges in accounts service



commit e80c5104533e4754306b8b30ff3053a4d2ca34ac
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 21 20:17:03 2010 -0500

    Adapt to streamlined privileges in accounts service

 src/main.c |  119 ++++++++++++++++++------------------------------------------
 1 files changed, 36 insertions(+), 83 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index eaeb5a1..bb60f28 100644
--- a/src/main.c
+++ b/src/main.c
@@ -467,6 +467,7 @@ update_data_change_buttons (GObject           *source,
         gboolean is_authorized;
 
         error = NULL;
+	is_authorized = FALSE;
         result = polkit_authority_check_authorization_finish (d->authority,
                                                               res,
                                                               &error);
@@ -479,9 +480,6 @@ update_data_change_buttons (GObject           *source,
                     polkit_authorization_result_get_is_challenge (result)) {
                         is_authorized = TRUE;
                 }
-                else {
-                        is_authorized = FALSE;
-                }
 
                 g_object_unref (result);
         }
@@ -491,7 +489,6 @@ update_data_change_buttons (GObject           *source,
                 gtk_widget_hide (get_widget (d, "user-icon-nonbutton"));
 
                 gtk_widget_show (get_widget (d, "change-name-button"));
-                gtk_widget_show (get_widget (d, "change-password-button"));
                 gtk_widget_show (get_widget (d, "change-email-button"));
                 gtk_widget_show (get_widget (d, "change-language-button"));
                 gtk_widget_show (get_widget (d, "change-location-button"));
@@ -501,7 +498,6 @@ update_data_change_buttons (GObject           *source,
                 gtk_widget_show (get_widget (d, "user-icon-nonbutton"));
 
                 gtk_widget_hide (get_widget (d, "change-name-button"));
-                gtk_widget_hide (get_widget (d, "change-password-button"));
                 gtk_widget_hide (get_widget (d, "change-email-button"));
                 gtk_widget_hide (get_widget (d, "change-language-button"));
                 gtk_widget_hide (get_widget (d, "change-location-button"));
@@ -516,8 +512,11 @@ update_account_type_change_buttons (GObject           *source,
         GError *error;
         PolkitAuthorizationResult *result;
         gboolean is_authorized;
+        gboolean can_change_password;
+	UmUser *user;
 
         error = NULL;
+	is_authorized = FALSE;
         result = polkit_authority_check_authorization_finish (d->authority,
                                                               res,
                                                               &error);
@@ -530,9 +529,6 @@ update_account_type_change_buttons (GObject           *source,
                     polkit_authorization_result_get_is_challenge (result)) {
                         is_authorized = TRUE;
                 }
-                else {
-                        is_authorized = FALSE;
-                }
 
                 g_object_unref (result);
         }
@@ -543,6 +539,21 @@ update_account_type_change_buttons (GObject           *source,
         else {
                 gtk_widget_hide (get_widget (d, "change-account-type-button"));
         }
+
+        user = get_selected_user (d);
+        if (um_user_get_uid (user) == geteuid ()) {
+		can_change_password = TRUE;
+	}
+	else {
+		can_change_password = is_authorized;
+	}
+
+        if (can_change_password) {
+                gtk_widget_show (get_widget (d, "change-password-button"));
+        }
+        else {
+                gtk_widget_hide (get_widget (d, "change-password-button"));
+        }
 }
 
 static void
@@ -555,7 +566,7 @@ update_change_buttons (UserAccountDialog *d, UmUser *u)
                 action = "org.freedesktop.accounts.change-own-user-data";
         }
         else {
-                action = "org.freedesktop.accounts.change-user-data";
+                action = "org.freedesktop.accounts.user-administration";
         }
 
         subject = polkit_unix_process_new (getpid ());
@@ -570,7 +581,7 @@ update_change_buttons (UserAccountDialog *d, UmUser *u)
                                               d);
         polkit_authority_check_authorization (d->authority,
                                               subject,
-                                              "org.freedesktop.accounts.change-account-type",
+                                              "org.freedesktop.accounts.user-administration",
                                               NULL,
                                               0,
                                               NULL,
@@ -580,15 +591,17 @@ update_change_buttons (UserAccountDialog *d, UmUser *u)
 }
 
 static void
-update_add_button (GObject           *source,
-                   GAsyncResult      *res,
-                   UserAccountDialog *d)
+update_create_buttons_cb (GObject           *source,
+                          GAsyncResult      *res,
+                          UserAccountDialog *d)
 {
         GError *error;
         PolkitAuthorizationResult *result;
         gboolean is_authorized;
+        UmUser *user;
 
         error = NULL;
+ 	is_authorized = FALSE;
         result = polkit_authority_check_authorization_finish (d->authority,
                                                               res,
                                                               &error);
@@ -601,77 +614,25 @@ update_add_button (GObject           *source,
                     polkit_authorization_result_get_is_challenge (result)) {
                         is_authorized = TRUE;
                 }
-                else {
-                        is_authorized = FALSE;
-                }
 
                 g_object_unref (result);
         }
 
-        gtk_widget_set_sensitive (get_widget (d, "add-user-button"), is_authorized);
 
-        if (!gtk_widget_is_sensitive (get_widget (d, "add-user-button")) &&
-            !gtk_widget_is_sensitive (get_widget (d, "delete-user-button"))) {
-                gtk_widget_hide (get_widget (d, "add-delete-buttonbox"));
-        }
-        else {
+        if (is_authorized) {
                 gtk_widget_show (get_widget (d, "add-delete-buttonbox"));
-        }
-}
-
-static void
-prevent_selfdestruction (UserAccountDialog *d)
-{
-        UmUser *user;
-
-        user = get_selected_user (d);
-
-        if (user && um_user_get_uid (user) == getuid ()) {
-                gtk_widget_set_sensitive (get_widget (d, "delete-user-button"), FALSE);
-        }
-}
 
-static void
-update_delete_button (GObject           *source,
-                      GAsyncResult      *res,
-                      UserAccountDialog *d)
-{
-        GError *error;
-        PolkitAuthorizationResult *result;
-        gboolean is_authorized;
+                user = get_selected_user (d);
 
-        error = NULL;
-        result = polkit_authority_check_authorization_finish (d->authority,
-                                                              res,
-                                                              &error);
-        if (error) {
-                g_warning ("polkit check failed: %s", error->message);
-                g_error_free (error);
-        }
-        else {
-                if (polkit_authorization_result_get_is_authorized (result) ||
-                    polkit_authorization_result_get_is_challenge (result)) {
-                        is_authorized = TRUE;
+                if (user && um_user_get_uid (user) == getuid ()) {
+                        gtk_widget_set_sensitive (get_widget (d, "delete-user-button"), FALSE);
                 }
-                else {
-                        is_authorized = FALSE;
-                }
-
-                g_object_unref (result);
-        }
-
-        gtk_widget_set_sensitive (get_widget (d, "delete-user-button"), is_authorized);
-
-        if (!gtk_widget_is_sensitive (get_widget (d, "add-user-button")) &&
-            !gtk_widget_is_sensitive (get_widget (d, "delete-user-button"))) {
-                gtk_widget_hide (get_widget (d, "add-delete-buttonbox"));
+		else {
+                        gtk_widget_set_sensitive (get_widget (d, "delete-user-button"), TRUE);
+		}
         }
         else {
-                gtk_widget_show (get_widget (d, "add-delete-buttonbox"));
-        }
-
-        if (is_authorized) {
-                prevent_selfdestruction (d);
+                gtk_widget_hide (get_widget (d, "add-delete-buttonbox"));
         }
 }
 
@@ -684,19 +645,11 @@ update_create_buttons (UserAccountDialog *d)
 
         polkit_authority_check_authorization (d->authority,
                                               subject,
-                                              "org.freedesktop.accounts.create-user",
-                                              NULL,
-                                              0,
-                                              NULL,
-                                              (GAsyncReadyCallback)update_add_button,
-                                              d);
-        polkit_authority_check_authorization (d->authority,
-                                              subject,
-                                              "org.freedesktop.accounts.delete-user",
+                                              "org.freedesktop.accounts.user-administration",
                                               NULL,
                                               0,
                                               NULL,
-                                              (GAsyncReadyCallback)update_delete_button,
+                                              (GAsyncReadyCallback)update_create_buttons_cb,
                                               d);
 
         g_object_unref (subject);



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