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
//! Owner-only, local-only Windows named pipes, behind a safe API.
//!
//! The daemon's local listener is a named pipe, created by tokio's overlapped
//! named-pipe server so reads and writes can run at once on one end. Creating
//! that end with a chosen DACL is an `unsafe` call tokio cannot make safe, so
//! this crate builds the security attributes:
//!
//! - [`OwnerOnlySecurity`] holds a protected DACL that grants full access to
//! the current user's SID, plus LocalSystem and Administrators, which Win32
//! lets into a kernel object whatever its DACL says; naming them keeps the
//! access check simple. No other user is admitted.
//! - [`reject_remote_client`] refuses a client that reached the machine over
//! SMB. The pipe is also created with `PIPE_REJECT_REMOTE_CLIENTS`, so the
//! kernel refuses such a client before any byte is exchanged; this check
//! catches one that gets further than that.
//!
//! Other platforms have no named pipes, so every function here reports
//! [`io::ErrorKind::Unsupported`].
use io;
pub use OwnerOnlySecurity;
/// Create the security attributes for a pipe whose DACL admits only the current
/// user, LocalSystem and Administrators.
///
/// Hold the returned value for as long as the pipe end is created, and pass
/// [`OwnerOnlySecurity::attributes_ptr`] as tokio's
/// `create_with_security_attributes_raw` argument. The pointer stays valid for
/// the value's whole life; it is not an owning handle.
/// Named pipes exist only on Windows.
/// Refuse a client that reached the pipe from another machine. Call it before
/// reading anything from the connection.
/// [`reject_remote_client`] for a caller that already holds the raw handle,
/// such as tokio's `NamedPipeServer`, whose `AsRawHandle` is not public.
/// Create one end of `pipe_name`, the daemon's local listener end on Windows:
/// overlapped, byte mode, remote clients refused, and with an owner-only DACL.
/// `first` marks the process's first end for that name. Needs the `tokio`
/// feature, because the end is tokio's server type.
/// Named pipes exist only on Windows.
/// The SID of the current user, as `S-1-5-21-…`, so a test or check can compare
/// it with a client's SID without opening a token itself.
/// The current user's SID as a string exists only on Windows.