698723
From d375206fe822903b16f3b9006ea47ffd938d88cb Mon Sep 17 00:00:00 2001
698723
From: Deepak Rawat <drawat.floss@gmail.com>
698723
Date: Mon, 25 Jan 2021 09:14:08 -0800
698723
Subject: [PATCH] logind: Introduce RebootWithFlags and others
698723
698723
Add new systemd-logind WithFlags version for Reboot and others. These
698723
methods add a unit64 parameter, with which can send additional control flags.
698723
698723
(cherry picked from commit 00971ea5164e2e7a5f2d7ffe12a566b62d282556)
698723
698723
Related: #1269726
698723
---
698723
 src/basic/login-util.h      |   8 +
698723
 src/login/logind-dbus.c     | 498 +++++++++++++++++++++++++++++++-----
698723
 src/systemctl/systemctl.c   |  26 ++
698723
 src/systemd/sd-bus-vtable.h |  19 +-
698723
 4 files changed, 480 insertions(+), 71 deletions(-)
698723
698723
diff --git a/src/basic/login-util.h b/src/basic/login-util.h
698723
index e1e62e12b7..9832207458 100644
698723
--- a/src/basic/login-util.h
698723
+++ b/src/basic/login-util.h
698723
@@ -4,6 +4,14 @@
698723
 #include <stdbool.h>
698723
 #include <unistd.h>
698723
 
698723
+#define SD_LOGIND_ROOT_CHECK_INHIBITORS           (UINT64_C(1) << 0)
698723
+
698723
+/* For internal use only */
698723
+#define SD_LOGIND_INTERACTIVE                     (UINT64_C(1) << 63)
698723
+
698723
+#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC (SD_LOGIND_ROOT_CHECK_INHIBITORS)
698723
+#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_ALL    (SD_LOGIND_ROOT_CHECK_INHIBITORS|SD_LOGIND_INTERACTIVE)
698723
+
698723
 bool session_id_valid(const char *id);
698723
 
698723
 static inline bool logind_running(void) {
698723
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
698723
index 3f122fcbd9..0c43fbb3e0 100644
698723
--- a/src/login/logind-dbus.c
698723
+++ b/src/login/logind-dbus.c
698723
@@ -1698,14 +1698,14 @@ static int verify_shutdown_creds(
698723
                 Manager *m,
698723
                 sd_bus_message *message,
698723
                 InhibitWhat w,
698723
-                bool interactive,
698723
                 const char *action,
698723
                 const char *action_multiple_sessions,
698723
                 const char *action_ignore_inhibit,
698723
+                uint64_t flags,
698723
                 sd_bus_error *error) {
698723
 
698723
         _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
698723
-        bool multiple_sessions, blocked;
698723
+        bool multiple_sessions, blocked, interactive;
698723
         uid_t uid;
698723
         int r;
698723
 
698723
@@ -1728,6 +1728,7 @@ static int verify_shutdown_creds(
698723
 
698723
         multiple_sessions = r > 0;
698723
         blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid, NULL);
698723
+        interactive = flags & SD_LOGIND_INTERACTIVE;
698723
 
698723
         if (multiple_sessions && action_multiple_sessions) {
698723
                 r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_multiple_sessions, NULL, interactive, UID_INVALID, &m->polkit_registry, error);
698723
@@ -1737,12 +1738,19 @@ static int verify_shutdown_creds(
698723
                         return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
698723
         }
698723
 
698723
-        if (blocked && action_ignore_inhibit) {
698723
-                r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_ignore_inhibit, NULL, interactive, UID_INVALID, &m->polkit_registry, error);
698723
-                if (r < 0)
698723
-                        return r;
698723
-                if (r == 0)
698723
-                        return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
698723
+        if (blocked) {
698723
+                /* We don't check polkit for root here, because you can't be more privileged than root */
698723
+                if (uid == 0 && (flags & SD_LOGIND_ROOT_CHECK_INHIBITORS))
698723
+                        return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED,
698723
+                                                 "Access denied to root due to active block inhibitor");
698723
+
698723
+                if (action_ignore_inhibit) {
698723
+                        r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_ignore_inhibit, NULL, interactive, UID_INVALID, &m->polkit_registry, error);
698723
+                        if (r < 0)
698723
+                                return r;
698723
+                        if (r == 0)
698723
+                                return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
698723
+                }
698723
         }
