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
//! The permission bits that ostrya forces on the entries that it creates inside
//! a `bare-user-shared` repository.
//!
//! `mkdirat` and `openat(O_CREAT)` reduce their mode argument by the
//! file-creation mask of the calling process, so the mode argument alone cannot
//! give a guarantee. Each helper here applies the wanted bits with `fchmod`
//! after the create, and the mask does not apply to `fchmod`. All other
//! repository modes keep the masked result, so the helpers return at once for
//! them.
//!
//! A directory gets `02770`. The setgid bit is part of the forced mode, because
//! `mkdirat` inherits it from the parent. If an `fchmod` leaves the bit out, it
//! clears the bit, and group inheritance stops below that level. If a
//! non-privileged `chmod` sets the `S_ISGID` bit on a directory, the directory
//! keeps the bit. The silent-clear rule of the kernel applies to 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 exists before the call can belong to another uid, and then
//! `fchmod` returns `EPERM`.
//!
//! [`force_created_dir`] opens the entry and calls `fchmod` on the descriptor.
//! Linux does not support `AT_SYMLINK_NOFOLLOW` in `fchmodat`, so a chmod by
//! path has a symlink-swap race. An `openat` with `O_NOFOLLOW` and then an
//! `fchmod` on the descriptor has no such race.
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;
/// Forces [`SHARED_DIR_MODE`] on the directory that the calling code created
/// at `path` under `dir`.
///
/// Call this on the arm of the create that made the directory. In all other
/// repository modes, the function returns at once.
pub
/// Forces `bits` on an open descriptor of an entry that the calling code
/// created.
///
/// Call this on the arm of the create that made the entry. In all other
/// repository modes, the function returns at once.
pub