Set umask to 022 when creating config files. (refs #2221)
authorTim Pierce <twp@curoverse.com>
Thu, 3 Apr 2014 18:00:16 +0000 (14:00 -0400)
committerTim Pierce <twp@curoverse.com>
Thu, 3 Apr 2014 18:00:16 +0000 (14:00 -0400)
docker/build_tools/config.rb

index a31895baf540eceb5bff8831aa79b85d239286f5..7acb888419d9a71ee3656abd66c6a11c52dc4c14 100755 (executable)
@@ -34,35 +34,34 @@ Dir.glob('*/generated/*') do |stale_file|
   File.delete(stale_file)
 end
 
+File.umask(022)
 Dir.glob('*/*.in') do |template_file|
   generated_dir = File.join(File.dirname(template_file), 'generated')
   Dir.mkdir(generated_dir) unless Dir.exists? generated_dir
   output_path = File.join(generated_dir, File.basename(template_file, '.in'))
-  output = File.open(output_path, "w")
-  File.open(template_file) do |input|
-    input.each_line do |line|
+  File.open(output_path, "w") do |output|
+    File.open(template_file) do |input|
+      input.each_line do |line|
 
-      @count = 0
-      while @count < 10
-        @out = line.gsub!(/@@(.*?)@@/) do |var|
-          if config.key?(Regexp.last_match[1])
-            config[Regexp.last_match[1]]
-          else
-            var.gsub!(/@@/, '@_NOT_FOUND_@')
+        # This count is used to short-circuit potential
+        # infinite loops of variable substitution.
+        @count = 0
+        while @count < 10
+          @out = line.gsub!(/@@(.*?)@@/) do |var|
+            if config.key?(Regexp.last_match[1])
+              config[Regexp.last_match[1]]
+            else
+              var.gsub!(/@@/, '@_NOT_FOUND_@')
+            end
           end
+          break if @out.nil?
+          @count += 1
         end
-        break if @out.nil?
-        @count += 1
-      end
 
-      output.write(line)
+        output.write(line)
+      end
     end
   end
-  # Copy the owner's read+execute bits to group and other.
-  owner_perms = output.stat.mode & 0700
-  group_perms = (owner_perms & 0500) >> 3
-  output.chmod(owner_perms | group_perms | (group_perms >> 3))
-  output.close
 end
 
 # Copy the ssh public key file to base/generated (if a path is given)