4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/metadata/ScanProfile/modules/HostScanItemFile.rb', line 4
def parse_data(ssu, data, &_blk)
if data.nil?
d = scan_definition
st = Time.now
$log.info "Scanning [Profile-Files] information."
yield({:msg => 'Scanning Profile-File'}) if block_given?
fs_files = d["stats"].collect { |s| s["target"] }.uniq
$log.info "Retrieving file metadata for targets."
files = ssu.shell_exec("ls -lLd --full-time #{fs_files.join(' ')} 2>/dev/null; true").split("\n")
files = MiqLinux::Utils.parse_ls_l_fulltime(files)
files.each do |f|
f.delete(:hard_links)
f[:rsc_type] = f.delete(:ftype)
f[:contents] = nil
end
md5_files = files.collect { |f| f[:name] if f[:rsc_type] == 'file' }.compact
$log.info "Retrieving md5 values for targets."
md5_files = ssu.shell_exec("md5sum #{md5_files.join(' ')} 2>/dev/null; true").split("\n")
md5_files.each do |line|
parts = line.chomp.split(' ')
md5, fname = parts[0], parts[1..-1].join(' ')
file = files.find { |f| f[:name] == fname }
file[:md5] = md5 unless file.nil?
end
cat_files = d["stats"].collect { |s| s["target"] if s["content"] }.compact.uniq
unless cat_files.empty?
$log.info "Retrieving content for specified targets."
cat_files = ssu.shell_exec("ls -1d #{cat_files.join(' ')} 2>/dev/null; true").split("\n")
cat_files.each do |fname|
fname = fname.chomp
next if fname.empty?
file = files.find { |f| f[:name] == fname }
$log.debug "Retrieving content for #{fname}."
file[:contents] = ssu.shell_exec("cat #{fname} 2>/dev/null; true")
end
end
d[:data] = files
$log.info "Scanning [Profile-Files] information ran for [#{Time.now - st}] seconds."
end
end
|