Nmap Development mailing list archives

Re: Locking a mutex by name?


From: Ron <ron () skullsecurity net>
Date: Sat, 15 Nov 2008 08:30:02 -0600

Patrick Donnelly wrote:

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.

All right, I implemented it like that and it appears to be working. You
can take a look at it, if you'd like, in:
svn://svn.insecure.org/nmap-exp/ron/nmap-smb

But suffice to say, I'm doing this:

--
local mutexes = setmetatable({}, {__mode = "k"});
[...]
local function get_mutex(smbstate)
    local mutex_name = "SMB-"
    local mutex

    -- Decide whether to use the name or the ip address as the unique
identifier
    if(smbstate['name'] ~= nil) then
        mutex_name = mutex_name .. smbstate['name']
    else
        mutex_name = mutex_name .. smbstate['ip']
    end

    if(mutexes[smbstate] == nil) then
        mutex = nmap.mutex(mutex_name)
        mutexes[smbstate] = mutex
    else
        mutex = mutexes[smbstate]
    end

    stdnse.print_debug(3, "SMB: Using mutex named '%s'", mutex_name)

    return mutex
end
--


Thanks for the help!

Ron

-- 
Ron Bowes
http://www.skullsecurity.org/

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


Current thread: