From 46c8b7ca9f0760154863b8ea5fd850645bcca579 Mon Sep 17 00:00:00 2001 From: Jeron Aldaron Lau Date: Sat, 2 Mar 2024 22:22:21 -0600 Subject: [PATCH 1/3] Wip testing for illumos --- TESTING.md | 22 ++++++++++++++++++++++ src/os/unix.rs | 17 ++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/TESTING.md b/TESTING.md index 7dc6b61..f98df8e 100644 --- a/TESTING.md +++ b/TESTING.md @@ -2,6 +2,28 @@ This file outlines the regression testing plan for all platforms. +## Linux / Fedora Silverblue + +## Linux / Ubuntu + +## Windows + +## MacOS + +## FreeBSD + +## Illumos + +Testing is done on Tribblix (virtualized on Fedora Silverblue): + + + +Download the 64-bit x86/x64 standard image. + +Install it in GNOME Boxes. + + + ## Redox diff --git a/src/os/unix.rs b/src/os/unix.rs index bde8d7b..3d576bb 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -29,7 +29,8 @@ use crate::{ target_os = "dragonfly", target_os = "bitrig", target_os = "openbsd", - target_os = "netbsd" + target_os = "netbsd", + target_os = "illumos", )))] #[repr(C)] struct PassWd { @@ -65,6 +66,20 @@ struct PassWd { pw_fields: i32, } +#[cfg(target_os = "illumos")] +#[repr(C)] +struct PassWd { + pw_name: *const c_void, + pw_passwd: *const c_void, + pw_uid: u32, + pw_gid: u32, + pw_age: *const c_void, + pw_comment: *const c_void, + pw_gecos: *const c_void, + pw_dir: *const c_void, + pw_shell: *const c_void, +} + extern "system" { fn getpwuid_r( uid: u32, From d931201a6135127e487ff76532d12173f52d51e0 Mon Sep 17 00:00:00 2001 From: Jeron Aldaron Lau Date: Sat, 2 Mar 2024 23:34:07 -0600 Subject: [PATCH 2/3] Ran a test --- TESTING.md | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/os/unix.rs | 18 +++++++++--------- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/TESTING.md b/TESTING.md index f98df8e..7b76cfb 100644 --- a/TESTING.md +++ b/TESTING.md @@ -20,9 +20,53 @@ Testing is done on Tribblix (virtualized on Fedora Silverblue): Download the 64-bit x86/x64 standard image. -Install it in GNOME Boxes. +Install it in GNOME Boxes (select operating system OpenIndiana Hipster). +Set 4 GiB memory, and 16 GiB Storage limit +Login as `jack` (password `jack`) + +```shell +su - root # password `tribblix` +format # 0, quit +./live_install -G c1t0d0 develop # replace c1t0d0 with disk +reboot -p +``` + +Login as `jack` (password `jack`) + +Now, install Rust (use bash instead of sh, sh doesn't work) + +```shell +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash # 1 +source "$HOME/.cargo/env" +``` + +### Testing + +```shell +git clone https://github.com/ardaku/whoami.git +cd whoami +# run both debug and release +cargo run --example whoami-demo +cargo run --example whoami-demo --release +``` + +Expected output is + +```console +WhoAmI 1.5.0-pre.0 + +User's Language whoami::langs(): +User's Name whoami::realname(): Unknown +User's Username whoami::username(): unknown +Device's Pretty Name whoami::devicename(): tribblix +Device's Hostname whoami::fallible::hostname(): tribblix +Device's Platform whoami::platform(): Illumos +Device's OS Distro whoami::distro(): Tribblix +Device's Desktop Env. whoami::desktop_env(): Unknown: Unknown +Device's CPU Arch whoami::arch(): Unknown: +``` ## Redox diff --git a/src/os/unix.rs b/src/os/unix.rs index 3d576bb..8cf14cb 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -69,15 +69,15 @@ struct PassWd { #[cfg(target_os = "illumos")] #[repr(C)] struct PassWd { - pw_name: *const c_void, - pw_passwd: *const c_void, - pw_uid: u32, - pw_gid: u32, - pw_age: *const c_void, - pw_comment: *const c_void, - pw_gecos: *const c_void, - pw_dir: *const c_void, - pw_shell: *const c_void, + pw_name: *const c_void, + pw_passwd: *const c_void, + pw_uid: u32, + pw_gid: u32, + pw_age: *const c_void, + pw_comment: *const c_void, + pw_gecos: *const c_void, + pw_dir: *const c_void, + pw_shell: *const c_void, } extern "system" { From 682445fd19e8c78943e0ec02b1fba225ac9f1702 Mon Sep 17 00:00:00 2001 From: Jeron Aldaron Lau Date: Sat, 2 Mar 2024 16:08:46 -0800 Subject: [PATCH 3/3] Fix Illumos bugs --- TESTING.md | 6 ++--- src/os/unix.rs | 70 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/TESTING.md b/TESTING.md index 7b76cfb..172359e 100644 --- a/TESTING.md +++ b/TESTING.md @@ -58,14 +58,14 @@ Expected output is WhoAmI 1.5.0-pre.0 User's Language whoami::langs(): -User's Name whoami::realname(): Unknown -User's Username whoami::username(): unknown +User's Name whoami::realname(): Tribblix Jack +User's Username whoami::username(): jack Device's Pretty Name whoami::devicename(): tribblix Device's Hostname whoami::fallible::hostname(): tribblix Device's Platform whoami::platform(): Illumos Device's OS Distro whoami::distro(): Tribblix Device's Desktop Env. whoami::desktop_env(): Unknown: Unknown -Device's CPU Arch whoami::arch(): Unknown: +Device's CPU Arch whoami::arch(): Unknown: i86pc ``` ## Redox diff --git a/src/os/unix.rs b/src/os/unix.rs index 8cf14cb..2f88676 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -80,6 +80,17 @@ struct PassWd { pw_shell: *const c_void, } +#[cfg(target_os = "illumos")] +extern "system" { + fn getpwuid_r( + uid: u32, + pwd: *mut PassWd, + buf: *mut c_void, + buflen: c_int, + ) -> *mut PassWd; +} + +#[cfg(not(target_os = "illumos"))] extern "system" { fn getpwuid_r( uid: u32, @@ -88,6 +99,9 @@ extern "system" { buflen: usize, result: *mut *mut PassWd, ) -> i32; +} + +extern "system" { fn geteuid() -> u32; fn gethostname(name: *mut c_void, len: usize) -> i32; } @@ -219,22 +233,41 @@ fn getpwuid(name: Name) -> Result { // Get PassWd `struct`. let passwd = unsafe { - let ret = getpwuid_r( - geteuid(), - passwd.as_mut_ptr(), - buffer.as_mut_ptr() as *mut c_void, - BUF_SIZE, - _passwd.as_mut_ptr(), - ); - - if ret != 0 { - return Err(Error::last_os_error()); + #[cfg(not(target_os = "illumos"))] + { + let ret = getpwuid_r( + geteuid(), + passwd.as_mut_ptr(), + buffer.as_mut_ptr() as *mut c_void, + BUF_SIZE, + _passwd.as_mut_ptr(), + ); + + if ret != 0 { + return Err(Error::last_os_error()); + } + + let _passwd = _passwd.assume_init(); + + if _passwd.is_null() { + return Err(super::err_null_record()); + } } - let _passwd = _passwd.assume_init(); + #[cfg(target_os = "illumos")] + { + use std::convert::TryInto; + + let ret = getpwuid_r( + geteuid(), + passwd.as_mut_ptr(), + buffer.as_mut_ptr() as *mut c_void, + BUF_SIZE.try_into().unwrap_or(c_int::MAX), + ); - if _passwd.is_null() { - return Err(super::err_null_record()); + if ret.is_null() { + return Err(Error::last_os_error()); + } } passwd.assume_init() @@ -359,7 +392,6 @@ pub(crate) fn lang() -> impl Iterator { target_os = "freebsd", target_os = "netbsd", target_os = "openbsd", - target_os = "illumos" ))] #[repr(C)] struct UtsName { @@ -370,6 +402,16 @@ struct UtsName { machine: [c_char; 256], } +#[cfg(target_os = "illumos")] +#[repr(C)] +struct UtsName { + sysname: [c_char; 257], + nodename: [c_char; 257], + release: [c_char; 257], + version: [c_char; 257], + machine: [c_char; 257], +} + #[cfg(target_os = "dragonfly")] #[repr(C)] struct UtsName {