1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-09 06:56:35 +00:00

merge soc07 r4860 - Add verbose data file path reporting. Some more changes might be coming, for example to change the conditions under which this information is displayed.

This commit is contained in:
fyodor
2007-08-11 03:59:18 +00:00
parent cb799fcef9
commit 5e3bb361f2
10 changed files with 120 additions and 0 deletions

View File

@@ -103,10 +103,13 @@
/* Character pool memory allocation */
#include "MACLookup.h"
#include "NmapOps.h"
#include "nmap.h"
#include "nmap_error.h"
#include "charpool.h"
extern NmapOps o;
struct MAC_entry {
int prefix; /* -1 means none set */
char *vendor;
@@ -156,6 +159,8 @@ static void mac_prefix_init() {
error("Unable to open %s. Ethernet vendor correlation will not be performed ", filename);
return;
}
/* Record where this data file was found. */
o.loaded_data_files["nmap-mac-prefixes"] = filename;
while(fgets(line, sizeof(line), fp)) {
lineno++;

View File

@@ -309,6 +309,9 @@ class NmapOps {
the file names defined in this map instead of searching for a matching
file. */
std::map<std::string, std::string> requested_data_files;
/* A map from data file names to the paths at which they were actually found.
Only files that were actually read should be in this map. */
std::map<std::string, std::string> loaded_data_files;
bool mass_dns;
int resolve_all;
char *dns_servers;

View File

@@ -1793,6 +1793,9 @@ int nmap_main(int argc, char *argv[]) {
num_host_exp_groups = 0;
free(host_exp_group);
if (o.verbose)
printdatafilepaths();
printfinaloutput();
free_scan_lists(ports);

View File

@@ -147,6 +147,8 @@ static void rpc_services_init() {
if (!fp) {
fatal("Unable to open %s for reading rpc information", filename);
}
/* Record where this data file was found. */
o.loaded_data_files["nmap-rpc"] = filename;
while(fgets(line, sizeof(line), fp)) {
lineno++;

View File

@@ -2138,6 +2138,8 @@ char filename[256];
if (nmap_fetchfile(filename, sizeof(filename), dbname) != 1){
fatal("OS scan requested but I cannot find %s file. It should be in %s, ~/.nmap/ or .", dbname, NMAPDATADIR);
}
/* Record where this data file was found. */
o.loaded_data_files[dbname] = filename;
return parse_fingerprint_file(filename);
}

View File

@@ -1807,3 +1807,98 @@ void printfinaloutput() {
log_flush_all();
}
/* Returns the position of the last directory separator (slash, also backslash
on Win32) in a path. Returns -1 if none was found. */
static int find_last_path_separator(const std::string& path) {
#ifndef WIN32
const char *PATH_SEPARATORS = "/";
#else
const char *PATH_SEPARATORS = "\\/";
#endif
return path.find_last_of(PATH_SEPARATORS);
}
/* Returns the directory name part of a path (everything up to the last
directory separator. If there is no separator, returns ".". If there is only
one separator and it is the first character, returns "/". */
static std::string get_dirname(const std::string& path) {
int i;
i = find_last_path_separator(path);
if (i == -1)
return ".";
else if (i == 0)
return "/";
else
return path.substr(0, i);
}
/* Returns the file name part of a path (everything after the last directory
separator). */
static std::string get_filename(const std::string& path) {
int i;
i = find_last_path_separator(path);
if (i == -1)
return path;
else
return path.substr(i + 1);
}
/* A record consisting of a data file name ("nmap-services", "nmap-os-db",
etc.), and the directory and file in which is was found. This is a
broken-down version of what is stored in o.loaded_data_files. It is used in
printdatafilepaths. */
struct data_file_record {
std::string data_file;
std::string dir;
std::string file;
/* Compares this record to another. First, compare the directory names, then
compare the file names. */
bool operator<(const struct data_file_record& other) {
int cmp;
cmp = dir.compare(other.dir);
if (cmp == 0)
cmp = file.compare(other.file);
return cmp < 0;
}
};
/* Prints the names of data files that were loaded and the paths at which they
were found. */
void printdatafilepaths() {
std::list<struct data_file_record> df;
std::list<struct data_file_record>::iterator iter;
std::map<std::string, std::string>::iterator map_iter;
/* Copy the elements of o.loaded_data_files (each a (data file, path) pair) to
a list of data_file_records to make them easier to manipulate. */
for (map_iter = o.loaded_data_files.begin(); map_iter != o.loaded_data_files.end(); map_iter++) {
struct data_file_record r;
r.data_file = map_iter->first;
r.dir = get_dirname(map_iter->second);
r.file = get_filename(map_iter->second);
df.push_back(r);
}
/* Sort the list, first by directory name, then by file name. This ensures
that records with the same directory name are contiguous. */
df.sort();
/* Iterate over the list and display file names. */
iter = df.begin();
while (iter != df.end()) {
std::string dir = iter->dir;
/* Write the directory name. */
log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "Read from %s:", dir.c_str());
/* Write files in that directory on the same line. */
while (iter != df.end() && iter->dir == dir) {
log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, " %s", iter->file.c_str());
iter++;
}
log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, ".\n");
}
}

View File

@@ -205,5 +205,9 @@ void printStatusMessage();
of an Nmap run */
void printfinaloutput();
/* Prints the names of data files that were loaded and the paths at which they
were found. */
void printdatafilepaths();
char* xml_convert (const char* str);
#endif /* OUTPUT_H */

View File

@@ -133,6 +133,8 @@ static int nmap_protocols_init() {
if (!fp) {
fatal("Unable to open %s for reading protocol information", filename);
}
/* Record where this data file was found. */
o.loaded_data_files["nmap-protocols"] = filename;
memset(protocol_table, 0, sizeof(protocol_table));

View File

@@ -1147,6 +1147,8 @@ static void parse_nmap_service_probes(AllProbes *AP) {
}
parse_nmap_service_probe_file(AP, filename);
/* Record where this data file was found. */
o.loaded_data_files["nmap-service-probes"] = filename;
}
AllProbes *AllProbes::global_AP;

View File

@@ -156,6 +156,8 @@ static int nmap_services_init() {
if (!fp) {
fatal("Unable to open %s for reading service information", filename);
}
/* Record where this data file was found. */
o.loaded_data_files["nmap-services"] = filename;
memset(service_table, 0, sizeof(service_table));