mirror of
https://github.com/nmap/nmap.git
synced 2026-08-03 22:29:06 +00:00
merge soc07 r4803 - Implement the --services option using a filename translation map and some additional logic in nmap_fetchfile.
This commit is contained in:
parent
3f2f00900a
commit
b642be63c5
2 changed files with 24 additions and 1 deletions
|
|
@ -299,6 +299,11 @@ class NmapOps {
|
|||
int ttl; // Time to live
|
||||
int badsum;
|
||||
char *datadir;
|
||||
/* A map from abstract data file names like "nmap-services" and "nmap-os-db"
|
||||
to paths which have been requested by the user. nmap_fetchfile will return
|
||||
the file names defined in this map instead of searching for a matching
|
||||
file. */
|
||||
std::map<std::string, std::string> requested_data_files;
|
||||
bool mass_dns;
|
||||
int resolve_all;
|
||||
char *dns_servers;
|
||||
|
|
|
|||
20
nmap.cc
20
nmap.cc
|
|
@ -506,6 +506,7 @@ int nmap_main(int argc, char *argv[]) {
|
|||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"datadir", required_argument, 0, 0},
|
||||
{"services", required_argument, 0, 0},
|
||||
{"debug", optional_argument, 0, 'd'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"iflist", no_argument, 0, 0},
|
||||
|
|
@ -718,6 +719,9 @@ int nmap_main(int argc, char *argv[]) {
|
|||
}
|
||||
} else if (strcmp(long_options[option_index].name, "datadir") == 0) {
|
||||
o.datadir = strdup(optarg);
|
||||
} else if (strcmp(long_options[option_index].name, "services") == 0) {
|
||||
o.requested_data_files["nmap-services"] = optarg;
|
||||
o.fastscan++;
|
||||
} else if (optcmp(long_options[option_index].name, "append-output") == 0) {
|
||||
o.append_output = 1;
|
||||
} else if (strcmp(long_options[option_index].name, "noninteractive") == 0) {
|
||||
|
|
@ -2580,8 +2584,11 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) {
|
|||
struct passwd *pw;
|
||||
char dot_buffer[512];
|
||||
static int warningcount = 0;
|
||||
std::map<std::string, std::string>::iterator iter;
|
||||
|
||||
/* First we try [--datadir]/file, then $NMAPDIR/file
|
||||
/* First, check the map of requested data file names. If there's an entry for
|
||||
file, use it and return.
|
||||
Otherwise, we try [--datadir]/file, then $NMAPDIR/file
|
||||
next we try ~user/nmap/file
|
||||
then we try NMAPDATADIR/file <--NMAPDATADIR
|
||||
finally we try ./file
|
||||
|
|
@ -2591,6 +2598,17 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) {
|
|||
--datadir -> $NMAPDIR -> nmap.exe directory -> NMAPDATADIR -> .
|
||||
*/
|
||||
|
||||
/* Check the map of requested data file names. */
|
||||
iter = o.requested_data_files.find(file);
|
||||
if (iter != o.requested_data_files.end()) {
|
||||
Strncpy(filename_returned, iter->second.c_str(), bufferlen);
|
||||
/* If a special file name was requested, we must not return any other file
|
||||
name. Return a positive result even if the file doesn't exist or is not
|
||||
readable. It is the caller's responsibility to report the error if the
|
||||
file can't be accessed. */
|
||||
return fileexistsandisreadable(filename_returned) || 1;
|
||||
}
|
||||
|
||||
if (o.datadir) {
|
||||
res = snprintf(filename_returned, bufferlen, "%s/%s", o.datadir, file);
|
||||
if (res > 0 && res < bufferlen) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue