mirror of
https://github.com/systemd/systemd.git
synced 2025-01-18 10:04:04 +03:00
logind: introduce LockedHint and SetLockedHint (#3238)
Desktop environments can keep this property up to date to allow applications to easily track session's Lock status.
This commit is contained in:
parent
fe1ef0f86e
commit
42d35e1301
@ -180,6 +180,24 @@ static int property_get_idle_since_hint(
|
||||
return sd_bus_message_append(reply, "t", u);
|
||||
}
|
||||
|
||||
static int property_get_locked_hint(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Session *s = userdata;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(s);
|
||||
|
||||
return sd_bus_message_append(reply, "b", session_get_locked_hint(s) > 0);
|
||||
}
|
||||
|
||||
int bus_session_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
Session *s = userdata;
|
||||
int r;
|
||||
@ -279,6 +297,35 @@ static int method_set_idle_hint(sd_bus_message *message, void *userdata, sd_bus_
|
||||
return sd_bus_reply_method_return(message, NULL);
|
||||
}
|
||||
|
||||
static int method_set_locked_hint(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
|
||||
Session *s = userdata;
|
||||
uid_t uid;
|
||||
int r, b;
|
||||
|
||||
assert(message);
|
||||
assert(s);
|
||||
|
||||
r = sd_bus_message_read(message, "b", &b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
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;
|
||||
|
||||
if (uid != 0 && uid != s->user->uid)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session may set locked hint");
|
||||
|
||||
session_set_locked_hint(s, b);
|
||||
|
||||
return sd_bus_reply_method_return(message, NULL);
|
||||
}
|
||||
|
||||
int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error) {
|
||||
Session *s = userdata;
|
||||
const char *swho;
|
||||
@ -487,12 +534,14 @@ const sd_bus_vtable session_vtable[] = {
|
||||
SD_BUS_PROPERTY("IdleHint", "b", property_get_idle_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("IdleSinceHint", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("IdleSinceHintMonotonic", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("LockedHint", "b", property_get_locked_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
|
||||
SD_BUS_METHOD("Terminate", NULL, NULL, bus_session_method_terminate, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Activate", NULL, NULL, bus_session_method_activate, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Lock", NULL, NULL, bus_session_method_lock, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Unlock", NULL, NULL, bus_session_method_lock, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetIdleHint", "b", NULL, method_set_idle_hint, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetLockedHint", "b", NULL, method_set_locked_hint, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Kill", "si", NULL, bus_session_method_kill, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("TakeControl", "b", NULL, method_take_control, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("ReleaseControl", NULL, NULL, method_release_control, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
|
@ -852,6 +852,23 @@ void session_set_idle_hint(Session *s, bool b) {
|
||||
manager_send_changed(s->manager, "IdleHint", "IdleSinceHint", "IdleSinceHintMonotonic", NULL);
|
||||
}
|
||||
|
||||
int session_get_locked_hint(Session *s) {
|
||||
assert(s);
|
||||
|
||||
return s->locked_hint;
|
||||
}
|
||||
|
||||
void session_set_locked_hint(Session *s, bool b) {
|
||||
assert(s);
|
||||
|
||||
if (s->locked_hint == b)
|
||||
return;
|
||||
|
||||
s->locked_hint = b;
|
||||
|
||||
session_send_changed(s, "LockedHint", NULL);
|
||||
}
|
||||
|
||||
static int session_dispatch_fifo(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
|
||||
Session *s = userdata;
|
||||
|
||||
|
@ -105,6 +105,8 @@ struct Session {
|
||||
bool idle_hint;
|
||||
dual_timestamp idle_hint_timestamp;
|
||||
|
||||
bool locked_hint;
|
||||
|
||||
bool in_gc_queue:1;
|
||||
bool started:1;
|
||||
bool stopping:1;
|
||||
@ -132,6 +134,8 @@ int session_activate(Session *s);
|
||||
bool session_is_active(Session *s);
|
||||
int session_get_idle_hint(Session *s, dual_timestamp *t);
|
||||
void session_set_idle_hint(Session *s, bool b);
|
||||
int session_get_locked_hint(Session *s);
|
||||
void session_set_locked_hint(Session *s, bool b);
|
||||
int session_create_fifo(Session *s);
|
||||
int session_start(Session *s);
|
||||
int session_stop(Session *s, bool force);
|
||||
|
@ -232,6 +232,10 @@
|
||||
send_interface="org.freedesktop.login1.Session"
|
||||
send_member="SetIdleHint"/>
|
||||
|
||||
<allow send_destination="org.freedesktop.login1"
|
||||
send_interface="org.freedesktop.login1.Session"
|
||||
send_member="SetLockedHint"/>
|
||||
|
||||
<allow send_destination="org.freedesktop.login1"
|
||||
send_interface="org.freedesktop.login1.Session"
|
||||
send_member="Kill"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user