- Lock the session from the power button or `chandra-ctl lock` - Unlock with a face or the password; the password always works - Add compositor lock module with tests, and a polkit unlock policy (org.chandra.unlock) - Document the lock flow in docs/lock.md and link it from the README - Add generated interface bindings for the compositor and widget components
This commit is contained in:
1 parent
7501fc3ad9
commit
c790f96e58
131 files changed
+4693
-274
No files matched your search
@@ -29,7 +29,8 @@ fn auth_bus(tag : String) -> String? {
|
||||
}
|
||||
|
||||
///| The mock polkitd: owns org.freedesktop.PolicyKit1, records the agent that registers, and
|
||||
/// collects answers to the BeginAuthentication calls it makes.
|
||||
/// collects answers to the BeginAuthentication calls it makes. Also handles CheckAuthorization /
|
||||
/// CancelCheckAuthorization for org.chandra.unlock using `unix-process`.
|
||||
struct MockAuthority {
|
||||
bus : @network.DBus
|
||||
mut agent : String
|
||||
@@ -37,6 +38,14 @@ struct MockAuthority {
|
||||
mut refuse : String
|
||||
/// Answers to BeginAuthentication: "ok" or the error name.
|
||||
answers : Array[String]
|
||||
/// Subjects passed to CheckAuthorization.
|
||||
check_subjects : Array[@network.DValue]
|
||||
/// Cancel ids passed to CancelCheckAuthorization.
|
||||
cancelled_ids : Array[String]
|
||||
/// Monotonic cookie counter for CheckAuthorization -> BeginAuthentication.
|
||||
mut check_seq : Int
|
||||
/// In-flight CheckAuthorization calls: (cookie, cancel_id, call_msg).
|
||||
pending_checks : Array[(String, String, @network.DMessage)]
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -50,7 +59,16 @@ fn MockAuthority::new(path : String) -> MockAuthority {
|
||||
1000,
|
||||
)
|
||||
guard r is Some({ body: [U32(1U)], .. }) else { abort("could not own org.freedesktop.PolicyKit1") }
|
||||
let a = { bus, agent: "", refuse: "", answers: [] }
|
||||
let a = {
|
||||
bus,
|
||||
agent: "",
|
||||
refuse: "",
|
||||
answers: [],
|
||||
check_subjects: [],
|
||||
cancelled_ids: [],
|
||||
check_seq: 0,
|
||||
pending_checks: [],
|
||||
}
|
||||
bus.set_on_call(fn(m) {
|
||||
match m.meth {
|
||||
"RegisterAuthenticationAgent" =>
|
||||
@@ -66,6 +84,68 @@ fn MockAuthority::new(path : String) -> MockAuthority {
|
||||
}
|
||||
}
|
||||
"UnregisterAuthenticationAgent" => bus.reply(m, [])
|
||||
"CheckAuthorization" =>
|
||||
match m.body {
|
||||
[Struct([Str("unix-process"), Arr(_, _)]) as subj, Str(action_id), _, U32(_), Str(cancel_id)] => {
|
||||
a.check_subjects.push(subj)
|
||||
a.check_seq = a.check_seq + 1
|
||||
let cookie = "unlock-cookie-" + a.check_seq.to_string()
|
||||
a.pending_checks.push((cookie, cancel_id, m))
|
||||
let ids : Array[@network.DValue] = [
|
||||
Struct([
|
||||
Str("unix-user"),
|
||||
@network.dict("v", [("uid", Variant(U32(@polkit.own_uid().reinterpret_as_uint())))]),
|
||||
]),
|
||||
]
|
||||
ignore(
|
||||
bus.call(
|
||||
@network.DMessage::call(a.agent, @polkit.agent_path, @polkit.agent_iface, "BeginAuthentication", [
|
||||
Str(action_id),
|
||||
Str("Authentication is required to unlock the screen"),
|
||||
Str(""),
|
||||
@network.DValue::Arr("{ss}", []),
|
||||
Str(cookie),
|
||||
Arr("(sa{sv})", ids),
|
||||
]),
|
||||
on_reply=fn(rm) {
|
||||
let ok = rm.mtype == @network.method_return
|
||||
a.answers.push(if ok { "ok" } else { rm.error_name })
|
||||
match a.pending_checks.search_by(c => c.0 == cookie) {
|
||||
Some(idx) => {
|
||||
let (_, _, req_msg) = a.pending_checks.remove(idx)
|
||||
bus.reply(req_msg, [Struct([Bool(ok), Bool(false), @network.dict("s", [])])])
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
_ => bus.reply_error(m, "org.freedesktop.DBus.Error.InvalidArgs", "bad CheckAuthorization args")
|
||||
}
|
||||
"CancelCheckAuthorization" =>
|
||||
match m.body {
|
||||
[Str(cancel_id)] => {
|
||||
a.cancelled_ids.push(cancel_id)
|
||||
match a.pending_checks.search_by(c => c.1 == cancel_id) {
|
||||
Some(idx) => {
|
||||
let (cookie, _, req_msg) = a.pending_checks.remove(idx)
|
||||
ignore(
|
||||
bus.call(
|
||||
@network.DMessage::call(a.agent, @polkit.agent_path, @polkit.agent_iface, "CancelAuthentication", [
|
||||
Str(cookie),
|
||||
]),
|
||||
on_reply=fn(_) { () },
|
||||
),
|
||||
)
|
||||
bus.reply(req_msg, [Struct([Bool(false), Bool(false), @network.dict("s", [])])])
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
bus.reply(m, [])
|
||||
}
|
||||
_ => bus.reply_error(m, "org.freedesktop.DBus.Error.InvalidArgs", "bad CancelCheckAuthorization args")
|
||||
}
|
||||
_ => bus.reply_error(m, "org.freedesktop.DBus.Error.UnknownMethod", m.meth)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user