698723
 
698723
         if (!multiple_sessions && !blocked && action) {
698723
@@ -1765,9 +1773,11 @@ static int method_do_shutdown_or_sleep(
698723
                 const char *action_multiple_sessions,
698723
                 const char *action_ignore_inhibit,
698723
                 const char *sleep_verb,
698723
+                bool with_flags,
698723
                 sd_bus_error *error) {
698723
 
698723
-        int interactive, r;
698723
+        int interactive = false, r;
698723
+        uint64_t flags = 0;
698723
 
698723
         assert(m);
698723
         assert(message);
698723
@@ -1775,10 +1785,20 @@ static int method_do_shutdown_or_sleep(
698723
         assert(w >= 0);
698723
         assert(w <= _INHIBIT_WHAT_MAX);
698723
 
698723
-        r = sd_bus_message_read(message, "b", &interactive);
698723
+        if (with_flags)
698723
+                r = sd_bus_message_read(message, "t", &flags);
698723
+        else
698723
+                r = sd_bus_message_read(message, "b", &interactive);
698723
+
698723
         if (r < 0)
698723
                 return r;
698723
 
698723
+        if (with_flags && (flags & ~SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC))
698723
+                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
698723
+                                         "Invalid flags parameter");
698723
+
698723
+        SET_FLAG(flags, SD_LOGIND_INTERACTIVE, interactive);
698723
+
698723
         /* Don't allow multiple jobs being executed at the same time */
698723
         if (m->action_what)
698723
                 return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, "There's already a shutdown or sleep operation in progress");
698723
@@ -1795,8 +1815,8 @@ static int method_do_shutdown_or_sleep(
698723
                         return r;
698723
         }
698723
 
698723
-        r = verify_shutdown_creds(m, message, w, interactive, action, action_multiple_sessions,
698723
-                                  action_ignore_inhibit, error);
698723
+        r = verify_shutdown_creds(m, message, w, action, action_multiple_sessions,
698723
+                                  action_ignore_inhibit, flags, error);
698723
         if (r != 0)
698723
                 return r;
698723
 
698723
@@ -1818,6 +1838,7 @@ static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error
698723
                         "org.freedesktop.login1.power-off-multiple-sessions",
698723
                         "org.freedesktop.login1.power-off-ignore-inhibit",
698723
                         NULL,
698723
+                        sd_bus_message_is_method_call(message, NULL, "PowerOffWithFlags"),
698723
                         error);
698723
 }
698723
 
698723
@@ -1832,6 +1853,7 @@ static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *
698723
                         "org.freedesktop.login1.reboot-multiple-sessions",
698723
                         "org.freedesktop.login1.reboot-ignore-inhibit",
698723
                         NULL,
698723
+                        sd_bus_message_is_method_call(message, NULL, "RebootWithFlags"),
698723
                         error);
698723
 }
698723
 
698723
@@ -1846,6 +1868,7 @@ static int method_halt(sd_bus_message *message, void *userdata, sd_bus_error *er
698723
                         "org.freedesktop.login1.halt-multiple-sessions",
698723
                         "org.freedesktop.login1.halt-ignore-inhibit",
698723
                         NULL,
698723
+                        sd_bus_message_is_method_call(message, NULL, "HaltWithFlags"),
698723
                         error);
698723
 }
698723
 
698723
@@ -1860,6 +1883,7 @@ static int method_suspend(sd_bus_message *message, void *userdata, sd_bus_error
698723
                         "org.freedesktop.login1.suspend-multiple-sessions",
698723
                         "org.freedesktop.login1.suspend-ignore-inhibit",
698723
                         "suspend",
698723
+                        sd_bus_message_is_method_call(message, NULL, "SuspendWithFlags"),
698723
                         error);
698723
 }
698723
 
698723
@@ -1874,6 +1898,7 @@ static int method_hibernate(sd_bus_message *message, void *userdata, sd_bus_erro
698723
                         "org.freedesktop.login1.hibernate-multiple-sessions",
698723
                         "org.freedesktop.login1.hibernate-ignore-inhibit",
698723
                         "hibernate",
698723
+                        sd_bus_message_is_method_call(message, NULL, "HibernateWithFlags"),
698723
                         error);
698723
 }
