~ubuntu-branches/debian/jessie/systemd/jessie

« back to all changes in this revision

Viewing changes to src/dbus-common.c

  • Committer: Package Import Robot
  • Author(s): Tollef Fog Heen, Tollef Fog Heen, Michael Biebl
  • Date: 2012-04-03 19:59:17 UTC
  • mfrom: (1.1.10) (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20120403195917-l532urrbg4pkreas
Tags: 44-1
[ Tollef Fog Heen ]
* New upstream version.
  - Backport 3492207: journal: PAGE_SIZE is not known on ppc and other
    archs
  - Backport 5a2a2a1: journal: react with immediate rotation to a couple
    of more errors
  - Backport 693ce21: util: never follow symlinks in rm_rf_children()
    Fixes CVE-2012-1174, closes: #664364
* Drop output message from init-functions hook, it's pointless.
* Only rmdir /lib/init/rw if it exists.
* Explicitly order debian-fixup before sysinit.target to prevent a
  possible race condition with the creation of sockets.  Thanks to
  Michael Biebl for debugging this.
* Always restart the initctl socket on upgrades, to mask sysvinit
  removing it.

[ Michael Biebl ]
* Remove workaround for non-interactive sessions from pam config again.
* Create compat /dev/initctl symlink in case we are upgrading from a system
  running a newer version of sysvinit (using /run/initctl) and sysvinit is
  replaced with systemd-sysv during the upgrade. Closes: #663219
* Install new man pages.
* Build-Depend on valac (>= 0.12) instead of valac-0.12. Closes: #663323

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
        assert(user || host);
178
178
 
179
179
        if (user && host)
180
 
                asprintf(&p, "exec:path=ssh,argv1=-xT,argv2=%s@%s,argv3=systemd-stdio-bridge", user, host);
 
180
                asprintf(&p, "unixexec:path=ssh,argv1=-xT,argv2=%s@%s,argv3=systemd-stdio-bridge", user, host);
181
181
        else if (user)
182
 
                asprintf(&p, "exec:path=ssh,argv1=-xT,argv2=%s@localhost,argv3=systemd-stdio-bridge", user);
 
182
                asprintf(&p, "unixexec:path=ssh,argv1=-xT,argv2=%s@localhost,argv3=systemd-stdio-bridge", user);
183
183
        else if (host)
184
 
                asprintf(&p, "exec:path=ssh,argv1=-xT,argv2=%s,argv3=systemd-stdio-bridge", host);
 
184
                asprintf(&p, "unixexec:path=ssh,argv1=-xT,argv2=%s,argv3=systemd-stdio-bridge", host);
185
185
 
186
186
        if (!p) {
187
187
                dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
222
222
        if (geteuid() == 0)
223
223
                return bus_connect(DBUS_BUS_SYSTEM, _bus, NULL, error);
224
224
 
225
 
        if (!(bus = dbus_connection_open_private("exec:path=pkexec,argv1=" SYSTEMD_STDIO_BRIDGE_BINARY_PATH, error)))
 
225
        bus = dbus_connection_open_private("unixexec:path=pkexec,argv1=" SYSTEMD_STDIO_BRIDGE_BINARY_PATH, error);
 
226
        if (!bus)
226
227
                return -EIO;
227
228
 
228
229
        dbus_connection_set_exit_on_disconnect(bus, FALSE);
259
260
                DBusMessage *message,
260
261
                const char *introspection,
261
262
                const char *interfaces,
262
 
                const BusProperty *properties) {
 
263
                const BusBoundProperties *bound_properties) {
263
264
 
264
265
        DBusError error;
265
266
        DBusMessage *reply = NULL;
278
279
                if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID))
279
280
                        goto oom;
280
281
 
281
 
        } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Get") && properties) {
 
282
        } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Get") && bound_properties) {
282
283
                const char *interface, *property;
 
284
                const BusBoundProperties *bp;
283
285
                const BusProperty *p;
 
286
                void *data;
 
287
                DBusMessageIter iter, sub;
284
288
 
285
289
                if (!dbus_message_get_args(
286
290
                            message,
290
294
                            DBUS_TYPE_INVALID))
291
295
                        return bus_send_error_reply(c, message, &error, -EINVAL);
292
296
 
293
 
                for (p = properties; p->property; p++)
294
 
                        if (streq(p->interface, interface) && streq(p->property, property))
295
 
                                break;
296
 
 
297
 
                if (p->property) {
298
 
                        DBusMessageIter iter, sub;
299
 
 
300
 
                        if (!(reply = dbus_message_new_method_return(message)))
301
 
                                goto oom;
302
 
 
303
 
                        dbus_message_iter_init_append(reply, &iter);
304
 
 
305
 
                        if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->signature, &sub))
