chiark / gitweb /
Prep v233.3: Moved four functions, that did not need adaptation in elogind-dbus.c...
authorSven Eden <yamakuzure@gmx.net>
Thu, 20 Jul 2017 16:16:13 +0000 (18:16 +0200)
committerSven Eden <yamakuzure@gmx.net>
Thu, 20 Jul 2017 16:16:13 +0000 (18:16 +0200)
src/login/elogind-dbus.c
src/login/elogind-dbus.h
src/login/logind-dbus.c

index 7f0f706763d6be240396b9a67d9b4a2b63e05d4f..a9b39c238835162535daefbf20e83c81ecd01154 100644 (file)
 #include "user-util.h"
 
 
-int have_multiple_sessions(
-                Manager *m,
-                uid_t uid) {
-
-        Session *session;
-        Iterator i;
-
-        assert(m);
-
-        /* Check for other users' sessions. Greeter sessions do not
-         * count, and non-login sessions do not count either. */
-        HASHMAP_FOREACH(session, m->sessions, i)
-                if (session->class == SESSION_USER &&
-                    session->user->uid != uid)
-                        return true;
-
-        return false;
-}
-
 static int bus_manager_log_shutdown(
                 Manager *m,
                 InhibitWhat w,
@@ -98,28 +79,6 @@ static int bus_manager_log_shutdown(
                           NULL);
 }
 
