feat: add experimental standalone SMB service for Finder

This commit is contained in:
Meghdad committed 2026-10-16 15:09:41 +03:30
1 parent c9006c11dd
commit b9cb187f0d
55 files changed
+7961 -10

No files matched your search

+6 -1
View File
@@ -1,10 +1,11 @@
# Architecture
RouterShelf has four operational layers:
RouterShelf has independent web and SMB service executables within these operational layers:
| Layer | Responsibility | Repository location |
| --- | --- | --- |
| Go application | Safe directory reads, HTTP responses, TLS and ACME, connection limits, privilege drop | `cmd/routershelf` |
| Private SMB application | Independent account/config, selected root, signed SMB, write policy and privilege drop | `cmd/routershelf-smb`, `internal/smbwire` |
| Embedded theme | NAIS styling, favicon, copied links, playlist generation | `internal/theme` |
| Router lifecycle | USB checks, process restart, time startup, host firewall hooks, flash persistence | `deploy/padavan` |
| Network gateway | Public DNS destination, destination NAT, LAN hairpin reply routing | Configuration documented in `docs/getting-started.md` |
@@ -28,3 +29,7 @@ The legacy dashboard is a separate Netcat/shell example, with its own configurat
The Go module path is currently `routershelf`, a local standalone module identity. If a real repository remote is established later, change the module path and the `routershelf/internal/theme` import together if a hosted module path is desired. No remote namespace is assumed.
Read [setup](getting-started.md), [operations](operations.md), and [security](../SECURITY.md) for configuration and maintenance boundaries.
## Independent private SMB path
`Finder -> specific private IPv4 SMB listener -> os.Root selected private USB folder`. This path needs no web server, certificates, NTP startup or gateway NAT. The SMB supervisor uses its own JSON path, executable, process tree and `/tmp/routershelf-smb/` lock. It never sources the web environment, changes firewall rules or signals the web service. The web binary does not import SMB code. Both may access USB storage, so resource pressure and deliberately overlapping data remain shared operational risks. See [SMB setup and lifecycle](smb.md) and [implementation decision](smb-implementation.md).
+2
View File
@@ -1,5 +1,7 @@
# Environment configuration
This guide describes the web service. The independent SMB service uses private JSON and `RS_SMB_CONFIG`; its supervisor also accepts `RS_SMB_BINARY`. Neither reads the web settings. See the [SMB configuration reference](smb.md#configuration-reference).
Network-specific settings live in a private `.env` file. The public `.env.example` contains only illustrative values. Changing a domain, subnet, USB mount, or port does not require editing Go or shell source and does not require rebuilding the application.
## Loading and precedence
+6
View File
@@ -78,3 +78,9 @@ Validated: example and live config checks, invalid-port rejection, Go environmen
The application now renders a directory's readable regular `index.html` before listing it, and serves direct HTML requests inline. Recognized CSS/JavaScript/image/font assets have explicit MIME types. Other files retain attachment downloads. No separate root or URL prefix, new env settings, or gateway rules were added.
The binary was deployed with the previous version kept for rollback. Tests covered folder/root index precedence, direct HTML and assets, HEAD, preserved downloads, listing link attributes, and an escaping index symlink. A temporary live page rendered over HTTPS with CSS and JavaScript; its direct HTML link rendered too. HEAD confirmed HTML without attachment disposition, a normal text file still had attachment disposition, and PUT remained 405. Temporary probe files were removed after testing. Static pages intentionally permit browser-side active content; no PHP/CGI/server-side execution was added.
## 10. Optional SMB repository implementation (2026-10-16)
A separate experimental SMB executable, private JSON configuration, source-confined protocol implementation, independent supervisor, templates and guides were added to the repository. Existing web implementation/configuration and installed paths remain unchanged. Local protocol/race/fuzz checks, native macOS SMB operations and actual Finder browsing/copy/rename/metadata sample checks passed; both static MIPS builds compile. See the detailed [SMB validation record](smb-validation.md).
Router access for this change was read-only inspection of kernel, RAM, BusyBox, SMB command/listener availability and exFAT mount behavior. No SMB binary was deployed or executed there. Target kernel/resource/exFAT/Finder/coexistence/boot/rollback validation requires a separately approved session.
+3
View File
@@ -1,5 +1,8 @@
# Deploy the public HTTPS directory service
For authenticated Finder access without web setup, follow the independent [SMB installation guide](smb.md). This page installs the public web service.
## Architecture and paths
```text
+3
View File
@@ -1,5 +1,8 @@
# Maintenance and recovery
This page covers the existing web installation. SMB has separate [status, update, rollback and removal procedures](smb.md#install-status-update-and-remove); stopping or updating one service does not operate the other.
## Routine care
| Frequency / event | Check |
+29
View File
@@ -0,0 +1,29 @@
# SMB implementation decision
RouterShelf retains its MIT project license and one repository. A second Go executable embeds a narrowly adapted Apache-2.0 SMB implementation; it has no web package imports, certificate logic, public NAT or shared lifecycle. The web executable does not import SMB. Their configuration files, process trees, installed names and runtime directories are separate. SMB uses size-bounded, strictly typed JSON rather than shell configuration: share policy and password-equivalent hashes stay out of environment/argument values, configuration is never executed, and the only application environment input is the independent `RS_SMB_CONFIG` path. The existing web environment contract remains compatible.
## Candidates investigated
| Candidate | Suitability for this initial target |
| --- | --- |
| [Samba](https://www.samba.org/samba/docs/current/man-html/smbd.8.html) | Established implementation with mature authentication, locking and Mac integration. A preferred comparison baseline. A reproducible, maintained static MIPS build with its required dependencies, Linux 3.4 support, exFAT policy and measured combined memory footprint was not established here. Shipping a guessed firmware binary or requiring package installation would not meet this task. GPL obligations would also need a complete corresponding-source distribution plan if bundled. It remains a possible future backend after those checks. |
| [ksmbd](https://www.kernel.org/doc/html/latest/filesystems/smb/ksmbd.html) | Kernel SMB implementation plus userspace utilities, rather than an independent static userspace service for the unmodified 3.4 kernel. Introducing a kernel component is outside this device's constraints. |
| [macos-fuse-t/go-smb2](https://github.com/macos-fuse-t/go-smb2) | Mac-oriented implementation, dual AGPL/commercial licensed. Upstream explicitly identifies authentication, impersonation, parallel connections and locking as early or incomplete. Those are central requirements here; it was not chosen. |
| [go-filesystems/smb](https://github.com/go-filesystems/smb) | Pure Go, BSD-3-Clause, filesystem abstraction with authentication and signing. Young project; would require a separately verified host-filesystem driver and bounded positional I/O throughout. Not integrated during this change. |
| [softwarity/smbserver v0.1.1](https://github.com/softwarity/smbserver/tree/v0.1.1) | Chosen as an experimental implementation base: pure Go, existing pinned x/crypto dependency, os.Root, NTLMv2, required signing, source filtering, read-only mode, real-socket/fuzz tests and reported native-client CI. One user/share scope is explicit. Upstream defaults and ephemeral metadata are inappropriate for this router, so a local source adaptation is maintained with its license and provenance. Upstream CI claims are not RouterShelf validation. |
This choice favors a locally buildable executable with inspectable policy over introducing deployment dependencies. It does **not** establish production readiness or substitute for a security audit. SMB is a large protocol; the young backend and local modifications need continued maintenance, fuzzing, independent review and real-client coverage. See [upstream adaptation inventory](../internal/smbwire/UPSTREAM.md).
## Resource and persistence decisions
The binary targets Go 1.26, Linux/MIPS LE soft-float, CGO disabled. Kernel availability, RSS, throughput, CPU impact on routing, disk failure behavior and boot recovery must be measured on the actual router after approval. No performance estimate is inferred from desktop tests or upstream benchmarks.
Protocol allocations are bounded by request size, connections and handles, not file length. Fixed low limits and a 20 MiB GC target leave room for testing alongside the web service, but cannot guarantee a combined hard quota. Exceeding directory limits returns an error rather than silently omitting names. Server-local sharing checks and byte-range locks protect cooperating SMB clients; external writers bypass those checks. SMB2 packet signing is mandatory, but there is no SMB encryption, so network privacy remains a LAN/VPN responsibility.
exFAT metadata is represented by ordinary disk sidecars where supported by the client, not acknowledged into temporary RAM streams. Do not promise persistent ACLs, Finder tags, resource-fork compatibility, Time Machine or application-specific safe saving until those paths are verified. Close/flush/write-through failures are reported. Transfer interruption and power loss still require file verification and backups; this is not an atomic upload API.
## Maintenance and distribution
Keep upstream source provenance, retained tests and Apache license together; review both upstream fixes and local policy changes when upgrading. Protocol source is embedded under `internal/smbwire`, not fetched at deployment. `go.mod`/`go.sum` remain compatible with the existing web dependencies. Distributors must include the project MIT license, NAIS license where distributing web assets, SMB Apache-2.0 license and Go-module license notices. No binaries have been published by this change.
Never ship real JSON config or NT hashes. Include only `.smb.example.json`, `.env.example`, source, licenses and documentation in public source archives. Generated `dist/` executables are local validation artifacts and must be packaged separately with their notices if a binary release is later authorized. Inspect archive contents; Git ignore rules alone are insufficient.
+56
View File
@@ -0,0 +1,56 @@
# SMB validation record
Recorded 2026-10-16. SMB remains experimental. No SMB executable, configuration or test data was copied to the router, and no router process, firewall, mount, startup hook or routing configuration was changed.
## Actual local checks
Development host: macOS 27.0.1, ARM64, Go 1.26.5. Test data and account credentials were synthetic and temporary; no private web settings were needed.
| Check | Observed result |
| --- | --- |
| `make test` | Shell syntax, unchanged public web sample config validation, seven Python localhost stress-runner tests, web regression tests and SMB Go tests pass |
| `go test -race ./cmd/routershelf-smb ./internal/smbwire` | Pass, including startup/root replacement shutdown, authenticated operations, read-only policy, confinement, locks, sharing, concurrent writes and close/delete errors |
| `make build-mipsle build-smb-mipsle` | Both build with CGO disabled, Linux/MIPS little-endian, soft-float; file inspection reports statically linked ELF32 MIPS binaries. SMB executable is approximately 3.6 MiB; this is disk size, not RSS |
| Protocol fuzzing | Ten seconds, two workers of `FuzzMessage`, 554,883 executions; no failure. This is bounded smoke fuzzing, not exhaustive protocol/security validation |
| Native macOS writable smoke script | Built-in `mount_smbfs`: rejects incorrect password, mounts with correct account, creates folder, uploads, moves/renames, downloads with matching SHA-256, deletes files/folder and unmounts successfully |
| Native macOS read-only smoke script | Reads succeed; incorrect password, write, mkdir, rename and delete refused |
| Actual Finder GUI, localhost | Shows selected share and file, Quick Look displays expected text, creates/names a folder, renames a file, copies a folder into the share and back to local storage |
| Finder copy integrity / metadata sample | 2,228,224-byte synthetic file matches SHA-256 after upload and download; a custom extended attribute survives the round trip using an on-disk `._` AppleDouble sidecar |
| Interrupted protocol transfer | 12 MiB written in 64 KiB chunks, connection closed halfway, a new authenticated connection explicitly reopens and writes remaining offsets; on-disk SHA-256 matches. This tests controlled protocol reconnection, not Finder's automatic resume |
| Concurrent operations | Two clients write disjoint 64 KiB ranges to one file, rename through an open handle, close and verify all bytes; conflicting share modes and byte-range locked I/O/truncation fail |
| Confinement | Traversal, encoded traversal, escaping symlinks, rename escape, nonregular data files and writes outside selected root refused; valid internal links remain usable |
| Service independence | SMB config ignores poisoned web domain/root/mount environment values; starts and stops without web service or TLS config. Web tests/build remain independent and its application/supervisor implementation is unchanged |
| Repository hygiene | Public templates have placeholders only; real JSON/hash files, binaries and diagnostic output are excluded from public source distribution; whitespace and local documentation links checked |
The first native attempt used a 16-credit server window: mount/authentication succeeded but mkdir stalled. The final implementation grants up to 128 credits and subsequent normal native mounts passed. The original temporary mount was detached, the recovery server stopped, and temporary files removed. This failure is why native tests accompany protocol tests. Transfer allocations remain separately bounded by the 64 KiB I/O/frame limits and synchronous request handling.
Native command reproduction (development Mac only):
```sh
go build -o dist/routershelf-smb ./cmd/routershelf-smb
python3 -B scripts/test_smb_macos.py "$PWD/dist/routershelf-smb"
python3 -B scripts/test_smb_macos.py "$PWD/dist/routershelf-smb" --read-only
```
The script contacts localhost only and uses a temporary account/share. Its operation worker and mount commands have deadlines. A kernel filesystem operation may still require manual ejection on a client/kernel bug; inspect only the printed/temporary test volume, never unmount a real share to clean up this test. Do not run it on the router.
## Read-only target inspection
SSH inspection confirmed Linux 3.4.113, MIPS, BusyBox 1.24.2 and 126,280 KiB total RAM. The USB filesystem reports exFAT, read/write, `fmask=0000,dmask=0000` and `errors=remount-ro`. Thus mode bits do not isolate private data on that mount; a storage error may change it to read-only. No `smbd`/`smbpasswd` command was found in the inspected PATH, and no TCP 445/1445 listener appeared at that inspection. This is not a complete firmware binary/service inventory.
These read-only observations confirm constraints, not SMB execution compatibility. Private addresses, mount identifiers, credentials and raw router dumps are deliberately absent from this record.
## Outstanding checks requiring an approved device session
Do not infer these results from compilation or desktop checks:
- Execute the new MIPS binary on Linux 3.4.113 and verify kernel/syscall compatibility, dropped UID/GID and supplementary groups, random source and startup behavior.
- Verify exact USB mount identity, configured selected-root and protected-path checks, exFAT naming/case behavior, disk-full and remount-read-only error reporting, non-root write permissions and metadata sidecar persistence.
- Connect from Finder over the actual LAN and chosen port: registered login, bad password, read-only and writable sharing; folder/file operations, Unicode/case-only renames, packages, tagged/resource-fork files, metadata after restart and application-specific saves. The local custom-attribute sample is not comprehensive Mac metadata validation.
- Transfer large scratch files in both directions with independent checksums; interrupt transfers and service/network connections at bounded points, inspect partial destinations, reconnect and verify safe retry. No automatic native resume or atomic overwrite guarantee is established.
- Coordinate simultaneous client operations with expected locks/share access. Keep other local/FTP/SFTP writers away from the test roots.
- With explicit load bounds and stop criteria, measure resident memory, peak memory, CPU, free space, routing latency and Wi-Fi/SSH health with SMB alone, web alone, and both. Check behavior at connection/handle/directory bounds. A 20 MiB GC target is not a measured memory ceiling.
- Exercise approved USB unavailable/reinsert, supervisor crash/restart, configuration error, binary rollback, independent web/SMB stop/update, host-firewall reload and controlled reboot cases. Do not unplug valuable storage during writes; use backed-up scratch media/data and a deliberate plan.
- Check that allowed private clients connect while guest/WAN/untrusted sources are denied, with no gateway SMB forwarding and no change to web exposure or unrelated rules.
Use [deployment and rollback](smb.md#install-status-update-and-remove). Upload to new names, retain known-good private backups, validate, stop only the verified SMB supervisor, rename into place, restart and verify. Revert the binary/config/script independently if a check fails. No target load, reboot, kernel compatibility, USB loss recovery or production-readiness claim is made by this change.
+140
View File
@@ -0,0 +1,140 @@
# Finder access with RouterShelf SMB
RouterShelf has two independent executables. `routershelf` publishes unauthenticated read-only web content. `routershelf-smb` provides authenticated private storage access through Finder's built-in SMB client. Either works alone. SMB requires no web domain, certificates, web environment file, gateway forwarding, Mac extensions, or additional Mac software.
**Experimental:** local protocol tests and cross-compilation are separate from native-client and hardware validation. See [SMB validation](smb-validation.md) for actual results. Back up valuable data before enabling writes. This release supports one selected directory, one account, and one read-only/read-write policy per instance. It is not a multi-user ACL server, Time Machine target, domain server, or highly available NAS.
## Choose private storage
Use separate sibling directories on USB, for example:
```text
/media/DISK_ID/private-storage/ authenticated SMB files
/media/DISK_ID/public-storage/ deliberately public web files
/media/DISK_ID/.smb-service/ executable and private update backups
/etc/storage/routershelf-smb.json administrator-owned credentials/config
```
Replace `DISK_ID` with your actual mount. Create the selected private directory deliberately while the disk is mounted. The service never creates a missing root or serves the whole mount. Never share `/`, the USB mount itself, a service directory, certificate cache, backup directory, or administrator home. Select one root containing the folders you want available; every descendant, including hidden files, is available to the authenticated account. Symlinks cannot escape that root. On filesystems supporting hard links, an administrator must also exclude hard links to sensitive files.
`public_roots` must list every web root on this storage, especially a customized `RS_ROOT`. The standard `public-storage` sibling is checked automatically. Default private service directories, this executable and the config are excluded; add customized certificate/cache/binary/backup paths to `protected_paths`. These exclusions cannot be overridden by allowing public overlap. Overlap is refused unless `allow_public_overlap` is explicitly true. Separate processes cannot discover arbitrary web installations: listing the actual public roots is the administrator's responsibility. If you deliberately share a web root, **every SMB upload/rename into it may immediately publish the file without web authentication**. Use a private staging directory and move reviewed files into publication deliberately. The web service retains its own existing path filtering and GET/HEAD policy; SMB credentials do not protect web copies.
exFAT has mount-wide ownership/mode behavior, limited Unix metadata and no POSIX ACL isolation. A separate non-root service UID reduces process privilege but does not isolate secrets on a broadly writable exFAT mount. Put credentials on a permission-enforcing administrator-owned filesystem such as `/etc/storage`; do not rely on `chmod` on exFAT. Restrict other disk accounts and local writers separately. Use only one RouterShelf SMB instance per writable root; independent instances and FTP/SFTP/local programs do not share its locks.
## Build and configure
On the development computer, with Go 1.26+:
```sh
make test
make build-smb-mipsle
# For a local desktop executable:
go build -o dist/routershelf-smb ./cmd/routershelf-smb
umask 077
cp .smb.example.json smb.json
chmod 600 smb.json
```
Edit private `smb.json`. The sample intentionally has an unusable hash and placeholder paths. Keep its mode 0600. On macOS use a hidden terminal prompt to generate a password-equivalent NT hash without putting the password in arguments or shell history:
```sh
read -r -s 'smb_password?New unique SMB password (12+ characters): '
printf '\n'
printf '%s' "$smb_password" | ./dist/routershelf-smb -hash-password
unset smb_password
```
Paste the output into `nt_hash` privately. Do not reuse a router/admin password. The hash is as sensitive as the password: anyone holding it can authenticate. Do not put it in issues, screenshots, logs, archives or backups intended for publication. Finder receives the original password; the server verifies NTLMv2 challenge responses using the hash. There is no guest, anonymous or empty-password mode.
For LAN access set `listen` to the router's specific private IPv4 and port 445; put your trusted client subnet(s) in `allow`. `127.0.0.1:1445` and `127.0.0.1/32` are safe local defaults. Start read-only. Set `read_only` to false only after verifying the selected root and backup. Use a dedicated available non-root UID/GID if supported by the mount; the defaults are 65533, distinct from the web service’s 65534; verify that this ID is available on your firmware. Root is used only to read protected config, bind a privileged port and drop supplementary groups/UID/GID before serving files. An already unprivileged process must match both configured IDs and use an available unprivileged port. Do not disable privilege dropping.
Check on the machine with the real paths (the computer cannot validate a router-only USB path):
```sh
./dist/routershelf-smb -config /absolute/private/smb.json -check-config
```
Validation does not listen, write files, change firewall or check password strength from its hash. It requires existing paths and a protected regular config file. On Linux the running service additionally requires `storage_mount` to be an exact `/proc/mounts` mountpoint. On a desktop Mac this mountpoint requirement is omitted for local testing.
## Configuration reference
The only environment setting is `RS_SMB_CONFIG`, the absolute JSON config path. `-config` overrides it; `-check-config` validates and exits. No web `RS_*` setting is consulted, and no shell file is sourced. Unknown JSON fields, extra objects, and configs above 32 KiB are rejected without echoing input. Change configuration by restarting only SMB. Credentials are read once at startup.
| JSON field | Default / contract |
| --- | --- |
| `listen` | `127.0.0.1:1445`; a specific private/loopback IPv4 and numeric port; no wildcard, DNS, public IPv4 or IPv6 |
| `storage_mount` | Required existing absolute USB mount; exact Linux mount presence checked before listening and every two seconds |
| `root` | Required existing directory strictly under that mount; selected explicitly; never created automatically |
| `share` | `Storage`; direct Finder share name; no separators/spaces or reserved `IPC$` |
| `user` | Required single account name; no OS account/password database needed |
| `nt_hash` | Required 32 hex digits; placeholders and empty-password hash refused |
| `read_only` | `true`; refuses data, directory, metadata, rename and delete mutations |
| `allow` | Required explicit private/loopback IPv4 CIDRs; applied before authentication; no unrestricted prefixes |
| `protected_paths` | Additional sensitive paths that must not overlap the share; default service directories and running executable are also excluded |
| `public_roots` | Additional actual public roots; standard `storage_mount/public-storage` always checked |
| `allow_public_overlap` | `false`; deliberate opt-in to overlapping publication |
| `uid`, `gid` | 65533; positive non-root IDs, applied before file service starts |
| `diagnostics` | `false`; opt-in command/status/credit and peer-event logging without filenames or NTLM tokens; use bounded private logs |
| `case_insensitive` | `true` for exFAT; use false for a case-sensitive filesystem |
Paths must be clean and absolute. Root/config symlinks are resolved during validation. Existing inaccessible public-root paths cause validation failure. Private config cannot reside inside the share. The web `.env.example`, deployed binary name, environment precedence and `/tmp/public-share-*` paths remain unchanged.
## Finder
With SMB running, in Finder choose **Go → Connect to Server** (⌘K):
```text
smb://ROUTER_LAN_IP/Storage
```
Replace `ROUTER_LAN_IP`; do not type that placeholder literally. For an explicitly configured high port, use `smb://ROUTER_LAN_IP:1445/Storage`. Enter the configured account and original password as a registered user. Use the complete share URL: automatic network discovery and browsing a server's share list are not implemented. Save to Keychain only on a trusted Mac. Eject the share before service updates or removing USB storage.
Browse/open/download in either mode. With writes enabled you can upload, create folders, rename, move within the share and delete. Moving across shares/filesystems is a client copy then deletion and is not atomic. Deletions are permanent; this service has no recycle bin or snapshots. Finder may keep cached views until refresh/reconnect. After a password change, eject and replace stale Keychain credentials.
## Privacy and filesystem behavior
SMB2.0.2/2.1 (SMB3.0 fallback) uses NTLMv2 and mandatory packet signing. **Signing does not encrypt filenames or contents.** Use a trusted isolated LAN, or an independently secured VPN for access from elsewhere. Never forward TCP 445/1445, enable a public tunnel, add SMB to the web NAT plan, or reuse the web service's public firewall allowance. SMB binds IPv4 only and checks peer source prefixes; a source-masquerading proxy can defeat source-based distinctions, so also keep gateway and host firewall exposure private.
The service changes no firewall rules. If existing firewall policy blocks LAN SMB, an administrator must allow only the chosen IPv4/interface/client subnet and service port, with an explicit drop for other sources to that port. Use a separately owned SMB chain/hook, preserve SSH and unrelated rules, and test denied guest/WAN sources. Do not flush tables or permit SMB through the existing public web chain. If firmware already listens on 445, leave it alone and select a high port for this initial service. Firewall/persistence changes need separate deployment approval and firmware-specific review.
The exFAT profile advertises case-insensitive, case-preserving names. There are no persistent named streams or ACLs. Per-file read-only/locked mode changes are refused rather than acknowledged on a mount that may ignore them; use the share’s `read_only` policy. Finder can create `._filename` AppleDouble sidecars and `.DS_Store` files on disk; retain these with their files if metadata matters. Some applications may require streams, ACLs, resource forks or Apple extensions that this profile cannot provide. Unsupported requests return errors; no metadata is acknowledged into volatile streams. Finder tags, resource-fork round trips, packages and application-specific saves still require native testing. Do not clean sidecars automatically. Files visible through SMB include dotfiles; the web service still filters them.
Writes use bounded 64 KiB chunks, not whole-file memory. Four connections, 64 total handles, eight compound commands and 1,024 entries per scanned directory bound work. Larger directories return a resource error, rather than an incomplete successful listing; divide large collections into folders. Authentication has a 30-second per-frame deadline and authenticated reads a five-minute idle deadline; reconnect idle clients as needed. The Go memory target is 20 MiB, **not a hard quota**. Protocol state, filesystem caches, firmware and the web process need additional RAM; target resource measurements remain required before enabling both under load.
SMB share access checks and byte-range locks coordinate clients of this instance; unlocked applications may still overwrite each other by design. Writes acknowledge OS writes, honor write-through, and synchronize writable handles on explicit close/flush; errors are returned. OS/device caching, exFAT and power failure can still lose data. A network cut may leave a partial destination file or an uncertain last write; it is not a transaction and does not roll back an overwrite. Keep the source, retry to a distinct temporary name, compare length/checksum and then rename into place. No durable handles, transactional uploads, crash recovery, or automatic resume are promised. Never unplug a disk during writes; back up and check it after an unsafe disconnect.
The executable closes sessions and exits when the root identity or mount disappears/changes (poll interval two seconds). It retains an `os.Root` descriptor rather than falling back to a RAM directory. A kernel/device I/O hang can delay shutdown; do not force router reboots or kill unrelated services as an automatic recovery action. The supervisor retries after ten seconds; it never initializes a missing disk. Finder may reconnect by path; failed copies must still be verified and retried.
## Install, status, update and remove
These are procedures for an approved deployment, **not actions performed by the repository implementation**. First inspect firmware USB/startup hooks, current port listeners, mount ownership/free space, available UID/GID and firewall policy read-only. Do not stop firmware Samba or any web process. Build the static Linux/MIPS little-endian soft-float executable; no router compiler/runtime/library/package installation is needed. Cross-compilation alone does not prove Linux 3.4 compatibility.
1. Back up USB data, and the existing SMB binary/config/script privately if present. Eject any connected Finder share. Keep binaries/backups outside both shared roots.
2. Upload the binary using SCP to a new filename such as `routershelf-smb.new` in the private service directory. Upload config to a new protected file on permission-enforcing storage, and the supervisor to a new filename. Inspect permissions and checksums. Do not overwrite a running binary in place.
3. Validate the new binary with `-config /absolute/private/routershelf-smb.json.new -check-config` on the router. This only reads configuration and paths. Run target smoke/Finder checks only with approval. Preserve the previous names privately, then rename the validated files into their installed paths on their respective filesystems.
4. For foreground startup, export `RS_SMB_BINARY` (absolute installed executable) and `RS_SMB_CONFIG` (absolute private JSON), then run `sh /absolute/path/routershelf-smb-service.sh`, installed from `deploy/padavan/smb-supervisor.example.sh`. It needs neither web supervisor nor web environment. Observe the ready/error message; logs can contain private diagnostics, so do not publish them. For background operation route output to an existing bounded private firmware log facility (for example BusyBox `logger`), not an unbounded RAM log.
5. Only after successful manual checks, add a separate invocation with those two variables to the verified USB-aware hook. Do not replace existing web, Wi-Fi, NTP or SSH hooks. Save changed `/etc/storage` config/scripts/hooks using the firmware's normal persistence action only when needed; USB binary updates alone do not require a flash save. Full reboot behavior remains a target check.
The supervisor owns `/tmp/routershelf-smb/` exclusively; `supervisor.pid` and `child.pid` are diagnostic, never authorization to signal a process. Inspect `/proc/PID/cmdline` before sending SIGTERM to the supervisor. It signals/waits only for the child it launched and removes its runtime lock. Wait for cleanup before starting one replacement. After a crash or SIGKILL a stale lock refuses startup; verify both processes are gone, then remove only the stale SMB runtime files/directory. Do not remove live lock directories or web PID files.
For status check the verified supervisor/child command lines, UID/GID and `VmRSS` in `/proc/PID/status`, exact mount, free space and logs, then try Finder login and a read. A PID is not a readiness guarantee; a waiting supervisor may have no child while storage/config is unavailable. Do not include full config, hash, private filenames or raw logs in a public support request.
For updates, stop only the verified SMB supervisor and wait for child cleanup, rename a checked new binary/config into place, restart only SMB and verify login/file checks. To roll back, stop SMB, restore the known-good private binary/config/script, restart it and check again. Keep the same data root and data; binary rollback cannot undo deleted/overwritten files. Restore user data from backup separately if necessary. The certificate cache and web service need no change.
For removal, eject Finder shares, remove only the SMB hook invocation, stop the verified SMB supervisor, wait for child/lock cleanup, remove its executable/config/script and any separately owned SMB firewall rules. Save flash once if persistent hooks/config changed. Keep USB data and private backups until intentionally retired. Web installation paths, startup, NAT, certificates and sharing continue independently.
## Troubleshooting
| Symptom | Check |
| --- | --- |
| Cannot connect | Exact private IPv4, port, complete share URL, USB availability, matching `allow`, narrow host firewall policy, another listener on 445 |
| Login fails | Registered user, original password, correct NT hash, stale Keychain entry; no guest mode |
| Read works but upload fails | `read_only`, disk full/read-only mount, UID/GID mount permissions, directory entry/handle/lock limits |
| Config validation fails | Protected regular file, absolute existing paths, replaced hash placeholder, unknown fields, public overlap |
| Supervisor runs without child | Missing executable/config/storage or repeated startup errors; inspect private diagnostics |
| Finder metadata/app save fails | No native streams/ACLs/AAPL/leases; keep sidecars; test that application on a scratch share |
| Copy interrupted | Retain source, reconnect, inspect partial destination, retry under a distinct name and verify checksum |
| Directory fails to list | More than 1,024 entries, exhausted handles, storage I/O error; split folders, close extra clients and check disk |
| Memory pressure/routing lag | Stop SMB first, preserve web/routing, inspect actual RSS and firmware memory; reduce client activity and avoid simultaneous large workloads |
Read [implementation decision](smb-implementation.md), [security boundaries](../SECURITY.md), and [validation record](smb-validation.md) before distributing or deploying.