Skip to content

Commit 7349063

Browse files
committed
fix(cli): name the check that refused, and a remedy that can remove it
A reporter brought a full ProcMon trace to DeusData#1856 and still could not say which check refused their install. That is not their failing: the binary discards the answer before printing it. cli_activation_production_context_init() validates the cache, rendezvous and log directories -- it is the emitter MOST likely to hold a useful detail -- and it printed CLI_ACTIVATION_REFUSED_MESSAGE bare, through the raw sink rather than cli_activation_diagnostic(). So the reader got "Check the errors above" with nothing above. That is the exact dead end DeusData#1416 and DeusData#1537 already fixed; the property was repaired on the paths that had tests and left broken on this sibling, which had none. Route it through the attributing helper: the refusal now names the transaction refusal note or cbm_daemon_ipc_validation_detail(). The remedy was also wrong for the reported shape. `icacls <dir> /remove:g <sid>` cannot remove an INHERITED ACE, and the stock C:\ grant for Authenticated Users reaches every new child directory exactly that way -- so a reporter following our advice watches the command succeed and the refusal persist. The refusal now says whether the ACE was inherited, and the advice names `icacls <dir> /inheritance:r /grant:r "%USERNAME%":(OI)(CI)F` for that case. No safety check is relaxed. An install directory writable by other accounts is still refused; it is now refused in terms the reader can act on. The new contract test guards the CLASS rather than this one call site: any emitter of a refusal constant that bypasses the attributing helper fails it, which is what would have caught this. It fails on the previous tree naming src/cli/cli.c:750, plus the missing inherited-ACE report and the missing /inheritance:r remedy. Local: cli 314 passed; activation_transaction daemon_ipc daemon_bootstrap daemon_version 110 passed, 1 skipped (user namespaces are Linux-only, runs on the Linux leg); make -f Makefile.cbm lint-ci clean. Reported by zaferavci1. Refs DeusData#1856 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent aacf96a commit 7349063

4 files changed

Lines changed: 133 additions & 4 deletions

File tree

‎scripts/test.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ bash "$ROOT/tests/test_soak_daemon_recovery_contract.sh"
215215
echo "=== Step 0e: Windows launcher bundle contract ==="
216216
bash "$ROOT/tests/test_windows_bundle_contract.sh"
217217

218+
echo "=== Step 0e2: activation refusal diagnostic contract ==="
219+
bash "$ROOT/tests/test_activation_diagnostic_contract.sh"
220+
218221
echo "=== Step 0f: tree-sitter runtime Makefile dependencies ==="
219222
bash "$ROOT/tests/test_makefile_ts_runtime_dependencies.sh"
220223

