Documentation
¶
Overview ¶
Package unattended gives the Windows service (`remohop service install --unattended`) the interactive console session: its screen, including the sign-in screen, the lock screen and UAC prompts on the secure desktop, and its keyboard and mouse.
A Windows service runs as LocalSystem in session 0, which has no display. The service therefore stays the network endpoint and does the encoding, and for anything that needs the desktop it starts a helper process: the same remohop binary (`remohop service session-helper`), with a copy of the service's own token moved into the console session, started on winsta0\Winlogon. The helper's capture and input threads attach to whichever desktop currently receives input (Default, Winlogon, the screen saver) before every operation, so they follow the user from the desktop to the lock screen to a UAC prompt and back. As LocalSystem on the input desktop its SendInput is not filtered by UIPI, and GDI capture works on the secure desktop where the Desktop Duplication API and ffmpeg's grabbers do not reach.
Service and helper talk over a named pipe the helper creates for its launch only: a random name, an access list that admits LocalSystem alone, remote clients rejected. Each end checks the process ID of the other (the helper accepts only the service that started it; the service only the helper it started) and both prove knowledge of a per-launch secret, which the service hands the helper through an inherited anonymous pipe (its standard input), never on the command line. The helper refuses to run unless it is LocalSystem, so nobody else can start one usefully.
The service follows the console session: when the user logs off, another user takes over through fast user switching, or a remote desktop connection moves the session away from the console, the helper of the old session is ended and the next request starts one in the new console session. Helpers are started on demand and end when idle.
Ctrl+Alt+Del is raised by the service itself with SendSAS, which Windows allows only when the SoftwareSASGeneration policy permits services.
Index ¶
- Constants
- Variables
- func Active() bool
- func ConsoleSession() (uint32, bool)
- func DesktopKind(name string) string
- func Enable(io.Writer) (func(), error)
- func RestoreSAS(SASChange) error
- func RunHelper(context.Context, io.Reader, io.Writer) error
- func RunInConsole(context.Context, string, []string) ([]byte, error)
- func SASAvailable() (bool, string)
- func SASPolicyAllows() bool
- type CaptureStats
- type ConsoleProcess
- type SASChange
Constants ¶
const SASPolicyHint = `Windows lets services send Ctrl+Alt+Del only if the policy "Disable or enable software Secure Attention Sequence" ` +
`is Enabled for Services: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, SoftwareSASGeneration=1`
SASPolicyHint says how to allow the service to send Ctrl+Alt+Del (kept short: viewers show at most 300 characters of a reason).
const SessionEnv = "REMOHOP_UNATTENDED_SESSION"
SessionEnv selects which session the service shows: "console" (the default) is the physical console, whatever is on it (a user's desktop or the sign-in screen); "active" prefers a session with a user logged in, the console's if it has one, else a remote desktop session.
Variables ¶
var ErrNotActive = errWindowsOnly
ErrNotActive is returned when the process is not a service with unattended access.
var ErrStreamClosed = errors.New("unattended: the stream was closed")
ErrStreamClosed is what Stream.Copy returns once the service closed the stream itself.
Functions ¶
func Active ¶
func Active() bool
Active reports whether this process is the Windows service with unattended access enabled; never on this system.
func ConsoleSession ¶
ConsoleSession: there is no console session to start programs in here.
func DesktopKind ¶
DesktopKind describes a desktop name for people.
func RunInConsole ¶
RunInConsole is only available on Windows.
func SASAvailable ¶
SASAvailable reports that Ctrl+Alt+Del cannot be raised here.
func SASPolicyAllows ¶
func SASPolicyAllows() bool
SASPolicyAllows reports that no policy lets anything raise Ctrl+Alt+Del here.
Types ¶
type CaptureStats ¶
type CaptureStats struct {
Window float64 `json:"window_s"`
// Loops is capture attempts; Frames changed frames sent, Same
// unchanged ones, Fails failed captures.
Loops int `json:"loops"`
Frames int `json:"frames"`
Same int `json:"same"`
Fails int `json:"fails"`
// GrabMS is the average capture (BitBlt and copy), GrabMaxMS the
// longest; CmpMS the average comparison with the previous frame;
// WriteMS the average write of a changed frame to the pipe (long when
// the service is behind).
GrabMS float64 `json:"grab_ms"`
GrabMaxMS float64 `json:"grab_max_ms"`
CmpMS float64 `json:"cmp_ms"`
WriteMS float64 `json:"write_ms"`
// Dropped is set by the service: frames and repeats it did not write
// to ffmpeg because a newer one came first (ffmpeg was behind).
Dropped int `json:"dropped,omitempty"`
// Service side: reading a changed frame from the pipe (IPCMS) and
// writing a frame into ffmpeg (FeedMS), on average.
IPCMS float64 `json:"ipc_ms,omitempty"`
FeedMS float64 `json:"feed_ms,omitempty"`
}
CaptureStats are the console-session helper's capture timings over a stretch of a stream (Window seconds), with the service's side of the pipe: where the time of a frame goes before ffmpeg has it. The service logs them; a GDI capture that cannot keep up shows as GrabMS near the frame period.
type ConsoleProcess ¶
type ConsoleProcess struct {
Stdin io.WriteCloser
Stdout, Stderr io.ReadCloser
}
ConsoleProcess is a program started in the console session; never here.
func StartInConsole ¶
StartInConsole is only available on Windows.
type SASChange ¶
type SASChange struct {
// Prev is the value before, HadPrev whether there was one.
Prev uint32 `json:"prev"`
HadPrev bool `json:"had_prev"`
// Set is the value AllowSAS wrote.
Set uint32 `json:"set"`
}
SASChange is what AllowSAS changed in the SoftwareSASGeneration policy, kept by the desktop app's administrator step so that turning unattended access off can put it back (RestoreSAS).