From 43088a2316873d6cbfff124c8f2f90a3989fe1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Wed, 15 Jul 2026 14:22:03 +0200 Subject: [PATCH] Add nas.js logic layer (command builders + parsers) Injection-safe sh -c wrapper (static script + positional args), KWallet password flow into a 0600 cred file for mount, smbclient/-g share parsing, findmnt mounted-state parsing, and the pkexec helper invocations. Co-Authored-By: Claude Opus 4.8 (1M context) --- package/contents/code/nas.js | 181 +++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 package/contents/code/nas.js diff --git a/package/contents/code/nas.js b/package/contents/code/nas.js new file mode 100644 index 0000000..23b4350 --- /dev/null +++ b/package/contents/code/nas.js @@ -0,0 +1,181 @@ +/* + * nas.js — command builders + output parsers for the Synology NAS plasmoid. + * + * These functions are pure: they build shell command strings and parse the + * text those commands produce. The QML layer owns a Plasma5Support executable + * DataSource and actually runs them. + * + * Security model: + * - The plasma5support "executable" engine does NOT use a shell; it tokenises + * with KShell and runs the program directly. So every command is wrapped as + * `sh -c '' _ ...`. The script text is constant + * (no interpolation) and all dynamic, possibly-hostile values arrive as + * positional parameters ($1, $2, ...). This makes shell injection via a + * share/host/user name impossible. + * - Passwords live in KWallet. On mount we read the password *inside* the + * shell straight into a 0600 credentials file — it never appears in QML, + * in argv, or in `ps`. (The one exception is the initial save in the config + * page, where the freshly-typed password is handed to kwallet-query.) + */ + +// KWallet folder + wallet used for all stored NAS passwords. +var WALLET = "kdewallet"; +var WALLET_FOLDER = "Synology NAS"; +var HELPER = "/usr/lib/synology-nas/helper"; + +// POSIX single-quote escaping: wrap in '...' and replace ' with '\''. +function sq(s) { + return "'" + String(s).replace(/'/g, "'\\''") + "'"; +} + +// Build `sh -c '