Nmap Development mailing list archives
Re: Locking a mutex by name?
From: "Patrick Donnelly" <batrick.donnelly () gmail com>
Date: Sat, 15 Nov 2008 01:01:55 -0700
On Fri, Nov 14, 2008 at 7:04 PM, Ron <ron () skullsecurity net> wrote:
Patrick Donnelly wrote:On Fri, Nov 14, 2008 at 6:07 PM, Ron <ron () skullsecurity net> wrote: You really only need to worry that the thread using the mutex keeps a reference to it from the point it locks it to the point it releases it. How you decide to keep the reference is up to you. It could be as simple as: local mutex; -- ... other code function action(host, port) mutex = nmap.mutex("SMB-"..host.ip); -- do stuff... endGood point, I wasn't thinking of it that way. It still feels cleaner, to me, for the SMB library to look after it, simply because there will always need to be a lock when SMB is being used, and only for the parts of the script while a SMB transaction is going on. This also ensures that programmers don't forget to lock the mutex when writing scripts (since they won't notice the issue until running multiple scripts simultaneously). My thought is that the nselib is a better place for it.
Yes, in the case of a library that is best. As for storing the mutexes for a library, placing them in the registry feels very wrong to me. I've looked at the smb library in nselib/smb.lua. Right now it appears the library has a global lock, so only on smb connection can be active at a time? So instead you want the mutexes on a per-host basis? If this is the case, I recommend using a local mutexes table , with smb connection keys and mutex values, that holds the mutexes for you for each smb connection. The table will have weak keys so an smb connection can be collected (and thus the mutex as well). Each mutex will still be passed the "SMB-hostname" string so you can ensure only one smb connection per host. I've attached a patch that does this. Cheers, -- -Patrick Donnelly "One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say." -Will Durant
Attachment:
smb_mutex.patch
Description:
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- Locking a mutex by name? Ron (Nov 13)
- Re: Locking a mutex by name? Patrick Donnelly (Nov 13)
- Re: Locking a mutex by name? Ron (Nov 14)
- Re: Locking a mutex by name? Patrick Donnelly (Nov 14)
- Re: Locking a mutex by name? Ron (Nov 14)
- Re: Locking a mutex by name? Patrick Donnelly (Nov 14)
- Re: Locking a mutex by name? Ron (Nov 14)
- Re: Locking a mutex by name? Patrick Donnelly (Nov 14)
- Re: Locking a mutex by name? Ron (Nov 14)
- Re: Locking a mutex by name? Kris Katterjohn (Nov 14)
- Re: Locking a mutex by name? Patrick Donnelly (Nov 14)
- Re: Locking a mutex by name? Ron (Nov 15)
- Re: Locking a mutex by name? Ron (Nov 14)
- Re: Locking a mutex by name? Patrick Donnelly (Nov 13)