1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-15 20:29:03 +00:00

Add a function free_services that tells Nmap to reload the nmap-services

file again when it needs it. This is called from nmap_free_mem, because
cp_free (also called by nmap_free_mem) invalidates members of the
services data structures.

In normal use this doesn't matter. It only matters when reinvoking the
engine several times with --interactive.
This commit is contained in:
david
2010-02-26 22:29:03 +00:00
parent 9f55412954
commit 49e36a57f3
3 changed files with 22 additions and 5 deletions

View File

@@ -1993,6 +1993,7 @@ void nmap_free_mem() {
cp_free(); cp_free();
free_dns_servers(); free_dns_servers();
free_etchosts(); free_etchosts();
free_services();
if (o.reference_FPs) { if (o.reference_FPs) {
delete o.reference_FPs; delete o.reference_FPs;
o.reference_FPs = NULL; o.reference_FPs = NULL;

View File

@@ -129,13 +129,13 @@ bool service_node_ratio_compare(const service_node& a, const service_node& b) {
} }
extern NmapOps o; extern NmapOps o;
static int numtcpports = 0; static int numtcpports;
static int numudpports = 0; static int numudpports;
static int numsctpports = 0; static int numsctpports;
static std::map<port_spec, service_node> service_table; static std::map<port_spec, service_node> service_table;
static std::list<service_node> services_by_ratio; static std::list<service_node> services_by_ratio;
static int services_initialized = 0; static int services_initialized;
static int ratio_format = 0; // 0 = /etc/services no-ratio format. 1 = new nmap format static int ratio_format; // 0 = /etc/services no-ratio format. 1 = new nmap format
static int nmap_services_init() { static int nmap_services_init() {
if (services_initialized) return 0; if (services_initialized) return 0;
@@ -152,6 +152,13 @@ static int nmap_services_init() {
int ratio_n, ratio_d; int ratio_n, ratio_d;
char ratio_str[32]; char ratio_str[32];
numtcpports = 0;
numudpports = 0;
numsctpports = 0;
service_table.clear();
services_by_ratio.clear();
ratio_format = 0;
if (nmap_fetchfile(filename, sizeof(filename), "nmap-services") != 1) { if (nmap_fetchfile(filename, sizeof(filename), "nmap-services") != 1) {
#ifndef WIN32 #ifndef WIN32
error("Unable to find nmap-services! Resorting to /etc/services"); error("Unable to find nmap-services! Resorting to /etc/services");
@@ -277,6 +284,13 @@ static int nmap_services_init() {
return 0; return 0;
} }
void free_services() {
/* This doesn't free anything, because the service_table is allocated
statically. It just marks the table as needing to be reinitialized because
other things have been freed, for example the cp_strdup-allocated members
of service_node. */
services_initialized = 0;
}
/* Adds ports whose names match mask and one or more protocols /* Adds ports whose names match mask and one or more protocols

View File

@@ -118,4 +118,6 @@ int addportsfromservmask(char *mask, u8 *porttbl, int range_type);
struct servent *nmap_getservbyport(int port, const char *proto); struct servent *nmap_getservbyport(int port, const char *proto);
void gettoppts(double level, char *portlist, struct scan_lists * ports); void gettoppts(double level, char *portlist, struct scan_lists * ports);
void free_services();
#endif #endif