Sha256: c2a904c5a653e7f0de8cc8e8960da0553895d2c4129d3330eee6bb34cf3c1c40

Contents?: true

Size: 590 Bytes

Versions: 4

Compression:

Stored size: 590 Bytes

Contents

require 'etc'

module RExec
  
  # Set the user of the current process. Supply either a user ID
  # or a user name.
  #
  # Be aware that on Mac OS X / Ruby 1.8 there are bugs when the user id
  # is negative (i.e. it doesn't work). For example "nobody" with uid -2
  # won't work.
  def self.change_user(user)
    if user.kind_of?(String)
      user = Etc.getpwnam(user).uid
    end

    Process::Sys.setuid(user)
  end
  
  
  # Get the user of the current process. Returns the user name.
  def self.current_user
    uid = Process::Sys.getuid
    
    Etc.getpwuid(uid).name
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rexec-1.2.1 lib/rexec/priviledges.rb
rexec-1.1.12 lib/rexec/priviledges.rb
rexec-1.1.11 lib/rexec/priviledges.rb
rexec-1.1.10 lib/rexec/priviledges.rb