CI / test (push) Failing after 18s
run0, pkexec and other polkit prompts used whatever third-party agent was
installed: a plain toolkit window saying "start transient unit
'run-p15802-i1990.service'". The compositor now registers as the session's
polkit authentication agent and asks in its own dialog:
- a centered card over a dimmed screen, above all windows and client menus,
themed (dark/light follow the Dark mode switch), keyboard-first: Enter,
Esc, Tab order, Alt+R show/hide, Alt+D details, Ctrl+U clear
- for run0 it shows the command it will run ("gparted /dev/sda", as root)
from run0's command line (pid from polkit's details or the unit name),
pkexec's command from its details, polkit's message otherwise; Details
lists the requester, target user, unit and action id
- account picker when several admins can answer (group members expanded)
- the PAM conversation through polkit-agent-helper-1: polkit 126's socket
first, else the setuid helper on a socket pair (new sys spawn-socket on the
native, Rust and MoonBit hosts); password, echo-on prompts, info (fingerprint)
and errors (faillock) shown as they come; wrong password shakes and retries;
spinner while PAM checks; Caps Lock warning
- typing through the clients' xkb keymap (groups, Shift, AltGr, Caps Lock),
US layout when there is none
- no client has keyboard focus or input while it is up; the password is
wiped after sending and never logged
Settings > Session > "Chandra password dialog" (state.edn :auth-agent
:system when off) switches back to the third-party agent, which
chandra-session now finds and the compositor starts (also when polkit
refuses our agent). Tests: polkit_test (keymaps, helper protocol, run0
parsing, dialog states, the socket-pair route) and auth_test (mock polkit
Authority on a private dbus-daemon, mock helper; CHANDRA_AUTH_SHOTS writes
a PNG per state). Docs: docs/auth-dialog.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
217 lines
5.4 KiB
MoonBit
217 lines
5.4 KiB
MoonBit
///| `chandra:host/sys`: the OS surface, over compositor/sys's native implementation (the same
|
|
/// C shim the native compositor uses).
|
|
|
|
///|
|
|
#borrow(path, data)
|
|
extern "C" fn c_append_file(path : Bytes, data : Bytes) -> Int = "wh_append_file"
|
|
|
|
///| Fds beyond the first that arrived with the last `recvmsg` on a socket, for `take-fd`.
|
|
let extra_fds : Map[Int, Array[Int]] = {}
|
|
|
|
///|
|
|
fn drop_extra_fds(sock : Int) -> Unit {
|
|
match extra_fds.get(sock) {
|
|
Some(left) => {
|
|
for f in left {
|
|
@sys.close_fd(f)
|
|
}
|
|
extra_fds.remove(sock)
|
|
}
|
|
None => ()
|
|
}
|
|
}
|
|
|
|
///|
|
|
fn s32(v : Int) -> Array[@wt.Val] {
|
|
[S32(v)]
|
|
}
|
|
|
|
///|
|
|
fn boolean(b : Bool) -> Array[@wt.Val] {
|
|
[Bool(b)]
|
|
}
|
|
|
|
///|
|
|
let none : Array[@wt.Val] = []
|
|
|
|
///|
|
|
fn sys_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] {
|
|
[
|
|
("unix-listen", a => s32(@sys.unix_listen(a[0].to_string()))),
|
|
("unix-accept", a => s32(@sys.unix_accept(a[0].to_int()))),
|
|
("unix-connect", a => s32(@sys.unix_connect(a[0].to_string()))),
|
|
(
|
|
"close-fd",
|
|
a => {
|
|
let fd = a[0].to_int()
|
|
if fd >= 0 {
|
|
// A closed client socket's number is reused by the next one: drop what it left.
|
|
drop_extra_fds(fd)
|
|
@sys.close_fd(fd)
|
|
}
|
|
none
|
|
},
|
|
),
|
|
(
|
|
"unlink",
|
|
a => {
|
|
@sys.unlink(a[0].to_string())
|
|
none
|
|
},
|
|
),
|
|
("poll-read", a => s32(@sys.poll_read(a[0].to_int(), a[1].to_int()))),
|
|
(
|
|
"wait-readable",
|
|
a => {
|
|
let fds = a[0].to_list().map(v => v.to_int())
|
|
for f in display_wait_fds() {
|
|
fds.push(f)
|
|
}
|
|
s32(@sys.wait_readable(fds, a[1].to_int()))
|
|
},
|
|
),
|
|
(
|
|
"recvmsg",
|
|
a => {
|
|
let fd = a[0].to_int()
|
|
// Fds from the previous read nobody took would leak: close them.
|
|
drop_extra_fds(fd)
|
|
let max_len = a[1].to_int()
|
|
let received = fn(count : Int, got : Int, data : Bytes) -> Array[@wt.Val] {
|
|
[
|
|
Record([
|
|
("count", S32(count)),
|
|
("fd", S32(got)),
|
|
("data", @wt.Val::bytes(data)),
|
|
]),
|
|
]
|
|
}
|
|
if max_len <= 0 {
|
|
return received(0, -1, b"")
|
|
}
|
|
let buf = FixedArray::make(max_len, b'\x00')
|
|
let (n, fds) = @sys.recvmsg_fds(fd, buf, max_len)
|
|
if n < 0 {
|
|
for f in fds {
|
|
@sys.close_fd(f)
|
|
}
|
|
return received(n, -1, b"")
|
|
}
|
|
let got = if fds.length() > 0 { fds[0] } else { -1 }
|
|
if fds.length() > 1 {
|
|
extra_fds.set(fd, fds[1:].to_array())
|
|
}
|
|
received(n, got, Bytes::from_fixedarray(buf, len=n))
|
|
},
|
|
),
|
|
(
|
|
"take-fd",
|
|
a => {
|
|
let sock = a[0].to_int()
|
|
match extra_fds.get(sock) {
|
|
Some(q) if q.length() > 0 => {
|
|
let f = q.remove(0)
|
|
if q.length() == 0 {
|
|
extra_fds.remove(sock)
|
|
}
|
|
s32(f)
|
|
}
|
|
_ => s32(-1)
|
|
}
|
|
},
|
|
),
|
|
(
|
|
"sendmsg",
|
|
a => {
|
|
let data = a[1].to_bytes()
|
|
if data.length() == 0 {
|
|
return s32(0)
|
|
}
|
|
s32(@sys.sendmsg_fd(a[0].to_int(), data, a[2].to_int()))
|
|
},
|
|
),
|
|
("memfd-create", a => s32(@sys.memfd_create(a[0].to_string(), a[1].to_int()))),
|
|
(
|
|
"pwrite",
|
|
a => {
|
|
let fd = a[0].to_int()
|
|
let data = a[1].to_bytes()
|
|
let off = a[2].to_int()
|
|
s32(
|
|
if off < 0 {
|
|
@sys.write_nonblock(fd, data)
|
|
} else {
|
|
@sys.pwrite_bytes(fd, data, off)
|
|
},
|
|
)
|
|
},
|
|
),
|
|
(
|
|
"mmap-read",
|
|
a => [@wt.Val::bytes(@sys.mmap_read(a[0].to_int(), a[1].to_int()))],
|
|
),
|
|
(
|
|
"mmap-read-at",
|
|
a => {
|
|
let (fd, off, len) = (a[0].to_int(), a[1].to_int(), a[2].to_int())
|
|
if fd < 0 || off < 0 || len <= 0 {
|
|
return [@wt.Val::bytes(b"")]
|
|
}
|
|
[@wt.Val::bytes(@sys.mmap_read_at(fd, off, len))]
|
|
},
|
|
),
|
|
(
|
|
"read-file",
|
|
a => [@wt.Val::bytes(@sys.read_file_bytes(a[0].to_string()))],
|
|
),
|
|
(
|
|
"write-file",
|
|
a => s32(@sys.write_file_bytes(a[0].to_string(), a[1].to_bytes())),
|
|
),
|
|
(
|
|
"append-file",
|
|
a => s32(c_append_file(@utf8.encode(a[0].to_string()), a[1].to_bytes())),
|
|
),
|
|
(
|
|
"read-proc",
|
|
a => [@wt.Val::bytes(@sys.read_proc_bytes(a[0].to_string()))],
|
|
),
|
|
("mkdir-p", a => boolean(@sys.mkdir_p(a[0].to_string()))),
|
|
(
|
|
"list-desktop-files",
|
|
a => [@wt.Val::strings(@sys.list_desktop_files(a[0].to_string()))],
|
|
),
|
|
(
|
|
"sleep-ms",
|
|
a => {
|
|
let ms = a[0].to_int()
|
|
if ms > 0 {
|
|
@sys.sleep_ms(ms)
|
|
}
|
|
none
|
|
},
|
|
),
|
|
("monotonic-ms", _ => [U64(@sys.monotonic_ms())]),
|
|
(
|
|
"log",
|
|
a => {
|
|
eprint(a[0].to_string())
|
|
none
|
|
},
|
|
),
|
|
("getpid", _ => s32(@sys.getpid())),
|
|
("take-sigusr1", _ => boolean(@sys.take_sigusr1())),
|
|
("wall-time-field", a => s32(@sys.wall_time_field(a[0].to_int()))),
|
|
("getenv", a => [Str(@sys.getenv(a[0].to_string()))]),
|
|
("has-exe", a => boolean(@sys.has_exe(a[0].to_string()))),
|
|
(
|
|
"spawn",
|
|
a => boolean(@sys.spawn(a[0].to_string(), a[1].to_string())),
|
|
),
|
|
(
|
|
"spawn-socket",
|
|
a => s32(@sys.spawn_socket(a[0].to_string().split("\n").map(v => v.to_string()).to_array())),
|
|
),
|
|
]
|
|
}
|