Forum: Ruby Status of getresuid? Dropping privilege temporarily...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (johncarter)
on 2007-06-26 05:55
(Received via mailing list)
I wanted to reliably temporarily or permanently drop privileges from
Ruby so I tried porting the code in ...

But rapidly found that...
   a) They strongly recommend you use setresuid/getresuid
   b) Ruby strangely enough has setresuid but not getresuid.

Any idea why?

Anyhoo, here is a crude sudo based hack around...

module Privilege

    def Privilege::drop_privilege_temporarily(&block)
       # Doesn't look like we've been sudone... So do nothing...
       if ENV.has_key? "SUDO_UID"


       sudo_uid = ENV["SUDO_UID"].to_i

       current_uid = Process::Sys::geteuid

          Process::Sys::seteuid( sudo_uid)

          Process::Sys::seteuid( current_uid)


# p Process::Sys::geteuid
# Privilege::drop_privilege_temporarily do
#    p Process::Sys::geteuid
# end
# p Process::Sys::geteuid

John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email :
New Zealand
This topic is locked and can not be replied to.