From 3c00fe9f419cef63520f16b051950a5693d74d6e Mon Sep 17 00:00:00 2001 From: usa Date: Thu, 24 Apr 2014 14:19:21 +0000 Subject: [PATCH] * 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 --- ChangeLog | 7 +++++++ lib/fileutils.rb | 4 ++-- lib/webrick/utils.rb | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index ac6a27621b..3f7ab2004f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Apr 24 23:17:25 2014 NAKAMURA Usaku + + * lib/fileutils.rb (fu_get_uid, fu_get_gid): Etc.getpwnam/getgrnam may + returns nil. + + * lib/webrick/utils.rb (su): ditto. + Thu Apr 24 22:55:22 2014 Tanaka Akira * bootstraptest/test_io.rb: Add etc.so to $" before require 'tmpdir'. 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)