1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-08 21:51:28 +00:00

Tolerate missing script.db; categories will not work.

This commit is contained in:
dmiller
2022-09-08 18:14:50 +00:00
parent d6bea8dcde
commit dee423f798

View File

@@ -711,9 +711,13 @@ local function get_chosen_scripts (rules)
check_rules(rules); check_rules(rules);
local db_env = {Entry = nil}; local db_env = {Entry = nil};
local db_closure = assert(loadfile(script_database_path, "t", db_env), local db_closure = loadfile(script_database_path, "t", db_env)
"database appears to be corrupt or out of date;\n".. if not db_closure then
"\tplease update using: nmap --script-updatedb"); log_write("stdout",
"NSE script database appears to be corrupt or out of date;\n"..
"\tplease update using: nmap --script-updatedb");
db_closure = function () return end
end
local chosen_scripts, files_loaded = {}, {}; local chosen_scripts, files_loaded = {}, {};
local used_rules, forced_rules = {}, {}; local used_rules, forced_rules = {}, {};
@@ -1316,28 +1320,35 @@ if script_database_update then
local t, path = cnse.fetchfile_absolute('scripts/'); -- fetch script directory local t, path = cnse.fetchfile_absolute('scripts/'); -- fetch script directory
assert(t == 'directory', 'could not locate scripts directory'); assert(t == 'directory', 'could not locate scripts directory');
script_database_path = path.."script.db"; script_database_path = path.."script.db";
local db = assert(open(script_database_path, 'w')); local db = open(script_database_path, 'w')
local scripts = {}; -- If user requested update with --script-updatedb, a failure here is fatal.
for f in lfs.dir(path) do if cnse.scriptupdatedb then
if match(f, '%.nse$') then assert(db, "Could not open script.db for writing")
scripts[#scripts+1] = path.."/"..f;
end
end end
sort(scripts); -- If we're doing this for convenience only, it's ok to fail.
for i, script in ipairs(scripts) do if db then
script = Script.new(script); local scripts = {};
if ( script ) then for f in lfs.dir(path) do
sort(script.categories); if match(f, '%.nse$') then
db:write('Entry { filename = "', script.basename, '", '); scripts[#scripts+1] = path.."/"..f;
db:write('categories = {');
for j, category in ipairs(script.categories) do
db:write(' "', lower(category), '",');
end end
db:write(' } }\n');
end end
sort(scripts);
for i, script in ipairs(scripts) do
script = Script.new(script);
if ( script ) then
sort(script.categories);
db:write('Entry { filename = "', script.basename, '", ');
db:write('categories = {');
for j, category in ipairs(script.categories) do
db:write(' "', lower(category), '",');
end
db:write(' } }\n');
end
end
db:close();
log_write("stdout", "Script Database updated successfully.");
end end
db:close();
log_write("stdout", "Script Database updated successfully.");
end end
-- Load all user chosen scripts -- Load all user chosen scripts