diff --git a/nse_main.cc b/nse_main.cc index 039c0706a..cc6a4cb90 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -35,8 +35,23 @@ struct thread_record { unsigned int registry_idx; // index in the main state registry double runlevel; struct run_record rr; + std::string get_id(); }; +/* Gets the basename of a script filename and removes any ".nse" extension. */ +std::string thread_record::get_id() { + char *abbrev; + + abbrev = path_get_basename(filename.c_str()); + if (abbrev == NULL) + /* On memory error just return the whole filename. */ + return filename; + if (nse_check_extension(SCRIPT_ENGINE_EXTENSION, abbrev)) + abbrev[strlen(abbrev) - strlen(SCRIPT_ENGINE_EXTENSION)] = '\0'; + + return std::string(abbrev); +} + int current_hosts = 0; int errfunc = 0; std::list > torun_scripts; @@ -56,7 +71,6 @@ int process_preparehost(lua_State* L, Target* target, std::listset_id(filename); - } else { - sr->set_id(id); - free(id); - } - - return SCRIPT_ENGINE_SUCCESS; -} - /* try all host and all port rules against the * state of the current target * make a list with run records for the scripts