698723
 
698723
@@ -1888,6 +1913,7 @@ static int method_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_e
698723
                         "org.freedesktop.login1.hibernate-multiple-sessions",
698723
                         "org.freedesktop.login1.hibernate-ignore-inhibit",
698723
                         "hybrid-sleep",
698723
+                        sd_bus_message_is_method_call(message, NULL, "HybridSleepWithFlags"),
698723
                         error);
698723
 }
698723
 
698723
@@ -1902,6 +1928,7 @@ static int method_suspend_then_hibernate(sd_bus_message *message, void *userdata
698723
                         "org.freedesktop.login1.hibernate-multiple-sessions",
698723
                         "org.freedesktop.login1.hibernate-ignore-inhibit",
698723
                         "hybrid-sleep",
698723
+                        sd_bus_message_is_method_call(message, NULL, "SuspendThenHibernateWithFlags"),
698723
                         error);
698723
 }
698723
 
698723
@@ -2089,8 +2116,8 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_
698723
         } else
698723
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unsupported shutdown type");
698723
 
698723
-        r = verify_shutdown_creds(m, message, INHIBIT_SHUTDOWN, false,
698723
-                                  action, action_multiple_sessions, action_ignore_inhibit, error);
698723
+        r = verify_shutdown_creds(m, message, INHIBIT_SHUTDOWN, action, action_multiple_sessions,
698723
+                                  action_ignore_inhibit, 0, error);
698723
         if (r != 0)
698723
                 return r;
698723
 
