Subject: 1.3.10: SendMessage(WM_COPYDATA) in a Win32 program fails within Cygwin
From: Mitch Davis <[email-masked]>
To: [email-masked]
Cc: Mitch Davis <[email-masked]>, [email-masked]
Date: Thu, 30 May 2002 02:50:41 +1000

Hello,

Thank you for Cygwin - Cygwin rocks!

I would like to use plink (a command-line
SSH program from the "PuTTY" suite) to
connect my W2K PC to a Linux host, using the
ssh v2 protocol, and RSA keys, via the
"pageant" key agent.

I would also like to be able to invoke plink (a
conventional "console" Win32 app) both from a
W2K cmd.exe window, and from a bash window.

My problem is, plink works under cmd.exe, but doesn't
work under bash.  It also doesn't work if I invoke
cmd.exe inside bash, then invoke plink from the cmd.exe.
By "doesn't work", I mean plink is unable to fetch any
keys from "pageant", the SSH key agent.

I got the source for putty (go Open Source!) and compiled it
using Microsoft Visual Studio 6.  I have found where in
plink the problem is happening:

  http://cvs.tartarus.org/putty/pageantc.c?rev=1.5

Look for SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) & cds).
This returns 1 (success) when run under cmd.exe, and 0
when run under bash, or cmd.exe under bash.  (If SendMessage
returns 0, the keys can't be fetched and authentication with
keys fails.

Version:

  I am using PuTTY compiled from source checked
  out using CVS at around May 29 14:10 GMT.
  The compiler is Visual C++ 6.0.  Exactly the same
  problem happens with the binaries distributed on
  the PuTTY web site.

  The version of cygwin on my computer is no more
  than one day old.  The cygwin1.dll is version
  1.3.10.

  The OS is Windows 2000 Professional, Version
  5.0.2195 Service Pack 2 Build 2195.

  The server is running OpenSSH v3.1p1 from
  very new binary RPMs supplied by Red Hat.
  The OS is Red Hat 7.2.  SSH is configured to
  use winbind via PAM so users can log in with their
  Windows username.  The winbind part is working
  fine.

Protocols:

  I have to use a profile because we can only use
  ssh v2 protocol, and plink has no -2 switch to force v2.

  The profile works perfectly using putty.exe
  (the GUI ssh), with and without the agent running.

Here's what I get when I run plink from cmd.exe:

M:\src\putty>.\pageant "e:\mjd\identity"
<then I authenticate>
M:\src\putty>.\plink -v server date
Looking up host "server"
Connecting to 192.168.1.16 port 22
Server version: SSH-1.99-OpenSSH_3.1p1
We claim version: SSH-2.0-PuTTY-Local: May 30 2002 00:51:02
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange
Host key fingerprint is:
ssh-rsa 1024 24:4e:e9:2b:6b:3b:76:6c:c2:b2:4d:26:07:fb:48:47
Using username "mitch davis".
Pageant is running. Requesting keys.
agent_query: hwnd=0040010A
agent_query: mapname=PageantRequest00000510
agent_query: filemap=000001D4
agent_query: id=1
do_ssh2_authconn: r=00811BF0 responselen=480
Pageant has 1 SSH2 keys
Trying Pageant key #0
Authenticating with public key "mitch [email-masked]" from agent
agent_query: hwnd=0040010A
agent_query: mapname=PageantRequest00000510
agent_query: filemap=000001D4
agent_query: id=1
Sending Pageant's response
Access granted
Opened channel for session
Requesting OpenSSH-style agent forwarding
Agent forwarding enabled
Started a shell/command
Server sent command exit status 0
Thu May 30 01:52:20 EST 2002

M:\src\putty>

(In other words, exactly what I expect)

Here's what I get when I run plink from cygwin bash:

mjd@eng02 [m:/src/putty] ./plink -v server date
Looking up host "server"
Connecting to 192.168.1.16 port 22
Server version: SSH-1.99-OpenSSH_3.1p1
We claim version: SSH-2.0-PuTTY-Local: May 30 2002 00:51:02
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange
Host key fingerprint is:
ssh-rsa 1024 24:4e:e9:2b:6b:3b:76:6c:c2:b2:4d:26:07:fb:48:47
Using username "mitch davis".
Pageant is running. Requesting keys.
agent_query: hwnd=0040010A
agent_query: mapname=PageantRequest000005f8
agent_query: filemap=000002A0
agent_query: id=0
do_ssh2_authconn: r=00000000 responselen=0
mitch davis@cvssrv's password: _

(In other words, id==0, the key can't be
retrieved, and ssh.c falls back to a password.

Things I've not tried:

  Trying to reproduce this on another computer.
  (Should I?)

  Downgrading Cygwin.  (An earlier version
  chopped my Windows username ("Mitch Davis")
  and fed it to plink in two pieces; of course,
  plink couldn't work)

My questions:

 - Do you know what the problem might be?
 - Do you know what might be causing SendMessage to
   fail?  (I'm not a Windows programmer).
 - Can you suggest or provide a test program that
   could be used to isolate or further test the
   problem?  (Is the one at the end of pageantc.c
   a good one to try?)

Your help would be greatly appreciated.  I have
also sent this question to the PuTTY maintainer,
to see if he can see the problem from his end.

Many thanks,

Mitch.
---
mailto:[email-masked]

----------------------------------------------------------------------------
------------------------
The information contained in this message and any attachments is 
confidential and intended for the named recipient(s). If you have received
this message in error, please contact sender by return e-mail and 
destroy the message and any attachments. 
Any opinions or undertakings expressed in this message are those of the 
individual sender except where the sender expressly and with authority 
states them to be the opinions of Extel. 
----------------------------------------------------------------------------
------------------------

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/