Index: nse_main.lua =================================================================== --- nse_main.lua (revision 27093) +++ nse_main.lua (working copy) @@ -328,7 +328,7 @@ if not self[rule] then return nil end -- No rule for this script? local file_closure = self.file_closure; -- Rebuild the environment for the running thread. - local env = { + local env = { SCRIPT_PATH = self.filename, SCRIPT_NAME = self.short_basename, SCRIPT_TYPE = script_type, @@ -350,7 +350,8 @@ print_debug(1, "A thread for %s yielded unexpectedly in the file or %s function:\n%s\n", self.filename, rule, traceback(co)); - elseif s and rule_return then + elseif s and (self.force or rule_return) then + print_debug(1,("%s set for execution: portrule %s, force %s"):format(self.short_basename,tostring(rule_return ), tostring(self.force))); local thread = { co = co, env = env, @@ -387,7 +388,7 @@ -- filename The filename (path) of the script to load. -- Returns: -- script The script (class) created. - function Script.new (filename, selected_by_name) + function Script.new (filename, selected_by_name, force) assert(type(filename) == "string", "string expected"); if not find(filename, "%.nse$") then log_error( @@ -471,6 +472,7 @@ dependencies = rawget(env, "dependencies"), threads = {}, selected_by_name = not not selected_by_name, + force = not not force, }; return setmetatable(script, {__index = Script, __metatable = Script}); end @@ -560,8 +562,15 @@ -- we return true. Otherwise we test if it is a filename or if -- the script_entry.filename matches the pattern. local function m (pattern) + local force = false; + if pattern:sub(1,1) == "+" then + pattern = pattern:sub(2); + force = true; + end -- Check categories - if r_categories[lower(pattern)] then return true end + if r_categories[lower(pattern)] then + return true, force + end -- Check filename with wildcards pattern = gsub(pattern, "%.nse$", ""); -- remove optional extension pattern = gsub(pattern, "[%^%$%(%)%%%.%[%]%+%-%?]", "%%%1"); -- esc magic @@ -569,17 +578,18 @@ pattern = "^"..pattern.."$"; -- anchor to beginning and end local found = not not find(escaped_basename, pattern); selected_by_name = selected_by_name or found; - return found; + return found, force; end local env = {m = m}; for globalized_rule, rule_table in pairs(entry_rules) do - if setfenv(rule_table.compiled_rule, env)() then -- run the compiled rule + local found, force = setfenv(rule_table.compiled_rule, env)() + if found then -- run the compiled rule used_rules[rule_table.original_rule] = true; local t, path = cnse.fetchscript(filename); if t == "file" then if not files_loaded[path] then - chosen_scripts[#chosen_scripts+1] = Script.new(path, selected_by_name); + chosen_scripts[#chosen_scripts+1] = Script.new(path, selected_by_name,force); files_loaded[path] = true; -- do not break so other rules can be marked as used end @@ -597,6 +607,11 @@ -- Now load any scripts listed by name rather than by category. for rule, loaded in pairs(used_rules) do if not loaded then -- attempt to load the file/directory + local forcescript = false; + if(rule:sub(1,1)== '+') then + forcescript = true; + rule = rule:sub(2) + end local t, path = cnse.fetchscript(rule); if t == nil then -- perhaps omitted the extension? t, path = cnse.fetchscript(rule..".nse"); @@ -604,14 +619,15 @@ if t == nil then error("'"..rule.."' did not match a category, filename, or directory"); elseif t == "file" and not files_loaded[path] then - local script = Script.new(path, true); + local script = Script.new(path, true, forcescript); chosen_scripts[#chosen_scripts+1] = script; files_loaded[path] = true; elseif t == "directory" then for f in cnse.dir(path) do local file = path .."/".. f if find(f, "%.nse$") and not files_loaded[file] then - chosen_scripts[#chosen_scripts+1] = Script.new(file); + local script = Script.new(file,false,forcescript ); + chosen_scripts[#chosen_scripts+1] = script; files_loaded[file] = true; end end