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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
https://github.com/dbus2/zbus/pull/757
--- cargo-crates/zbus-4.2.0/src/connection/handshake/client.rs.orig 2006-07-24 01:21:28 UTC
+++ cargo-crates/zbus-4.2.0/src/connection/handshake/client.rs
@@ -95,21 +95,16 @@ impl Client {
#[instrument(skip(self))]
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
async fn send_zero_byte(&mut self) -> Result<()> {
- let written = self
- .common
- .socket_mut()
- .write_mut()
- .send_zero_byte()
- .await
- .map_err(|e| {
- Error::Handshake(format!("Could not send zero byte with credentials: {}", e))
- })
- .and_then(|n| match n {
- None => Err(Error::Handshake(
- "Could not send zero byte with credentials".to_string(),
- )),
- Some(n) => Ok(n),
- })?;
+ let write = self.common.socket_mut().write_mut();
+
+ let written = match write.send_zero_byte().await.map_err(|e| {
+ Error::Handshake(format!("Could not send zero byte with credentials: {}", e))
+ })? {
+ // This likely means that the socket type is unable to send SCM_CREDS.
+ // Let's try to send the 0 byte as a regular message.
+ None => write.sendmsg(&[0], &[]).await?,
+ Some(n) => n,
+ };
if written != 1 {
return Err(Error::Handshake(
--- cargo-crates/zbus-4.2.0/src/connection/handshake/common.rs.orig 2006-07-24 01:21:28 UTC
+++ cargo-crates/zbus-4.2.0/src/connection/handshake/common.rs
@@ -122,17 +122,13 @@ impl Common {
if self.first_command {
// The first command is sent by the client so we can assume it's the server.
self.first_command = false;
- // leading 0 is sent separately for `freebsd` and `dragonfly`.
- #[cfg(not(any(target_os = "freebsd", target_os = "dragonfly")))]
- {
- if self.recv_buffer[0] != b'\0' {
- return Err(Error::Handshake(
- "First client byte is not NUL!".to_string(),
- ));
- }
-
- start_index = 1;
+ if self.recv_buffer[0] != b'\0' {
+ return Err(Error::Handshake(
+ "First client byte is not NUL!".to_string(),
+ ));
}
+
+ start_index = 1;
};
let line_bytes = self.recv_buffer.drain(..=lf_index);
--- cargo-crates/zbus-4.2.0/src/connection/socket/tcp.rs.orig 2006-07-24 01:21:28 UTC
+++ cargo-crates/zbus-4.2.0/src/connection/socket/tcp.rs
@@ -26,32 +26,25 @@ impl ReadHalf for Arc<Async<TcpStream>> {
}
}
+ #[cfg(windows)]
async fn peer_credentials(&mut self) -> io::Result<crate::fdo::ConnectionCredentials> {
- #[cfg(windows)]
- let creds = {
- let stream = self.clone();
- crate::Task::spawn_blocking(
- move || {
- use crate::win32::{tcp_stream_get_peer_pid, ProcessToken};
+ let stream = self.clone();
+ crate::Task::spawn_blocking(
+ move || {
+ use crate::win32::{tcp_stream_get_peer_pid, ProcessToken};
- let pid = tcp_stream_get_peer_pid(stream.get_ref())? as _;
- let sid = ProcessToken::open(if pid != 0 { Some(pid as _) } else { None })
- .and_then(|process_token| process_token.sid())?;
- io::Result::Ok(
- crate::fdo::ConnectionCredentials::default()
- .set_process_id(pid)
- .set_windows_sid(sid),
- )
- },
- "peer credentials",
- )
- .await
- }?;
-
- #[cfg(not(windows))]
- let creds = crate::fdo::ConnectionCredentials::default();
-
- Ok(creds)
+ let pid = tcp_stream_get_peer_pid(stream.get_ref())? as _;
+ let sid = ProcessToken::open(if pid != 0 { Some(pid as _) } else { None })
+ .and_then(|process_token| process_token.sid())?;
+ io::Result::Ok(
+ crate::fdo::ConnectionCredentials::default()
+ .set_process_id(pid)
+ .set_windows_sid(sid),
+ )
+ },
+ "peer credentials",
+ )
+ .await
}
}
|