Module: ServerEngine::Privilege
- Defined in:
- lib/serverengine/privilege.rb
Class Method Summary collapse
Class Method Details
.change(user, group) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/serverengine/privilege.rb', line 38 def self.change(user, group) if group etc_group = get_etc_group(group) Process::GID.change_privilege(etc_group.gid) end if user etc_pw = get_etc_passwd(user) user_groups = [etc_pw.gid] Etc.setgrent Etc.group { |gr| user_groups << gr.gid if gr.mem.include?(etc_pw.name) } # emulate 'id -G' Process.groups = Process.groups | user_groups Process::UID.change_privilege(etc_pw.uid) end nil end |
.get_etc_group(group) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/serverengine/privilege.rb', line 30 def self.get_etc_group(group) if group.to_i.to_s == group Etc.getgrgid(group.to_i) else Etc.getgrnam(group) end end |
.get_etc_passwd(user) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/serverengine/privilege.rb', line 22 def self.get_etc_passwd(user) if user.to_i.to_s == user Etc.getpwuid(user.to_i) else Etc.getpwnam(user) end end |