~ubuntu-branches/debian/sid/hal/sid

« back to all changes in this revision

Viewing changes to hald/linux/addons/addon-macbookpro-backlight.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • Revision ID: james.westby@ubuntu.com-20071023123358-xaf8mjc5n84d5gtz
Tags: upstream-0.5.10
ImportĀ upstreamĀ versionĀ 0.5.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
}
216
216
#endif
217
217
 
 
218
static gboolean
 
219
check_priv (DBusConnection *connection, 
 
220
            DBusMessage *message, 
 
221
            const char *udi, 
 
222
            const char *action)
 
223
#ifdef HAVE_POLKIT
 
224
{
 
225
        gboolean ret;
 
226
        char *polkit_result;
 
227
        const char *invoked_by_syscon_name;
 
228
        DBusMessage *reply;
 
229
        DBusError error;
 
230
 
 
231
        ret = FALSE;
 
232
        polkit_result = NULL;
 
233
 
 
234
        invoked_by_syscon_name = dbus_message_get_sender (message);
 
235
        
 
236
        dbus_error_init (&error);
 
237
        polkit_result = libhal_device_is_caller_privileged (halctx,
 
238
                                                            udi,
 
239
                                                            action,
 
240
                                                            invoked_by_syscon_name,
 
241
                                                            &error);
 
242
        if (polkit_result == NULL) {
 
243
                reply = dbus_message_new_error_printf (message,
 
244
                                                       "org.freedesktop.Hal.Device.Error",
 
245
                                                       "Cannot determine if caller is privileged for action '%s'",
 
246
                                                       action);
 
247
                dbus_connection_send (connection, reply, NULL);
 
248
                goto out;
 
249
        }
 
250
        if (strcmp (polkit_result, "yes") != 0) {
 
251
 
 
252
                reply = dbus_message_new_error_printf (message,
 
253
                                                       "org.freedesktop.Hal.Device.PermissionDeniedByPolicy",
 
254
                                                       "%s %s <-- (action, result)",
 
255
                                                       action, polkit_result);
 
256
                dbus_connection_send (connection, reply, NULL);
 
257
                goto out;
 
258
        }
 
259
 
 
260
        ret = TRUE;
 
261
 
 
262
out:
 
263
        if (polkit_result != NULL)
 
264
                libhal_free_string (polkit_result);
 
265
        return ret;
 
266
}
 
267
#else
 
268
{
 
269
        return TRUE;
 
270
}
 
271
#endif
 
272
 
218
273
static int last_keyboard_brightness = -1;
219
274
 
220
275
static DBusHandlerResult
222
277
{
223
278
        DBusError err;
224
279
        DBusMessage *reply;
 
280
        const char *udi;
 
281
 
 
282
        udi = dbus_message_get_path (message);
225
283
 
226
284
        /*dbg ("filter_function: sender=%s destination=%s obj_path=%s interface=%s method=%s", 
227
285
             dbus_message_get_sender (message), 
237
295
                                         "SetBrightness")) {
238
296
                int brightness;
239
297
 
 
298
                if (!check_priv (connection, message, udi, "org.freedesktop.hal.power-management.lcd-panel"))
 
299
                        goto error;
 
300
 
240
301
                dbus_error_init (&err);
241
302
                if (dbus_message_get_args (message, 
242
303
                                           &err,
271
332
                                                "GetBrightness")) {
272
333
                int brightness;
273
334
 
 
335
                if (!check_priv (connection, message, udi, "org.freedesktop.hal.power-management.lcd-panel"))
 
336
                        goto error;
 
337
 
274
338
                dbus_error_init (&err);
275
339
                if (dbus_message_get_args (message, 
276
340
                                           &err,
299
363
                                                "GetBrightness")) {
300
364
                int brightness[2];
301
365
 
 
366
                if (!check_priv (connection, message, udi, "org.freedesktop.hal.power-management.light-sensor"))
 
367
                        goto error;
 
368
 
302
369
                brightness[0] = read_light_sensor (FALSE); /* right */
303
370
                brightness[1] = read_light_sensor (TRUE); /* left */
304
371
 
323
390
                                                "org.freedesktop.Hal.Device.KeyboardBacklight", 
324
391
                                                "GetBrightness")) {
325
392
 
 
393
                if (!check_priv (connection, message, udi, "org.freedesktop.hal.power-management.keyboard-backlight"))
 
394
                        goto error;
 
395
 
326
396
                /* I can't get this working so just cache last SetBrightness value :-/ */
327
397
                if (last_keyboard_brightness == -1 ) {
328
398
                        reply = dbus_message_new_error (message,
365
435
                                                "SetBrightness")) {
366
436
                int brightness;
367
437
 
 
438
                if (!check_priv (connection, message, udi, "org.freedesktop.hal.power-management.keyboard-backlight"))
 
439
                        goto error;
368
440
 
369
441
                dbus_error_init (&err);
370
442
                if (dbus_message_get_args (message,