2015-08-03 03:11:01 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
|
|
|
# license: All rights reserved
|
|
|
|
|
2015-09-10 09:19:00 +00:00
|
|
|
module FindFiles
|
2015-08-03 03:11:01 +00:00
|
|
|
TYPES = {
|
|
|
|
block: 'b',
|
|
|
|
character: 'c',
|
|
|
|
directory: 'd',
|
|
|
|
pipe: 'p',
|
|
|
|
file: 'f',
|
|
|
|
link: 'l',
|
|
|
|
socket: 's',
|
2015-09-10 01:39:43 +00:00
|
|
|
door: 'D',
|
2015-08-03 03:11:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 09:19:00 +00:00
|
|
|
def find_files(path, opts = {})
|
2015-08-03 03:11:01 +00:00
|
|
|
depth = opts[:depth]
|
2015-09-05 14:07:54 +00:00
|
|
|
type = TYPES[opts[:type].to_sym]
|
2015-08-03 03:11:01 +00:00
|
|
|
|
|
|
|
cmd = "find #{path}"
|
|
|
|
cmd += " -maxdepth #{depth.to_i}" if depth.to_i > 0
|
|
|
|
cmd += " -type #{type}" unless type.nil?
|
|
|
|
|
2015-09-10 09:19:00 +00:00
|
|
|
result = vulcano.run_command(cmd)
|
|
|
|
exit_status = result.exit_status
|
2015-08-03 03:11:01 +00:00
|
|
|
|
2015-09-10 09:19:00 +00:00
|
|
|
return [nil, exit_status] unless exit_status == 0
|
|
|
|
files = result.stdout.split("\n").
|
|
|
|
map(&:strip).
|
|
|
|
find_all { |x| !x.empty? }
|
|
|
|
[files, exit_status]
|
2015-08-03 03:11:01 +00:00
|
|
|
end
|
|
|
|
end
|