1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-22 07:29:01 +00:00

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
This commit is contained in:
batrick
2011-09-20 16:18:35 +00:00
parent 613527e7e2
commit 6069b50ce3

View File

@@ -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 =