Blob Blame History Raw
--- gnome-panel-2.22.2/gnome-panel/panel-consolekit.c	2008-10-12 18:57:57.000000000 -0400
+++ foo/gnome-panel/panel-consolekit.c	2008-10-12 18:56:40.000000000 -0400
@@ -649,11 +649,75 @@
 	}
 }
 
+#ifdef HAVE_POLKIT
+static gboolean
+panel_consolekit_can_do_action (PanelConsolekit *manager,
+                              const char      *action_id)
+{
+        PolKitGnomeContext *gnome_context;
+        PolKitAction *action;
+        PolKitCaller *caller;
+        DBusError dbus_error;
+        PolKitError *error;
+        PolKitResult result;
+
+        gnome_context = polkit_gnome_context_get (NULL);
+
+        if (gnome_context == NULL) {
+                return FALSE;
+        }
+
+        if (gnome_context->pk_tracker == NULL) {
+                return FALSE;
+        }
+
+        dbus_error_init (&dbus_error);
+        caller = polkit_tracker_get_caller_from_pid (gnome_context->pk_tracker,
+                                                     getpid (),
+                                                     &dbus_error);
+        dbus_error_free (&dbus_error);
+
+        if (caller == NULL) {
+                return FALSE;
+        }
+
+        action = polkit_action_new ();
+
+        if (!polkit_action_set_action_id (action, action_id)) {
+                polkit_action_unref (action);
+                polkit_caller_unref (caller);
+                return FALSE;
+        }
+
+        result = POLKIT_RESULT_UNKNOWN;
+        error = NULL;
+        result = polkit_context_is_caller_authorized (gnome_context->pk_context,
+                                                      action, caller, FALSE,
+                                                      &error);
+        if (polkit_error_is_set (error)) {
+                polkit_error_free (error);
+        }
+        polkit_action_unref (action);
+        polkit_caller_unref (caller);
+
+        return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
+}
+#endif
+
 gboolean
 panel_consolekit_can_restart (PanelConsolekit *manager)
 {
 #ifdef HAVE_POLKIT
-	return panel_consolekit_ensure_ck_connection (manager, NULL);
+        gboolean res;
+
+        res = panel_consolekit_ensure_ck_connection (manager, NULL);
+
+        if (!res) {
+                return FALSE;
+        }
+
+        return panel_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart") ||
+               panel_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart-multiple-users");
 #else
 	return FALSE;
 #endif
@@ -663,7 +727,16 @@
 panel_consolekit_can_stop (PanelConsolekit *manager)
 {
 #ifdef HAVE_POLKIT
-	return panel_consolekit_ensure_ck_connection (manager, NULL);
+        gboolean res;
+
+        res = panel_consolekit_ensure_ck_connection (manager, NULL);
+
+        if (!res) {
+                return FALSE;
+        }
+
+        return panel_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.stop") ||
+               panel_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.stop-multiple-users");
 #else
 	return FALSE;
 #endif