-static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
-
-        static const char * const signal_name[_INHIBIT_WHAT_MAX] = {
-                [INHIBIT_SHUTDOWN] = "PrepareForShutdown",
-                [INHIBIT_SLEEP] = "PrepareForSleep"
-        };
-
-        int active = _active;
-
-        assert(m);
-        assert(w >= 0);
-        assert(w < _INHIBIT_WHAT_MAX);
-        assert(signal_name[w]);
-
-        return sd_bus_emit_signal(m->bus,
-                                  "/org/freedesktop/login1",
-                                  "org.freedesktop.login1.Manager",
-                                  signal_name[w],
-                                  "b",
-                                  active);
-}
-
 /* elogind specific helper to make HALT and REBOOT possible. */
 static int run_helper(const char *helper) {
         int pid = fork();
@@ -264,21 +223,6 @@ int manager_dispatch_delayed(Manager *manager, bool timeout) {
         return 1;
 }
 
-static int manager_inhibit_timeout_handler(
-                        sd_event_source *s,
-                        uint64_t usec,
-                        void *userdata) {
-
-        Manager *manager = userdata;
-        int r;
-
-        assert(manager);
-        assert(manager->inhibit_timeout_source == s);
-
-        r = manager_dispatch_delayed(manager, true);
-        return (r < 0) ? r : 0;
-}
-
 static int delay_shutdown_or_sleep(
                 Manager *m,
                 InhibitWhat w,
@@ -350,68 +294,6 @@ int bus_manager_shutdown_or_sleep_now_or_later(
         return r;
 }
 
-int verify_shutdown_creds(
-                Manager *m,
-                sd_bus_message *message,
-                InhibitWhat w,
-                bool interactive,
-                const char *action,
-                const char *action_multiple_sessions,
-                const char *action_ignore_inhibit,
-                sd_bus_error *error) {
-
-        _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
-        bool multiple_sessions, blocked;
-        uid_t uid;
-        int r;
-
-        assert(m);
-        assert(message);
-        assert(w >= 0);
-        assert(w <= _INHIBIT_WHAT_MAX);
-
-        r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);
-        if (r < 0)
-                return r;
-
-        r = sd_bus_creds_get_euid(creds, &uid);
-        if (r < 0)
-                return r;
-
-        r = have_multiple_sessions(m, uid);
-        if (r < 0)
-                return r;
-
-        multiple_sessions = r > 0;
-        blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid, NULL);
-
-        if (multiple_sessions && action_multiple_sessions) {
-                r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_multiple_sessions, NULL, interactive, UID_INVALID, &m->polkit_registry, error);
-                if (r < 0)
-                        return r;
-                if (r == 0)
-                        return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
-        }
-
-        if (blocked && action_ignore_inhibit) {
-                r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_ignore_inhibit, NULL, interactive, UID_INVALID, &m->polkit_registry, error);
-                if (r < 0)
-                        return r;
-                if (r == 0)
-                        return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
-        }
-
-        if (!multiple_sessions && !blocked && action) {
-                r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action, NULL, interactive, UID_INVALID, &m->polkit_registry, error);
-                if (r < 0)
-                        return r;
-                if (r == 0)
-                        return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
-        }
-
-        return 0;
-}
-
 static int method_do_shutdown_or_sleep(
                 Manager *m,
                 sd_bus_message *message,
index 4b7640d7ddae03071044cbd88961ca6aea36494d..87ab2b8691766860a08fb4a29f63ec606f787d97 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "logind.h"
 
-int have_multiple_sessions(Manager *m, uid_t uid);
 int manager_scheduled_shutdown_handler(sd_event_source *s, uint64_t usec,
                                        void *userdata);
 int method_hibernate   (sd_bus_message *message, void *userdata, sd_bus_error *error);
@@ -31,6 +30,11 @@ int method_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_error *e
 int method_poweroff    (sd_bus_message *message, void *userdata, sd_bus_error *error);
 int method_reboot      (sd_bus_message *message, void *userdata, sd_bus_error *error);
 int method_suspend     (sd_bus_message *message, void *userdata, sd_bus_error *error);
+
+
+/* prototypes for former static functions in logind-dbus.c */
+int manager_inhibit_timeout_handler(sd_event_source *s, uint64_t usec, void *userdata);
+int send_prepare_for(Manager *m, InhibitWhat w, bool _active);
 int verify_shutdown_creds(Manager *m, sd_bus_message *message, InhibitWhat w,
                           bool interactive, const char *action,
                           const char *action_multiple_sessions,
index 971b447a7cacef640fdac75a0eb4f59f59b4218c..f22859c7472a7234b0bed507f6822583d3ab7b7c 100644 (file)
@@ -1390,7 +1390,6 @@ static int method_flush_devices(sd_bus_message *message, void *userdata, sd_bus_
         return sd_bus_reply_method_return(message, NULL);
 }
 
-#if 0 /// elogind has its own variant in elogind-dbus.c
 static int have_multiple_sessions(
                 Manager *m,
                 uid_t uid) {
@@ -1410,6 +1409,7 @@ static int have_multiple_sessions(
         return false;
 }
 
+#if 0 /// elogind has its own variant in elogind-dbus.c
 static int bus_manager_log_shutdown(
                 Manager *m,
                 InhibitWhat w,
@@ -1604,8 +1604,13 @@ int manager_dispatch_delayed(Manager *manager, bool timeout) {
 
         return 1;
 }
+#endif // 0
 
+#if 0 /// elogind-dbus.c needs to access this
 static int manager_inhibit_timeout_handler(
+#else
+int manager_inhibit_timeout_handler(
+#endif // 0
                         sd_event_source *s,
                         uint64_t usec,
                         void *userdata) {
@@ -1620,6 +1625,7 @@ static int manager_inhibit_timeout_handler(
         return (r < 0) ? r : 0;
 }
 
+#if 0 /// elogind has its own variant in elogind-dbus.c
 static int delay_shutdown_or_sleep(
                 Manager *m,
                 InhibitWhat w,
@@ -1655,8 +1661,13 @@ static int delay_shutdown_or_sleep(
 
         return 0;
 }
+#endif // 0
 
+#if 0 /// elogind-dbus.c needs to access this
 static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
+#else
+int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
+#endif // 0
 
         static const char * const signal_name[_INHIBIT_WHAT_MAX] = {
                 [INHIBIT_SHUTDOWN] = "PrepareForShutdown",
@@ -1678,6 +1689,7 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
                                   active);
 }
 
+#if 0 /// elogind has its own variant in elogind-dbus.c
 int bus_manager_shutdown_or_sleep_now_or_later(
                 Manager *m,
                 const char *unit_name,
@@ -1714,8 +1726,13 @@ int bus_manager_shutdown_or_sleep_now_or_later(
 
         return r;
 }
+#endif // 0
 
+#if 0 /// elogind-dbus.c needs to access this
 static int verify_shutdown_creds(
+#else
+int verify_shutdown_creds(
+#endif // 0
                 Manager *m,
                 sd_bus_message *message,
                 InhibitWhat w,
@@ -1777,6 +1794,7 @@ static int verify_shutdown_creds(
         return 0;
 }
 
+#if 0 /// elogind has its own variant in elogind-dbus.c
 static int method_do_shutdown_or_sleep(
                 Manager *m,
                 sd_bus_message *message,