306
 
                                goto oom;
307
 
 
308
 
                        if ((r = p->append(&sub, property, (void*) p->data)) < 0) {
309
 
 
310
 
                                if (r == -ENOMEM)
311
 
                                        goto oom;
312
 
 
313
 
                                dbus_message_unref(reply);
314
 
                                return bus_send_error_reply(c, message, NULL, r);
315
 
                        }
316
 
 
317
 
                        if (!dbus_message_iter_close_container(&iter, &sub))
318
 
                                goto oom;
319
 
                } else {
320
 
                        if (!nulstr_contains(interfaces, interface))
321
 
                                dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
322
 
                        else
323
 
                                dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
324
 
 
325
 
                        return bus_send_error_reply(c, message, &error, -EINVAL);
326
 
                }
327
 
 
328
 
        } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "GetAll") && properties) {
 
297
                for (bp = bound_properties; bp->interface; bp++) {
 
298
                        if (!streq(bp->interface, interface))
 
299
                                continue;
 
300
 
 
301
                        for (p = bp->properties; p->property; p++)
 
302
                                if (streq(p->property, property))
 
303
                                        goto get_prop;
 
304
                }
 
305
 
 
306
                /* no match */
 
307
                if (!nulstr_contains(interfaces, interface))
 
308
                        dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
 
309
                else
 
310
                        dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
 
311
 
 
312
                return bus_send_error_reply(c, message, &error, -EINVAL);
 
313
 
 
314
get_prop:
 
315
                reply = dbus_message_new_method_return(message);
 
316
                if (!reply)
 
317
                        goto oom;
 
318
 
 
319
                dbus_message_iter_init_append(reply, &iter);
 
320
 
 
321
                if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->signature, &sub))
 
322
                        goto oom;
 
323
 
 
324
                data = (char*)bp->base + p->offset;
 
325
                if (p->indirect)
 
326
                        data = *(void**)data;
 
327
                r = p->append(&sub, property, data);
 
328
                if (r < 0) {
 
329
                        if (r == -ENOMEM)
 
330
                                goto oom;
 
331
 
 
332
                        dbus_message_unref(reply);
 
333
                        return bus_send_error_reply(c, message, NULL, r);
 
334
                }
 
335
 
 
336
                if (!dbus_message_iter_close_container(&iter, &sub))
 
337
                        goto oom;
 
338
 
 
339
        } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "GetAll") && bound_properties) {
329
340
                const char *interface;
 
341
                const BusBoundProperties *bp;
330
342
                const BusProperty *p;
331
343
                DBusMessageIter iter, sub, sub2, sub3;
332
344
 
350
362
                if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub))
351
363
                        goto oom;
352
364
 
353
 
                for (p = properties; p->property; p++) {
354
 
                        if (interface[0] && !streq(p->interface, interface))
 
365
                for (bp = bound_properties; bp->interface; bp++) {
 
366
                        if (interface[0] && !streq(bp->interface, interface))
355
367
                                continue;
356
368
 
357
 
                        if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &sub2) ||
358
 
                            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &p->property) ||
359
 
                            !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, p->signature, &sub3))
360
 
                                goto oom;
361
 
 
362
 
                        if ((r = p->append(&sub3, p->property, (void*) p->data)) < 0) {
363
 
 
364
 
                                if (r == -ENOMEM)
365
 
                                        goto oom;
366
 
 
367
 
                                dbus_message_unref(reply);
368
 
                                return bus_send_error_reply(c, message, NULL, r);
 
369
                        for (p = bp->properties; p->property; p++) {
 
370
                                void *data;
 
371
 
 
372
                                if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &sub2) ||
 
373
                                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &p->property) ||
 
374
                                    !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, p->signature, &sub3))
 
375
                                        goto oom;
 
376
 
 
377
                                data = (char*)bp->base + p->offset;
 
378
                                if (p->indirect)
 
379
                                        data = *(void**)data;
 
380
                                r = p->append(&sub3, p->property, data);
 
381
                                if (r < 0) {
 
382
                                        if (r == -ENOMEM)
 
383
                                                goto oom;
 
384
 
 
385
                                        dbus_message_unref(reply);
 
386
                                        return bus_send_error_reply(c, message, NULL, r);
 
387
                                }
 
388
 
 
389
                                if (!dbus_message_iter_close_container(&sub2, &sub3) ||
 
390
                                    !dbus_message_iter_close_container(&sub, &sub2))
 
391
                                        goto oom;
369
392
                        }
370
 
 
371
 
                        if (!dbus_message_iter_close_container(&sub2, &sub3) ||
372
 
                            !dbus_message_iter_close_container(&sub, &sub2))
373
 
                                goto oom;
