diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-24 14:19:21 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-24 14:19:21 +0000 |
commit | 3c00fe9f419cef63520f16b051950a5693d74d6e (patch) | |
tree | 685672ded33d665ba107865810294777b66276fc /lib | |
parent | a87c3b4869daaadbeeea0b5b067bc9cd19ac4911 (diff) |
* lib/fileutils.rb (fu_get_uid, fu_get_gid): Etc.getpwnam/getgrnam may
returns nil.
* lib/webrick/utils.rb (su): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fileutils.rb | 4 | ||||
-rw-r--r-- | lib/webrick/utils.rb | 3 |
2 files changed, 3 insertions, 4 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 1b7bb11b18..0dfbf41d6c 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1106,7 +1106,7 @@ module FileUtils when /\A\d+\z/ user.to_i else - Etc.getpwnam(user).uid + Etc.getpwnam(user) ? Etc.getpwnam(user).uid : nil end end private_module_function :fu_get_uid @@ -1119,7 +1119,7 @@ module FileUtils when /\A\d+\z/ group.to_i else - Etc.getgrnam(group).gid + Etc.getgrnam(group) ? Etc.getgrnam(group).gid : nil end end private_module_function :fu_get_gid diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index a6b5cc6a9c..185b1723f3 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -41,8 +41,7 @@ module WEBrick ## # Changes the process's uid and gid to the ones of +user+ def su(user) - if defined?(Etc) - pw = Etc.getpwnam(user) + if defined?(Etc) && (pw = Etc.getpwnam(user)) Process::initgroups(user, pw.gid) Process::Sys::setgid(pw.gid) Process::Sys::setuid(pw.uid) |