-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcopycomment
More file actions
executable file
·68 lines (48 loc) · 1.36 KB
/
Copy pathcopycomment
File metadata and controls
executable file
·68 lines (48 loc) · 1.36 KB
1
2
3
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl
#
# Copy FINDING_DETAILS to COMMENTS if the status is NotAFinding
#
use XML::LibXML;
if ($#ARGV != 1) {
usage();
}
$input = XML::LibXML->load_xml(location => $ARGV[0]);
@vuls = $input->findnodes('/CHECKLIST/STIGS/iSTIG/VULN');
die "No vulnerabilities found in $ARGV[0]\n" if (scalar(@vuls) == 0);
foreach my $vul (@vuls) {
my $v = $vul->findvalue('STIG_DATA[VULN_ATTRIBUTE="Vuln_Num"]/ATTRIBUTE_DATA');
die "Internal error: cannot find vulnerability number\n"
if (! defined($v) || $v eq '');
my $status = $vul->findvalue('STATUS');
if ($status ne 'NotAFinding' && $status ne 'Not_Applicable') {
print "Skipping $v, status is $status\n";
next;
}
my $details = $vul->findvalue('FINDING_DETAILS');
if (defined($details) && $details ne '') {
print "Copying FINDING_DETAILS to COMMENTS for $v\n";
my $comments = ($vul->findnodes('COMMENTS'))[0];
die "Internal error: no COMMENTS for $v\n"
if (! defined($comments));
my ($ct) = $comments->childNodes();
if (defined($ct)) {
$ct->setData($details);
} else {
$comments->appendTextNode($details);
}
}
}
#
# Make sure we don't have any self-closing tags
#
for my $node ($input->findnodes('//*[not(node())]')) {
$node->appendChild($input->createTextNode(''));
}
$input->toFile($ARGV[1], 0);
exit 0;
sub usage {
print <<"EOF";
Usage: $0 input-file output-file
EOF
exit 1;
}