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
//! Read [`Credentials`] for the other end of a local connection.
//!
//! [`PeerCredentials`] serves a listener checking an accepted connection and a
//! client checking the service it reached. Pass the result to
//! [`crate::peer::authenticate`] with a [`crate::peer::Policy`], while the
//! connection is still open and before dispatching anything. See
//! [`crate::peer`] for what the credentials do and do not prove.
//!
//! On Unix, `same_user` compares this process's effective user with the user
//! the kernel recorded for the connection; failing to read it is an error,
//! never a same-user result. `pid` is `None` when the kernel reports none, for
//! example for a Linux peer in another PID namespace, which
//! [`crate::peer::ExpectedProcess`] rejects. Linux reports the PID and user
//! captured when the peer connected, listened or created the socket pair.
//! macOS reports the user captured then but the PID of the socket's most recent
//! owner, so after a descriptor is passed or inherited the two can describe
//! different processes.
//!
//! On Windows, a server sees its client's PID and a client sees the server's,
//! reported as `pid`. A server reads its client's user from the connection
//! itself when it can: it impersonates the client, reads that token's user,
//! and returns the thread to the token it had before on every path, a panic
//! included. The connection carries no user while a client under dynamic
//! context tracking has not had a message read by the server yet, or when the client allows only
//! anonymous impersonation; the server then looks the user up by PID instead.
//! A client has no call that reads its server's context, so it always looks
//! the server up by PID. A lookup by PID describes whichever process has the
//! PID now: if the peer has exited while another process holds its handle, a
//! process that reused the PID is checked instead. `user_evidence` says which
//! of the two answered. A pipe that reports no PID, or a user that cannot be
//! read, is an error.
use crateCredentials;
use io;
/// A connection that can report [`Credentials`] for its peer: the crate's
/// adapters, std and Tokio Unix streams, and `interprocess` local sockets on
/// Windows. [`super::Duplex`] and the accept loop in `serve` require it.