1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! The elevated path's program gate, beside the batch gate: the program must be a fully
//! qualified `.exe`/`.com` path with no `"` or `%` in it, and the directory must hold no `%`.
//!
//! The launch is `ShellExecuteEx` with `SEE_MASK_CLASSNAME` and `lpClass = "exefile"`, which runs
//! `HKCR\exefile\shell\runas\command` (`"%1" %*`) on `lpFile`: the class branch returns before
//! shell32's lookup and rewrites (Wine `shlexec.c` `SHELL_execute`, `:1790-1802`).
//!
//! What is measured (`tests/windows_shell_execute.rs`, x64 and arm64 runners) is an ELEVATED
//! caller's `exefile` launch: it consults no App Paths registration, finds nothing by a bare name,
//! and takes a `%` in `lpFile` or `lpDirectory` literally. The production route is different: cosca
//! calls `ShellExecuteEx` only when the caller is NOT elevated, and that launch goes through the
//! consent service. That route is unmeasured, so every rule here is conservative until it is: a
//! fully qualified path leaves no lookup to make, an `.exe`/`.com` name leaves no extensionless
//! name for `PATHEXT` to complete, and a `%` is refused rather than trusted to stay literal.
//! Whether `PATHEXT` applies to a name already ending in `.exe` is unmeasured on every route (see
//! [`crate::resolve::reject_unloadable_image`]). The rewrites shell32 makes without a class —
//! quotes stripped, a `file:` URL decoded, `shell:`, `::{CLSID}`, `www`, `%VAR%` — are refused by
//! the same rules, since none of those spellings is a fully qualified image path free of `"` and
//! `%`.
use Path;
use crateError;
/// Refuse an elevated program unless it is a fully qualified `.exe`/`.com` path with no `"` or `%`:
/// [`reject_quote`], [`crate::resolve::reject_unloadable_image`], [`reject_percent`] and
/// [`reject_not_fully_qualified`], in that order.
pub
/// Refuse an elevated `current_dir()` holding a `%`, for [`reject_percent`]'s reason.
pub
/// Refuse a `%` in `path`, conservatively: shell32 expands `%VAR%` in `lpFile` and `lpDirectory`
/// on a launch without a class, and whether the consent launch cosca makes does is unmeasured. An
/// elevated caller's `exefile` launch takes it literally (measured), but cosca never makes that
/// launch. The string is refused before any search, so `InvalidInput`.
/// Refuse a program holding a `"`, a deliberate over-refusal: no Win32 file name contains one, and
/// in `exefile`'s `"%1" %*` command it would close the quote around `%1` early, so the command line
/// `CreateProcessW` parses names a file other than the one checked.
/// Refuse an elevated program that is not fully qualified: a drive and a root (`C:\`), or a UNC,
/// verbatim or device prefix (`\\server\share`, `\\?\`, `\\.\`). A relative or bare name
/// leaves ShellExecuteEx a lookup to make — App Paths, `lpDirectory`, `PATH` — and whether the consent launch makes one is
/// unmeasured; an elevated caller's `exefile` launch finds nothing by a bare name (measured). A
/// drive-relative (`C:x.exe`) or rooted (`\x.exe`) token would be resolved against a current
/// directory, so it is refused too.