Skip to content

Commit 559bb98

Browse files
committed
fix Tabby#10301 Still cannot login with pageant
two problems: 1. pageant protocol does not support streaming, so PageantStream should receive enough data for pageant, and then forward into. 2. [SECURITY_ATTRIBUTES] should have the correct nLength 3. [SetSecurityDescriptorOwner] in version 0.58 have bug, upgrade to 0.59 is ok.
1 parent be5c22e commit 559bb98

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

pageant/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ rust-version = "1.75"
1313
futures.workspace = true
1414
thiserror.workspace = true
1515
rand.workspace = true
16+
byteorder.workspace = true
1617
log.workspace = true
1718
tokio = { workspace = true, features = ["io-util", "rt"] }
1819
bytes.workspace = true
1920
delegate.workspace = true
20-
windows = { version = "0.58", features = [
21+
windows = { version = "0.59", features = [
2122
"Win32_UI_WindowsAndMessaging",
2223
"Win32_System_Memory",
2324
"Win32_Security",

pageant/src/pageant_impl.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use byteorder::{BigEndian, ByteOrder};
12
use std::io::IoSlice;
23
use std::mem::size_of;
34
use std::pin::Pin;
@@ -61,7 +62,14 @@ impl PageantStream {
6162
if n == 0 {
6263
break;
6364
}
64-
let msg = buf.split().freeze();
65+
if buf.len() < 4 {
66+
continue;
67+
}
68+
let len = BigEndian::read_u32(&buf) as usize;
69+
if buf.len() < len + 4 {
70+
continue;
71+
}
72+
let msg = buf.split_to(len + 4).freeze();
6573
let Ok(response) = query_pageant_direct(cookie.clone(), &msg).map_err(|e| {
6674
debug!("Pageant query failed: {:?}", e);
6775
e
@@ -253,14 +261,14 @@ pub fn query_pageant_direct(cookie: String, msg: &[u8]) -> Result<Vec<u8>, Error
253261
let sa = SECURITY_ATTRIBUTES {
254262
lpSecurityDescriptor: &mut sd as *mut _ as *mut _,
255263
bInheritHandle: true.into(),
256-
..Default::default()
264+
nLength: size_of::<SECURITY_ATTRIBUTES>() as u32,
257265
};
258266

259267
let psd = PSECURITY_DESCRIPTOR(&mut sd as *mut _ as *mut _);
260268

261269
unsafe {
262270
InitializeSecurityDescriptor(psd, 1)?;
263-
SetSecurityDescriptorOwner(psd, user.User.Sid, false)?;
271+
SetSecurityDescriptorOwner(psd, Some(user.User.Sid), false)?;
264272
}
265273

266274
let mut map: MemoryMap = MemoryMap::new(map_name.clone(), _AGENT_MAX_MSGLEN, Some(sa))?;

0 commit comments

Comments
 (0)