1 |
pterjan |
24923 |
diff --git a/RELEASE b/RELEASE |
2 |
|
|
index 6b733f7..115152d 100644 |
3 |
|
|
diff --git a/configure.ac b/configure.ac |
4 |
|
|
index 3c79a48..a9461f7 100644 |
5 |
|
|
--- a/configure.ac |
6 |
|
|
+++ b/configure.ac |
7 |
|
|
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. |
8 |
|
|
|
9 |
|
|
m4_define([up_major_version], [0]) |
10 |
|
|
m4_define([up_minor_version], [9]) |
11 |
|
|
-m4_define([up_micro_version], [5]) |
12 |
|
|
+m4_define([up_micro_version], [6]) |
13 |
|
|
m4_define([up_version], |
14 |
|
|
[up_major_version.up_minor_version.up_micro_version]) |
15 |
|
|
|
16 |
|
|
@@ -150,9 +150,20 @@ PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-1 >= 0.76]) |
17 |
|
|
AC_SUBST(DBUS_GLIB_CFLAGS) |
18 |
|
|
AC_SUBST(DBUS_GLIB_LIBS) |
19 |
|
|
|
20 |
|
|
-PKG_CHECK_MODULES(POLKIT, [polkit-gobject-1 >= 0.91]) |
21 |
|
|
-AC_SUBST(POLKIT_CFLAGS) |
22 |
|
|
-AC_SUBST(POLKIT_LIBS) |
23 |
|
|
+# polkit >= 0.97 uses polkit_authority_get_sync() rather than |
24 |
|
|
+# polkit_authority_get |
25 |
|
|
+PKG_CHECK_MODULES(POLKIT, \ |
26 |
|
|
+ polkit-gobject-1 >= 0.97, |
27 |
|
|
+ has_new_polkit=yes, |
28 |
|
|
+ has_new_polkit=no) |
29 |
|
|
+if test x$has_new_polkit = xno; then |
30 |
|
|
+ PKG_CHECK_MODULES(POLKIT, \ |
31 |
|
|
+ polkit-backend-1 \ |
32 |
|
|
+ polkit-gobject-1 >= 0.91) |
33 |
|
|
+else |
34 |
|
|
+ AC_DEFINE(USE_SECURITY_POLKIT_NEW, 1, [if we should use PolicyKit's new API]) |
35 |
|
|
+fi |
36 |
|
|
+ |
37 |
|
|
|
38 |
|
|
PKG_CHECK_MODULES(GIO, [gio-2.0 >= 2.16.1]) |
39 |
|
|
AC_SUBST(GIO_CFLAGS) |
40 |
|
|
diff --git a/libupower-glib/up-device.c b/libupower-glib/up-device.c |
41 |
|
|
index 3aecfd3..41097b2 100644 |
42 |
|
|
--- a/libupower-glib/up-device.c |
43 |
|
|
+++ b/libupower-glib/up-device.c |
44 |
|
|
@@ -450,7 +450,8 @@ up_device_to_text (UpDevice *device) |
45 |
|
|
device->priv->kind == UP_DEVICE_KIND_KEYBOARD || |
46 |
|
|
device->priv->kind == UP_DEVICE_KIND_UPS) |
47 |
|
|
g_string_append_printf (string, " present: %s\n", up_device_bool_to_string (device->priv->is_present)); |
48 |
|
|
- if (device->priv->kind == UP_DEVICE_KIND_BATTERY || |
49 |
|
|
+ if (device->priv->kind == UP_DEVICE_KIND_PHONE || |
50 |
|
|
+ device->priv->kind == UP_DEVICE_KIND_BATTERY || |
51 |
|
|
device->priv->kind == UP_DEVICE_KIND_MOUSE || |
52 |
|
|
device->priv->kind == UP_DEVICE_KIND_KEYBOARD) |
53 |
|
|
g_string_append_printf (string, " rechargeable: %s\n", up_device_bool_to_string (device->priv->is_rechargeable)); |
54 |
|
|
@@ -490,6 +491,10 @@ up_device_to_text (UpDevice *device) |
55 |
|
|
if (device->priv->kind == UP_DEVICE_KIND_BATTERY || |
56 |
|
|
device->priv->kind == UP_DEVICE_KIND_MOUSE || |
57 |
|
|
device->priv->kind == UP_DEVICE_KIND_KEYBOARD || |
58 |
|
|
+ device->priv->kind == UP_DEVICE_KIND_PHONE || |
59 |
|
|
+ device->priv->kind == UP_DEVICE_KIND_TABLET || |
60 |
|
|
+ device->priv->kind == UP_DEVICE_KIND_COMPUTER || |
61 |
|
|
+ device->priv->kind == UP_DEVICE_KIND_MEDIA_PLAYER || |
62 |
|
|
device->priv->kind == UP_DEVICE_KIND_UPS) |
63 |
|
|
g_string_append_printf (string, " percentage: %g%%\n", device->priv->percentage); |
64 |
|
|
if (device->priv->kind == UP_DEVICE_KIND_BATTERY) { |
65 |
|
|
diff --git a/src/up-daemon.c b/src/up-daemon.c |
66 |
|
|
index 3fb952b..532ebe8 100644 |
67 |
|
|
--- a/src/up-daemon.c |
68 |
|
|
+++ b/src/up-daemon.c |
69 |
|
|
@@ -323,6 +323,7 @@ up_daemon_about_to_sleep (UpDaemon *daemon, DBusGMethodInvocation *context) |
70 |
|
|
UP_DAEMON_ERROR_GENERAL, |
71 |
|
|
"Sleep has already been requested and is pending"); |
72 |
|
|
dbus_g_method_return_error (context, error); |
73 |
|
|
+ g_error_free (error); |
74 |
|
|
goto out; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
@@ -376,6 +377,7 @@ up_daemon_deferred_sleep_cb (UpDaemonDeferredSleep *sleep) |
78 |
|
|
"Failed to spawn: %s, stdout:%s, stderr:%s", error_local->message, stdout, stderr); |
79 |
|
|
g_error_free (error_local); |
80 |
|
|
dbus_g_method_return_error (sleep->context, error); |
81 |
|
|
+ g_error_free (error); |
82 |
|
|
goto out; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
@@ -470,6 +472,7 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context) |
86 |
|
|
UP_DAEMON_ERROR_GENERAL, |
87 |
|
|
"No kernel support"); |
88 |
|
|
dbus_g_method_return_error (context, error); |
89 |
|
|
+ g_error_free (error); |
90 |
|
|
goto out; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
@@ -486,6 +489,7 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context) |
94 |
|
|
UP_DAEMON_ERROR_GENERAL, |
95 |
|
|
"Sleep has already been requested and is pending"); |
96 |
|
|
dbus_g_method_return_error (context, error); |
97 |
|
|
+ g_error_free (error); |
98 |
|
|
goto out; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
@@ -507,13 +511,21 @@ up_daemon_suspend_allowed (UpDaemon *daemon, DBusGMethodInvocation *context) |
102 |
|
|
gboolean ret; |
103 |
|
|
PolkitSubject *subject = NULL; |
104 |
|
|
UpDaemonPrivate *priv = daemon->priv; |
105 |
|
|
+ GError *error; |
106 |
|
|
|
107 |
|
|
subject = up_polkit_get_subject (priv->polkit, context); |
108 |
|
|
if (subject == NULL) |
109 |
|
|
goto out; |
110 |
|
|
|
111 |
|
|
- ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.suspend", context); |
112 |
|
|
- dbus_g_method_return (context, ret); |
113 |
|
|
+ error = NULL; |
114 |
|
|
+ ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.suspend", &error); |
115 |
|
|
+ if (error) { |
116 |
|
|
+ dbus_g_method_return_error (context, error); |
117 |
|
|
+ g_error_free (error); |
118 |
|
|
+ } |
119 |
|
|
+ else { |
120 |
|
|
+ dbus_g_method_return (context, ret); |
121 |
|
|
+ } |
122 |
|
|
|
123 |
|
|
out: |
124 |
|
|
if (subject != NULL) |
125 |
|
|
@@ -563,6 +575,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context) |
126 |
|
|
UP_DAEMON_ERROR_GENERAL, |
127 |
|
|
"No kernel support"); |
128 |
|
|
dbus_g_method_return_error (context, error); |
129 |
|
|
+ g_error_free (error); |
130 |
|
|
goto out; |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
@@ -572,6 +585,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context) |
134 |
|
|
UP_DAEMON_ERROR_GENERAL, |
135 |
|
|
"Not enough swap space"); |
136 |
|
|
dbus_g_method_return_error (context, error); |
137 |
|
|
+ g_error_free (error); |
138 |
|
|
goto out; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
@@ -582,6 +596,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context) |
142 |
|
|
UP_DAEMON_ERROR_GENERAL, |
143 |
|
|
"Swap space is encrypted, use AllowHibernateEncryptedSwap to override"); |
144 |
|
|
dbus_g_method_return_error (context, error); |
145 |
|
|
+ g_error_free (error); |
146 |
|
|
goto out; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
@@ -598,6 +613,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context) |
150 |
|
|
UP_DAEMON_ERROR_GENERAL, |
151 |
|
|
"Sleep has already been requested and is pending"); |
152 |
|
|
dbus_g_method_return_error (context, error); |
153 |
|
|
+ g_error_free (error); |
154 |
|
|
goto out; |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
@@ -619,13 +635,21 @@ up_daemon_hibernate_allowed (UpDaemon *daemon, DBusGMethodInvocation *context) |
158 |
|
|
gboolean ret; |
159 |
|
|
PolkitSubject *subject = NULL; |
160 |
|
|
UpDaemonPrivate *priv = daemon->priv; |
161 |
|
|
+ GError *error; |
162 |
|
|
|
163 |
|
|
subject = up_polkit_get_subject (priv->polkit, context); |
164 |
|
|
if (subject == NULL) |
165 |
|
|
goto out; |
166 |
|
|
|
167 |
|
|
- ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.hibernate", context); |
168 |
|
|
- dbus_g_method_return (context, ret); |
169 |
|
|
+ error = NULL; |
170 |
|
|
+ ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.hibernate", &error); |
171 |
|
|
+ if (error) { |
172 |
|
|
+ dbus_g_method_return_error (context, error); |
173 |
|
|
+ g_error_free (error); |
174 |
|
|
+ } |
175 |
|
|
+ else { |
176 |
|
|
+ dbus_g_method_return (context, ret); |
177 |
|
|
+ } |
178 |
|
|
|
179 |
|
|
out: |
180 |
|
|
if (subject != NULL) |
181 |
|
|
diff --git a/src/up-polkit.c b/src/up-polkit.c |
182 |
|
|
index 3611afb..0ca2433 100644 |
183 |
|
|
--- a/src/up-polkit.c |
184 |
|
|
+++ b/src/up-polkit.c |
185 |
|
|
@@ -52,12 +52,19 @@ static gpointer up_polkit_object = NULL; |
186 |
|
|
PolkitSubject * |
187 |
|
|
up_polkit_get_subject (UpPolkit *polkit, DBusGMethodInvocation *context) |
188 |
|
|
{ |
189 |
|
|
+ GError *error; |
190 |
|
|
const gchar *sender; |
191 |
|
|
PolkitSubject *subject; |
192 |
|
|
|
193 |
|
|
sender = dbus_g_method_get_sender (context); |
194 |
|
|
subject = polkit_system_bus_name_new (sender); |
195 |
|
|
|
196 |
|
|
+ if (subject == NULL) { |
197 |
|
|
+ error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to get PolicyKit subject"); |
198 |
|
|
+ dbus_g_method_return_error (context, error); |
199 |
|
|
+ g_error_free (error); |
200 |
|
|
+ } |
201 |
|
|
+ |
202 |
|
|
return subject; |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
@@ -69,11 +76,14 @@ up_polkit_check_auth (UpPolkit *polkit, PolkitSubject *subject, const gchar *act |
206 |
|
|
{ |
207 |
|
|
gboolean ret = FALSE; |
208 |
|
|
GError *error; |
209 |
|
|
- GError *error_local; |
210 |
|
|
+ GError *error_local = NULL; |
211 |
|
|
PolkitAuthorizationResult *result; |
212 |
|
|
|
213 |
|
|
/* check auth */ |
214 |
|
|
- result = polkit_authority_check_authorization_sync (polkit->priv->authority, subject, action_id, NULL, POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, NULL, &error_local); |
215 |
|
|
+ result = polkit_authority_check_authorization_sync (polkit->priv->authority, |
216 |
|
|
+ subject, action_id, NULL, |
217 |
|
|
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, |
218 |
|
|
+ NULL, &error_local); |
219 |
|
|
if (result == NULL) { |
220 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message); |
221 |
|
|
dbus_g_method_return_error (context, error); |
222 |
|
|
@@ -100,20 +110,20 @@ out: |
223 |
|
|
* up_polkit_is_allowed: |
224 |
|
|
**/ |
225 |
|
|
gboolean |
226 |
|
|
-up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, DBusGMethodInvocation *context) |
227 |
|
|
+up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, GError **error) |
228 |
|
|
{ |
229 |
|
|
gboolean ret = FALSE; |
230 |
|
|
- GError *error; |
231 |
|
|
- GError *error_local; |
232 |
|
|
+ GError *error_local = NULL; |
233 |
|
|
PolkitAuthorizationResult *result; |
234 |
|
|
|
235 |
|
|
/* check auth */ |
236 |
|
|
- result = polkit_authority_check_authorization_sync (polkit->priv->authority, subject, action_id, NULL, POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE, NULL, &error_local); |
237 |
|
|
+ result = polkit_authority_check_authorization_sync (polkit->priv->authority, |
238 |
|
|
+ subject, action_id, NULL, |
239 |
|
|
+ POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE, |
240 |
|
|
+ NULL, &error_local); |
241 |
|
|
if (result == NULL) { |
242 |
|
|
- error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message); |
243 |
|
|
- dbus_g_method_return_error (context, error); |
244 |
|
|
+ g_set_error (error, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message); |
245 |
|
|
g_error_free (error_local); |
246 |
|
|
- g_error_free (error); |
247 |
|
|
goto out; |
248 |
|
|
} |
249 |
|
|
|
250 |
|
|
@@ -240,7 +250,17 @@ up_polkit_init (UpPolkit *polkit) |
251 |
|
|
} |
252 |
|
|
goto out; |
253 |
|
|
} |
254 |
|
|
+ |
255 |
|
|
+#ifdef USE_SECURITY_POLKIT_NEW |
256 |
|
|
+ polkit->priv->authority = polkit_authority_get_sync (NULL, &error); |
257 |
|
|
+ if (polkit->priv->authority == NULL) { |
258 |
|
|
+ g_error ("failed to get pokit authority: %s", error->message); |
259 |
|
|
+ g_error_free (error); |
260 |
|
|
+ goto out; |
261 |
|
|
+ } |
262 |
|
|
+#else |
263 |
|
|
polkit->priv->authority = polkit_authority_get (); |
264 |
|
|
+#endif |
265 |
|
|
out: |
266 |
|
|
return; |
267 |
|
|
} |
268 |
|
|
diff --git a/src/up-polkit.h b/src/up-polkit.h |
269 |
|
|
index acee70e..1ddac58 100644 |
270 |
|
|
--- a/src/up-polkit.h |
271 |
|
|
+++ b/src/up-polkit.h |
272 |
|
|
@@ -60,7 +60,7 @@ gboolean up_polkit_check_auth (UpPolkit *polkit, |
273 |
|
|
gboolean up_polkit_is_allowed (UpPolkit *polkit, |
274 |
|
|
PolkitSubject *subject, |
275 |
|
|
const gchar *action_id, |
276 |
|
|
- DBusGMethodInvocation *context); |
277 |
|
|
+ GError **error); |
278 |
|
|
gboolean up_polkit_get_uid (UpPolkit *polkit, |
279 |
|
|
PolkitSubject *subject, |
280 |
|
|
uid_t *uid); |
281 |
|
|
diff --git a/src/up-qos.c b/src/up-qos.c |
282 |
|
|
index 0ce3eea..f08c439 100644 |
283 |
|
|
--- a/src/up-qos.c |
284 |
|
|
+++ b/src/up-qos.c |
285 |
|
|
@@ -262,6 +262,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean |
286 |
|
|
if (type == UP_QOS_KIND_UNKNOWN) { |
287 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "type invalid: %s", type_text); |
288 |
|
|
dbus_g_method_return_error (context, error); |
289 |
|
|
+ g_error_free (error); |
290 |
|
|
goto out; |
291 |
|
|
} |
292 |
|
|
|
293 |
|
|
@@ -270,6 +271,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean |
294 |
|
|
if (sender == NULL) { |
295 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "no DBUS sender"); |
296 |
|
|
dbus_g_method_return_error (context, error); |
297 |
|
|
+ g_error_free (error); |
298 |
|
|
goto out; |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
@@ -291,6 +293,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean |
302 |
|
|
if (!retval) { |
303 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get UID"); |
304 |
|
|
dbus_g_method_return_error (context, error); |
305 |
|
|
+ g_error_free (error); |
306 |
|
|
goto out; |
307 |
|
|
} |
308 |
|
|
|
309 |
|
|
@@ -299,6 +302,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean |
310 |
|
|
if (!retval) { |
311 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get PID"); |
312 |
|
|
dbus_g_method_return_error (context, error); |
313 |
|
|
+ g_error_free (error); |
314 |
|
|
goto out; |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
@@ -307,6 +311,7 @@ up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean |
318 |
|
|
if (cmdline == NULL) { |
319 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get cmdline"); |
320 |
|
|
dbus_g_method_return_error (context, error); |
321 |
|
|
+ g_error_free (error); |
322 |
|
|
goto out; |
323 |
|
|
} |
324 |
|
|
|
325 |
|
|
@@ -359,6 +364,7 @@ up_qos_cancel_request (UpQos *qos, guint cookie, DBusGMethodInvocation *context) |
326 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, |
327 |
|
|
"Cannot find request for #%i", cookie); |
328 |
|
|
dbus_g_method_return_error (context, error); |
329 |
|
|
+ g_error_free (error); |
330 |
|
|
goto out; |
331 |
|
|
} |
332 |
|
|
|
333 |
|
|
@@ -367,6 +373,7 @@ up_qos_cancel_request (UpQos *qos, guint cookie, DBusGMethodInvocation *context) |
334 |
|
|
if (sender == NULL) { |
335 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "no DBUS sender"); |
336 |
|
|
dbus_g_method_return_error (context, error); |
337 |
|
|
+ g_error_free (error); |
338 |
|
|
goto out; |
339 |
|
|
} |
340 |
|
|
|
341 |
|
|
@@ -388,6 +395,8 @@ up_qos_cancel_request (UpQos *qos, guint cookie, DBusGMethodInvocation *context) |
342 |
|
|
/* TODO: if persistent remove from datadase */ |
343 |
|
|
|
344 |
|
|
g_signal_emit (qos, signals [REQUESTS_CHANGED], 0); |
345 |
|
|
+ |
346 |
|
|
+ dbus_g_method_return (context, NULL); |
347 |
|
|
out: |
348 |
|
|
if (subject != NULL) |
349 |
|
|
g_object_unref (subject); |
350 |
|
|
@@ -430,6 +439,7 @@ up_qos_set_minimum_latency (UpQos *qos, const gchar *type_text, gint value, DBus |
351 |
|
|
if (type == UP_QOS_KIND_UNKNOWN) { |
352 |
|
|
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "type invalid: %s", type_text); |
353 |
|
|
dbus_g_method_return_error (context, error); |
354 |
|
|
+ g_error_free (error); |
355 |
|
|
return; |
356 |
|
|
} |
357 |
|
|
|