LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Launcher: no access to your files for Linux apps, with Landlock
Federico Pereira2898c78e4ae0
diff --git a/server/Makefile b/server/Makefileindex 2a207d3..7f3a491 100644--- a/server/Makefile+++ b/server/Makefile@@ -237,6 +237,14 @@ build/broker-restrict-test: tests/broker_restrict_test.c $(BROKER_RESTRICT_SRC)@mkdir -p build$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/broker_restrict_test.c $(BROKER_RESTRICT_SRC) -Wl,--wrap=open./$@ || { rm -f $@; exit 1; }+# tests/launch_cli.c: the real Linux app launcher outside the desktop, for tests/fwlinux/files.sh+# (built by `make test`, run by that script in the VM)+LAUNCH_CLI_SRC := src/apps.c src/fsops.c src/hw/defaults.c src/hw/mimeapps.c src/sec/cgroup.c src/sec/sandbox.c \+ src/sec/restrict.c src/fw/rules.c src/fw/fwmap.c src/sec/json.c+test: build/launch-cli+build/launch-cli: tests/launch_cli.c $(LAUNCH_CLI_SRC) src/apps.h $(wildcard src/sec/*.h src/fw/*.h src/hw/*.h)+ @mkdir -p build+ $(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/launch_cli.c $(LAUNCH_CLI_SRC)build/fw-rules-test: tests/fw_rules_test.c src/fw/rules.c src/fw/fwmap.c src/sec/json.c $(wildcard src/fw/*.h) src/sec/json.h@mkdir -p build$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/fw_rules_test.c src/fw/rules.c src/fw/fwmap.c src/sec/json.cdiff --git a/server/src/apps.c b/server/src/apps.cindex cad2a01..9ac87b8 100644--- a/server/src/apps.c+++ b/server/src/apps.c@@ -12,11 +12,19 @@* - JS cannot create .desktop files: lord.fs is read-only and LordOS app packages are installed* in another folder (~/.local/share/lordos/apps), so a command cannot be* invented from the UI.- * App output goes to ~/.cache/lordos/apps.log (trimmed when it exceeds 1 MB). */+ * App output goes to ~/.cache/lordos/apps.log (trimmed when it exceeds 1 MB).+ *+ * An app the owner restricted with "no access to your files" (Settings → Privacy, firewall id+ * desktop:<id>, sec/restrict.h) starts under Landlock (sandbox_apply_files): only its own config,+ * cache and data folders, the system read-only, /tmp and the runtime dir, plus the one file or+ * folder it was opened with. A restriction set while the app runs applies at its next launch. */#include "apps.h"#include "hw/defaults.h"#include "fsops.h"#include "sec/cgroup.h"+#include "sec/restrict.h"+#include "sec/sandbox.h"+#include "fw/rules.h"#include <ctype.h>#include <dirent.h>@@ -391,6 +399,135 @@ static void open_log(void) {if (fd >= 0) { dup2(fd, 1); dup2(fd, 2); if (fd > 2) close(fd); }}+/* ---- "no access to your files": the Landlock plan (built before fork) ---- */++typedef struct {+ SandboxFilesCfg cfg;+ char buf[2 * SANDBOX_FILES_MAX][PATH_MAX];+ int nbuf, nrw, nro;+} FilesPlan;++static const char *plan_str(FilesPlan *p, const char *fmt, const char *a, const char *b) {+ if (p->nbuf >= 2 * SANDBOX_FILES_MAX) return NULL;+ int n = snprintf(p->buf[p->nbuf], PATH_MAX, fmt, a, b);+ if (n < 0 || n >= PATH_MAX) return NULL;+ return p->buf[p->nbuf++];+}++static void plan_add(FilesPlan *p, int rw, const char *fmt, const char *a, const char *b) {+ int *n = rw ? &p->nrw : &p->nro;+ const char **list = rw ? p->cfg.rw : p->cfg.ro;+ if (*n >= SANDBOX_FILES_MAX) return;+ const char *s = plan_str(p, fmt, a, b);+ if (!s) return;+ for (int i = 0; i < *n; i++) if (!strcmp(list[i], s)) { p->nbuf--; return; }+ list[(*n)++] = s;+ list[*n] = NULL;+}++/* A name that may become a folder of its own under ~/.config, ~/.cache or ~/.local/share:+ * plain characters, not hidden, and never one of the folders that hold the user's secrets or+ * LordOS's own decisions. */+static int dir_name_ok(const char *c) {+ static const char *const deny[] = { "lordos", "ssh", "gnupg", "local", "config", "cache", "pki", "password-store",+ "thumbnails", "autostart", "systemd", "environment.d", "dconf", "keyrings", NULL };+ size_t n = strlen(c);+ if (!n || n > 100 || c[0] == '.' || c[0] == '-') return 0;+ for (const char *q = c; *q; q++) if (!isalnum((unsigned char)*q) && !strchr("._-+", *q)) return 0;+ for (int i = 0; deny[i]; i++) if (!strcasecmp(c, deny[i])) return 0;+ return 1;+}++/* The app's own names: its .desktop id, the last part of a reverse-DNS id, the program and its+ * window class, as written and in lowercase. */+static int app_names(const DesktopApp *a, char out[][160], int max) {+ char tmp[6][160];+ int nt = 0;+ snprintf(tmp[nt++], 160, "%.159s", a->id);+ const char *dot = strrchr(a->id, '.');+ if (dot && dot[1]) snprintf(tmp[nt++], 160, "%.159s", dot + 1);+ if (a->bin[0]) snprintf(tmp[nt++], 160, "%.159s", a->bin);+ static const char *const suffixes[] = { "-esr", "-stable", "-bin", NULL };+ for (int i = 0; suffixes[i] && a->bin[0]; i++) {+ size_t bl = strlen(a->bin), sl = strlen(suffixes[i]);+ if (bl > sl && !strcmp(a->bin + bl - sl, suffixes[i])) { snprintf(tmp[nt++], 160, "%.*s", (int)(bl - sl), a->bin); break; }+ }+ if (a->wmclass[0]) snprintf(tmp[nt++], 160, "%.159s", a->wmclass);+ int n = 0;+ for (int i = 0; i < nt; i++)+ for (int lower = 0; lower < 2; lower++) {+ char c[160];+ memcpy(c, tmp[i], sizeof c);+ c[sizeof c - 1] = 0;+ if (lower) for (char *q = c; *q; q++) *q = (char)tolower((unsigned char)*q);+ if (!dir_name_ok(c)) continue;+ int dup = 0;+ for (int k = 0; k < n; k++) dup |= !strcmp(out[k], c);+ if (!dup && n < max) memcpy(out[n++], c, sizeof c);+ }+ return n;+}++static int is_dir(const char *p) { struct stat st; return !lstat(p, &st) && S_ISDIR(st.st_mode); }++/* What a restricted app may touch (see sandbox.h). file: the realpath it was opened with, or NULL. */+static FilesPlan *files_plan(const DesktopApp *a, const char *file) {+ const char *home = getenv("HOME");+ if (!home || home[0] != '/') return NULL;+ FilesPlan *p = calloc(1, sizeof *p);+ if (!p) return NULL;+ p->cfg.runtime_dir = getenv("XDG_RUNTIME_DIR");+ char names[12][160];+ int nn = app_names(a, names, 12), have_config = 0;+ char path[PATH_MAX];+ for (int i = 0; i < nn; i++) {+ static const char *const own[] = { "%s/.config/%s", "%s/.local/share/%s", "%s/.local/state/%s", "%s/.cache/%s", "%s/.%s", NULL };+ for (int k = 0; own[k]; k++) {+ snprintf(path, sizeof path, own[k], home, names[i]);+ if (!is_dir(path)) continue; /* only what exists (no symlinks out of the home) */+ plan_add(p, 1, "%s%s", path, "");+ if (k == 0 || k == 4) have_config = 1;+ }+ }+ /* programs whose data folder isn't named after them (program name prefix → folder in the+ * home and in ~/.cache); created if missing, like the app would */+ static const struct { const char *prog, *dir; } alias[] = { { "firefox", "mozilla" }, { "librewolf", "librewolf" },+ { "icecat", "mozilla" }, { NULL, NULL } };+ for (int k = 0; alias[k].prog && a->bin[0]; k++) {+ if (strncmp(a->bin, alias[k].prog, strlen(alias[k].prog))) continue;+ snprintf(path, sizeof path, "%s/.%s", home, alias[k].dir);+ mkdir(path, 0700);+ if (is_dir(path)) { plan_add(p, 1, "%s%s", path, ""); have_config = 1; }+ snprintf(path, sizeof path, "%s/.cache/%s", home, alias[k].dir);+ mkdir(path, 0700);+ if (is_dir(path)) plan_add(p, 1, "%s%s", path, "");+ }+ /* none yet: its folders under the program's name, so it can save its settings */+ if (!have_config && a->bin[0] && dir_name_ok(a->bin)) {+ static const char *const make[] = { "%s/.config", "%s/.config/%s", "%s/.local", "%s/.local/share", "%s/.local/share/%s",+ "%s/.cache", "%s/.cache/%s", NULL };+ for (int k = 0; make[k]; k++) { snprintf(path, sizeof path, make[k], home, a->bin); mkdir(path, 0700); }+ plan_add(p, 1, "%s/.config/%s", home, a->bin);+ plan_add(p, 1, "%s/.local/share/%s", home, a->bin);+ plan_add(p, 1, "%s/.cache/%s", home, a->bin);+ }+ /* caches shared by every app that hold nothing of the user's (not all of ~/.cache: its+ * thumbnails are pictures of the user's documents) */+ static const char *const caches[] = { "fontconfig", "mesa_shader_cache", "mesa_shader_cache_db", "radv_builtin_shaders",+ "gstreamer-1.0", "ibus", "at-spi", NULL };+ for (int k = 0; caches[k]; k++) plan_add(p, 1, "%s/.cache/%s", home, caches[k]);+ /* the desktop's look and settings, read only */+ static const char *const look[] = { ".config/gtk-3.0", ".config/gtk-4.0", ".config/fontconfig", ".config/dconf",+ ".config/mimeapps.list", ".config/user-dirs.dirs", ".config/user-dirs.locale",+ ".config/kdeglobals", ".config/Trolltech.conf", ".config/qt5ct", ".config/qt6ct",+ ".config/pulse", ".local/share/fonts", ".local/share/icons", ".local/share/themes",+ ".local/share/mime", ".local/share/applications", ".fonts", ".icons", ".themes", NULL };+ for (int k = 0; look[k]; k++) plan_add(p, 0, "%s/%s", home, look[k]);+ /* "Open with": that file or folder only */+ if (file) plan_add(p, 1, "%s%s", file, "");+ return p;+}+static int launch(const char *id, const char *file);int apps_launch(const char *id) { return launch(id, NULL); }@@ -428,6 +565,18 @@ static int launch(const char *id, const char *file) {if (ok && e->path[0] == '/') snprintf(cwd, sizeof cwd, "%s", e->path);free(e);if (!ok) { free(buf); return -1; }+ /* "no access to your files": Landlock before execve. Without Landlock in the kernel the app+ * doesn't start (the owner asked for it to be kept away from their files). */+ FilesPlan *plan = NULL;+ char fwid[FW_APP_MAX];+ snprintf(fwid, sizeof fwid, "desktop:%s", id);+ if (restrict_blocks(fwid, FW_R_NO_FILES)) {+ if (!sandbox_landlock_abi() || !(plan = files_plan(a, file))) {+ fprintf(stderr, "apps: %s is restricted to no files, but Landlock is not available: not launched\n", id);+ free(buf);+ return -1;+ }+ }pid_t pid = fork();if (pid == 0) {@@ -445,9 +594,15 @@ static int launch(const char *id, const char *file) {const char *home = getenv("HOME");if (!cwd[0] || chdir(cwd)) { if (home && chdir(home)) {} }app_scope_enter(id); /* its own app-lordos-<id>.scope cgroup (the monitor attributes it) */+ if (plan && sandbox_apply_files(&plan->cfg)) {+ static const char msg[] = "apps: could not apply the no-files restriction (Landlock): not launched\n";+ if (write(2, msg, sizeof msg - 1) < 0) {}+ _exit(126);+ }execve(prog, argv, environ);_exit(127);}+ free(plan);free(buf);if (pid < 0) return -1;waitpid(pid, NULL, 0);diff --git a/server/src/sec/sandbox.c b/server/src/sec/sandbox.cindex 07615ac..ed93b3f 100644--- a/server/src/sec/sandbox.c+++ b/server/src/sec/sandbox.c@@ -151,6 +151,68 @@ static int apply_landlock(const SandboxConfig *cfg, const int *ro_fds, const int#endif}+/* ---- "no files" for Linux apps (sandbox.h) ---- */++int sandbox_landlock_abi(void) {+#ifdef HAVE_LANDLOCK+ int abi = ll_abi();+ return abi > 0 ? abi : 0;+#else+ return 0;+#endif+}++int sandbox_apply_files(const SandboxFilesCfg *cfg) {+#ifdef HAVE_LANDLOCK+ int abi = ll_abi();+ if (abi < 1) return -1;+ uint64_t ro = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_EXECUTE;+ uint64_t rw = ro | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG |+ LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_SYM |+ LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_CHAR |+ LANDLOCK_ACCESS_FS_MAKE_BLOCK;+ uint64_t handled = rw;+ /* REFER (ABI 2): handled and granted in the writable folders. Leaving it unhandled would make+ * every rename between folders fail, which breaks browsers and editors. */+ if (abi >= 2) { handled |= LANDLOCK_ACCESS_FS_REFER; rw |= LANDLOCK_ACCESS_FS_REFER; }+ if (abi >= 3) { handled |= LANDLOCK_ACCESS_FS_TRUNCATE; rw |= LANDLOCK_ACCESS_FS_TRUNCATE; }+ /* IOCTL_DEV (ABI 5) is not handled: GPU and sound ioctls stay as they are */+ uint64_t file_rw = (LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_WRITE_FILE |+ (abi >= 3 ? LANDLOCK_ACCESS_FS_TRUNCATE : 0)) & handled;+ struct landlock_ruleset_attr attr;+ memset(&attr, 0, sizeof attr);+ attr.handled_access_fs = handled;+ int rs = ll_create(&attr, sizeof attr);+ if (rs < 0) return -1;+ /* not "/run" or "/var" as a whole: /run/media/<user> and /var/mail are the user's */+ static const char *const sys_ro[] = { "/usr", "/bin", "/sbin", "/lib", "/lib32", "/lib64", "/libx32", "/etc", "/opt",+ "/var/lib", "/var/cache", "/sys", "/run/dbus", "/run/systemd", "/run/udev",+ "/run/resolvconf", "/run/NetworkManager", "/run/cups", "/run/avahi-daemon",+ "/run/lock", NULL };+ static const char *const sys_rw[] = { "/tmp", "/var/tmp", "/dev", "/proc", NULL };+ for (int i = 0; sys_ro[i]; i++) ll_path(rs, sys_ro[i], ro);+ for (int i = 0; sys_rw[i]; i++) ll_path(rs, sys_rw[i], rw);+ if (cfg->runtime_dir) ll_path(rs, cfg->runtime_dir, rw);+ for (int i = 0; i < SANDBOX_FILES_MAX && cfg->ro[i]; i++) {+ struct stat st;+ if (stat(cfg->ro[i], &st)) continue;+ ll_path(rs, cfg->ro[i], S_ISDIR(st.st_mode) ? ro : (LANDLOCK_ACCESS_FS_READ_FILE & handled));+ }+ for (int i = 0; i < SANDBOX_FILES_MAX && cfg->rw[i]; i++) {+ struct stat st;+ if (stat(cfg->rw[i], &st)) continue;+ ll_path(rs, cfg->rw[i], S_ISDIR(st.st_mode) ? rw : file_rw);+ }+ if (apply_nopriv()) { close(rs); return -1; }+ int r = ll_enforce(rs);+ close(rs);+ return r ? -1 : 0;+#else+ (void)cfg;+ return -1;+#endif+}+/* ---- seccomp-bpf: allowlist ---- */#if defined(__x86_64__)diff --git a/server/src/sec/sandbox.h b/server/src/sec/sandbox.hindex 4a3bd60..b82c707 100644--- a/server/src/sec/sandbox.h+++ b/server/src/sec/sandbox.h@@ -69,4 +69,27 @@ typedef struct {* only works for comparing fds of the process itself (pid1 == pid2 == getpid()). */int sandbox_apply_helper(const SandboxHelperCfg *cfg);+/* ---- "no access to your files" for Linux apps (the launcher, apps.c) ----+ * Landlock only: no seccomp, no capability changes, no network or scoping rules, so a normal+ * GTK/Qt app or browser keeps working; device ioctls are not handled (the device restrictions are+ * lord-netperm's). What the app may touch:+ * read and execute: the system (/usr, /etc, /opt, /var/lib, /var/cache, /sys, a few service+ * folders of /run), plus ro[];+ * read and write: /tmp, /var/tmp, /dev, /proc, the runtime dir, plus rw[] (its own config, cache and+ * data dirs, and the file or folder the user opened it with);+ * everything else under the home folder and the user's mounts is denied. Applied in the+ * launcher's child, after it entered its scope and right before execve; it also sets+ * no_new_privs (Landlock requires it), so setuid programs started by the app don't gain+ * privileges. Doesn't allocate (safe after fork). 0 applied, -1 not (kernel without Landlock:+ * the caller decides). */+#define SANDBOX_FILES_MAX 48+typedef struct {+ const char *runtime_dir;+ const char *rw[SANDBOX_FILES_MAX + 1]; /* NULL-terminated */+ const char *ro[SANDBOX_FILES_MAX + 1];+} SandboxFilesCfg;+int sandbox_apply_files(const SandboxFilesCfg *cfg);+/* Landlock ABI of the running kernel (0 = none). */+int sandbox_landlock_abi(void);+#endifdiff --git a/server/tests/fwlinux/files.sh b/server/tests/fwlinux/files.shnew file mode 100755index 0000000..862ae06--- /dev/null+++ b/server/tests/fwlinux/files.sh@@ -0,0 +1,104 @@+#!/bin/bash+# files.sh — "no access to your files" for Linux apps: the launcher (src/apps.c) starts a+# restricted app under Landlock (sec/sandbox.c, sandbox_apply_files). Uses build/launch-cli, the+# real launcher code outside the desktop. Applies at the next launch.+#+# bash server/tests/fwlinux/files.sh (from server/, after make -C server test)+#+# 1-3: a stand-in app (files_probe.py) through a .desktop: it can't read ~/Documents, the home+# folder or firewall.json, can use its own folders, /tmp and the runtime dir, and can open+# the one file it was opened with (not the one next to it).+# 4: a real GTK 4 app (gtk4-print-editor, under strace) opened with a file: it starts, reads+# that file, and is refused ~/Documents.+. "$(dirname "$0")/lib.sh"+D=$(cd "$(dirname "$0")" && pwd)+CLI=$D/../../build/launch-cli+[ -x "$CLI" ] || { echo "missing build/launch-cli (make -C server test)"; exit 2; }+APPS=~/.local/share/applications+mkdir -p "$APPS" ~/Documents ~/fwlinux-open+echo secret > ~/Documents/fwlinux-secret.txt+echo "opened with" > ~/fwlinux-open/note.txt+echo sibling > ~/fwlinux-open/fwlinux-sibling.txt+mkdir -p ~/.config/fwprobe ~/.cache/fwprobe+PROBE=/tmp/fwlinux-files-probe-$U.py # outside the home folder: the restricted app must be able to run it+cp "$D/files_probe.py" "$PROBE"+cat > "$APPS/fwprobe.desktop" <<DESK+[Desktop Entry]+Type=Application+Name=Files restriction probe+Exec=python3 $PROBE %f+MimeType=text/plain;+NoDisplay=false+DESK+OUT=/tmp/fwlinux-files-$U.json+probe() { # probe [file]: launches and waits for the result+ rm -f "$OUT"+ "$CLI" fwprobe "$@" >/dev/null 2>&1+ for i in $(seq 1 50); do [ -s "$OUT" ] && break; sleep 0.1; done+}+val() { python3 -c "import json;print(json.load(open('$OUT')).get('$1','missing'))" 2>/dev/null; }+expect() { local key=$1 want=$2 got; got=$(val "$key"); case "$got" in $want*) ok "$key → $got";; *) bad "$key → $got (expected $want)";; esac; }++echo "1. not restricted: the app reads ~/Documents"+restrict desktop:fwprobe ""+probe+expect read_documents ok+expect list_home ok++echo "2. no-files: only its own folders, the system, /tmp and the runtime dir"+restrict desktop:fwprobe no-files+probe+expect read_documents "Permission denied"+expect list_documents "Permission denied"+expect list_home "Permission denied"+expect read_firewall_json "Permission denied"+expect write_autostart "Permission denied"+expect read_ssh "Permission denied"+expect read_system ok+expect write_tmp ok+expect write_own_config ok+expect write_own_cache ok+expect rename_in_own_config ok+expect read_desktop_files ok+expect write_runtime_dir ok++echo "3. no-files, opened with a file (\"Open with\")"+probe ~/fwlinux-open/note.txt+expect read_opened_file ok+expect write_opened_file ok+expect read_next_to_opened "Permission denied"+expect read_documents "Permission denied"++if command -v gtk4-print-editor >/dev/null && command -v strace >/dev/null && [ -S "/run/user/$U/wayland-0" ]; then+ echo "4. a real GTK 4 app (gtk4-print-editor, traced with strace), restricted"+ TR=/tmp/fwlinux-gtk-$U.trace+ gtk() { # gtk <name> <Exec arguments> [file]: a .desktop for the editor, launched restricted+ cat > "$APPS/$1.desktop" <<DESK+[Desktop Entry]+Type=Application+Name=GTK editor (files test)+Exec=strace -f -qq -e trace=openat -o $TR gtk4-print-editor $2+MimeType=text/plain;+DESK+ restrict "desktop:$1" no-files+ rm -f "$TR"+ WAYLAND_DISPLAY=wayland-0 XDG_RUNTIME_DIR=/run/user/$U "$CLI" "$1" ${3:+"$3"}+ sleep 4+ }+ # a: its command line names a file in ~/Documents (not passed by "Open with"): refused+ gtk fwgtkdoc "$HOME/Documents/fwlinux-secret.txt"+ PID=$(pgrep -u "$U" -n -x gtk4-print-edit)+ [ -n "$PID" ] && ok "it starts and stays up under the restriction (pid $PID)" || bad "gtk4-print-editor did not stay up"+ [ -n "$PID" ] && grep -q "^NoNewPrivs:.*1" /proc/$PID/status && ok "no_new_privs is set (Landlock)" || bad "no_new_privs not set"+ grep -E "Documents/fwlinux-secret.txt.*EACCES" "$TR" >/dev/null && ok "its open of ~/Documents/fwlinux-secret.txt → EACCES" || bad "~/Documents was not refused: $(grep fwlinux-secret "$TR" | head -1)"+ [ -n "$PID" ] && kill "$PID" 2>/dev/null; sleep 0.5+ # b: opened with a file ("Open with" → %f): that file is readable+ gtk fwgtkopen "%f" "$HOME/fwlinux-open/note.txt"+ PID=$(pgrep -u "$U" -n -x gtk4-print-edit)+ grep -E "fwlinux-open/note.txt.*= [0-9]+$" "$TR" >/dev/null && ok "it opens the file passed by Open with" || bad "the passed file was not opened: $(grep note.txt "$TR" | head -1)"+ [ -n "$PID" ] && kill "$PID" 2>/dev/null+ rm -f "$APPS/fwgtkdoc.desktop" "$APPS/fwgtkopen.desktop" "$TR"+fi+rm -f "$APPS/fwprobe.desktop" "$APPS/fwgtk.desktop" ~/Documents/fwlinux-secret.txt "$OUT"+rm -rf ~/fwlinux-open ~/.config/fwprobe ~/.cache/fwprobe+fwlinux_donediff --git a/server/tests/fwlinux/files_probe.py b/server/tests/fwlinux/files_probe.pynew file mode 100755index 0000000..b0bf5d8--- /dev/null+++ b/server/tests/fwlinux/files_probe.py@@ -0,0 +1,33 @@+#!/usr/bin/python3+# files_probe.py — stand-in app for tests/fwlinux/files.sh: launched by the real launcher+# (build/launch-cli) through a .desktop, it tries what a restricted app should and shouldn't be+# able to do and writes the results as JSON to /tmp/fwlinux-files-<uid>.json.+import json, os, sys+home = os.environ["HOME"]+res = {}+def t(name, fn):+ try:+ fn(); res[name] = "ok"+ except OSError as e:+ res[name] = os.strerror(e.errno) if e.errno else str(e)+def rd(p): open(p, "rb").read(1)+def wr(p): open(p, "ab").close()+def ls(p): os.listdir(p)+t("read_documents", lambda: rd(home + "/Documents/fwlinux-secret.txt"))+t("list_documents", lambda: ls(home + "/Documents"))+t("list_home", lambda: ls(home))+t("read_firewall_json", lambda: rd(home + "/.config/lordos/firewall.json"))+t("write_autostart", lambda: wr(home + "/.config/autostart/fwlinux.desktop"))+t("read_ssh", lambda: ls(home + "/.ssh"))+t("read_system", lambda: rd("/usr/share/applications/" + sorted(os.listdir("/usr/share/applications"))[0]))+t("write_tmp", lambda: wr("/tmp/fwlinux-probe-tmp"))+t("write_own_config", lambda: wr(home + "/.config/fwprobe/settings.ini"))+t("write_own_cache", lambda: wr(home + "/.cache/fwprobe/cache.bin"))+t("rename_in_own_config", lambda: (wr(home + "/.config/fwprobe/a.tmp"), os.rename(home + "/.config/fwprobe/a.tmp", home + "/.config/fwprobe/a")))+t("read_desktop_files", lambda: ls(home + "/.local/share/applications"))+t("write_runtime_dir", lambda: wr(os.environ.get("XDG_RUNTIME_DIR", "/run/user/%d" % os.getuid()) + "/fwlinux-probe"))+if len(sys.argv) > 1:+ t("read_opened_file", lambda: rd(sys.argv[1]))+ t("write_opened_file", lambda: wr(sys.argv[1]))+ t("read_next_to_opened", lambda: rd(os.path.join(os.path.dirname(sys.argv[1]), "fwlinux-sibling.txt")))+json.dump(res, open("/tmp/fwlinux-files-%d.json" % os.getuid(), "w"))diff --git a/server/tests/launch_cli.c b/server/tests/launch_cli.cnew file mode 100644index 0000000..76d8fe3--- /dev/null+++ b/server/tests/launch_cli.c@@ -0,0 +1,41 @@+/* launch_cli.c — the Linux app launcher (src/apps.c) outside the desktop, for the end-to-end+ * tests of the firewall's "no access to your files" (tests/fwlinux/files.sh).+ *+ * build/launch-cli <desktop id> [file]+ *+ * Reads ~/.config/lordos/firewall.json into the same store lord.fw uses (sec/restrict.h) and+ * calls apps_launch / apps_launch_with: the real launcher code, Landlock plan included. Outside+ * a session the app stays in the caller's cgroup (the cgroup service only places lord-server's+ * own binaries). A test tool: never installed. */+#include "apps.h"+#include "fsops.h"+#include "fw/rules.h"+#include "sec/broker.h"+#include "sec/perms.h"+#include "sec/restrict.h"++#include <stdio.h>+#include <limits.h>+#include <stdlib.h>++/* restrict.c's other users (the broker, the permission store) aren't part of this tool */+void brokersrv_revoke(const char *app, const char *perm) { (void)app; (void)perm; }+PermState perm_get(const char *app_id, Perm p) { (void)app_id; (void)p; return PERM_ASK; }++int main(int argc, char **argv) {+ if (argc < 2 || argc > 3) { fprintf(stderr, "usage: launch-cli <desktop id> [file]\n"); return 2; }+ const char *home = getenv("HOME");+ char path[4096], err[200] = "";+ snprintf(path, sizeof path, "%s/.config/lordos/firewall.json", home ? home : "/nonexistent");+ FwStore *s = fw_store_new();+ if (!s || fw_load(s, path, err, sizeof err) < 0) fprintf(stderr, "launch-cli: %s: %s (no restrictions)\n", path, err);+ restrict_set_store(s);+ char real[4096];+ const char *user = getenv("USER");+ if (home && realpath(home, real)) fsops_init(real, user ? user : ""); /* the roots "Open with" accepts */+ const DesktopApp *list;+ apps_list("en", &list);+ int r = argc == 3 ? apps_launch_with(argv[1], argv[2]) : apps_launch(argv[1]);+ printf("launch-cli: %s → %s\n", argv[1], r ? "not launched" : "launched");+ return r ? 1 : 0;+}