mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 17:59:04 +00:00
merge soc07 r4899:4902 - Add a note to the reference guide saying that --servicedb implies -F; Rewrite in C the dirname and basename replacements used in printdatafilepaths and move them into nbase. Their names are now path_get_dirname and path_get_basename.; Give a fatal error in printdatafilepaths if memory can't be allocated, rather than returning silently.
This commit is contained in:
@@ -3110,8 +3110,10 @@ overwhelming requests. Specify <option>--open</option> to only see
|
|||||||
<indexterm significance="normal"><primary>--servicedb</primary></indexterm>
|
<indexterm significance="normal"><primary>--servicedb</primary></indexterm>
|
||||||
<para>Asks Nmap to use the specified services file rather than
|
<para>Asks Nmap to use the specified services file rather than
|
||||||
the <filename>nmap-services</filename> data file that
|
the <filename>nmap-services</filename> data file that
|
||||||
comes with Nmap. See the description for <option>--datadir</option>
|
comes with Nmap. Using this option also causes a fast scan
|
||||||
for more information on Nmap's data files.</para>
|
(<option>-F</option>) to be used. See the description for
|
||||||
|
<option>--datadir</option> for more information on Nmap's data
|
||||||
|
files.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|||||||
65
output.cc
65
output.cc
@@ -1807,45 +1807,6 @@ void printfinaloutput() {
|
|||||||
log_flush_all();
|
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",
|
/* 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
|
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
|
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 data_file;
|
||||||
std::string dir;
|
std::string dir;
|
||||||
std::string file;
|
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. */
|
compare the file names. */
|
||||||
bool operator<(const struct data_file_record& other) {
|
bool operator<(const struct data_file_record& other) {
|
||||||
int cmp;
|
int cmp;
|
||||||
@@ -1880,9 +1842,20 @@ void printdatafilepaths() {
|
|||||||
a list of data_file_records to make them easier to manipulate. */
|
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++) {
|
for (map_iter = o.loaded_data_files.begin(); map_iter != o.loaded_data_files.end(); map_iter++) {
|
||||||
struct data_file_record r;
|
struct data_file_record r;
|
||||||
|
char *s;
|
||||||
|
|
||||||
r.data_file = map_iter->first;
|
r.data_file = map_iter->first;
|
||||||
r.dir = get_dirname(map_iter->second);
|
s = path_get_dirname(map_iter->second.c_str());
|
||||||
r.file = get_filename(map_iter->second);
|
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);
|
df.push_back(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1917,12 +1890,12 @@ void printdatafilepaths() {
|
|||||||
print a brief message unless we are also in debugging mode. */
|
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());
|
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) {
|
} else if (num_dirs == 1 && o.debugging || num_dirs > 1) {
|
||||||
/* If files were read from more than one directory was found, or if they
|
/* If files were read from more than one directory, or if they were read
|
||||||
were read from one directory and we are in debugging mode, display all
|
from one directory and we are in debugging mode, display all the files
|
||||||
the files grouped by directory. */
|
grouped by directory. */
|
||||||
iter = df.begin();
|
iter = df.begin();
|
||||||
while (iter != df.end()) {
|
while (iter != df.end()) {
|
||||||
std::string dir = iter->dir;
|
dir = iter->dir;
|
||||||
/* Write the directory name. */
|
/* Write the directory name. */
|
||||||
log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "Read from %s:", dir.c_str());
|
log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "Read from %s:", dir.c_str());
|
||||||
/* Write files in that directory on the same line. */
|
/* Write files in that directory on the same line. */
|
||||||
|
|||||||
Reference in New Issue
Block a user