mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Refactor Windows sandbox setup and service helpers (#45455)
## What changed - Extract helper copying, token-user SID queries, provisioning pipe ownership, and service runtime lifecycle into dedicated modules. - Simplify command-runner resolution and extract setup configuration loading, payload execution, provisioning request exchange, and response handling into helpers. - Parameterize installation-record registry access and return the saved installation record from authenticated user registration. ## Testing Add tests for explicit setup `cwd` selection and effective workspace roots, plus valid and invalid token-user SID queries. Move existing helper-copy and freshness tests alongside the extracted copy implementation. GitOrigin-RevId: ffb39adae7611baa95e85c89f9a31ef7a779e217
This commit is contained in:
1 parent
7a48b95c6c
commit
1a02867bd1
19 files changed
+640
-486
No files matched your search
@@ -0,0 +1,56 @@
|
||||
//! Owns the token-user SID query used by sandbox token construction.
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use std::ffi::c_void;
|
||||
use windows_sys::Win32::Foundation::GetLastError;
|
||||
use windows_sys::Win32::Foundation::HANDLE;
|
||||
use windows_sys::Win32::Security::CopySid;
|
||||
use windows_sys::Win32::Security::GetLengthSid;
|
||||
use windows_sys::Win32::Security::GetTokenInformation;
|
||||
use windows_sys::Win32::Security::TOKEN_USER;
|
||||
use windows_sys::Win32::Security::TokenUser;
|
||||
|
||||
pub(crate) unsafe fn get_user_sid_bytes(h_token: HANDLE) -> Result<Vec<u8>> {
|
||||
let mut needed: u32 = 0;
|
||||
GetTokenInformation(h_token, TokenUser, std::ptr::null_mut(), 0, &mut needed);
|
||||
if needed == 0 {
|
||||
return Err(anyhow!("TokenUser size query returned 0"));
|
||||
}
|
||||
let mut user_buf: Vec<u8> = vec![0u8; needed as usize];
|
||||
let ok = GetTokenInformation(
|
||||
h_token,
|
||||
TokenUser,
|
||||
user_buf.as_mut_ptr() as *mut c_void,
|
||||
needed,
|
||||
&mut needed,
|
||||
);
|
||||
if ok == 0 || (needed as usize) < std::mem::size_of::<TOKEN_USER>() {
|
||||
return Err(anyhow!(
|
||||
"GetTokenInformation(TokenUser) failed: {}",
|
||||
GetLastError()
|
||||
));
|
||||
}
|
||||
let token_user: TOKEN_USER = std::ptr::read_unaligned(user_buf.as_ptr() as *const TOKEN_USER);
|
||||
let sid_len = GetLengthSid(token_user.User.Sid);
|
||||
if sid_len == 0 {
|
||||
return Err(anyhow!(
|
||||
"GetLengthSid(TokenUser) failed: {}",
|
||||
GetLastError()
|
||||
));
|
||||
}
|
||||
let mut user_sid_bytes = vec![0u8; sid_len as usize];
|
||||
if CopySid(
|
||||
sid_len,
|
||||
user_sid_bytes.as_mut_ptr() as *mut c_void,
|
||||
token_user.User.Sid,
|
||||
) == 0
|
||||
{
|
||||
return Err(anyhow!("CopySid(TokenUser) failed: {}", GetLastError()));
|
||||
}
|
||||
Ok(user_sid_bytes)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "token_user_tests.rs"]
|
||||
mod tests;
|
||||
Reference in new issue
Block a user