sharkcz / rpms / gdm

Forked from rpms/gdm 4 years ago
Clone
7d61654
diff -up gdm-2.21.10/gui/simple-greeter/gdm-greeter-login-window.c.ck-multi gdm-2.21.10/gui/simple-greeter/gdm-greeter-login-window.c
7d61654
--- gdm-2.21.10/gui/simple-greeter/gdm-greeter-login-window.c.ck-multi	2008-04-05 20:39:49.000000000 -0400
7d61654
+++ gdm-2.21.10/gui/simple-greeter/gdm-greeter-login-window.c	2008-04-05 20:42:23.000000000 -0400
7d61654
@@ -1036,20 +1036,41 @@ static PolKitAction *
7d61654
 get_action_from_error (GError *error)
7d61654
 {
7d61654
         PolKitAction *action;
7d61654
-        const char   *paction;
7d61654
+        char 	     *paction;
7d61654
+	char	     *p;
7d61654
 
7d61654
         action = polkit_action_new ();
7d61654
 
7d61654
         paction = NULL;
7d61654
         if (g_str_has_prefix (error->message, "Not privileged for action: ")) {
7d61654
-                paction = error->message + strlen ("Not privileged for action: ");
7d61654
+                paction = g_strdup (error->message + strlen ("Not privileged for action: "));
7d61654
+		p = strchr (paction, ' ');
7d61654
+		if (p) 
7d61654
+			*p = '\0';
7d61654
         }
7d61654
         g_debug ("GdmGreeterLoginWindow: Requesting priv for '%s'", paction);
7d61654
 
7d61654
         polkit_action_set_action_id (action, paction);
7d61654
 
7d61654
+	g_free (paction);
7d61654
+
7d61654
         return action;
7d61654
 }
7d61654
+
7d61654
+static PolKitResult
7d61654
+get_result_from_error (GError *error)
7d61654
+{
7d61654
+	PolKitResult result = POLKIT_RESULT_UNKNOWN;
7d61654
+	const char *p;
7d61654
+
7d61654
+	p = strrchr (error->message, ' ');
7d61654
+	if (p) {
7d61654
+		p++;
7d61654
+		polkit_result_from_string_representation (p, &result);
7d61654
+	}
7d61654
+
7d61654
+	return result;
7d61654
+}
7d61654
 #endif
7d61654
 
7d61654
 static void
7d61654
@@ -1076,11 +1097,40 @@ do_system_restart (GdmGreeterLoginWindow
7d61654
 
7d61654
                 if (dbus_g_error_has_name (error, "org.freedesktop.ConsoleKit.Manager.NotPrivileged")) {
7d61654
                         PolKitAction *action;
7d61654
+                        PolKitAction *action2;
7d61654
+			PolKitResult  result;
7d61654
+			GtkWidget    *dialog;
7d61654
                         guint         xid;
7d61654
                         pid_t         pid;
7d61654
 
7d61654
+			result = get_result_from_error (error);
7d61654
                         action = get_action_from_error (error);
7d61654
 
7d61654
+			if (result == POLKIT_RESULT_NO) {
7d61654
+				action2 = polkit_action_new ();
7d61654
+				polkit_action_set_action_id (action2,
7d61654
+							     "org.freedesktop.consolekit.system.restart-multiple-users");
7d61654
+				dialog = gtk_message_dialog_new (GTK_WINDOW (login_window),
7d61654
+								 GTK_DIALOG_MODAL,
7d61654
+								 GTK_MESSAGE_ERROR,
7d61654
+								 GTK_BUTTONS_OK,
7d61654
+								 _("Failed to restart computer"));
7d61654
+				if (polkit_action_equal (action, action2)) {
7d61654
+					gtk_message_dialog_format_secondary_text (dialog,
7d61654
+										  _("You are not allowed to restart the computer "
7d61654
+										    "because multiple users are logged in"));
7d61654
+				}
7d61654
+				gtk_dialog_run (GTK_DIALOG (dialog));
7d61654
+				gtk_widget_destroy (dialog);
7d61654
+
7d61654
+				polkit_action_unref (action);
7d61654
+				polkit_action_unref (action2);
7d61654
+
7d61654
+				g_error_free (error);
7d61654
+
7d61654
+				return;
7d61654
+			}
7d61654
+
7d61654
                         xid = 0;
7d61654
                         pid = getpid ();
7d61654
 
7d61654
@@ -1128,14 +1178,41 @@ do_system_stop (GdmGreeterLoginWindow *l
7d61654
 
7d61654
                 if (dbus_g_error_has_name (error, "org.freedesktop.ConsoleKit.Manager.NotPrivileged")) {
7d61654
                         PolKitAction *action;
7d61654
+                        PolKitAction *action2;
7d61654
+			PolKitResult  result;
7d61654
+			GtkWidget    *dialog;
7d61654
                         guint         xid;
7d61654
                         pid_t         pid;
7d61654
 
7d61654
                         xid = 0;
7d61654
                         pid = getpid ();
7d61654
 
7d61654
+			result = get_result_from_error (error);
7d61654
                         action = get_action_from_error (error);
7d61654
 
7d61654
+			if (result == POLKIT_RESULT_NO) {
7d61654
+				action2 = polkit_action_new ();
7d61654
+				polkit_action_set_action_id (action2,
7d61654
+							     "org.freedesktop.consolekit.system.stop-multiple-users");
7d61654
+				dialog = gtk_message_dialog_new (GTK_WINDOW (login_window),
7d61654
+								 GTK_DIALOG_MODAL,
7d61654
+								 GTK_MESSAGE_ERROR,
7d61654
+								 GTK_BUTTONS_OK,
7d61654
+								 _("Failed to stop computer"));
7d61654
+				if (polkit_action_equal (action, action2)) {
7d61654
+					gtk_message_dialog_format_secondary_text (dialog,
7d61654
+										  _("You are not allowed to stop the computer "
7d61654
+										    "because multiple users are logged in"));
7d61654
+				}
7d61654
+				gtk_dialog_run (GTK_DIALOG (dialog));
7d61654
+				gtk_widget_destroy (dialog);
7d61654
+
7d61654
+				polkit_action_unref (action);
7d61654
+				polkit_action_unref (action2);
7d61654
+
7d61654
+				return;
7d61654
+			}
7d61654
+
7d61654
                         g_error_free (error);
7d61654
                         error = NULL;
7d61654
                         res = polkit_gnome_auth_obtain (action,