From 6069b50ce3be802c86ef23d65b478fc966510697 Mon Sep 17 00:00:00 2001 From: batrick Date: Tue, 20 Sep 2011 16:18:35 +0000 Subject: [PATCH] Add loader for searching nselib/ for ?.lua files. nselib/ can be in multiple directories that nmap will search, e.g. ~/.nmap/nselib $NMAPDIR/nselib /usr/share/nmap/nselib etc. Resolves Daniel Miller's request [1]. [1] http://seclists.org/nmap-dev/2011/q3/817 --- nse_main.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/nse_main.lua b/nse_main.lua index b135bc8a3..62530add8 100644 --- a/nse_main.lua +++ b/nse_main.lua @@ -117,10 +117,17 @@ local nmap = require "nmap"; local cnse, rules = ...; -- The NSE C library and Script Rules -do -- Append the nselib directory to the Lua search path - local t, path = assert(cnse.fetchfile_absolute("nselib/")); - assert(t == "directory", "could not locate nselib directory!"); - package.path = path.."?.lua;"..package.path; +do -- Add loader to look in nselib/?.lua (nselib/ can be in multiple places) + local function loader (lib) + local name = "nselib/"..lib..".lua"; + local type, path = cnse.fetchfile_absolute(name); + if type == "file" then + return loadfile(path); + else + return "\n\tNSE failed to find "..name.." in search paths."; + end + end + insert(package.loaders, loader); end local script_database_type, script_database_path =