X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-dbus.c;h=bbb4ae2de66a912168a68bf5c658551f4f95c815;hb=e5f5b5b9c92d59ef3cb5169982cb6f436c9206fa;hp=bcfcba2d0770a9d8bb974de5031006ed6fa02b93;hpb=def9a7aa0182e5ecca3ac61b26f75136a5c4f103;p=elogind.git diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index bcfcba2d0..bbb4ae2de 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -23,7 +23,6 @@ #include #include #include -#include #include "sd-id128.h" #include "sd-messages.h" @@ -40,9 +39,10 @@ #include "audit.h" #include "bus-util.h" #include "bus-error.h" -#include "logind.h" -#include "bus-errors.h" +#include "bus-common-errors.h" #include "udev-util.h" +#include "selinux-util.h" +#include "logind.h" static int property_get_idle_hint( sd_bus *bus, @@ -727,7 +727,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use /* Now, let's wait until the slice unit and stuff got * created. We send the reply back from - * session_send_create_reply().*/ + * session_send_create_reply(). */ return 1; @@ -1029,14 +1029,13 @@ static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *us if (!pw) return errno ? -errno : -ENOENT; - r = bus_verify_polkit_async(bus, - &m->polkit_registry, - message, - CAP_SYS_ADMIN, - "org.freedesktop.login1.set-user-linger", - interactive, - error, - method_set_user_linger, m); + r = bus_verify_polkit_async( + message, + CAP_SYS_ADMIN, + "org.freedesktop.login1.set-user-linger", + interactive, + &m->polkit_registry, + error); if (r < 0) return r; if (r == 0) @@ -1144,7 +1143,7 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { return -ENOMEM; mkdir_p_label("/etc/udev/rules.d", 0755); - label_init("/etc"); + mac_selinux_init("/etc"); r = write_string_file_atomic_label(file, rule); if (r < 0) return r; @@ -1160,7 +1159,7 @@ static int flush_devices(Manager *m) { d = opendir("/etc/udev/rules.d"); if (!d) { if (errno != ENOENT) - log_warning("Failed to open /etc/udev/rules.d: %m"); + log_warning_errno(errno, "Failed to open /etc/udev/rules.d: %m"); } else { struct dirent *de; @@ -1176,7 +1175,7 @@ static int flush_devices(Manager *m) { continue; if (unlinkat(dirfd(d), de->d_name, 0) < 0) - log_warning("Failed to unlink %s: %m", de->d_name); + log_warning_errno(errno, "Failed to unlink %s: %m", de->d_name); } } @@ -1202,14 +1201,13 @@ static int method_attach_device(sd_bus *bus, sd_bus_message *message, void *user if (!seat_name_is_valid(seat)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Seat %s is not valid", seat); - r = bus_verify_polkit_async(bus, - &m->polkit_registry, - message, - CAP_SYS_ADMIN, - "org.freedesktop.login1.attach-device", - interactive, - error, - method_attach_device, m); + r = bus_verify_polkit_async( + message, + CAP_SYS_ADMIN, + "org.freedesktop.login1.attach-device", + interactive, + &m->polkit_registry, + error); if (r < 0) return r; if (r == 0) @@ -1234,14 +1232,13 @@ static int method_flush_devices(sd_bus *bus, sd_bus_message *message, void *user if (r < 0) return r; - r = bus_verify_polkit_async(bus, - &m->polkit_registry, - message, - CAP_SYS_ADMIN, - "org.freedesktop.login1.flush-devices", - interactive, - error, - method_flush_devices, m); + r = bus_verify_polkit_async( + message, + CAP_SYS_ADMIN, + "org.freedesktop.login1.flush-devices", + interactive, + &m->polkit_registry, + error); if (r < 0) return r; if (r == 0) @@ -1303,9 +1300,11 @@ static int bus_manager_log_shutdown( q = NULL; } - return log_struct(LOG_NOTICE, MESSAGE_ID(SD_MESSAGE_SHUTDOWN), + return log_struct(LOG_NOTICE, + LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN), p, - q, NULL); + q, + NULL); } static int lid_switch_ignore_handler(sd_event_source *e, uint64_t usec, void *userdata) { @@ -1535,8 +1534,7 @@ static int method_do_shutdown_or_sleep( blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid, NULL); if (multiple_sessions) { - r = bus_verify_polkit_async(m->bus, &m->polkit_registry, message, CAP_SYS_BOOT, - action_multiple_sessions, interactive, error, method, m); + r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_multiple_sessions, interactive, &m->polkit_registry, error); if (r < 0) return r; if (r == 0) @@ -1544,8 +1542,7 @@ static int method_do_shutdown_or_sleep( } if (blocked) { - r = bus_verify_polkit_async(m->bus, &m->polkit_registry, message, CAP_SYS_BOOT, - action_ignore_inhibit, interactive, error, method, m); + r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_ignore_inhibit, interactive, &m->polkit_registry, error); if (r < 0) return r; if (r == 0) @@ -1553,8 +1550,7 @@ static int method_do_shutdown_or_sleep( } if (!multiple_sessions && !blocked) { - r = bus_verify_polkit_async(m->bus, &m->polkit_registry, message, CAP_SYS_BOOT, - action, interactive, error, method, m); + r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action, interactive, &m->polkit_registry, error); if (r < 0) return r; if (r == 0) @@ -1691,7 +1687,7 @@ static int method_can_shutdown_or_sleep( blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid, NULL); if (multiple_sessions) { - r = bus_verify_polkit(m->bus, message, CAP_SYS_BOOT, action_multiple_sessions, false, &challenge, error); + r = bus_verify_polkit(message, CAP_SYS_BOOT, action_multiple_sessions, false, &challenge, error); if (r < 0) return r; @@ -1704,7 +1700,7 @@ static int method_can_shutdown_or_sleep( } if (blocked) { - r = bus_verify_polkit(m->bus, message, CAP_SYS_BOOT, action_ignore_inhibit, false, &challenge, error); + r = bus_verify_polkit(message, CAP_SYS_BOOT, action_ignore_inhibit, false, &challenge, error); if (r < 0) return r; @@ -1720,7 +1716,7 @@ static int method_can_shutdown_or_sleep( /* If neither inhibit nor multiple sessions * apply then just check the normal policy */ - r = bus_verify_polkit(m->bus, message, CAP_SYS_BOOT, action, false, &challenge, error); + r = bus_verify_polkit(message, CAP_SYS_BOOT, action, false, &challenge, error); if (r < 0) return r; @@ -1840,7 +1836,7 @@ static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata, if (m->action_what & w) return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, "The operation inhibition has been requested for is already running"); - r = bus_verify_polkit_async(bus, &m->polkit_registry, message, CAP_SYS_BOOT, + r = bus_verify_polkit_async(message, CAP_SYS_BOOT, w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") : w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") : w == INHIBIT_IDLE ? "org.freedesktop.login1.inhibit-block-idle" : @@ -1848,7 +1844,7 @@ static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata, w == INHIBIT_HANDLE_SUSPEND_KEY ? "org.freedesktop.login1.inhibit-handle-suspend-key" : w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" : "org.freedesktop.login1.inhibit-handle-lid-switch", - false, error, method_inhibit, m); + false, &m->polkit_registry, error); if (r < 0) return r; if (r == 0) @@ -1925,6 +1921,7 @@ const sd_bus_vtable manager_vtable[] = { SD_BUS_PROPERTY("HandleSuspendKey", "s", property_get_handle_action, offsetof(Manager, handle_suspend_key), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HandleHibernateKey", "s", property_get_handle_action, offsetof(Manager, handle_hibernate_key), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HandleLidSwitch", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("HandleLidSwitchDocked", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch_docked), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("IdleAction", "s", property_get_handle_action, offsetof(Manager, idle_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("IdleActionUSec", "t", NULL, offsetof(Manager, idle_action_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("PreparingForShutdown", "b", property_get_preparing, 0, 0), @@ -2114,9 +2111,10 @@ int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdat return 0; r = unit_name_from_dbus_path(path, &unit); + if (r == -EINVAL) /* not a unit */ + return 0; if (r < 0) - /* quietly ignore non-units paths */ - return r == -EINVAL ? 0 : r; + return r; session = hashmap_get(m->session_units, unit); if (session)