lib/fusuma/plugin/appmatcher/user_switcher.rb in fusuma-plugin-appmatcher-0.1.6 vs lib/fusuma/plugin/appmatcher/user_switcher.rb in fusuma-plugin-appmatcher-0.2.0
- old
+ new
@@ -1,17 +1,21 @@
# frozen_string_literal: true
-require 'fusuma/custom_process'
-require 'etc'
+require "fusuma/custom_process"
+require "etc"
module Fusuma
module Plugin
module Appmatcher
+ # Drop sudo privileges
class UserSwitcher
include CustomProcess
User = Struct.new(:username, :uid, :gid)
+
+ attr_reader :login_user
+
def initialize
- username = ENV['SUDO_USER'] || Etc.getlogin
+ 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