class Fusuma::Plugin::Appmatcher::UserSwitcher
Constants
- User
Public Class Methods
new()
click to toggle source
# File lib/fusuma/plugin/appmatcher/user_switcher.rb, line 12 def initialize username = ENV['SUDO_USER'] || Etc.getlogin uid = `id -u #{username}`.chomp.to_i gid = `id -g #{username}`.chomp.to_i @login_user = User.new(username, uid, gid) end
Public Instance Methods
as_user(user = @login_user) { |user| ... }
click to toggle source
Execute the provided block in a child process as the specified user The parent blocks until the child finishes.
# File lib/fusuma/plugin/appmatcher/user_switcher.rb, line 29 def as_user(user = @login_user) fork do drop_priv(user) yield(user) if block_given? end end
drop_priv(user)
click to toggle source
Drops privileges to that of the specified user
# File lib/fusuma/plugin/appmatcher/user_switcher.rb, line 20 def drop_priv(user) # Process.initgroups(user.username, user.gid) Process::Sys.setegid(user.gid) Process::Sys.setgid(user.gid) Process::Sys.setuid(user.uid) end