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
// Copyright (c) 2026 Erik Lening (hollowpointer) and Contributors
//
// This file is part of Zond Engine, licensed under the GNU Affero General
// Public License, version 3 or later. See the LICENSE file for details, or
// <https://www.gnu.org/licenses/agpl-3.0.html>.
//
// SPDX-License-Identifier: AGPL-3.0-or-later
//! # Creating a file inside a journal
//!
//! Two things that must not be separated: the mode it is created with, and who
//! it then belongs to.
//!
//! A journal holds the addresses an engagement was pointed at, so every file is
//! `0600` from creation rather than chmod'd after — and when the scan ran under
//! `sudo`, it is given to the user who invoked it rather than left to root.
//! [`paths`](super::paths) explains why the journal goes to the invoking user's
//! home; this is the other half of that answer, without which it goes to their
//! home and stays unreadable to them.
//!
//! **They live together because separating them cost exactly that.** The cursor
//! had its own copy of the mode and none of the ownership, so a sweep run with
//! `sudo` left `cursor.json` owned by root beside a manifest and findings owned
//! by the user. An unprivileged listing could read the plan and not the
//! progress, and reported every scan as untouched.
use fs;
use Path;
/// Creates or truncates a file in a journal: private, and the invoking user's.
///
/// The mode is set as the file is created rather than after, so there is no
/// moment where what a scan is recording can be read by anyone else. The
/// directory is `0700` as well, which would cover it either way — this is the
/// belt to that pair of braces, and it costs one flag.
pub
/// Creates a file that must not already exist: private, and the invoking
/// user's.
///
/// [`create_private`] for the case where existing is the failure rather than
/// something to truncate — a lock, whose whole job is to be refused when
/// somebody else got there first.
pub
/// Gives something a journal wrote under `sudo` to the user who invoked it.
///
/// Best effort: a journal left owned by root is one they can neither read nor
/// prune, which is worth trying to avoid and not worth failing a scan over.
///
/// Called for directories too, which is why it is separate from
/// [`create_private`] as well as inside it.
pub
pub