From 1599aa6fe842142765b0b2842d82e73e8ecdcd31 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 5 May 2012 18:02:33 +0000 Subject: [PATCH] Make osclass XML elements children of the osmatch element they belong to. Add the --deprecated-xml-osclass to restore the old output. --- CHANGELOG | 9 +++++++++ NmapOps.cc | 1 + NmapOps.h | 6 ++++++ docs/nmap.dtd | 4 ++-- nmap.cc | 6 +++++- output.cc | 21 +++++++++++++++++---- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index eccf48d9c..9f1310342 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,14 @@ # Nmap Changelog ($Id$); -*-text-*- +o In XML output, elements are now child elements of the + they belong to. Old output was thus: + ...... + New output is: + ...... + 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 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: diff --git a/NmapOps.cc b/NmapOps.cc index 07ff45005..10d83dfd9 100644 --- a/NmapOps.cc +++ b/NmapOps.cc @@ -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; diff --git a/NmapOps.h b/NmapOps.h index 7d6dbb923..345571a6d 100644 --- a/NmapOps.h +++ b/NmapOps.h @@ -320,7 +320,13 @@ class NmapOps { bool mass_dns; int resolve_all; char *dns_servers; + + // Logging options bool log_errors; + // If true, write as in xmloutputversion 1.03 + // rather than as in 1.04 and later. + bool deprecated_xml_osclass; + bool traceroute; bool reason; bool adler32; diff --git a/docs/nmap.dtd b/docs/nmap.dtd index 26084a87c..614d91f1e 100644 --- a/docs/nmap.dtd +++ b/docs/nmap.dtd @@ -235,7 +235,7 @@ output CDATA #REQUIRED > - + - + 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++) {