Index: scripts/SSH-hostkey.nse =================================================================== --- scripts/SSH-hostkey.nse (revision 10361) +++ scripts/SSH-hostkey.nse (working copy) @@ -32,12 +32,16 @@ require("stdnse") require("shortport") -require("openssl") require("bin") require("bit") require("base64") require("hash") +if not pcall(require, "openssl") then + require("nmap") + nmap.quiet_error("Optional module openssl is not installed") +end + id = "SSH Hostkey" author = "Sven Klemm " description = "Show SSH Hostkeys" Index: nse_nmaplib.cc =================================================================== --- nse_nmaplib.cc (revision 10361) +++ nse_nmaplib.cc (working copy) @@ -48,6 +48,23 @@ static int l_get_timing_level(lua_State *L); static int l_get_dns_servers(lua_State *L); +static int l_quiet_error(lua_State *L) { + size_t len; + const char *p; + char *s; + + p = luaL_checklstring(L, -1, &len); + s = (char *) lua_newuserdata(L, len + 1); + strcpy(s, p); + + luaL_getmetatable(L, "nmap.error"); + lua_setmetatable(L, -2); + + lua_error(L); + + return 0; +} + int l_clock_ms(lua_State *L); static int mutex_i; @@ -137,6 +154,7 @@ {"timing_level", l_get_timing_level}, {"mutex", l_mutex}, {"get_dns_servers", l_get_dns_servers}, + {"quiet_error", l_quiet_error}, {NULL, NULL} }; Index: nse_init.cc =================================================================== --- nse_init.cc (revision 10361) +++ nse_init.cc (working copy) @@ -115,26 +115,28 @@ lua_setfenv(L, -2); // set it if (lua_pcall(L, 0, 0, 0) != 0) // Call the function (loads globals) { - // Check for dependency errors - lua_getfield(L, LUA_REGISTRYINDEX, REQUIRE_ERRORS); - lua_pushvalue(L, -2); // the error - lua_gettable(L, -2); - if (lua_toboolean(L, -1)) // The error was thrown by require - { - if (o.verbose > 3 && !o.debugging) - error("%s: '%s' could not be loaded due to missing dependency '%s'", - SCRIPT_ENGINE, filename, lua_tostring(L, -1)); - SCRIPT_ENGINE_DEBUGGING( - error("%s: '%s' threw a run time error and could not be loaded.\n%s", - SCRIPT_ENGINE, filename, lua_tostring(L, -3)); - ) - } else { - error("%s: '%s' threw a run time error and could not be loaded.", - SCRIPT_ENGINE, filename); - SCRIPT_ENGINE_DEBUGGING( - error("%s", lua_tostring(L, -3)); - ) + void *p = lua_touserdata(L, -1); + if (p != NULL) { + if (lua_getmetatable(L, -1)) { + lua_getfield(L, LUA_REGISTRYINDEX, "nmap.error"); + if (lua_rawequal(L, -1, -2)) { + lua_pop(L, 2); + if (o.debugging) { + error("%s: '%s' threw a quiet error.", + SCRIPT_ENGINE, filename); + SCRIPT_ENGINE_DEBUGGING( + error("%s", (const char *) p); + ) + } + return 0; + } + } } + error("%s: '%s' threw a run time error and could not be loaded.", + SCRIPT_ENGINE, filename); + SCRIPT_ENGINE_DEBUGGING( + error("%s", lua_tostring(L, -3)); + ) return 0; }