Nmap Development mailing list archives
Re: XML structured script output (storing results per script instance)
From: Daniel Miller <bonsaiviking () gmail com>
Date: Thu, 2 Aug 2012 22:05:25 -0500
On Wed, Aug 1, 2012 at 8:44 PM, Patrick Donnelly <batrick () batbytes com> wrote:
Use luaL_unref instead of setting it to nil manually. luaL_ref also sets the table for you. You don't need this code: + lua_pushvalue(lstate, pos); + lua_rawseti(lstate, -2, key); /* _R[NSE_SCRIPT_RESULT][key] = return_value *
This makes sense, applied.
luaL_newstate, but, these return a "main thread" as a lua_State (L_NSE is this main thread). The threads (coroutines) that NSE creates (in nse_main.lua) are created using lua_newthread [1] which also returns a lua_State but is in the same global state. All Lua data (tables, LUA_REGISTRYINDEX, etc.) can be accessed from any lua_State in the same global state. [This is actually a pretty common confusion when it comes to Lua.] [1] http://www.lua.org/source/5.2/lcorolib.c.html#luaB_cocreate
I think I get it. I've attached a couple patches; does the 0030 patch handle this correctly now? Also, I think I did the right thing in the 0031 patch in order to wrap the call in lua_pcall. Am I missing anything there that you can see? Thanks so much for your help with this.
You don't need another data structure representation of the output. You just need to try to look at the problem as how you can let Lua do the heavy lifting through calls to XML for you. I believe most of our XML calls are already bound for you in the cnse library.
Because the call to ScriptResult::write_xml() comes from output.cc, I really don't see how to make this an entirely-Lua problem. I would like to, since the recursive traversal would be cleaner in Lua than in C, but I've already got the necessary functions written, and I think to call back to Lua from C would require stashing a Lua function somewhere in the registry, which seems more messy than it is worth. Thoughts? Dan
Attachment:
0030-Use-L_NSE-instead-of-ScriptResult-lstate.patch
Description:
Attachment:
0031-Wrap-script-xml-output-in-lua_pcall.patch
Description:
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July), (continued)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) Patrick Donnelly (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) Patrick Donnelly (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) Patrick Donnelly (Jul 20)
- Re: XML structured script output (storing results per script instance) David Fifield (Jul 31)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Jul 31)
- Re: XML structured script output (storing results per script instance) David Fifield (Jul 31)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 01)
- Re: XML structured script output (storing results per script instance) Daniel Miller (Aug 01)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 01)
- Re: XML structured script output (storing results per script instance) Daniel Miller (Aug 02)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 03)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Jul 31)