anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0322-logind-introduce-LockedHint-and-SetLockedHint-3238.patch

1abbee
From 75131b469fa9e1e2e3cb623fa1f3d36cba36af78 Mon Sep 17 00:00:00 2001
1abbee
From: Victor Toso <me@victortoso.com>
1abbee
Date: Wed, 11 May 2016 19:34:13 +0200
1abbee
Subject: [PATCH] logind: introduce LockedHint and SetLockedHint (#3238)
1abbee
1abbee
Desktop environments can keep this property up to date to allow
1abbee
applications to easily track session's Lock status.
1abbee
1abbee
Cherry-picked from: 42d35e1301928d08dd32ec51f0205252ae658ba5
1abbee
Resolves: #1335499
1abbee
---
23b3cf
 src/login/logind-session-dbus.c       | 50 +++++++++++++++++++++++++++
23b3cf
 src/login/logind-session.c            | 17 +++++++++
1abbee
 src/login/logind-session.h            |  4 +++
1abbee
 src/login/org.freedesktop.login1.conf |  4 +++
1abbee
 4 files changed, 75 insertions(+)
1abbee
1abbee
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
c62b8e
index 4e7edef52d..75b7186e8f 100644
1abbee
--- a/src/login/logind-session-dbus.c
1abbee
+++ b/src/login/logind-session-dbus.c
1abbee
@@ -180,6 +180,24 @@ static int property_get_idle_since_hint(
1abbee
         return sd_bus_message_append(reply, "t", u);
1abbee
 }
1abbee
 
1abbee
+static int property_get_locked_hint(
1abbee
+                sd_bus *bus,
1abbee
+                const char *path,
1abbee
+                const char *interface,
1abbee
+                const char *property,
1abbee
+                sd_bus_message *reply,
1abbee
+                void *userdata,
1abbee
+                sd_bus_error *error) {
1abbee
+
1abbee
+        Session *s = userdata;
1abbee
+
1abbee
+        assert(bus);
1abbee
+        assert(reply);
1abbee
+        assert(s);
1abbee
+
1abbee
+        return sd_bus_message_append(reply, "b", session_get_locked_hint(s) > 0);
1abbee
+}
1abbee
+
1abbee
 static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1abbee
         Session *s = userdata;
1abbee
         int r;
1abbee
@@ -255,6 +273,36 @@ static int method_set_idle_hint(sd_bus *bus, sd_bus_message *message, void *user
1abbee
         return sd_bus_reply_method_return(message, NULL);
1abbee
 }
1abbee
 
1abbee
+static int method_set_locked_hint(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1abbee
+        _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
1abbee
+        Session *s = userdata;
1abbee
+        uid_t uid;
1abbee
+        int r, b;
1abbee
+
1abbee
+        assert(bus);
1abbee
+        assert(message);
1abbee
+        assert(s);
1abbee
+
1abbee
+        r = sd_bus_message_read(message, "b", &b);
1abbee
+        if (r < 0)
1abbee
+                return r;
1abbee
+
1abbee
+        r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);
1abbee
+        if (r < 0)
1abbee
+                return r;
1abbee
+
1abbee
+        r = sd_bus_creds_get_euid(creds, &uid);
1abbee
+        if (r < 0)
1abbee
+                return r;
1abbee
+
1abbee
+        if (uid != 0 && uid != s->user->uid)
1abbee
+                return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session may set locked hint");
1abbee
+
1abbee
+        session_set_locked_hint(s, b);
1abbee
+
1abbee
+        return sd_bus_reply_method_return(message, NULL);
1abbee
+}
1abbee
+
1abbee
 static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
1abbee
         Session *s = userdata;
1abbee
         const char *swho;
1abbee
@@ -455,6 +503,7 @@ const sd_bus_vtable session_vtable[] = {
1abbee
         SD_BUS_PROPERTY("IdleHint", "b", property_get_idle_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1abbee
         SD_BUS_PROPERTY("IdleSinceHint", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1abbee
         SD_BUS_PROPERTY("IdleSinceHintMonotonic", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1abbee
+        SD_BUS_PROPERTY("LockedHint", "b", property_get_locked_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
1abbee
 
1abbee
         SD_BUS_METHOD("Terminate", NULL, NULL, method_terminate, SD_BUS_VTABLE_CAPABILITY(CAP_KILL)),
1abbee
         SD_BUS_METHOD("Activate", NULL, NULL, method_activate, SD_BUS_VTABLE_UNPRIVILEGED),
1abbee
@@ -462,6 +511,7 @@ const sd_bus_vtable session_vtable[] = {
1abbee
         SD_BUS_METHOD("Unlock", NULL, NULL, method_lock, 0),
1abbee
         SD_BUS_METHOD("SetIdleHint", "b", NULL, method_set_idle_hint, SD_BUS_VTABLE_UNPRIVILEGED),
1abbee
         SD_BUS_METHOD("Kill", "si", NULL, method_kill, SD_BUS_VTABLE_CAPABILITY(CAP_KILL)),
1abbee
+        SD_BUS_METHOD("SetLockedHint", "b", NULL, method_set_locked_hint, SD_BUS_VTABLE_UNPRIVILEGED),
1abbee
         SD_BUS_METHOD("TakeControl", "b", NULL, method_take_control, SD_BUS_VTABLE_UNPRIVILEGED),
1abbee
         SD_BUS_METHOD("ReleaseControl", NULL, NULL, method_release_control, SD_BUS_VTABLE_UNPRIVILEGED),
1abbee
         SD_BUS_METHOD("TakeDevice", "uu", "hb", method_take_device, SD_BUS_VTABLE_UNPRIVILEGED),
1abbee
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
c62b8e
index d2e7b40124..dc24539f12 100644
1abbee
--- a/src/login/logind-session.c
1abbee
+++ b/src/login/logind-session.c
1abbee
@@ -843,6 +843,23 @@ void session_set_idle_hint(Session *s, bool b) {
1abbee
         manager_send_changed(s->manager, "IdleHint", "IdleSinceHint", "IdleSinceHintMonotonic", NULL);
1abbee
 }
1abbee
 
1abbee
+int session_get_locked_hint(Session *s) {
1abbee
+        assert(s);
1abbee
+
1abbee
+        return s->locked_hint;
1abbee
+}
1abbee
+
1abbee
+void session_set_locked_hint(Session *s, bool b) {
1abbee
+        assert(s);
1abbee
+
1abbee
+        if (s->locked_hint == b)
1abbee
+                return;
1abbee
+
1abbee
+        s->locked_hint = b;
1abbee
+
1abbee
+        session_send_changed(s, "LockedHint", NULL);
1abbee
+}
1abbee
+
1abbee
 static int session_dispatch_fifo(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
1abbee
         Session *s = userdata;
1abbee
 
1abbee
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
c62b8e
index a007fb5e84..5002b68689 100644
1abbee
--- a/src/login/logind-session.h
1abbee
+++ b/src/login/logind-session.h
1abbee
@@ -111,6 +111,8 @@ struct Session {
1abbee
         bool idle_hint;
1abbee
         dual_timestamp idle_hint_timestamp;
1abbee
 
1abbee
+        bool locked_hint;
1abbee
+
1abbee
         bool in_gc_queue:1;
1abbee
         bool started:1;
1abbee
         bool stopping:1;
1abbee
@@ -137,6 +139,8 @@ int session_activate(Session *s);
1abbee
 bool session_is_active(Session *s);
1abbee
 int session_get_idle_hint(Session *s, dual_timestamp *t);
1abbee
 void session_set_idle_hint(Session *s, bool b);
1abbee
+int session_get_locked_hint(Session *s);
1abbee
+void session_set_locked_hint(Session *s, bool b);
1abbee
 int session_create_fifo(Session *s);
1abbee
 int session_start(Session *s);
1abbee
 int session_stop(Session *s, bool force);
1abbee
diff --git a/src/login/org.freedesktop.login1.conf b/src/login/org.freedesktop.login1.conf
c62b8e
index 1318328aa0..dc7e0bec20 100644
1abbee
--- a/src/login/org.freedesktop.login1.conf
1abbee
+++ b/src/login/org.freedesktop.login1.conf
181b3f
@@ -160,6 +160,10 @@
1abbee
                        send_interface="org.freedesktop.login1.Session"
181b3f
                        send_member="SetIdleHint"/>
181b3f
 
1abbee
+                
1abbee
+                       send_interface="org.freedesktop.login1.Session"
181b3f
+                       send_member="SetLockedHint"/>
181b3f
+
1abbee
                 
181b3f
                        send_interface="org.freedesktop.login1.Session"
181b3f
                        send_member="TakeControl"/>