[Win32utils-devel] Replace DL with Windows-PR

Luis Lavena luislavena at gmail.com
Fri Jun 27 03:53:10 EDT 2008


On Fri, Jun 27, 2008 at 3:19 AM, Berger, Daniel <Daniel.Berger at qwest.com> wrote:
>
>
>> -----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.
>

me neither, been looking for code examples on internet (that
communicate with Pageant) without success, I want fix this since is
randomly crashing, whcih could be related to what you described here.

> 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,
>

Thank you Daniel, I'll give it a whirl later today.

Regards,

-- 
Luis Lavena
AREA 17
-
Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams


More information about the win32utils-devel mailing list