‎src/cli/activation_transaction.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,17 @@ static bool activation_windows_acl_check(HANDLE handle, DWORD tolerated_untruste
712712
if (!trusted) {
713713
char label[128];
714714
LPSTR sid_text = NULL;
715-
(void)snprintf(label, sizeof(label), "acl-grants-cross-account-mutation to %s",
715+
/* #1856: say whether the grant is INHERITED. The remedy differs and
716+
* the wrong one silently does nothing: `icacls <dir> /remove:g <sid>`
717+
* cannot remove an inherited ACE -- that needs `/inheritance:r` --
718+
* and the stock `C:\` ACE for Authenticated Users reaches every new
719+
* child directory exactly this way. A reporter following the
720+
* generic advice sees the command succeed and the refusal persist. */
721+
bool inherited = (header->AceFlags & INHERITED_ACE) != 0;
722+
(void)snprintf(label, sizeof(label), "acl-grants-cross-account-mutation to %s%s",
716723
ConvertSidToStringSidA(sid, &sid_text) && sid_text ? sid_text
717-
: "unparsable-sid");
724+
: "unparsable-sid",
725+
inherited ? " (inherited from a parent directory)" : "");
718726
if (sid_text) {
719727
(void)LocalFree(sid_text);
720728
}

‎src/cli/cli.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ static void cli_activation_diagnostic(const cbm_cli_activation_ops_t *ops, const
240240
"error: activation was refused by a filesystem safety check before any "
241241
"change was made: %s\n"
242242
"error: this is not a session problem. If the flagged directory is one you "
243-
"trust, remove the flagged permission grant (icacls <dir> /remove:g <sid>) "
243+
"trust, remove the flagged permission grant (icacls <dir> /remove:g <sid>; "
244+
"an INHERITED grant needs icacls <dir> /inheritance:r /grant:r "
245+
"\"%%USERNAME%%\":(OI)(CI)F instead, because /remove:g cannot delete one) "
244246
"or use an owner-private directory for --dir/CBM_CACHE_DIR, then retry.",
245247
note);
246248
diagnostic = attributed;
@@ -747,7 +749,15 @@ static int cli_activation_guard(cbm_daemon_runtime_activation_action_t action,
747749
cli_activation_production_context_t context;
748750
if (!cli_activation_production_context_init(&context, action, target_version, target_build)) {
749751
cli_activation_production_context_close(&context);
750-
cli_activation_production_diagnostic(NULL, CLI_ACTIVATION_REFUSED_MESSAGE);
752+
/* #1856: this refusal used to print the generic text BARE. Every other
753+
* emitter routes through cli_activation_diagnostic, which appends the
754+
* transaction refusal note or cbm_daemon_ipc_validation_detail() and so
755+
* names the check that actually refused. Here the reader got "Check the
756+
* errors above" with nothing above -- exactly the dead end #1537/#1416
757+
* fixed on the other paths and missed on this one. Context init is
758+
* where the cache, rendezvous and log directories are validated, so it
759+
* is the emitter MOST likely to hold a detail worth showing. */
760+
cli_activation_diagnostic(NULL, CLI_ACTIVATION_REFUSED_MESSAGE);
751761
return CLI_TRUE;
752762
}
753763
printf("Stopping active CBM sessions and operations for %s...\n",
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
# Activation-refusal diagnostics must never point at evidence they do not show.
3+
#
4+
# #1416 and #1537 both landed because a refusal printed generic text and told
5+
# the reader to "check the errors above" when nothing was above. The fix was
6+
# cli_activation_diagnostic(): it appends the transaction refusal note, or
7+
# cbm_daemon_ipc_validation_detail(), so the message names the check that
8+
# actually refused.
9+
#
10+
# #1856 showed the fix was incomplete in the way that matters: the property was
11+
# repaired on the paths that had tests and left broken on a sibling call site
12+
# that had none. cli_activation_production_context_init() -- the emitter that
13+
# validates the cache, rendezvous and log directories, i.e. the one MOST likely
14+
# to hold a useful detail -- printed the constant bare. A reporter with a full
15+
# ProcMon trace still could not tell which check refused, because the binary
16+
# discarded the answer before printing.
17+
#
18+
# So the guard here is the CLASS, not the one call site: every emitter of the
19+
# refusal constants goes through the attributing helper. A future emitter that
20+
# bypasses it fails this test instead of reaching a reporter.
21+
set -euo pipefail
22+
23+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
24+
25+
python3 - "$ROOT" <<'PY'
26+
from __future__ import annotations
27+
28+
import pathlib
29+
import re
30+
import sys
31+
32+
root = pathlib.Path(sys.argv[1])
33+
failures: list[str] = []
34+
35+
36+
def require(condition: bool, message: str) -> None:
37+
if not condition:
38+
failures.append(message)
39+
40+
41+
cli = (root / "src" / "cli" / "cli.c").read_text(encoding="utf-8")
42+
43+
# 1. Every call that passes a refusal constant to a diagnostic sink must use the
44+
# attributing helper. cli_activation_production_diagnostic is the raw sink --
45+
# legitimate as an ops->visible_diagnostic member (it receives the ALREADY
46+
# attributed string), never as a direct emitter of the constant.
47+
ATTRIBUTING = "cli_activation_diagnostic"
48+
CONSTANTS = ("CLI_ACTIVATION_REFUSED_MESSAGE", "CLI_ACTIVATION_BUSY_MESSAGE")
49+
50+
for call in re.finditer(r"(\w*diagnostic)\s*\(([^;]*?)\)\s*;", cli, re.S):
51+
callee, arguments = call.group(1), call.group(2)
52+
if not any(constant in arguments for constant in CONSTANTS):
53+
continue
54+
if callee == ATTRIBUTING:
55+
continue
56+
line = cli.count("\n", 0, call.start()) + 1
57+
require(
58+
False,
59+
f"src/cli/cli.c:{line}: {callee}() emits a refusal constant directly. "
60+
f"Route it through {ATTRIBUTING}() so the message names the check that "
61+
"refused instead of pointing at errors that were never printed (#1856)",
62+
)
63+
64+
# 2. The helper must still be the one that appends both attribution channels --
65+
# deleting either turns the message back into a dead end.
66+
helper = re.search(
67+
r"static void cli_activation_diagnostic\((?:.|\n)*?\n\}\n", cli
68+
)
69+
require(helper is not None, "cli_activation_diagnostic() not found in src/cli/cli.c")
70+
body = helper.group(0) if helper else ""
71+
require(
72+
"cbm_activation_transaction_refusal_note()" in body,
73+
"cli_activation_diagnostic() must append the transaction refusal note (#1416)",
74+
)
75+
require(
76+
"cbm_daemon_ipc_validation_detail()" in body,
77+
"cli_activation_diagnostic() must append the daemon validation detail (#1537)",
78+
)
79+
80+
# 3. The remedy must be one that works. `icacls /remove:g` silently does nothing
81+
# to an INHERITED ACE -- and the stock C:\ grant for Authenticated Users
82+
# reaches every new child directory exactly that way, which is the shape
83+
# #1856 was reported against. Advice that cannot fix the reported case is
84+
# worse than none: the command succeeds and the refusal persists.
85+
require(
86+
"/inheritance:r" in body,
87+
"the refusal remedy must name icacls /inheritance:r for an inherited grant "
88+
"-- /remove:g cannot remove one, so the advice fails on the stock C:\\ ACE "
89+
"that #1856 reported",
90+
)
91+
92+
# 4. And the refusal itself must say which of the two shapes it hit, or the
93+
# reader cannot choose between those commands.
94+
transaction = (root / "src" / "cli" / "activation_transaction.c").read_text(encoding="utf-8")
95+
require(
96+
re.search(r"AceFlags\s*&\s*INHERITED_ACE", transaction) is not None,
97+
"src/cli/activation_transaction.c must report whether the refusing ACE was "
98+
"inherited, so the printed remedy matches the grant (#1856)",
99+
)
100+
101+
if failures:
102+
print("Activation diagnostic contract FAILED:")
103+
for failure in failures:
104+
print(f" - {failure}")
105+
sys.exit(1)
106+
107+
print("Activation diagnostic contract passed")
108+
PY

0 commit comments

Comments
 (0)