File tree 5 files changed +12
-33
lines changed
5 files changed +12
-33
lines changed Original file line number Diff line number Diff line change @@ -33,9 +33,9 @@ def daemonize
33
33
Puppet ::Util ::Log . reopen
34
34
rescue => detail
35
35
Puppet . err "Could not start #{ Puppet [ :name ] } : #{ detail } "
36
- Puppet ::Util ::secure_open ( "/tmp/daemonout" , "w" ) { |f |
36
+ Puppet ::Util ::replace_file ( "/tmp/daemonout" , 0644 ) do |f |
37
37
f . puts "Could not start #{ Puppet [ :name ] } : #{ detail } "
38
- }
38
+ end
39
39
exit ( 12 )
40
40
end
41
41
end
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def daemonize
22
22
$stderr. reopen $stdout
23
23
Puppet ::Util ::Log . reopen
24
24
rescue => detail
25
- Puppet ::Util . secure_open ( "/tmp/daemonout" , "w" ) { |f |
25
+ Puppet ::Util . replace_file ( "/tmp/daemonout" , 0644 ) { |f |
26
26
f . puts "Could not start #{ Puppet [ :name ] } : #{ detail } "
27
27
}
28
28
raise "Could not start #{ Puppet [ :name ] } : #{ detail } "
Original file line number Diff line number Diff line change @@ -58,6 +58,6 @@ def write_benchmarks
58
58
data = { }
59
59
end
60
60
data [ branch ] = $benchmarks
61
- Puppet ::Util . secure_open ( file , "w" ) { |f | f . print YAML . dump ( data ) }
61
+ Puppet ::Util . replace_file ( file , 0644 ) { |f | f . print YAML . dump ( data ) }
62
62
end
63
63
end
Original file line number Diff line number Diff line change @@ -481,28 +481,6 @@ def thinmark
481
481
482
482
module_function :memory , :thinmark
483
483
484
- def secure_open ( file , must_be_w , &block )
485
- raise Puppet ::DevError , "secure_open only works with mode 'w'" unless must_be_w == 'w'
486
- raise Puppet ::DevError , "secure_open only requires a block" unless block_given?
487
- Puppet . warning "#{ file } was a symlink to #{ File . readlink ( file ) } " if File . symlink? ( file )
488
- if File . exists? ( file ) or File . symlink? ( file )
489
- wait = File . symlink? ( file ) ? 5.0 : 0.1
490
- File . delete ( file )
491
- sleep wait # give it a chance to reappear, just in case someone is actively trying something.
492
- end
493
- begin
494
- File . open ( file , File ::CREAT |File ::EXCL |File ::TRUNC |File ::WRONLY , &block )
495
- rescue Errno ::EEXIST
496
- desc = File . symlink? ( file ) ? "symlink to #{ File . readlink ( file ) } " : File . stat ( file ) . ftype
497
- puts "Warning: #{ file } was apparently created by another process (as"
498
- puts "a #{ desc } ) as soon as it was deleted by this process. Someone may be trying"
499
- puts "to do something objectionable (such as tricking you into overwriting system"
500
- puts "files if you are running as root)."
501
- raise
502
- end
503
- end
504
- module_function :secure_open
505
-
506
484
# Because IO#binread is only available in 1.9
507
485
def binread ( file )
508
486
File . open ( file , 'rb' ) { |f | f . read }
Original file line number Diff line number Diff line change @@ -36,14 +36,15 @@ def self.page(*sections)
36
36
37
37
def self . pdf ( text )
38
38
puts "creating pdf"
39
- Puppet ::Util . secure_open ( "/tmp/puppetdoc.txt" , "w" ) do |f |
40
- f . puts text
41
- end
42
- rst2latex = which ( 'rst2latex' ) || which ( 'rst2latex.py' ) || raise ( "Could not find rst2latex" )
39
+ rst2latex = which ( 'rst2latex' ) || which ( 'rst2latex.py' ) ||
40
+ raise ( "Could not find rst2latex" )
41
+
43
42
cmd = %{#{ rst2latex } /tmp/puppetdoc.txt > /tmp/puppetdoc.tex}
44
- Puppet ::Util . secure_open ( "/tmp/puppetdoc.tex" , "w" ) do |f |
45
- # If we get here without an error, /tmp/puppetdoc.tex isn't a tricky cracker's symlink
46
- end
43
+ Puppet ::Util . replace_file ( "/tmp/puppetdoc.txt" ) { |f | f . puts text }
44
+ # There used to be an attempt to use secure_open / replace_file to secure
45
+ # the target, too, but that did nothing: the race was still here. We can
46
+ # get exactly the same benefit from running this effort:
47
+ File . unlink ( '/tmp/puppetdoc.tex' ) rescue nil
47
48
output = %x{#{ cmd } }
48
49
unless $CHILD_STATUS == 0
49
50
$stderr. puts "rst2latex failed"
You can’t perform that action at this time.
0 commit comments