698723
@@ -2683,60 +2710,395 @@ const sd_bus_vtable manager_vtable[] = {
698723
         SD_BUS_PROPERTY("NCurrentSessions", "t", property_get_hashmap_size, offsetof(Manager, sessions), 0),
698723
         SD_BUS_PROPERTY("UserTasksMax", "t", property_get_compat_user_tasks_max, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
698723
 
698723
-        SD_BUS_METHOD("GetSession", "s", "o", method_get_session, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("GetSessionByPID", "u", "o", method_get_session_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("GetUser", "u", "o", method_get_user, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("GetUserByPID", "u", "o", method_get_user_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("GetSeat", "s", "o", method_get_seat, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("ListSessions", NULL, "a(susso)", method_list_sessions, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("ListUsers", NULL, "a(uso)", method_list_users, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("ListSeats", NULL, "a(so)", method_list_seats, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("ListInhibitors", NULL, "a(ssssuu)", method_list_inhibitors, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CreateSession", "uusssssussbssa(sv)", "soshusub", method_create_session, 0),
698723
-        SD_BUS_METHOD("ReleaseSession", "s", NULL, method_release_session, 0),
698723
-        SD_BUS_METHOD("ActivateSession", "s", NULL, method_activate_session, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("ActivateSessionOnSeat", "ss", NULL, method_activate_session_on_seat, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("LockSession", "s", NULL, method_lock_session, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("UnlockSession", "s", NULL, method_lock_session, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("LockSessions", NULL, NULL, method_lock_sessions, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("UnlockSessions", NULL, NULL, method_lock_sessions, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("KillSession", "ssi", NULL, method_kill_session, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("KillUser", "ui", NULL, method_kill_user, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("TerminateSession", "s", NULL, method_terminate_session, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("TerminateUser", "u", NULL, method_terminate_user, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("TerminateSeat", "s", NULL, method_terminate_seat, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("SetUserLinger", "ubb", NULL, method_set_user_linger, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("AttachDevice", "ssb", NULL, method_attach_device, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("FlushDevices", "b", NULL, method_flush_devices, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("PowerOff", "b", NULL, method_poweroff, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("Reboot", "b", NULL, method_reboot, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("Halt", "b", NULL, method_halt, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("Suspend", "b", NULL, method_suspend, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("Hibernate", "b", NULL, method_hibernate, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("HybridSleep", "b", NULL, method_hybrid_sleep, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("SuspendThenHibernate", "b", NULL, method_suspend_then_hibernate, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanPowerOff", NULL, "s", method_can_poweroff, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanReboot", NULL, "s", method_can_reboot, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanHalt", NULL, "s", method_can_halt, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanSuspend", NULL, "s", method_can_suspend, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanHibernate", NULL, "s", method_can_hibernate, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanHybridSleep", NULL, "s", method_can_hybrid_sleep, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanSuspendThenHibernate", NULL, "s", method_can_suspend_then_hibernate, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("ScheduleShutdown", "st", NULL, method_schedule_shutdown, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CancelScheduledShutdown", NULL, "b", method_cancel_scheduled_shutdown, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("Inhibit", "ssss", "h", method_inhibit, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("CanRebootToFirmwareSetup", NULL, "s", method_can_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("SetRebootToFirmwareSetup", "b", NULL, method_set_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-        SD_BUS_METHOD("SetWallMessage", "sb", NULL, method_set_wall_message, SD_BUS_VTABLE_UNPRIVILEGED),
698723
-
698723
-        SD_BUS_SIGNAL("SessionNew", "so", 0),
698723
-        SD_BUS_SIGNAL("SessionRemoved", "so", 0),
698723
-        SD_BUS_SIGNAL("UserNew", "uo", 0),
698723
-        SD_BUS_SIGNAL("UserRemoved", "uo", 0),
698723
-        SD_BUS_SIGNAL("SeatNew", "so", 0),
698723
-        SD_BUS_SIGNAL("SeatRemoved", "so", 0),
698723
-        SD_BUS_SIGNAL("PrepareForShutdown", "b", 0),
698723
-        SD_BUS_SIGNAL("PrepareForSleep", "b", 0),
698723
+        SD_BUS_METHOD_WITH_NAMES("GetSession",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(session_id),
698723
+                                 "o",
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 method_get_session,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("GetSessionByPID",
698723
+                                 "u",
698723
+                                 SD_BUS_PARAM(pid),
698723
+                                 "o",
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 method_get_session_by_pid,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("GetUser",
698723
+                                 "u",
698723
+                                 SD_BUS_PARAM(uid),
698723
+                                 "o",
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 method_get_user,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("GetUserByPID",
698723
+                                 "u",
698723
+                                 SD_BUS_PARAM(pid),
698723
+                                 "o",
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 method_get_user_by_pid,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("GetSeat",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(seat_id),
698723
+                                 "o",
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 method_get_seat,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("ListSessions",
698723
+                                 NULL,,
698723
+                                 "a(susso)",
698723
+                                 SD_BUS_PARAM(sessions),
698723
+                                 method_list_sessions,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("ListUsers",
698723
+                                 NULL,,
698723
+                                 "a(uso)",
698723
+                                 SD_BUS_PARAM(users),
698723
+                                 method_list_users,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("ListSeats",
698723
+                                 NULL,,
698723
+                                 "a(so)",
698723
+                                 SD_BUS_PARAM(seats),
698723
+                                 method_list_seats,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("ListInhibitors",
698723
+                                 NULL,,
698723
+                                 "a(ssssuu)",
698723
+                                 SD_BUS_PARAM(inhibitors),
698723
+                                 method_list_inhibitors,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CreateSession",
698723
+                                 "uusssssussbssa(sv)",
698723
+                                 SD_BUS_PARAM(uid)
698723
+                                 SD_BUS_PARAM(pid)
698723
+                                 SD_BUS_PARAM(service)
698723
+                                 SD_BUS_PARAM(type)
698723
+                                 SD_BUS_PARAM(class)
698723
+                                 SD_BUS_PARAM(desktop)
698723
+                                 SD_BUS_PARAM(seat_id)
698723
+                                 SD_BUS_PARAM(vtnr)
698723
+                                 SD_BUS_PARAM(tty)
698723
+                                 SD_BUS_PARAM(display)
698723
+                                 SD_BUS_PARAM(remote)
698723
+                                 SD_BUS_PARAM(remote_user)
698723
+                                 SD_BUS_PARAM(remote_host)
698723
+                                 SD_BUS_PARAM(properties),
698723
+                                 "soshusub",
698723
+                                 SD_BUS_PARAM(session_id)
698723
+                                 SD_BUS_PARAM(object_path)
698723
+                                 SD_BUS_PARAM(runtime_path)
698723
+                                 SD_BUS_PARAM(fifo_fd)
698723
+                                 SD_BUS_PARAM(uid)
698723
+                                 SD_BUS_PARAM(seat_id)
698723
+                                 SD_BUS_PARAM(vtnr)
698723
+                                 SD_BUS_PARAM(existing),
698723
+                                 method_create_session,
698723
+                                 0),
698723
+        SD_BUS_METHOD_WITH_NAMES("ReleaseSession",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(session_id),
698723
+                                 NULL,,
698723
+                                 method_release_session,
698723
+                                 0),
698723
+        SD_BUS_METHOD_WITH_NAMES("ActivateSession",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(session_id),
698723
+                                 NULL,,
698723
+                                 method_activate_session,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("ActivateSessionOnSeat",
698723
+                                 "ss",
698723
+                                 SD_BUS_PARAM(session_id)
698723
+                                 SD_BUS_PARAM(seat_id),
698723
+                                 NULL,,
698723
+                                 method_activate_session_on_seat,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("LockSession",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(session_id),
698723
+                                 NULL,,
698723
+                                 method_lock_session,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("UnlockSession",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(session_id),
698723
+                                 NULL,,
698723
+                                 method_lock_session,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD("LockSessions",
698723
+                      NULL,
698723
+                      NULL,
698723
+                      method_lock_sessions,
698723
+                      SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD("UnlockSessions",
698723
+                      NULL,
698723
+                      NULL,
698723
+                      method_lock_sessions,
698723
+                      SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("KillSession",
698723
+                                 "ssi",
698723
+                                 SD_BUS_PARAM(session_id)
698723
+                                 SD_BUS_PARAM(who)
698723
+                                 SD_BUS_PARAM(signal_number),
698723
+                                 NULL,,
698723
+                                 method_kill_session,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("KillUser",
698723
+                                 "ui",
698723
+                                 SD_BUS_PARAM(uid)
698723
+                                 SD_BUS_PARAM(signal_number),
698723
+                                 NULL,,
698723
+                                 method_kill_user,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("TerminateSession",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(session_id),
698723
+                                 NULL,,
698723
+                                 method_terminate_session,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("TerminateUser",
698723
+                                 "u",
698723
+                                 SD_BUS_PARAM(uid),
698723
+                                 NULL,,
698723
+                                 method_terminate_user,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("TerminateSeat",
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(seat_id),
698723
+                                 NULL,,
698723
+                                 method_terminate_seat,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("SetUserLinger",
698723
+                                 "ubb",
698723
+                                 SD_BUS_PARAM(uid)
698723
+                                 SD_BUS_PARAM(enable)
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_set_user_linger,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("AttachDevice",
698723
+                                 "ssb",
698723
+                                 SD_BUS_PARAM(seat_id)
698723
+                                 SD_BUS_PARAM(sysfs_path)
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_attach_device,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("FlushDevices",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_flush_devices,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("PowerOff",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_poweroff,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("PowerOffWithFlags",
698723
+                                 "t",
698723
+                                 SD_BUS_PARAM(flags),
698723
+                                 NULL,,
698723
+                                 method_poweroff,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("Reboot",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_reboot,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("RebootWithFlags",
698723
+                                 "t",
698723
+                                 SD_BUS_PARAM(flags),
698723
+                                 NULL,,
698723
+                                 method_reboot,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("Halt",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_halt,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("HaltWithFlags",
698723
+                                 "t",
698723
+                                 SD_BUS_PARAM(flags),
698723
+                                 NULL,,
698723
+                                 method_halt,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("Suspend",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_suspend,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("SuspendWithFlags",
698723
+                                 "t",
698723
+                                 SD_BUS_PARAM(flags),
698723
+                                 NULL,,
698723
+                                 method_suspend,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("Hibernate",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_hibernate,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("HibernateWithFlags",
698723
+                                 "t",
698723
+                                 SD_BUS_PARAM(flags),
698723
+                                 NULL,,
698723
+                                 method_hibernate,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("HybridSleep",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_hybrid_sleep,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("HybridSleepWithFlags",
698723
+                                 "t",
698723
+                                 SD_BUS_PARAM(flags),
698723
+                                 NULL,,
698723
+                                 method_hybrid_sleep,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("SuspendThenHibernate",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(interactive),
698723
+                                 NULL,,
698723
+                                 method_suspend_then_hibernate,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("SuspendThenHibernateWithFlags",
698723
+                                 "t",
698723
+                                 SD_BUS_PARAM(flags),
698723
+                                 NULL,,
698723
+                                 method_suspend_then_hibernate,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanPowerOff",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_poweroff,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanReboot",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_reboot,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanHalt",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_halt,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanSuspend",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_suspend,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanHibernate",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_hibernate,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanHybridSleep",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_hybrid_sleep,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanSuspendThenHibernate",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_suspend_then_hibernate,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("ScheduleShutdown",
698723
+                                 "st",
698723
+                                 SD_BUS_PARAM(type)
698723
+                                 SD_BUS_PARAM(usec),
698723
+                                 NULL,,
698723
+                                 method_schedule_shutdown,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CancelScheduledShutdown",
698723
+                                 NULL,,
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(cancelled),
698723
+                                 method_cancel_scheduled_shutdown,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("Inhibit",
698723
+                                 "ssss",
698723
+                                 SD_BUS_PARAM(what)
698723
+                                 SD_BUS_PARAM(who)
698723
+                                 SD_BUS_PARAM(why)
698723
+                                 SD_BUS_PARAM(mode),
698723
+                                 "h",
698723
+                                 SD_BUS_PARAM(pipe_fd),
698723
+                                 method_inhibit,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("CanRebootToFirmwareSetup",
698723
+                                 NULL,,
698723
+                                 "s",
698723
+                                 SD_BUS_PARAM(result),
698723
+                                 method_can_reboot_to_firmware_setup,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("SetRebootToFirmwareSetup",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(enable),
698723
+                                 NULL,,
698723
+                                 method_set_reboot_to_firmware_setup,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+        SD_BUS_METHOD_WITH_NAMES("SetWallMessage",
698723
+                                 "sb",
698723
+                                 SD_BUS_PARAM(wall_message)
698723
+                                 SD_BUS_PARAM(enable),
698723
+                                 NULL,,
698723
+                                 method_set_wall_message,
698723
+                                 SD_BUS_VTABLE_UNPRIVILEGED),
698723
+
698723
+        SD_BUS_SIGNAL_WITH_NAMES("SessionNew",
698723
+                                 "so",
698723
+                                 SD_BUS_PARAM(session_id)
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 0),
698723
+        SD_BUS_SIGNAL_WITH_NAMES("SessionRemoved",
698723
+                                 "so",
698723
+                                 SD_BUS_PARAM(session_id)
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 0),
698723
+        SD_BUS_SIGNAL_WITH_NAMES("UserNew",
698723
+                                 "uo",
698723
+                                 SD_BUS_PARAM(uid)
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 0),
698723
+        SD_BUS_SIGNAL_WITH_NAMES("UserRemoved",
698723
+                                 "uo",
698723
+                                 SD_BUS_PARAM(uid)
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 0),
698723
+        SD_BUS_SIGNAL_WITH_NAMES("SeatNew",
698723
+                                 "so",
698723
+                                 SD_BUS_PARAM(seat_id)
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 0),
698723
+        SD_BUS_SIGNAL_WITH_NAMES("SeatRemoved",
698723
+                                 "so",
698723
+                                 SD_BUS_PARAM(seat_id)
698723
+                                 SD_BUS_PARAM(object_path),
698723
+                                 0),
698723
+        SD_BUS_SIGNAL_WITH_NAMES("PrepareForShutdown",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(start),
698723
+                                 0),
698723
+        SD_BUS_SIGNAL_WITH_NAMES("PrepareForSleep",
698723
+                                 "b",
698723
+                                 SD_BUS_PARAM(start),
698723
+                                 0),
698723
 
698723
         SD_BUS_VTABLE_END
698723
 };
698723
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
698723
index 8bcbf6bf4b..3dd7c1522f 100644
698723
--- a/src/systemctl/systemctl.c
698723
+++ b/src/systemctl/systemctl.c
698723
@@ -50,6 +50,7 @@
698723
 #include "list.h"
698723
 #include "locale-util.h"
698723
 #include "log.h"
698723
+#include "login-util.h"
698723
 #include "logs-show.h"
698723
 #include "macro.h"
698723
 #include "mkdir.h"
698723
@@ -3266,6 +3267,8 @@ static int logind_reboot(enum action a) {
698723
         };
698723
 
698723
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
698723
+        const char *method_with_flags;
698723
+        uint64_t flags = 0;
698723
         sd_bus *bus;
698723
         int r;
698723
 
698723
@@ -3284,6 +3287,29 @@ static int logind_reboot(enum action a) {
698723
         if (arg_dry_run)
698723
                 return 0;
698723
 
698723
+        SET_FLAG(flags, SD_LOGIND_ROOT_CHECK_INHIBITORS, arg_check_inhibitors > 0);
698723
+
698723
+        method_with_flags = strjoina(actions[a].method, "WithFlags");
698723
+
698723
+        r = sd_bus_call_method(
698723
+                        bus,
698723
+                        "org.freedesktop.login1",
698723
+                        "/org/freedesktop/login1",
698723
+                        "org.freedesktop.login1.Manager",
698723
+                        method_with_flags,
698723
+                        &error,
698723
+                        NULL,
698723
+                        "t", flags);
698723
+        if (r >= 0)
698723
+                return 0;
698723
+
698723
+        if (!sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_METHOD))
698723
+                return log_error_errno(r, "Failed to %s via logind: %s", actions[a].description, bus_error_message(&error, r));
698723
+
698723
+        /* Fallback to original methods in case there is older version of systemd-logind */
698723
+        log_debug("Method %s not available: %s. Falling back to %s", method_with_flags, bus_error_message(&error, r), actions[a].method);
698723
+        sd_bus_error_free(&error);
698723
+
698723
         r = sd_bus_call_method(
698723
                         bus,
698723
                         "org.freedesktop.login1",
698723
diff --git a/src/systemd/sd-bus-vtable.h b/src/systemd/sd-bus-vtable.h
698723
index 1268085498..8805e19477 100644
698723
--- a/src/systemd/sd-bus-vtable.h
698723
+++ b/src/systemd/sd-bus-vtable.h
698723
@@ -65,10 +65,12 @@ struct sd_bus_vtable {
698723
                         const char *result;
698723
                         sd_bus_message_handler_t handler;
698723
                         size_t offset;
698723
+                        const char *names;
698723
                 } method;
698723
                 struct {
698723
                         const char *member;
698723
                         const char *signature;
698723
+                        const char *names;
698723
                 } signal;
698723
                 struct {
698723
                         const char *member;
698723
@@ -91,7 +93,10 @@ struct sd_bus_vtable {
698723
                 },                                                      \
698723
         }
698723
 
698723
-#define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags)   \
698723
+/* helper macro to format method and signal parameters, one at a time */
698723
+#define SD_BUS_PARAM(x) #x "\0"
698723
+
698723
+#define SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, _in_names, _result, _out_names, _handler, _offset, _flags) \
698723
         {                                                               \
698723
                 .type = _SD_BUS_VTABLE_METHOD,                          \
698723
                 .flags = _flags,                                        \
698723
@@ -102,13 +107,18 @@ struct sd_bus_vtable {
698723
                         .result = _result,                              \
698723
                         .handler = _handler,                            \
698723
                         .offset = _offset,                              \
698723
+                        .names = _in_names _out_names,                  \
698723
                     },                                                  \
698723
                 },                                                      \
698723
         }
698723
+#define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags)   \
698723
+        SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, "", _result, "", _handler, _offset, _flags)
698723
+#define SD_BUS_METHOD_WITH_NAMES(_member, _signature, _in_names, _result, _out_names, _handler, _flags)   \
698723
+        SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, _in_names, _result, _out_names, _handler, 0, _flags)
698723
 #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags)   \
698723
-        SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, 0, _flags)
698723
+        SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, "", _result, "", _handler, 0, _flags)
698723
 
698723
-#define SD_BUS_SIGNAL(_member, _signature, _flags)                      \
698723
+#define SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, _out_names, _flags)                      \
698723
         {                                                               \
698723
                 .type = _SD_BUS_VTABLE_SIGNAL,                          \
698723
                 .flags = _flags,                                        \
698723
@@ -116,9 +126,12 @@ struct sd_bus_vtable {
698723
                     .signal = {                                         \
698723
                         .member = _member,                              \
698723
                         .signature = _signature,                        \
698723
+                        .names = _out_names,                            \
698723
                     },                                                  \
698723
                 },                                                      \
698723
         }
698723
+#define SD_BUS_SIGNAL(_member, _signature, _flags)   \
698723
+        SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, "", _flags)
698723
 
698723
 #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags)     \
698723
         {                                                               \