- 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
@@ -277,6 +277,115 @@ pub fn PolkitAgent::registered(self : PolkitAgent) -> Bool {
|
||||
self.registered
|
||||
}
|
||||
|
||||
///| Parse an unsigned 64-bit decimal integer (returns None if empty, >20 chars, or non-digit).
|
||||
fn parse_u64(s : String) -> UInt64? {
|
||||
if s.length() == 0 || s.length() > 20 {
|
||||
return None
|
||||
}
|
||||
let mut v = 0UL
|
||||
for c in s {
|
||||
if c < '0' || c > '9' {
|
||||
return None
|
||||
}
|
||||
v = v * 10UL + (c.to_int() - '0'.to_int()).to_uint64()
|
||||
}
|
||||
Some(v)
|
||||
}
|
||||
|
||||
///| Build a polkit `unix-process` subject from `/proc/<pid>/stat` and `/proc/<pid>/status` text.
|
||||
pub fn process_subject_for(pid : Int, stat : String, status : String) -> @network.DValue {
|
||||
let start_time = match stat.rev_find(")") {
|
||||
Some(i) => {
|
||||
let parts = stat[i + 1:].to_string().trim(chars=" \t\n").to_string().split(" ").map(v => v.to_string()).filter(v => v != "").to_array()
|
||||
if parts.length() > 19 {
|
||||
parse_u64(parts[19]).unwrap_or(0UL)
|
||||
} else {
|
||||
0UL
|
||||
}
|
||||
}
|
||||
None => 0UL
|
||||
}
|
||||
let uid = uid_from_status(status)
|
||||
Struct([
|
||||
Str("unix-process"),
|
||||
@network.dict("v", [
|
||||
("pid", Variant(U32(pid.reinterpret_as_uint()))),
|
||||
("start-time", Variant(U64(start_time))),
|
||||
("uid", Variant(I32(uid))),
|
||||
]),
|
||||
])
|
||||
}
|
||||
|
||||
///| The polkit subject representing the current agent process (`unix-process`).
|
||||
fn process_subject() -> @network.DValue {
|
||||
let pid = @sys.getpid()
|
||||
let stat = @utf8.decode_lossy(@sys.read_proc_bytes("/proc/" + pid.to_string() + "/stat"))
|
||||
let status = @utf8.decode_lossy(@sys.read_proc_bytes("/proc/" + pid.to_string() + "/status"))
|
||||
process_subject_for(pid, stat, status)
|
||||
}
|
||||
|
||||
///| Ask polkit to authorize `action_id` for the agent process, allowing user interaction: polkit
|
||||
/// then drives this same agent's dialog (face via PAM, then password), and the reply says whether
|
||||
/// it succeeded. Used for session unlock (org.chandra.unlock). False before registration or without a bus.
|
||||
pub fn PolkitAgent::check_unlock(
|
||||
self : PolkitAgent,
|
||||
action_id : String,
|
||||
cancel_id : String,
|
||||
on_result : (Bool) -> Unit,
|
||||
) -> Bool {
|
||||
if !self.registered {
|
||||
return false
|
||||
}
|
||||
match self.bus {
|
||||
Some(bus) => {
|
||||
let serial = bus.call(
|
||||
@network.DMessage::call(authority_name, authority_path, authority_iface, "CheckAuthorization", [
|
||||
process_subject(),
|
||||
Str(action_id),
|
||||
@network.dict("s", []),
|
||||
U32(1U), // AllowUserInteraction
|
||||
Str(cancel_id),
|
||||
]),
|
||||
on_reply=fn(m) {
|
||||
let ok = match m {
|
||||
{ mtype: 2, body: [Struct([Bool(a), ..]), ..], .. } => a
|
||||
{ mtype: 2, .. } => {
|
||||
alog("unlock: unexpected CheckAuthorization reply")
|
||||
false
|
||||
}
|
||||
_ => {
|
||||
alog("unlock: CheckAuthorization error: " + m.error_text())
|
||||
false
|
||||
}
|
||||
}
|
||||
on_result(ok)
|
||||
},
|
||||
)
|
||||
serial != 0
|
||||
}
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
///| Cancel an in-flight CheckAuthorization call identified by `cancel_id`.
|
||||
pub fn PolkitAgent::cancel_unlock(self : PolkitAgent, cancel_id : String) -> Unit {
|
||||
if cancel_id == "" {
|
||||
return
|
||||
}
|
||||
match self.bus {
|
||||
Some(bus) =>
|
||||
ignore(
|
||||
bus.call(
|
||||
@network.DMessage::call(authority_name, authority_path, authority_iface, "CancelCheckAuthorization", [
|
||||
Str(cancel_id),
|
||||
]),
|
||||
on_reply=fn(_) { () },
|
||||
),
|
||||
)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
///| Why the last start failed ("" when it didn't).
|
||||
pub fn PolkitAgent::error(self : PolkitAgent) -> String {
|
||||
self.error
|
||||
|
||||
Reference in new issue
Block a user