Skip to content

Commit 4c3d835

Browse files
author
Helen
committed
Merge pull request #140 from johngmyers/bug/master/2915-umask
(#2915) Don't expose keystore content when keystore initally empty
2 parents 953753d + 784a751 commit 4c3d835

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/puppet/provider/java_ks/keytool.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ def run_command(cmd, target=false, stdinfile=false, env={})
226226

227227
# the java keytool will not correctly deal with an empty target keystore
228228
# file. If we encounter an empty keystore target file, preserve the mode,
229-
# owner and group, and delete the empty file.
229+
# owner and group, temporarily raise the umask, and delete the empty file.
230230
if target and (File.exists?(target) and File.zero?(target))
231231
stat = File.stat(target)
232+
umask = File.umask(0077)
232233
File.delete(target)
233234
end
234235

@@ -259,12 +260,15 @@ def run_command(cmd, target=false, stdinfile=false, env={})
259260
end
260261
end
261262

262-
# for previously empty files, restore the mode, owner and group. The funky
263-
# double-take check is because on Suse defined? doesn't seem to behave
264-
# quite the same as on Debian, RedHat
263+
# for previously empty files, restore the umask, mode, owner and group.
264+
# The funky double-take check is because on Suse defined? doesn't seem
265+
# to behave quite the same as on Debian, RedHat
265266
if target and (defined? stat and stat)
266-
File.chmod(stat.mode, target)
267+
File.umask(umask)
268+
# Need to change group ownership before mode to prevent making the file
269+
# accessible to the wrong group.
267270
File.chown(stat.uid, stat.gid, target)
271+
File.chmod(stat.mode, target)
268272
end
269273

270274
return output

0 commit comments

Comments
 (0)