Password dialog: Chandra is its own polkit agent, drawn in the shell layer
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
This commit is contained in:
Claude committed 2026-11-26 00:17:04 +00:00
1 parent 2a67bc83d4
commit 0feea23a06
32 files changed
+3930 -43

No files matched your search

+9
View File
@@ -253,6 +253,15 @@ pub fn spawn(cmd : String, display : String) -> Bool {
c_spawn(str_to_utf8_bytes(cmd), str_to_utf8_bytes(display)) == 0
}
///|
extern "C" fn c_spawn_socket(argv : Bytes) -> Int = "mp_spawn_socket"
///| Run `argv` (an absolute program path, then its arguments) with its stdin and stdout on a
/// socket and return our end of it (-1 on failure). For polkit's authentication helper.
pub fn spawn_socket(argv : Array[String]) -> Int {
c_spawn_socket(str_to_utf8_bytes(argv.join("\n")))
}
///|
extern "C" fn c_take_sigusr1() -> Int = "mp_take_sigusr1"
+41
View File
@@ -10,6 +10,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <time.h>
#include <signal.h>
#include <sys/prctl.h>
@@ -565,3 +566,43 @@ moonbit_bytes_t mp_read_proc(moonbit_bytes_t path_bytes) {
memcpy(out, buf, n);
return out;
}
/* Run a program with its stdin and stdout on one end of a socket pair and return the other end
* (-1 on failure). `argv_bytes` holds the arguments separated by '\n'. stderr is inherited (the
* session log). The child is not waited for: SIGCHLD is ignored (see mp_spawn) or it is reaped
* by the double fork below. Used for polkit's setuid authentication helper. */
MOONBIT_FFI_EXPORT
int32_t mp_spawn_socket(moonbit_bytes_t argv_bytes) {
size_t n = Moonbit_array_length(argv_bytes);
char *buf = malloc(n + 1);
if (!buf) return -1;
memcpy(buf, argv_bytes, n);
buf[n] = 0;
char *argv[16];
int argc = 0;
char *save = NULL;
for (char *a = strtok_r(buf, "\n", &save); a && argc < 15; a = strtok_r(NULL, "\n", &save)) argv[argc++] = a;
argv[argc] = NULL;
if (argc == 0) { free(buf); return -1; }
int sv[2];
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) != 0) { free(buf); return -1; }
pid_t pid = fork();
if (pid < 0) { close(sv[0]); close(sv[1]); free(buf); return -1; }
if (pid == 0) {
/* Double fork so the helper is never our zombie. */
pid_t inner = fork();
if (inner != 0) _exit(inner < 0 ? 1 : 0);
signal(SIGCHLD, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
dup2(sv[1], 0);
dup2(sv[1], 1);
for (int fd = 3; fd < 1024; fd++) close(fd);
execv(argv[0], argv);
_exit(127);
}
close(sv[1]);
free(buf);
int status;
waitpid(pid, &status, 0);
return sv[0];
}
+6
View File
@@ -193,6 +193,12 @@ pub fn has_exe(name : String) -> Bool {
@hostsys.has_exe(name)
}
///| Run `argv` (an absolute program path, then its arguments) with its stdin and stdout on a
/// socket and return our end of it (-1 on failure). For polkit's authentication helper.
pub fn spawn_socket(argv : Array[String]) -> Int {
@hostsys.spawn_socket(argv.join("\n"))
}
///| Launch `cmd` detached with WAYLAND_DISPLAY set to `display`.
pub fn spawn(cmd : String, display : String) -> Bool {
@hostsys.spawn(cmd, display)