blame.rs

crates/veilvoice-guard/src/blame.rs

veilvoice-guard · 433 lines · read the source here · or on GitHub

Best-effort attribution: which program changed a file.

Read this before relying on it

Most of the time this cannot answer, and says so. Neither Windows nor Linux records who wrote to a file unless auditing has been switched on for that path in advance, and on a normal desktop it has not been. An unprivileged program cannot switch it on either.

So the honest design is a function that returns Blame::Unknown with a reason, and tells the user what would have to be configured for a real answer. A plausible guess would be worse than nothing here: naming the wrong program to somebody worried about surveillance is not a small error.

Where an answer can come from

  • Linux -- the kernel audit subsystem. With a watch in place (auditctl -w <path> -p wa -k veilvoice), ausearch reports the syscall, the pid and the executable name for every write. Reading those records usually needs root as well.
  • Windows -- object access auditing. With a SACL on the file and the "Audit File System" policy enabled, Security event 4663 records the process that opened it for write. wevtutil can query that log, though reading the Security log needs elevation.

Both are checked for, neither is configured by this crate, and the absence of either is reported rather than hidden. Setting them up is a deliberate act by an administrator, and pretending otherwise would misrepresent what a clean report means.

In plain words

Tries to say which program changed a file, and is careful about how sure it is.

It is a guess built from what was running at the time. It can be wrong, and it says so with every answer. Naming the wrong program confidently is worse than naming none, because somebody acts on it.

WHAT THIS FILE CONTAINS

433 lines defining 6 functions (3 public), 1 type and 0 constants. Everything below is read out of the source, so it cannot disagree with the code.

The types it owns.

  • enum Blame line 102 · What, if anything, is known about who changed a file.

What happens when it runs. These are the ways in: public, and nothing else in this file calls them, so they are what an outside caller reaches first.

  • Blame::describe line 123 · A single line for a terminal, an alert or a log.
  • Blame::is_known line 134 · Whether an actual name was found.
  • who_touched line 159 · Try to name the program that last wrote to path.
    reaches unconfigured

WHAT CALLS WHAT

no_window line 60 system_tool line 87 Blame::describe line 123 Blame::is_known line 134 unconfigured line 140 who_touched line 159 entry: a way in: public, and nothing in this file calls it helper: private to this file dashed: a call that goes back up, or across a wrapped rank The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.

The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.

The same graph as Mermaid source
%%{init: {"theme":"base","themeVariables":{"background":"#1a1b26","primaryColor":"#1f2335","primaryTextColor":"#c0caf5","primaryBorderColor":"#7aa2f7","secondaryColor":"#16161e","tertiaryColor":"#16161e","lineColor":"#737aa2","textColor":"#c0caf5","mainBkg":"#1f2335","nodeBorder":"#7aa2f7","clusterBkg":"#16161e","clusterBorder":"#2f3549","fontFamily":"ui-monospace, SFMono-Regular, Consolas, monospace","fontSize":"14px"}}}%%
flowchart TD
    n_no_window["no_window<br/>line 60"]
    n_system_tool["system_tool<br/>line 87"]
    n_describe(["Blame::describe<br/>line 123"])
    n_is_known(["Blame::is_known<br/>line 134"])
    n_unconfigured["unconfigured<br/>line 140"]
    n_who_touched(["who_touched<br/>line 159"])
    n_who_touched --> n_unconfigured
    click n_no_window href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-guard/src/blame.rs#L60" "open the source"
    click n_system_tool href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-guard/src/blame.rs#L87" "open the source"
    click n_describe href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-guard/src/blame.rs#L123" "open the source"
    click n_is_known href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-guard/src/blame.rs#L134" "open the source"
    click n_unconfigured href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-guard/src/blame.rs#L140" "open the source"
    click n_who_touched href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-guard/src/blame.rs#L159" "open the source"
    classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
    class n_describe,n_is_known,n_who_touched entry
    classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
    class n_no_window,n_system_tool,n_unconfigured helper
    subgraph chart_key ["Key"]
        direction LR
        key_entry["entry: a way in: public, and nothing in this file calls it"]
        key_helper["helper: private to this file"]
    end
    class key_entry entry
    class key_helper helper

This site loads no third-party script, so it cannot run Mermaid; the diagram above is the same nodes and edges drawn by the generator instead. GitHub renders the source below directly.

ITEMS

ItemLineDocumentation
no_window fn60Spawn without a console window.
system_tool fn87Resolve a system tool to an absolute path, rather than letting the operating system search for it.
Blame pub enum102What, if anything, is known about who changed a file.
Blame::describe pub fn123A single line for a terminal, an alert or a log.
Blame::is_known pub fn134Whether an actual name was found.
unconfigured fn140Build the "nobody configured auditing" answer for this platform.
who_touched pub fn159Try to name the program that last wrote to path.
linux mod182Who changed a file, as far as Linux can be made to say.
windows mod266The same question on Windows, asked of the installer database instead.