#!/usr/bin/env ruby # # A simple utility for watching a given directory for temporary files, # directories, etc. Primarily used to casually discover applications that # are vulnerable to race conditions or symlink foo. # # The irony? There is no mktemp that creates temporary directories, so # here in code that is designed to point out temporary directory/file # issues, I have to reinvent the wheel. # # Temporary files -- yer doing it wrong. # # Jon Hart require 'find' require 'ftools' require 'optparse' require 'ostruct' # generic options parser class Options def self.parse(name, args) options = OpenStruct.new options.verbose = false options.copy = nil options.exclude = [] options.sleep = 1 opts = OptionParser.new do |opts| opts.banner = "#{File.basename(name)} ( http://spoofed.org )" opts.banner += "\nUsage: #{name} [options] /dir/to/watch1 /watch/me/too ..." opts.on("-c", "--copy DIR") do |o| options.copy = o end opts.on("-e", "--exclude PATTERN") do |o| options.exclude << o end opts.on_tail("-h", "--help", "Show help") do puts opts exit end opts.on("-s", "--sleep SECS", "Sleep between checks") do |o| options.sleep = o.to_i end opts.on("-v", "--verbose", "Be verbose") do |o| options.verbose = o end end begin opts.parse!(args) rescue OptionParser::ParseError => e puts "#{e}\n\n#{opts}" exit(1) end options end end # given the path to a file, directory, etc, return a CSV of its info def getinfo(path) require 'etc.so' stat = File.lstat(path) info = [] info << "