Nmap Development mailing list archives

Re: using the credentials database


From: Patrik Karlsson <patrik () cqure net>
Date: Tue, 5 Jul 2011 23:41:19 +0200


On Jul 5, 2011, at 10:40 PM, Patrick Donnelly wrote:

On Tue, Jul 5, 2011 at 3:51 PM, Patrik Karlsson <patrik () cqure net> wrote:

On Jul 5, 2011, at 8:51 PM, Patrick Donnelly wrote:

On Mon, Jun 27, 2011 at 5:04 PM, Patrik Karlsson <patrik () cqure net> wrote:
I've added some documentation and a new function called getCredentials that will hopefully get you what you need.
Let me know if there's anything else you find missing :)

Sorry for being late to the party... I have a stylistic/efficiency
concern here. I'd prefer this function be an iterator [1,2] rather
than returning a potentially large table of tables. Something like:

for credential in c:credentials(creds.State.VALID) do
end

You can accomplish this quite naturally with coroutines [3,4].

[1] http://www.lua.org/pil/7.html
[2] http://www.lua.org/manual/5.1/manual.html#2.4.5
[3] http://www.lua.org/pil/9.3.html
[4] http://nmap.org/book/nse-parallelism.html#nse-parallelism-cm

--
- Patrick Donnelly


I modified the getCredentials function to return an iterator per your suggestion.
The attached patch contains my previous script argument patch as well as this change.

This still creates the table (self.storage:getAll()). I was thinking
that instead that the getAll method would call coroutine.yield instead
of building a table.

It may also be worthwhile to eliminate the tables completely by doing
something like:

for host, port, user, pass, state, service in c:getCredentials() do
end

Something to think about :). It will be much faster and more memory
efficient but may violate the object based design you were going for.
So it would be fine to keep the table in that case.

-- 
- Patrick Donnelly

Good point! I should have seen that, sorry.
I kept the getCredentials as is (returning a table) for the time being, but changed the getAll function so that it 
returns an iterator.
Here's yet another patch with all the changes incorporated.

Attachment: creds-cli-add-iter2.patch
Description:



//Patrik
--
Patrik Karlsson
http://www.cqure.net
http://www.twitter.com/nevdull77

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

Current thread: