summaryrefslogtreecommitdiff
blob: 29cc56955250642e4911fa2b020bad46df9ea6eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
From 281e67308b9828a35ad863c39bd09e595c5e8771 Mon Sep 17 00:00:00 2001
From: Gilles Dartiguelongue <eva@gentoo.org>
Date: Sun, 19 Apr 2009 16:45:29 +0200
Subject: [PATCH 1/2] Allow shutdown without PolicyKit.

 Straight forward fix to allow shutdown on systems not using policykit.

 If the system really doesn't have policykit, it will make things work
 as in 2.22.

 If pk is in gsm but not in ck, it'll still work as in 2.22.

 If pk is present in both, you just have to fix the logic to make
 gsm ask pk if the user has the permission to shutdown _before_ showing
 buttons and in case this is not possible, just damn fix pk.

 reported as http://bugzilla.gnome.org/show_bug.cgi?id=549150
---
 gnome-session/gsm-consolekit.c |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/gnome-session/gsm-consolekit.c b/gnome-session/gsm-consolekit.c
index 5541006..28f4cb7 100644
--- a/gnome-session/gsm-consolekit.c
+++ b/gnome-session/gsm-consolekit.c
@@ -541,7 +541,7 @@ request_restart_priv (GsmConsolekit *manager,
                 g_free (error_message);
         }
 #else
-        g_assert_not_reached ();
+        g_warning ("Failed to restart and Policykit support not enabled");
 #endif /* HAVE POLKIT */
 }
 
@@ -581,7 +581,7 @@ request_stop_priv (GsmConsolekit *manager,
                 }
         }
 #else
-        g_assert_not_reached ();
+        g_warning ("Failed to shutdown and Policykit support not enabled");
 #endif /* HAVE POLKIT */
 }
 
@@ -979,6 +979,15 @@ gsm_consolekit_can_do_action (GsmConsolekit *manager,
 
         return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
 }
+#else
+static gboolean
+gsm_consolekit_can_do_action (GsmConsolekit *manager,
+                              const char    *action_id)
+{
+        /* if we got here, res was true */
+        return TRUE;
+}
+#endif
 
 static gboolean
 gsm_consolekit_is_session_for_other_user (GsmConsolekit *manager,
@@ -1096,6 +1105,7 @@ gsm_consolekit_is_single_user (GsmConsolekit *manager)
         return single;
 }
 
+#ifdef HAVE_POLKIT_GNOME
 static void
 obtain_privileges_cb (PolKitAction  *action,
                       gboolean       gained_privilege,
@@ -1207,8 +1217,11 @@ gsm_consolekit_get_restart_privileges (GsmConsolekit *manager)
                                                           "org.freedesktop.consolekit.system.restart",
                                                           "org.freedesktop.consolekit.system.restart-multiple-users");
 #else
-        g_debug ("GsmConsolekit: built without PolicyKit-gnome support");
-        return FALSE;
+        g_signal_emit (G_OBJECT (manager),
+                       signals [PRIVILEGES_COMPLETED],
+                       0, TRUE, FALSE, FALSE);
+        g_debug ("GsmConsolekit: built without PolicyKit-gnome support, granting anyway");
+        return TRUE;
 #endif
 }
 
@@ -1220,33 +1233,26 @@ gsm_consolekit_get_stop_privileges (GsmConsolekit *manager)
                                                           "org.freedesktop.consolekit.system.stop",
                                                           "org.freedesktop.consolekit.system.stop-multiple-users");
 #else
-        g_debug ("GsmConsolekit: built without PolicyKit-gnome support");
-        return FALSE;
+        g_signal_emit (G_OBJECT (manager),
+                       signals [PRIVILEGES_COMPLETED],
+                       0, TRUE, FALSE, FALSE);
+        g_debug ("GsmConsolekit: built without PolicyKit-gnome support, granting anyway");
+        return TRUE;
 #endif
 }
 
 gboolean
 gsm_consolekit_can_restart (GsmConsolekit *manager)
 {
-#ifdef HAVE_POLKIT_GNOME
         return gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart") ||
                gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.restart-multiple-users");
-#else
-        g_debug ("GsmConsolekit: built without PolicyKit-gnome support - cannot restart system");
-        return FALSE;
-#endif
 }
 
 gboolean
 gsm_consolekit_can_stop (GsmConsolekit *manager)
 {
-#ifdef HAVE_POLKIT_GNOME
         return gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.stop") ||
                gsm_consolekit_can_do_action (manager, "org.freedesktop.consolekit.system.stop-multiple-users");
-#else
-        g_debug ("GsmConsolekit: built without PolicyKit-gnome support - cannot stop system");
-        return FALSE;
-#endif
 }
 
 gchar *
-- 
1.6.3.3