- 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
@@ -28,6 +28,12 @@ pub struct AgentLoop {
|
||||
mut id : String
|
||||
mut next_id : Int
|
||||
mut was_registered : Bool
|
||||
/// An unlock authorization (org.chandra.unlock) is out to polkit; ignore further `unlock`s.
|
||||
mut unlocking : Bool
|
||||
/// Cancellation id passed to polkit's CheckAuthorization / CancelCheckAuthorization.
|
||||
mut unlock_cancel_id : String
|
||||
/// Monotonic counter so stale CheckAuthorization replies after cancel are ignored.
|
||||
mut unlock_seq : Int
|
||||
/// Done: the main loop exits.
|
||||
mut finished : Bool
|
||||
}
|
||||
@@ -56,6 +62,9 @@ pub fn AgentLoop::new(
|
||||
id: "",
|
||||
next_id: 1,
|
||||
was_registered: false,
|
||||
unlocking: false,
|
||||
unlock_cancel_id: "",
|
||||
unlock_seq: 0,
|
||||
finished: false,
|
||||
}
|
||||
}
|
||||
@@ -73,6 +82,9 @@ pub fn AgentLoop::new_demo(link_fd : Int, mode : String) -> AgentLoop {
|
||||
id: "",
|
||||
next_id: 1,
|
||||
was_registered: false,
|
||||
unlocking: false,
|
||||
unlock_cancel_id: "",
|
||||
unlock_seq: 0,
|
||||
finished: false,
|
||||
}
|
||||
}
|
||||
@@ -160,10 +172,78 @@ fn AgentLoop::close_request(self : AgentLoop, result : Result[Unit, String]?) ->
|
||||
}
|
||||
}
|
||||
|
||||
///| Unlock the session: ask polkit to authorize org.chandra.unlock. polkit drives this agent's
|
||||
/// dialog (face via the polkit-1 PAM stack, then password); the reply tells the compositor
|
||||
/// `unlocked` or `unlock-failed`. Without polkit (demo) there is nothing to check.
|
||||
fn AgentLoop::begin_unlock(self : AgentLoop) -> Unit {
|
||||
match self.polkit {
|
||||
Some(p) => {
|
||||
if self.unlocking {
|
||||
return
|
||||
}
|
||||
self.unlock_seq = self.unlock_seq + 1
|
||||
let seq = self.unlock_seq
|
||||
let cid = "chandra-unlock-" + seq.to_string()
|
||||
self.unlocking = true
|
||||
self.unlock_cancel_id = cid
|
||||
let started = p.check_unlock("org.chandra.unlock", cid, fn(ok) {
|
||||
if self.unlock_seq != seq {
|
||||
return
|
||||
}
|
||||
self.unlocking = false
|
||||
self.unlock_cancel_id = ""
|
||||
ignore(self.link.send([if ok { "unlocked" } else { "unlock-failed" }]))
|
||||
})
|
||||
if !started {
|
||||
self.unlocking = false
|
||||
self.unlock_cancel_id = ""
|
||||
alog("unlock: polkit is not ready")
|
||||
ignore(self.link.send(["unlock-failed"]))
|
||||
}
|
||||
}
|
||||
None => ignore(self.link.send(["unlock-failed"]))
|
||||
}
|
||||
}
|
||||
|
||||
///| Cancel an in-flight unlock authorization (e.g., screen blanked again before completion).
|
||||
fn AgentLoop::cancel_unlock(self : AgentLoop) -> Unit {
|
||||
if !self.unlocking {
|
||||
return
|
||||
}
|
||||
let cid = self.unlock_cancel_id
|
||||
self.unlock_seq = self.unlock_seq + 1
|
||||
self.unlocking = false
|
||||
self.unlock_cancel_id = ""
|
||||
match self.machine {
|
||||
Some(m) if m.req.action_id == "org.chandra.unlock" =>
|
||||
self.close_request(Some(Err("The unlock request was cancelled")))
|
||||
_ => ()
|
||||
}
|
||||
match self.polkit {
|
||||
Some(p) => p.cancel_unlock(cid)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| A message from the compositor.
|
||||
fn AgentLoop::on_link(self : AgentLoop, line : FixedArray[Byte]) -> Unit {
|
||||
let f = split_fields(line)
|
||||
zero(line)
|
||||
// Session unlock (lock.mbt) is a one-field message, independent of any request/dialog id.
|
||||
if f.length() >= 1 && field_text(f[0]) == "unlock" {
|
||||
for b in f {
|
||||
zero(b)
|
||||
}
|
||||
self.begin_unlock()
|
||||
return
|
||||
}
|
||||
if f.length() >= 1 && field_text(f[0]) == "cancel-unlock" {
|
||||
for b in f {
|
||||
zero(b)
|
||||
}
|
||||
self.cancel_unlock()
|
||||
return
|
||||
}
|
||||
if f.length() < 2 {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user