Home page logo

nmap-dev logo Nmap Development mailing list archives

Re: [RFC] Username/Password NSE library
From: Kris Katterjohn <katterjohn () gmail com>
Date: Wed, 25 Jun 2008 14:11:18 -0500

Hash: SHA1

Patrick Donnelly wrote:
On Wed, Jun 25, 2008 at 10:23 AM, Kris Katterjohn <katterjohn () gmail com> wrote:
I understand this, I was merely pointing out that the closure was the method
of choice.  I mentioned it initially[1], and nobody seemed to think that
returning a table was better[2][3].

But, like I said, if returning a table is now the desired functionality, then
your changes seem fine.

It doesn't really return the table with the intent of sharing it with
the caller, just so the for loop can iterate over it. The main
advantage to this is the memory reaches a steady state; no new
closures or tables are made in a call to the library.

Responses like this would've been great a week ago :)

Pure playfulness aside, returning the table like this is good for loops like
the examples you and Thomas present, but will it be as simple as a closure if
you're not in this specific type of loop?

One of the main points IMO for the closure is the fact that you don't have to
keep track of where you are in the list, you just call it again to get the
next entry.

Only one closure is needed for each list, which should be a max of two per
script since Thomas' idea of being able to rewind the list.  So I don't think
this is too much overhead for being able to loop over the whole list, or pick
and choose at any time without having to keep track of indexes or whathaveyou.

I'm not going to pretend to know what everybody will be doing with this
library in their scripts, but I don't want to restrict them, or cause them to
have to keep track of more than they need to.

I have run into one problem which I didn't test last night: giving the library
a non-existent filename.  Rather than returning false and giving the caller an
error message like mine did, or returning the error message like I assume
yours is supposed to do[4], I get this rather nasty looking error message:

SCRIPT ENGINE: error while initializing script rules:
./nselib/unpwdb.lua:29: bad argument #1 to 'lines' (none: No such file or
stack traceback:
       [C]: in function 'lines'
       ./nselib/unpwdb.lua:29: in main chunk
       [C]: in function 'require'
       ./scripts/unpwdbtest.nse:7: in main chunk
       [C]: ?
       [C]: ?

This was just another design choice I added in. I don't feel the
try/catch mechanism is suitable for something like this. The act of
requiring the module (ex)(im)plicitly states a level of reliance. If
the module cannot get a database it can't do anything useful and
should therefore fail immediately.

But I don't think it should spew a bunch of crap on the screen when the script
can easily be told of the problem and it can return silently, or do whatever
else it thinks is appropriate (such as letting the user know of the problem).

Maybe a simple, one-line debug message can be printed from the library for

I also would suggest moving the module() call after loading the
databases (where the module can error). If we allow the module to
error, we do not want the call made before any errors. module()
changes package.loaded to the library's table and will cause
subsequent calls to require (by other threads) to return an empty
library table.

Hope that helps,

Kris Katterjohn

Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


Sent through the nmap-dev mailing list
Archived at http://SecLists.Org

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]