From 814560c996f8725c4df4e610038d4f8d38431920 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 9 Jan 2015 20:15:17 -0800 Subject: [PATCH 1/2] ruby2: fix fds. One of the Ruby 1.9->Ruby 2 upstream changes was that the handling of file descriptors on exec calls had two changes in defaults: - All non-primary FDs are closed by default - All FDs have CLOEXEC/close_on_exec set: http://ruby-doc.org/core-2.2.0/IO.html#method-i-close_on_exec-3D Fixes formorer/pwstore#3 Signed-off-by: Robin H. Johnson --- pws | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pws b/pws index c1c5a08..287d106 100755 --- a/pws +++ b/pws @@ -79,10 +79,10 @@ class GnuPG end def GnuPG.open3call(cmd, intxt, args, require_success = false, do_status=true) - inR, inW = IO.pipe - outR, outW = IO.pipe - errR, errW = IO.pipe - statR, statW = IO.pipe if do_status + inR, inW = IO.pipe.each { |fd| fd.close_on_exec = false } + outR, outW = IO.pipe.each { |fd| fd.close_on_exec = false } + errR, errW = IO.pipe.each { |fd| fd.close_on_exec = false } + statR, statW = IO.pipe.each { |fd| fd.close_on_exec = false } if do_status opt_statusfd, opt_output, arg_input = nil, nil, nil inO = $stdin outO = $stdout @@ -104,7 +104,7 @@ class GnuPG STDOUT.reopen(outW) STDERR.reopen(errW) begin - exec(*fullcmd) + exec(*fullcmd, :close_others => false) rescue Exception => e outW.puts("[PWSEXECERROR]: #{e}") exit(1) From 79c1243da00d17afe5bd60fb26d21276a9ea19ae Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 9 Jan 2015 20:22:38 -0800 Subject: [PATCH 2/2] If .users.asc exists as well as .users, use .users.asc instead; make life easier for changing stuff. Signed-off-by: Robin H. Johnson --- pws | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pws b/pws index 287d106..49d9b74 100755 --- a/pws +++ b/pws @@ -278,8 +278,9 @@ class GroupConfig end end + usersfile = self.find_users_file() if not goodsig - STDERR.puts ".users file is not signed properly. GnuPG said on stdout:" + STDERR.puts "#{usersfile} file is not signed properly. GnuPG said on stdout:" STDERR.puts outtxt STDERR.puts "and on stderr:" STDERR.puts stderrtxt @@ -289,21 +290,26 @@ class GroupConfig end if not trusted.include?(validsig) - STDERR.puts ".users file is signed by #{validsig} which is not in ~/.pws-trusted-users" + STDERR.puts "#{usersfile} file is signed by #{validsig} which is not in ~/.pws-trusted-users" exit(1) end if not exitstatus==0 - STDERR.puts "gpg verify failed for .users file" + STDERR.puts "gpg verify failed for #{usersfile} file" exit(1) end return outtxt end + def find_users_file + return %w{.users.asc .users}.find(nil) { |f| FileTest.exists?(f) } + end + def parse_file begin - f = File.open('.users') + usersfile = self.find_users_file() + f = File.open(usersfile) rescue Exception => e STDERR.puts e exit(1) @@ -600,8 +606,8 @@ class Ls end puts "#{dirname}:" Dir.chdir(dirname) do - unless FileTest.exists?(".users") - STDERR.puts "The .users file does not exists here. This is not a password store, is it?" + unless %w{.users .users.asc}.any? { |f| FileTest.exists?(f) } + STDERR.puts "The neither .users nor .users.asc exists here. This is not a password store, is it?" exit(1) end dir.sort.each do |filename|