|
| 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