diff --git a/nse_main.cc b/nse_main.cc index ed062e71e..2a5ae05fe 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -28,6 +28,7 @@ #define NSE_BASE "NSE_BASE" #define NSE_WAITING_TO_RUNNING "NSE_WAITING_TO_RUNNING" #define NSE_DESTRUCTOR "NSE_DESTRUCTOR" +#define NSE_SELECTED_BY_NAME "NSE_SELECTED_BY_NAME" #define MAX_FILENAME_LEN 4096 @@ -529,6 +530,12 @@ void nse_base (lua_State *L) lua_call(L, 0, 1); /* returns base thread */ } +void nse_selectedbyname (lua_State *L) +{ + lua_getfield(L, LUA_REGISTRYINDEX, NSE_SELECTED_BY_NAME); + lua_call(L, 0, 1); /* returns boolean, whether script was selected by name */ +} + static lua_State *L_NSE = NULL; void open_nse (void) diff --git a/nse_main.h b/nse_main.h index b7fa6f460..3f2e5251c 100644 --- a/nse_main.h +++ b/nse_main.h @@ -35,6 +35,7 @@ int nse_yield (lua_State *); void nse_restore (lua_State *, int); void nse_destructor (lua_State *, char); void nse_base (lua_State *); +void nse_selectedbyname (lua_State *); void open_nse (void); void script_scan (std::vector &targets); diff --git a/nse_nmaplib.cc b/nse_nmaplib.cc index 55d44cd70..62657e550 100644 --- a/nse_nmaplib.cc +++ b/nse_nmaplib.cc @@ -21,9 +21,6 @@ extern "C" { #include "nse_nmaplib.h" #include "nse_nsock.h" -/* This is used to index the registry in nse_main.lua. */ -#define NSE_SELECTED_BY_NAME "NSE_SELECTED_BY_NAME" - #define SCRIPT_ENGINE_PUSHSTRING_NOTNULL(c_str, str) if(c_str != NULL) {\ lua_pushstring(L, c_str); \ lua_setfield(L, -2, str); \ @@ -524,16 +521,9 @@ static int l_get_verbosity (lua_State *L) int verbosity; verbosity = o.verbose; - /* Call the SELECTED_BY_NAME function in nse_main.lua. When a script is - selected by name, we lie to it and say the verbosity is one higher than it - really is. */ - lua_getfield(L, LUA_REGISTRYINDEX, NSE_SELECTED_BY_NAME); - if (!lua_isnil(L, -1)) { - lua_call(L, 0, 1); - if (lua_toboolean(L, -1)) - verbosity += 1; - } - lua_pop(L, 1); + /* Check if script is selected by name. When a script is selected by name, + we lie to it and say the verbosity is one higher than it really is. */ + verbosity += (nse_selectedbyname(L), lua_toboolean(L, -1) ? 1 : 0); lua_pushnumber(L, verbosity); return 1;