aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim/src/process.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 10:18:00 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 10:18:00 +0900
commit3665099cd2ed5bbbc89201d240755218e16f19e1 (patch)
treebd82503d8e088080da83da2c4f4aadfe9bd792bd /crates/shirabe-php-shim/src/process.rs
parent112df62a01e482f33b68e1dac190f70085fcec64 (diff)
downloadphp-shirabe-3665099cd2ed5bbbc89201d240755218e16f19e1.tar.gz
php-shirabe-3665099cd2ed5bbbc89201d240755218e16f19e1.tar.zst
php-shirabe-3665099cd2ed5bbbc89201d240755218e16f19e1.zip
refactor(php-shim): give posix_getpwuid a typed PasswdEntry result
posix_getpwuid now returns Option<PasswdEntry> instead of a PhpMixed array, so Platform reads the field it wants rather than digging through the map. posix_getuid and posix_geteuid return u32, matching the uid PasswdEntry is looked up by. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/process.rs')
-rw-r--r--crates/shirabe-php-shim/src/process.rs58
1 files changed, 26 insertions, 32 deletions
diff --git a/crates/shirabe-php-shim/src/process.rs b/crates/shirabe-php-shim/src/process.rs
index e150d649..55cb7d00 100644
--- a/crates/shirabe-php-shim/src/process.rs
+++ b/crates/shirabe-php-shim/src/process.rs
@@ -396,42 +396,36 @@ pub fn getmypid() -> i64 {
std::process::id() as i64
}
-pub fn posix_getuid() -> i64 {
- nix::unistd::getuid().as_raw() as i64
+pub fn posix_getuid() -> u32 {
+ nix::unistd::getuid().as_raw()
}
-pub fn posix_geteuid() -> i64 {
- nix::unistd::geteuid().as_raw() as i64
+pub fn posix_geteuid() -> u32 {
+ nix::unistd::geteuid().as_raw()
}
-/// Looks up the passwd entry for `uid` and returns it in the shape of PHP's `posix_getpwuid`
-/// associative array, or `false` when no entry matches.
-pub fn posix_getpwuid(uid: i64) -> PhpMixed {
- let user = match nix::unistd::User::from_uid(nix::unistd::Uid::from_raw(uid as u32)) {
- Ok(Some(user)) => user,
- _ => return PhpMixed::Bool(false),
- };
- let mut entry = indexmap::IndexMap::new();
- entry.insert("name".to_string(), PhpMixed::String(user.name));
- entry.insert(
- "passwd".to_string(),
- PhpMixed::String(user.passwd.to_string_lossy().into_owned()),
- );
- entry.insert("uid".to_string(), PhpMixed::Int(user.uid.as_raw() as i64));
- entry.insert("gid".to_string(), PhpMixed::Int(user.gid.as_raw() as i64));
- entry.insert(
- "gecos".to_string(),
- PhpMixed::String(user.gecos.to_string_lossy().into_owned()),
- );
- entry.insert(
- "dir".to_string(),
- PhpMixed::String(user.dir.to_string_lossy().into_owned()),
- );
- entry.insert(
- "shell".to_string(),
- PhpMixed::String(user.shell.to_string_lossy().into_owned()),
- );
- PhpMixed::Array(entry)
+#[derive(Debug, Clone, Default, PartialEq, Eq)]
+pub struct PasswdEntry {
+ pub name: String,
+ pub passwd: String,
+ pub uid: i64,
+ pub gid: i64,
+ pub gecos: String,
+ pub dir: String,
+ pub shell: String,
+}
+
+pub fn posix_getpwuid(uid: u32) -> Option<PasswdEntry> {
+ let user = nix::unistd::User::from_uid(nix::unistd::Uid::from_raw(uid)).ok()??;
+ Some(PasswdEntry {
+ name: user.name,
+ passwd: user.passwd.to_string_lossy().into_owned(),
+ uid: user.uid.as_raw() as i64,
+ gid: user.gid.as_raw() as i64,
+ gecos: user.gecos.to_string_lossy().into_owned(),
+ dir: user.dir.to_string_lossy().into_owned(),
+ shell: user.shell.to_string_lossy().into_owned(),
+ })
}
pub fn posix_isatty(stream: PhpResource) -> bool {