- kurgan/hw/install.py (run elevated by setup.ps1): checks the base
interpreter can run hw_service.py, creates %ProgramData%\Kurgan or resets
its owner and access (Administrators own it; SYSTEM and Administrators full
control, users read), moves the fan and RAM settings there, then creates or
updates KurganHw through the service manager API (pywin32; sc.exe's quoting
from Windows PowerShell 5.1 isn't reliable): LocalSystem, automatic start,
restart after 5 s, 10 s and 60 s, the user's SID for the pipe. A running
service is stopped first; then it's started and must reach "running".
- kurgan/hw/migrate.py: "copy" (elevated) creates hw-settings.json from the
user's cooling and lighting.memory, never overwriting an existing file;
"strip" (as the user) removes them from settings.json once hw-settings.json
exists, keeping a dated backup. An invalid file on either side stops it.
- setup.ps1: creates the .venv if needed (the service runs from it), passes
the base interpreter, the user's SID and settings path to the elevated part,
which installs the service; then strips settings.json, registers and starts
the app's task, and prints the service's status.
- uninstall.ps1: also stops and deletes the service.
- python -m kurgan.hw.client prints the service's status (setup runs it).
- The pipe's "isn't running", "refused this user" and "closed the
connection" errors no longer repeat the Windows error text.
- Tests: migration (move, re-run, defaults, invalid files) and the install
module's parts that don't need admin rights.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- kurgan/hw/pipe.py, ctypes with overlapped I/O and timeouts throughout.
- Server: each connection on its own thread (the fan loop never waits on a
client); up to 8 at once. A client that sends nothing, or leaves a line
unfinished, for 30 s is dropped, and so is one that won't read its replies
(5 s write timeout). An oversized line gets a too_large reply, then the
connection closes. Remote clients are rejected.
- Access list (pipe_sddl): SYSTEM and Administrators full, the installing
user's SID FILE_GENERIC_READ | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES, and
nobody else. GENERIC_WRITE is avoided because for a pipe it includes
FILE_CREATE_PIPE_INSTANCE, which would let the user's other programs add an
instance and answer in the service's name. The first instance uses
FILE_FLAG_FIRST_PIPE_INSTANCE, so a squatter makes the service fail loudly.
- Client: identification-level impersonation only, and it refuses a pipe
whose owner isn't SYSTEM or Administrators (one an unelevated program
created while the service was down). Clear errors for "not running" and
"refused this user".
- Tests: 11 new, against real pipes: round trip, several clients at once,
silent and trickling clients dropped without affecting others, oversized
lines, prompt shutdown, owner check, and (unelevated) a user missing from
the access list is refused and the user can't add a pipe instance.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>