From 1dd2fa821debc663edc7534097ab33742b79a563 Mon Sep 17 00:00:00 2001 From: kris Date: Sat, 22 Dec 2007 06:56:22 +0000 Subject: [PATCH] adding nmap.fetchfile() function so scripts can find the nmap-* data files --- CHANGELOG | 3 +++ nse_nmaplib.cc | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 224255584..6ae21fd0c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ # Nmap Changelog ($Id$); -*-text-*- +o Added nmap.fetchfile() function for scripts so they can easily find + Nmap's nmap-* data files. [Kris] + 4.51BETA o We now have a detailed Zenmap Guide at diff --git a/nse_nmaplib.cc b/nse_nmaplib.cc index e31926b3a..8f5d48678 100644 --- a/nse_nmaplib.cc +++ b/nse_nmaplib.cc @@ -3,6 +3,7 @@ #include "nse_macros.h" #include "nse_debug.h" +#include "nmap.h" #include "nmap_error.h" #include "osscan.h" #include "NmapOps.h" @@ -39,6 +40,7 @@ static int l_set_port_version(lua_State* l, Target* target, Port* port); static int l_get_verbosity(lua_State *); static int l_get_debugging(lua_State *); static int l_get_have_ssl(lua_State *l); +static int l_fetchfile(lua_State *l); int l_clock_ms(lua_State* l); @@ -59,6 +61,7 @@ int set_nmaplib(lua_State* l) { {"verbosity", l_get_verbosity}, {"debugging", l_get_debugging}, {"have_ssl", l_get_have_ssl}, + {"fetchfile", l_fetchfile}, {NULL, NULL} }; @@ -526,3 +529,24 @@ static int l_get_have_ssl(lua_State *l) { #endif return 1; } + +static int l_fetchfile(lua_State *l) +{ + char buf[FILENAME_MAX]; + const char *req = lua_tostring(l, -1); + + if (!req) + goto err; + + if (nmap_fetchfile(buf, sizeof buf, (char *) req) != 1) + goto err; + + lua_pop(l, 1); + lua_pushstring(l, buf); + return 1; +err: + lua_pop(l, 1); + lua_pushnil(l); + return 0; +} +