-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Uehlinger
committed
May 15, 2010
1 parent
a17e641
commit cf89686
Showing
7 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'daemons/etc_extension' | ||
|
||
class CurrentProcess | ||
def self.change_privilege(user, group=user) | ||
puts "Changing process privilege to #{user}:#{group}" | ||
|
||
uid, gid = Process.euid, Process.egid | ||
target_uid = Etc.getpwnam(user).uid | ||
target_gid = Etc.getgrnam(group).gid | ||
|
||
if uid != target_uid || gid != target_gid | ||
Process.initgroups(user, target_gid) | ||
Process::GID.change_privilege(target_gid) | ||
Process::UID.change_privilege(target_uid) | ||
end | ||
rescue Errno::EPERM => e | ||
raise "Couldn't change user and group to #{user}:#{group}: #{e}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'etc' | ||
|
||
Etc.instance_eval do | ||
def groupname(gid) | ||
Etc.group {|e| return e.name if gid == e.gid } | ||
nil | ||
end | ||
def username(uid) | ||
Etc.passwd {|e| return e.name if uid == e.uid } | ||
nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ def exist? | |
|
||
def pid=(p) | ||
File.open(filename, 'w') {|f| | ||
f.chmod(0644) | ||
f.puts p #Process.pid | ||
} | ||
end | ||
|