Make osclass XML elements children of the osmatch element they belong to.

Add the --deprecated-xml-osclass to restore the old output.
This commit is contained in:
david 2012-05-05 18:02:33 +00:00
parent 20b56cb6a2
commit 1599aa6fe8
6 changed files with 40 additions and 7 deletions

View file

@ -1,5 +1,14 @@
# Nmap Changelog ($Id$); -*-text-*-
o In XML output, <osclass> elements are now child elements of the
<osmatch> they belong to. Old output was thus:
<os><osclass/><osclass/>...<osmatch/><osmatch/>...</os>
New output is:
<os><osmatch><osclass/><osclass/>...</osmatch>...</os>
The option --deprecated-xml-osclass restores the old output, in case
you use an Nmap XML parser that doesn't understand the new
structure. The xmloutputversion has been increased to 1.04.
o Added a new <target> element to XML output that indicates when a
target specification was ignored, perhaps because of a syntax error
or DNS failure. It looks like this:

View file

@ -317,6 +317,7 @@ void NmapOps::Initialize() {
spoof_mac_set = false;
mass_dns = true;
log_errors = false;
deprecated_xml_osclass = false;
resolve_all = 0;
dns_servers = NULL;
numhosts_scanned = 0;

View file

@ -320,7 +320,13 @@ class NmapOps {
bool mass_dns;
int resolve_all;
char *dns_servers;
// Logging options
bool log_errors;
// If true, write <os><osclass/><osmatch/></os> as in xmloutputversion 1.03
// rather than <os><osmatch><osclass/></osmatch></os> as in 1.04 and later.
bool deprecated_xml_osclass;
bool traceroute;
bool reason;
bool adler32;

View file

@ -235,7 +235,7 @@
output CDATA #REQUIRED
>
<!ELEMENT os ( portused* , osclass*, osmatch*, osfingerprint* ) >
<!ELEMENT os ( portused* , osmatch*, osfingerprint* ) >
<!ELEMENT portused EMPTY >
<!ATTLIST portused
@ -253,7 +253,7 @@
>
<!ELEMENT osmatch EMPTY >
<!ELEMENT osmatch (osclass*) >
<!ATTLIST osmatch
name CDATA #REQUIRED
accuracy %attr_numeric; #REQUIRED

View file

@ -621,6 +621,8 @@ void parse_options(int argc, char **argv) {
{"system-dns", no_argument, 0, 0},
{"log_errors", no_argument, 0, 0},
{"log-errors", no_argument, 0, 0},
{"deprecated_xml_osclass", no_argument, 0, 0},
{"deprecated-xml-osclass", no_argument, 0, 0},
{"dns_servers", required_argument, 0, 0},
{"dns-servers", required_argument, 0, 0},
{"port-ratio", required_argument, 0, 0},
@ -832,6 +834,8 @@ void parse_options(int argc, char **argv) {
o.dns_servers = strdup(optarg);
} else if (optcmp(long_options[option_index].name, "log-errors") == 0) {
o.log_errors = 1;
} else if (optcmp(long_options[option_index].name, "deprecated-xml-osclass") == 0) {
o.deprecated_xml_osclass = true;
} else if (strcmp(long_options[option_index].name, "webxml") == 0) {
o.setXSLStyleSheet("http://nmap.org/svn/docs/nmap.xsl");
} else if (strcmp(long_options[option_index].name, "oN") == 0) {
@ -1634,7 +1638,7 @@ int nmap_main(int argc, char *argv[]) {
xml_attribute("start", "%lu", (unsigned long) timep);
xml_attribute("startstr", "%s", mytime);
xml_attribute("version", "%s", NMAP_VERSION);
xml_attribute("xmloutputversion", "1.03");
xml_attribute("xmloutputversion", "1.04");
xml_close_start_tag();
xml_newline();

View file

@ -1322,7 +1322,19 @@ static void write_xml_osmatch(const FingerMatch *match, double accuracy) {
xml_attribute("name", "%s", match->OS_name);
xml_attribute("accuracy", "%d", (int) (accuracy * 100));
xml_attribute("line", "%d", match->line);
xml_close_empty_tag();
/* When o.deprecated_xml_osclass is true, we don't write osclass elements as
children of osmatch but rather as unrelated siblings. */
if (match->OS_class.empty() || o.deprecated_xml_osclass) {
xml_close_empty_tag();
} else {
unsigned int i;
xml_close_start_tag();
xml_newline();
for (i = 0; i < match->OS_class.size(); i++)
write_xml_osclass(&match->OS_class[i], accuracy);
xml_end_tag();
}
xml_newline();
}
@ -1485,9 +1497,10 @@ static void printosclassificationoutput(const struct
if (OSR->overall_results == OSSCAN_SUCCESS) {
/* Print the OS Classification results to XML output */
for (classno = 0; classno < OSR->OSC_num_matches; classno++)
write_xml_osclass(OSR->OSC[classno], OSR->OSC_Accuracy[classno]);
if (o.deprecated_xml_osclass) {
for (classno = 0; classno < OSR->OSC_num_matches; classno++)
write_xml_osclass(OSR->OSC[classno], OSR->OSC_Accuracy[classno]);
}
// Now to create the fodder for normal output
for (classno = 0; classno < OSR->OSC_num_matches; classno++) {