Skip to content

Commit 35b8b8a

Browse files
committed
set_thread_res_xid: -1 as None
1 parent e5b793b commit 35b8b8a

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

src/backend/libc/thread/syscalls.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ pub(crate) fn setuid_thread(uid: crate::ugid::Uid) -> io::Result<()> {
398398
#[cfg(linux_kernel)]
399399
#[inline]
400400
pub(crate) fn setresuid_thread(
401-
ruid: crate::ugid::Uid,
402-
euid: crate::ugid::Uid,
403-
suid: crate::ugid::Uid,
401+
ruid: Option<crate::ugid::Uid>,
402+
euid: Option<crate::ugid::Uid>,
403+
suid: Option<crate::ugid::Uid>,
404404
) -> io::Result<()> {
405405
#[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]
406406
const SYS: c::c_long = c::SYS_setresuid32 as c::c_long;
@@ -411,7 +411,13 @@ pub(crate) fn setresuid_thread(
411411
fn setresuid(ruid: c::uid_t, euid: c::uid_t, suid: c::uid_t) via SYS -> c::c_int
412412
}
413413

414-
unsafe { ret(setresuid(ruid.as_raw(), euid.as_raw(), suid.as_raw())) }
414+
unsafe {
415+
ret(setresuid(
416+
ruid.map_or(-1_i32 as u32, |x| x.as_raw()),
417+
euid.map_or(-1_i32 as u32, |x| x.as_raw()),
418+
suid.map_or(-1_i32 as u32, |x| x.as_raw()),
419+
))
420+
}
415421
}
416422

417423
#[cfg(linux_kernel)]
@@ -427,9 +433,9 @@ pub(crate) fn setgid_thread(gid: crate::ugid::Gid) -> io::Result<()> {
427433
#[cfg(linux_kernel)]
428434
#[inline]
429435
pub(crate) fn setresgid_thread(
430-
rgid: crate::ugid::Gid,
431-
egid: crate::ugid::Gid,
432-
sgid: crate::ugid::Gid,
436+
rgid: Option<crate::ugid::Gid>,
437+
egid: Option<crate::ugid::Gid>,
438+
sgid: Option<crate::ugid::Gid>,
433439
) -> io::Result<()> {
434440
#[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]
435441
const SYS: c::c_long = c::SYS_setresgid32 as c::c_long;
@@ -440,7 +446,13 @@ pub(crate) fn setresgid_thread(
440446
fn setresgid(rgid: c::gid_t, egid: c::gid_t, sgid: c::gid_t) via SYS -> c::c_int
441447
}
442448

443-
unsafe { ret(setresgid(rgid.as_raw(), egid.as_raw(), sgid.as_raw())) }
449+
unsafe {
450+
ret(setresgid(
451+
ruid.map_or(-1_i32 as u32, |x| x.as_raw()),
452+
euid.map_or(-1_i32 as u32, |x| x.as_raw()),
453+
suid.map_or(-1_i32 as u32, |x| x.as_raw()),
454+
))
455+
}
444456
}
445457

446458
/// # Safety

src/backend/linux_raw/conv.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,14 @@ impl<'a, Num: ArgNumber> From<crate::ugid::Uid> for ArgReg<'a, Num> {
842842
}
843843
}
844844

845+
#[cfg(feature = "thread")]
846+
impl<'a, Num: ArgNumber> From<Option<crate::ugid::Uid>> for ArgReg<'a, Num> {
847+
#[inline]
848+
fn from(t: Option<crate::ugid::Uid>) -> Self {
849+
c_uint(t.map_or(-1_i32 as u32, |x| x.as_raw()))
850+
}
851+
}
852+
845853
#[cfg(any(feature = "process", feature = "thread"))]
846854
impl<'a, Num: ArgNumber> From<crate::ugid::Gid> for ArgReg<'a, Num> {
847855
#[inline]
@@ -850,6 +858,14 @@ impl<'a, Num: ArgNumber> From<crate::ugid::Gid> for ArgReg<'a, Num> {
850858
}
851859
}
852860

861+
#[cfg(feature = "thread")]
862+
impl<'a, Num: ArgNumber> From<Option<crate::ugid::Gid>> for ArgReg<'a, Num> {
863+
#[inline]
864+
fn from(t: Option<crate::ugid::Gid>) -> Self {
865+
c_uint(t.map_or(-1_i32 as u32, |x| x.as_raw()))
866+
}
867+
}
868+
853869
#[cfg(feature = "runtime")]
854870
impl<'a, Num: ArgNumber> From<crate::runtime::How> for ArgReg<'a, Num> {
855871
#[inline]

src/backend/linux_raw/thread/syscalls.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ pub(crate) fn setuid_thread(uid: crate::ugid::Uid) -> io::Result<()> {
405405

406406
#[inline]
407407
pub(crate) fn setresuid_thread(
408-
ruid: crate::ugid::Uid,
409-
euid: crate::ugid::Uid,
410-
suid: crate::ugid::Uid,
408+
ruid: Option<crate::ugid::Uid>,
409+
euid: Option<crate::ugid::Uid>,
410+
suid: Option<crate::ugid::Uid>,
411411
) -> io::Result<()> {
412412
#[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]
413413
unsafe {
@@ -426,9 +426,9 @@ pub(crate) fn setgid_thread(gid: crate::ugid::Gid) -> io::Result<()> {
426426

427427
#[inline]
428428
pub(crate) fn setresgid_thread(
429-
rgid: crate::ugid::Gid,
430-
egid: crate::ugid::Gid,
431-
sgid: crate::ugid::Gid,
429+
rgid: Option<crate::ugid::Gid>,
430+
egid: Option<crate::ugid::Gid>,
431+
sgid: Option<crate::ugid::Gid>,
432432
) -> io::Result<()> {
433433
#[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]
434434
unsafe {

src/thread/id.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ pub fn set_thread_uid(uid: Uid) -> io::Result<()> {
105105
/// [Linux]: https://man7.org/linux/man-pages/man2/setresuid.2.html
106106
/// [linux_notes]: https://man7.org/linux/man-pages/man2/setresuid.2.html#NOTES
107107
#[inline]
108-
pub fn set_thread_res_uid(ruid: Uid, euid: Uid, suid: Uid) -> io::Result<()> {
109-
backend::thread::syscalls::setresuid_thread(ruid, euid, suid)
108+
pub fn set_thread_res_uid<R, E, S>(ruid: R, euid: E, suid: S) -> io::Result<()>
109+
where
110+
R: Into<Option<Uid>>,
111+
E: Into<Option<Uid>>,
112+
S: Into<Option<Uid>>,
113+
{
114+
backend::thread::syscalls::setresuid_thread(ruid.into(), euid.into(), suid.into())
110115
}
111116

112117
/// `setgid(gid)`—Sets the effective group ID of the current thread.
@@ -154,8 +159,13 @@ pub fn set_thread_gid(gid: Gid) -> io::Result<()> {
154159
/// [Linux]: https://man7.org/linux/man-pages/man2/setresgid.2.html
155160
/// [linux_notes]: https://man7.org/linux/man-pages/man2/setresgid.2.html#NOTES
156161
#[inline]
157-
pub fn set_thread_res_gid(rgid: Gid, egid: Gid, sgid: Gid) -> io::Result<()> {
158-
backend::thread::syscalls::setresgid_thread(rgid, egid, sgid)
162+
pub fn set_thread_res_gid<R, E, S>(rgid: R, egid: E, sgid: S) -> io::Result<()>
163+
where
164+
R: Into<Option<Gid>>,
165+
E: Into<Option<Gid>>,
166+
S: Into<Option<Gid>>,
167+
{
168+
backend::thread::syscalls::setresgid_thread(rgid.into(), egid.into(), sgid.into())
159169
}
160170

161171
/// `setgroups(groups)`—Sets the supplementary group IDs for the calling

0 commit comments

Comments
 (0)