diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-25 18:05:50 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-26 00:20:05 +0900 |
| commit | e0ba36807619780ff645efe0117281d32d5ace2a (patch) | |
| tree | b445222994d13466d3531b2dad5dedebeaca247e /crates/shirabe-php-shim | |
| parent | d4ec1dcb6fc04ff029ded35cc2fcc14f3bbc02ad (diff) | |
| download | php-shirabe-e0ba36807619780ff645efe0117281d32d5ace2a.tar.gz php-shirabe-e0ba36807619780ff645efe0117281d32d5ace2a.tar.zst php-shirabe-e0ba36807619780ff645efe0117281d32d5ace2a.zip | |
test: recover binary_installer full-compat port; implement posix_getpwuid
The stashed binary_installer port was blocked on posix_getpwuid (reached via
Platform::is_virtual_box_guest); implement it via getpwuid(3) extern "C". The
4 install-and-exec tests now pass with the stream I/O and Process cwd fixes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim')
| -rw-r--r-- | crates/shirabe-php-shim/src/process.rs | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/crates/shirabe-php-shim/src/process.rs b/crates/shirabe-php-shim/src/process.rs index b652bed..6999d99 100644 --- a/crates/shirabe-php-shim/src/process.rs +++ b/crates/shirabe-php-shim/src/process.rs @@ -371,9 +371,21 @@ pub fn pcntl_signal_get_handler(_signal: i64) -> PhpMixed { todo!() } +#[repr(C)] +struct Passwd { + pw_name: *const std::os::raw::c_char, + pw_passwd: *const std::os::raw::c_char, + pw_uid: u32, + pw_gid: u32, + pw_gecos: *const std::os::raw::c_char, + pw_dir: *const std::os::raw::c_char, + pw_shell: *const std::os::raw::c_char, +} + unsafe extern "C" { fn getuid() -> u32; fn geteuid() -> u32; + fn getpwuid(uid: u32) -> *const Passwd; } pub fn posix_getuid() -> i64 { @@ -386,9 +398,32 @@ pub fn posix_geteuid() -> i64 { (unsafe { geteuid() }) as i64 } -pub fn posix_getpwuid(_uid: i64) -> PhpMixed { - // TODO(phase-d): getpwuid(3) is not reachable without a libc/syscall crate. - todo!() +pub fn posix_getpwuid(uid: i64) -> PhpMixed { + // getpwuid(3) via libc (already linked); mirrors PHP posix_getpwuid returning an associative + // array of the passwd entry, or false when no entry matches the uid. + let pw = unsafe { getpwuid(uid as u32) }; + if pw.is_null() { + return PhpMixed::Bool(false); + } + let cstr = |p: *const std::os::raw::c_char| -> String { + if p.is_null() { + String::new() + } else { + unsafe { std::ffi::CStr::from_ptr(p) } + .to_string_lossy() + .into_owned() + } + }; + let pw = unsafe { &*pw }; + let mut entry = indexmap::IndexMap::new(); + entry.insert("name".to_string(), PhpMixed::String(cstr(pw.pw_name))); + entry.insert("passwd".to_string(), PhpMixed::String(cstr(pw.pw_passwd))); + entry.insert("uid".to_string(), PhpMixed::Int(pw.pw_uid as i64)); + entry.insert("gid".to_string(), PhpMixed::Int(pw.pw_gid as i64)); + entry.insert("gecos".to_string(), PhpMixed::String(cstr(pw.pw_gecos))); + entry.insert("dir".to_string(), PhpMixed::String(cstr(pw.pw_dir))); + entry.insert("shell".to_string(), PhpMixed::String(cstr(pw.pw_shell))); + PhpMixed::Array(entry) } pub fn posix_isatty(stream: PhpResource) -> bool { |
