[Win32utils-devel] Replace DL with Windows-PR

Berger, Daniel Daniel.Berger at qwest.com
Thu Jun 26 21:19:24 EDT 2008


 

> -----Original Message-----
> From: win32utils-devel-bounces at rubyforge.org 
> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of 
> Luis Lavena
> Sent: Thursday, June 26, 2008 5:02 AM
> To: Development and ideas for win32utils projects
> Subject: [Win32utils-devel] Replace DL with Windows-PR
> 
> Hello Guys,
> 
> I'm was starring my screen for many hours before send this. 
> This is a problem related to Capistrano Pageant interface 
> witch rely on DL interfaces to communicate.
> 
> The thing is this mechanism sometimes works, sometimes fail 
> by unknown reasons and sometimes segfault.
> 
> Tried different versions of Ruby from 1.8.5-p114 to 
> 1.8.6-p114 with same results.
> 
> The code in charge of this is located now in GitHub:
> 
> http://github.com/jamis/net-ssh/tree/cdcb65ac9ed69be4ecaeed543
> 26b927c99e2075e/lib/net/ssh/authentication/pageant.rb

<snip>

After looking this over I don't understand this portion:

# Start code snippet
ptr = Win.mapViewOfFile(filemap, Win::FILE_MAP_WRITE, 0, 0,
AGENT_MAX_MSGLEN)

if ptr.nil? || ptr.null?
   raise Net::SSH::Exception, "Mapping of file failed"
end

ptr[0] = query # HUH?

cds = [AGENT_COPYDATA_ID, mapname.size + 1, mapname]. pack("LLp").to_ptr
succ = Win.sendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL, cds,
Win::SMTO_NORMAL, 5000, id)

if succ > 0
   retlen = 4 + ptr.to_s(4).unpack("N")[0]
   res = ptr.to_s(retlen)
end

return res
# End code snippet

MapViewOfFile returns an address, not a pointer, unless this has
something to do with DL.

Even if it does return a pointer (ok, fine, unpack it), I don't
understand why you are assigning 'query' to ptr[0]. Something tells me
you don't want to change the address of the mapped view, but perhaps I
don't understand something.

Anyway, here's an attempt at using win32-mmap + windows-pr. Note that
the portion at the end is undefined since I'm not sure what you're
trying to do exactly:

# UNTESTED!
require 'win32/mmap'
require 'windows/thread'
require 'windows/window'
require 'windows/window/message'

module Net
   module SSH
      module Authentication
         module Pageant

            AGENT_MAX_MSGLEN  = 8192
            AGENT_COPYDATA_ID = 0x804e50ba

            class Socket
               include Windows::Thread
               include Windows::Window
               include Windows::Window::Message

               private_class_method :new

               def self.open(location=nil)
                  new
               end

               def initialize
                  @win = FindWindow("Pageant", "Pageant")

                  if @win == 0
                     raise Net::SSH::Exception, "pageant process not
running"
                  end

                  @res = nil
                  @pos = 0
               end

               def send(data, *args)
                  @res = send_query(data)
                  @pos = 0
               end

               def send_query(query)
                  mapname = "PageantRequest%08x\000" %
GetCurrentThreadId()

                  filemap = Win32::MMap.new(
                     :name => mapname,
                     :size => AGENT_MAX_MSGLEN
                  )

                  result = [0].pack('L'0

                  cds = [AGENT_COPYDATA_ID, mapname.size + 1,
mapname].pack("LLp")

                  succ = SendMessageTimeout(
                     @win,
                     WM_COPYDATA,
                     nil,
                     cds,
                     SMTO_NORMAL,
                     5000,
                     result
                  )

                  if succ > 0
                     # Do something
                     # res = ???
                  end

                  return res
               ensure
                  filemap.close
               end
            end
         end
      end
   end
end

The Windows::Window::Message module you'll have to grab from the
windows-pr cvs repo.

Regards,

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly 
prohibited and may be unlawful.  If you have received this communication 
in error, please immediately notify the sender by reply e-mail and destroy 
all copies of the communication and any attachments.


More information about the win32utils-devel mailing list