Nmap Development mailing list archives

Re: XML structured script output (storing results per script instance)


From: Patrick Donnelly <batrick () batbytes com>
Date: Wed, 1 Aug 2012 21:44:47 -0400

On Wed, Aug 1, 2012 at 6:15 PM, Daniel Miller <bonsaiviking () gmail com> wrote:
I think I understand the idea of luaL_ref, so I've attached a patch to use
that instead of a stringified pointer. I'd appreciate a look to see if I'm
doing it right (my testing shows no problems).

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 *

Can you explain better how I could use the L_NSE state instead of the one
passed to cnse.set_output()? Obviously if script output was a light userdata
object then I could pass that from one lua_State to another with
lua_touserdata and lua_pushlightuserdata, but I can't see how to do that
with a table.

The Lua registry is shared by all lua_State states in the same global
state. A new global state is created using lua_newstate or
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

Plus, we (I?) wanted to get away from yet another data
structure representation of the output. This gets to the same issue with
wrapping the calls in lua_pcall: in order to push the arguments, they all
need to be in the same lua_State. Or am I missing something?

You're missing something :).

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.

-- 
- Patrick Donnelly
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: