diff --git a/docs/refguide.xml b/docs/refguide.xml index 6b7b0a75a..852753df2 100644 --- a/docs/refguide.xml +++ b/docs/refguide.xml @@ -3110,8 +3110,10 @@ overwhelming requests. Specify to only see --servicedb Asks Nmap to use the specified services file rather than the nmap-services data file that - comes with Nmap. See the description for - for more information on Nmap's data files. + comes with Nmap. Using this option also causes a fast scan + () to be used. See the description for + for more information on Nmap's data + files. diff --git a/output.cc b/output.cc index 0d93b75cf..0c68c0250 100644 --- a/output.cc +++ b/output.cc @@ -1807,45 +1807,6 @@ 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 @@ -1854,7 +1815,8 @@ 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 + + /* 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; @@ -1880,9 +1842,20 @@ void printdatafilepaths() { 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; + char *s; + r.data_file = map_iter->first; - r.dir = get_dirname(map_iter->second); - r.file = get_filename(map_iter->second); + s = path_get_dirname(map_iter->second.c_str()); + if (s == NULL) + fatal("%s: failed to allocate temporary memory", __func__); + r.dir = std::string(s); + free(s); + s = path_get_basename(map_iter->second.c_str()); + if (s == NULL) + fatal("%s: failed to allocate temporary memory", __func__); + r.file = std::string(s); + free(s); + df.push_back(r); } @@ -1917,12 +1890,12 @@ void printdatafilepaths() { print a brief message unless we are also in debugging mode. */ log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "Read data files from: %s.\n", dir.c_str()); } else if (num_dirs == 1 && o.debugging || num_dirs > 1) { - /* If files were read from more than one directory was found, or if they - were read from one directory and we are in debugging mode, display all - the files grouped by directory. */ + /* If files were read from more than one directory, or if they were read + from one directory and we are in debugging mode, display all the files + grouped by directory. */ iter = df.begin(); while (iter != df.end()) { - std::string dir = iter->dir; + 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. */