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
//! The permission bits ostrya forces on the entries it creates inside a
//! `bare-user-shared` repository.
//!
//! `mkdirat` and `openat(O_CREAT)` reduce their mode argument by the calling
//! process's file-creation mask, so the mode argument alone cannot carry a
//! guarantee. Each helper here applies the wanted bits with `fchmod` after the
//! create, which the mask does not touch. Every other repository mode keeps the
//! masked result, so the helpers return immediately for it.
//!
//! A directory takes `02770`. The setgid bit is part of the forced mode:
//! `mkdirat` inherits it from the parent, and an `fchmod` that leaves it out
//! clears it, which stops group inheritance below that level. A directory keeps
//! an `S_ISGID` bit a non-privileged `chmod` sets; the kernel's silent-clear
//! rule covers non-directory files. The sticky bit stays off `tmp/` and off the
//! repository root, because the stale-staging reaper removes staging trees that
//! other members of the group own.
//!
//! A helper runs on the arm of a create where that call made the entry. An
//! entry that already stands may belong to another uid, where `fchmod` answers
//! `EPERM`.
//!
//! [`force_created_dir`] opens the entry and calls `fchmod` on the descriptor.
//! Linux does not honour `AT_SYMLINK_NOFOLLOW` in `fchmodat`, so a path-based
//! chmod carries a symlink-swap race that an `openat` with `O_NOFOLLOW`
//! followed by `fchmod` does not.
use AsFd;
use RepoMode;
use ;
use Arg;
/// The mode forced on a directory created inside a `bare-user-shared`
/// repository.
pub const SHARED_DIR_MODE: u32 = 0o2770;
/// The mode forced on a lock file created inside a `bare-user-shared`
/// repository.
pub const SHARED_LOCK_MODE: u32 = 0o660;
/// The mode forced on a regular file created inside a `bare-user-shared`
/// repository outside the object store, such as a `.commitpartial` marker.
pub const SHARED_FILE_MODE: u32 = 0o644;
/// Force [`SHARED_DIR_MODE`] on the directory `path` names under `dir`, which
/// the calling code has just created.
///
/// Call this on the arm of the create that made the directory. Every other
/// repository mode returns at once.
pub
/// Force `bits` on an open descriptor for an entry the calling code has just
/// created.
///
/// Call this on the arm of the create that made the entry. Every other
/// repository mode returns at once.
pub