diff --git a/src/backend/libc/thread/syscalls.rs b/src/backend/libc/thread/syscalls.rs index 9198a7fbe..13b291d81 100644 --- a/src/backend/libc/thread/syscalls.rs +++ b/src/backend/libc/thread/syscalls.rs @@ -398,9 +398,9 @@ pub(crate) fn setuid_thread(uid: crate::ugid::Uid) -> io::Result<()> { #[cfg(linux_kernel)] #[inline] pub(crate) fn setresuid_thread( - ruid: crate::ugid::Uid, - euid: crate::ugid::Uid, - suid: crate::ugid::Uid, + ruid: Option, + euid: Option, + suid: Option, ) -> io::Result<()> { #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))] const SYS: c::c_long = c::SYS_setresuid32 as c::c_long; @@ -411,7 +411,13 @@ pub(crate) fn setresuid_thread( fn setresuid(ruid: c::uid_t, euid: c::uid_t, suid: c::uid_t) via SYS -> c::c_int } - unsafe { ret(setresuid(ruid.as_raw(), euid.as_raw(), suid.as_raw())) } + unsafe { + ret(setresuid( + ruid.map_or(-1_i32 as u32, |x| x.as_raw()), + euid.map_or(-1_i32 as u32, |x| x.as_raw()), + suid.map_or(-1_i32 as u32, |x| x.as_raw()), + )) + } } #[cfg(linux_kernel)] @@ -427,9 +433,9 @@ pub(crate) fn setgid_thread(gid: crate::ugid::Gid) -> io::Result<()> { #[cfg(linux_kernel)] #[inline] pub(crate) fn setresgid_thread( - rgid: crate::ugid::Gid, - egid: crate::ugid::Gid, - sgid: crate::ugid::Gid, + rgid: Option, + egid: Option, + sgid: Option, ) -> io::Result<()> { #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))] const SYS: c::c_long = c::SYS_setresgid32 as c::c_long; @@ -440,7 +446,13 @@ pub(crate) fn setresgid_thread( fn setresgid(rgid: c::gid_t, egid: c::gid_t, sgid: c::gid_t) via SYS -> c::c_int } - unsafe { ret(setresgid(rgid.as_raw(), egid.as_raw(), sgid.as_raw())) } + unsafe { + ret(setresgid( + rgid.map_or(-1_i32 as u32, |x| x.as_raw()), + egid.map_or(-1_i32 as u32, |x| x.as_raw()), + sgid.map_or(-1_i32 as u32, |x| x.as_raw()), + )) + } } /// # Safety diff --git a/src/backend/linux_raw/conv.rs b/src/backend/linux_raw/conv.rs index 901451ae6..3d4693fe1 100644 --- a/src/backend/linux_raw/conv.rs +++ b/src/backend/linux_raw/conv.rs @@ -842,6 +842,14 @@ impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { } } +#[cfg(feature = "thread")] +impl<'a, Num: ArgNumber> From> for ArgReg<'a, Num> { + #[inline] + fn from(t: Option) -> Self { + c_uint(t.map_or(-1_i32 as u32, |x| x.as_raw())) + } +} + #[cfg(any(feature = "process", feature = "thread"))] impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { #[inline] @@ -850,6 +858,14 @@ impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { } } +#[cfg(feature = "thread")] +impl<'a, Num: ArgNumber> From> for ArgReg<'a, Num> { + #[inline] + fn from(t: Option) -> Self { + c_uint(t.map_or(-1_i32 as u32, |x| x.as_raw())) + } +} + #[cfg(feature = "runtime")] impl<'a, Num: ArgNumber> From for ArgReg<'a, Num> { #[inline] diff --git a/src/backend/linux_raw/thread/syscalls.rs b/src/backend/linux_raw/thread/syscalls.rs index 352e06150..c9dc7751c 100644 --- a/src/backend/linux_raw/thread/syscalls.rs +++ b/src/backend/linux_raw/thread/syscalls.rs @@ -405,9 +405,9 @@ pub(crate) fn setuid_thread(uid: crate::ugid::Uid) -> io::Result<()> { #[inline] pub(crate) fn setresuid_thread( - ruid: crate::ugid::Uid, - euid: crate::ugid::Uid, - suid: crate::ugid::Uid, + ruid: Option, + euid: Option, + suid: Option, ) -> io::Result<()> { #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))] unsafe { @@ -426,9 +426,9 @@ pub(crate) fn setgid_thread(gid: crate::ugid::Gid) -> io::Result<()> { #[inline] pub(crate) fn setresgid_thread( - rgid: crate::ugid::Gid, - egid: crate::ugid::Gid, - sgid: crate::ugid::Gid, + rgid: Option, + egid: Option, + sgid: Option, ) -> io::Result<()> { #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))] unsafe { diff --git a/src/thread/id.rs b/src/thread/id.rs index aa67c9eaa..a299628f3 100644 --- a/src/thread/id.rs +++ b/src/thread/id.rs @@ -105,8 +105,13 @@ pub fn set_thread_uid(uid: Uid) -> io::Result<()> { /// [Linux]: https://man7.org/linux/man-pages/man2/setresuid.2.html /// [linux_notes]: https://man7.org/linux/man-pages/man2/setresuid.2.html#NOTES #[inline] -pub fn set_thread_res_uid(ruid: Uid, euid: Uid, suid: Uid) -> io::Result<()> { - backend::thread::syscalls::setresuid_thread(ruid, euid, suid) +pub fn set_thread_res_uid(ruid: R, euid: E, suid: S) -> io::Result<()> +where + R: Into>, + E: Into>, + S: Into>, +{ + backend::thread::syscalls::setresuid_thread(ruid.into(), euid.into(), suid.into()) } /// `setgid(gid)`—Sets the effective group ID of the current thread. @@ -154,8 +159,13 @@ pub fn set_thread_gid(gid: Gid) -> io::Result<()> { /// [Linux]: https://man7.org/linux/man-pages/man2/setresgid.2.html /// [linux_notes]: https://man7.org/linux/man-pages/man2/setresgid.2.html#NOTES #[inline] -pub fn set_thread_res_gid(rgid: Gid, egid: Gid, sgid: Gid) -> io::Result<()> { - backend::thread::syscalls::setresgid_thread(rgid, egid, sgid) +pub fn set_thread_res_gid(rgid: R, egid: E, sgid: S) -> io::Result<()> +where + R: Into>, + E: Into>, + S: Into>, +{ + backend::thread::syscalls::setresgid_thread(rgid.into(), egid.into(), sgid.into()) } /// `setgroups(groups)`—Sets the supplementary group IDs for the calling