374
393
                }
375
394
 
376
395
                if (!dbus_message_iter_close_container(&iter, &sub))
377
396
                        goto oom;
378
397
 
379
 
        } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set") && properties) {
 
398
        } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set") && bound_properties) {
380
399
                const char *interface, *property;
381
400
                DBusMessageIter iter;
 
401
                const BusBoundProperties *bp;
382
402
                const BusProperty *p;
 
403
                DBusMessageIter sub;
 
404
                char *sig;
383
405
 
384
406
                if (!dbus_message_iter_init(message, &iter) ||
385
407
                    dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
398
420
                    dbus_message_iter_has_next(&iter))
399
421
                        return bus_send_error_reply(c, message, NULL, -EINVAL);
400
422
 
401
 
                for (p = properties; p->property; p++)
402
 
                        if (streq(p->interface, interface) && streq(p->property, property))
403
 
                                break;
404
 
 
405
 
                if (p->set) {
406
 
                        DBusMessageIter sub;
407
 
                        char *sig;
408
 
 
409
 
                        dbus_message_iter_recurse(&iter, &sub);
410
 
 
411
 
                        if (!(sig = dbus_message_iter_get_signature(&sub)))
412
 
                                goto oom;
413
 
 
414
 
                        if (!streq(sig, p->signature)) {
415
 
                                dbus_free(sig);
416
 
                                return bus_send_error_reply(c, message, NULL, -EINVAL);
417
 
                        }
418
 
 
 
423
                for (bp = bound_properties; bp->interface; bp++) {
 
424
                        if (!streq(bp->interface, interface))
 
425
                                continue;
 
426
 
 
427
                        for (p = bp->properties; p->property; p++)
 
428
                                if (streq(p->property, property))
 
429
                                        goto set_prop;
 
430
                }
 
431
 
 
432
                /* no match */
 
433
                if (!nulstr_contains(interfaces, interface))
 
434
                        dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
 
435
                else
 
436
                        dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
 
437
 
 
438
                return bus_send_error_reply(c, message, &error, -EINVAL);
 
439
 
 
440
set_prop:
 
441
                if (!p->set) {
 
442
                        dbus_set_error_const(&error, DBUS_ERROR_PROPERTY_READ_ONLY, "Property read-only");
 
443
                        return bus_send_error_reply(c, message, &error, -EINVAL);
 
444
                }
 
445
 
 
446
                dbus_message_iter_recurse(&iter, &sub);
 
447
 
 
448
                sig = dbus_message_iter_get_signature(&sub);
 
449
                if (!sig)
 
450
                        goto oom;
 
451
 
 
452
                if (!streq(sig, p->signature)) {
419
453
                        dbus_free(sig);
420
 
 
421
 
                        if ((r = p->set(&sub, property)) < 0) {
422
 
                                if (r == -ENOMEM)
423
 
                                        goto oom;
424
 
                                return bus_send_error_reply(c, message, NULL, r);
425
 
                        }
426
 
 
427
 
                        if (!(reply = dbus_message_new_method_return(message)))
 
454
                        return bus_send_error_reply(c, message, NULL, -EINVAL);
 
455
                }
 
456
 
 
457
                dbus_free(sig);
 
458
 
 
459
                r = p->set(&sub, property);
 
460
                if (r < 0) {
 
461
                        if (r == -ENOMEM)
428
462
                                goto oom;
429
 
                } else {
430
 
                        if (p->property)
431
 
                                dbus_set_error_const(&error, DBUS_ERROR_PROPERTY_READ_ONLY, "Property read-only");
432
 
                        else if (!nulstr_contains(interfaces, interface))
433
 
                                dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
434
 
                        else
435
 
                                dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
436
 
 
437
 
                        return bus_send_error_reply(c, message, &error, -EINVAL);
 
463
                        return bus_send_error_reply(c, message, NULL, r);
438
464
                }
439
465
 
 
466
                reply = dbus_message_new_method_return(message);
 
467
                if (!reply)
 
468
                        goto oom;
440
469
        } else {
441
470
                const char *interface = dbus_message_get_interface(message);
442
471
 
505
534
        return 0;
506
535
}
507
536
 
 
537
int bus_property_append_tristate_false(DBusMessageIter *i, const char *property, void *data) {
 
538
        int *b = data;
 
539
        dbus_bool_t db;
 
540
 
 
541
        assert(i);
 
542
        assert(property);
 
543
        assert(b);
 
544
 
 
545
        db = *b > 0;
 
546
 
 
547
        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &db))
 
548
                return -ENOMEM;
 
549
 
 
550
        return 0;
 
551
}
 
552
 
508
553
int bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data) {
509
554
        assert(i);
510
555
        assert(property);