@@ -568,6 +568,7 @@ pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> {
568568
569569#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
570570mod linux {
571+ use libc:: { self , uid_t, gid_t} ;
571572 use sys:: syscall:: { syscall, SYSPIVOTROOT } ;
572573 use { Errno , Result , NixPath } ;
573574
@@ -587,6 +588,38 @@ mod linux {
587588 Errno :: result ( res) . map ( drop)
588589 }
589590
591+ /// Sets the real, effective, and saved uid.
592+ /// ([see setresuid(2)](http://man7.org/linux/man-pages/man2/setresuid.2.html))
593+ ///
594+ /// * `ruid`: real user id
595+ /// * `euid`: effective user id
596+ /// * `suid`: saved user id
597+ /// * returns: Ok or libc error code.
598+ ///
599+ /// Err is returned if the user doesn't have permission to set this UID.
600+ #[ inline]
601+ pub fn setresuid ( ruid : uid_t , euid : uid_t , suid : uid_t ) -> Result < ( ) > {
602+ let res = unsafe { libc:: setresuid ( ruid, euid, suid) } ;
603+
604+ Errno :: result ( res) . map ( drop)
605+ }
606+
607+ /// Sets the real, effective, and saved gid.
608+ /// ([see setresuid(2)](http://man7.org/linux/man-pages/man2/setresuid.2.html))
609+ ///
610+ /// * `rgid`: real user id
611+ /// * `egid`: effective user id
612+ /// * `sgid`: saved user id
613+ /// * returns: Ok or libc error code.
614+ ///
615+ /// Err is returned if the user doesn't have permission to set this GID.
616+ #[ inline]
617+ pub fn setresgid ( rgid : gid_t , egid : gid_t , sgid : gid_t ) -> Result < ( ) > {
618+ let res = unsafe { libc:: setresgid ( rgid, egid, sgid) } ;
619+
620+ Errno :: result ( res) . map ( drop)
621+ }
622+
590623 #[ inline]
591624 #[ cfg( feature = "execvpe" ) ]
592625 pub fn execvpe ( filename : & CString , args : & [ CString ] , env : & [ CString ] ) -> Result < ( ) > {
0 commit comments