Граф коммитов

3547 Коммитов

Автор SHA1 Сообщение Дата
Ben Harris 580103fca2 Add a new COMPAT option for environments lacking SecureZeroMemory(),
rather than explicitly checking for Winelib.  It seems that w32api is
lacking it as well.

[originally from svn r9669]
2012-09-18 23:05:29 +00:00
Ben Harris bc8f2193f6 Allow remote-to-local forwardings to use IPv6.
RFC 4245 section 7.1 specifies the meaning of the "address to bind"
parameter in a "tcpip-forward" request.  "0.0.0.0" and "127.0.0.1" are
specified to be all interfaces and the loopback interface respectively
in IPv4, while "" and "localhost" are the address-family-agnostic
equivalents.  Switch PuTTY to using the latter, since it doesn't seem
right to force IPv4.

There's an argument that PuTTY should provide a means of configuring the
address family used for remote forwardings like it does for local ones.

[originally from svn r9668]
2012-09-18 21:50:47 +00:00
Ben Harris d5836982e2 Two related changes to timing code:
First, make absolute times unsigned.  This means that it's safe to 
depend on their overflow behaviour (which is undefined for signed 
integers).  This requires a little extra care in handling comparisons, 
but I think I've correctly adjusted them all.

Second, functions registered with schedule_timer() are guaranteed to be 
called with precisely the time that was returned by schedule_timer().  
Thus, it's only necessary to check these values for equality rather than 
doing risky range checks, so do that.

The timing code still does lots that's undefined, unnecessary, or just
wrong, but this is a good start.

[originally from svn r9667]
2012-09-18 21:42:48 +00:00
Ben Harris 41ad182710 Quell a (correct) GCC warning in the NO_HTMLHELP case.
[originally from svn r9666]
2012-09-17 22:28:07 +00:00
Ben Harris 942aca34d1 Should have been part of r9663: do use the platform-independent version
of smemclr when compiling with Winelib.

[originally from svn r9665]
[r9663 == 3b27c3e32b]
2012-09-13 23:00:29 +00:00
Ben Harris d63ce7d30a Tweak comment in Recipe that had become separated from its code.
[originally from svn r9664]
2012-09-13 22:34:53 +00:00
Ben Harris 3b27c3e32b Don't try to use SecureZeroMemory under Winelib, since it isn't available
there (yet).

[originally from svn r9663]
2012-09-13 22:34:18 +00:00
Ben Harris e7324f7934 Define SECURITY_WIN32 for Winelib/Cygwin builds as well as for VC.
This should perhaps go into winmisc.c: it's caused problems for
other people too:

<http://stackoverflow.com/questions/8530159/vs2010-build-error-at-putty-source>

[originally from svn r9662]
2012-09-13 22:33:27 +00:00
Ben Harris 5415b82930 In the cygwin Makefile, use "-o" on the windres command line to specify
the output file.  This appears to be supported by windres, and is
required by wrc (the Winelib resource compiler).

[originally from svn r9661]
2012-09-13 21:53:47 +00:00
Ben Harris 8c1d1be956 Most of the code for "nc" mode duplicated that for opening a session or
a fowarded port.  Arrange that this code is shared instead.  The main
visible change is a slight change of log messages.

[originally from svn r9655]
2012-09-08 19:46:07 +00:00
Simon Tatham 14539a7719 Hiroshi Oota points out that PuTTY's agent forwarding sockets can get
confused if they receive a request followed by immediate EOF, since we
currently send outgoing EOF as soon as we see the incoming one - and
then, when the response comes back from the real SSH agent, we send it
along anyway as channel data in spite of having sent EOF.

To fix this, I introduce a new field for each agent channel which
counts the number of calls to ssh_agentf_callback that are currently
expected, and we don't send EOF on an agent channel until we've both
received EOF and that value drops to zero.

[originally from svn r9651]
2012-09-08 10:40:36 +00:00
Ben Harris 33c58dd91b Factor out some common code for constructing SSH2_CHANNEL_OPEN.
[originally from svn r9649]
2012-09-01 12:28:38 +00:00
Ben Harris de6d59b500 struct winadj is unused now. G/c it.
[originally from svn r9648]
2012-09-01 12:10:27 +00:00
Ben Harris 98e562b7f6 All of the initial CHANNEL_REQUESTs are conditional on (ssh->mainchan &&
!ssh->ncmode), so bundle them up in a big block conditional on this rather
than checking it five times.

[originally from svn r9647]
2012-09-01 12:03:12 +00:00
Ben Harris 54da9ee07a do_ssh2_authconn() now installs the standard handlers for CHANNEL_SUCCESS
and CHANNEL_FAILURE as soon as it's opened a channel, so there's no need
for it to set them again later.

[originally from svn r9646]
2012-09-01 11:32:53 +00:00
Simon Tatham 8acd57afb5 Memory leak fixes reported by Balazs Domjan.
[originally from svn r9645]
2012-08-30 18:48:08 +00:00
Simon Tatham b631c1e18e Rename the various ssh2_maybe_setup_* functions to ssh2_setup_*, and
move the primary conditions out of them into their callers. Fixes a
crash in 'plink -N', since those functions would be called with a NULL
channel parameter and immediately dereference it to try to get c->ssh.

[originally from svn r9644]
2012-08-30 18:44:35 +00:00
Simon Tatham dbc8ea8e35 In openssh_read(), we shouldn't ever return SSH2_WRONG_PASSPHRASE for
an unencrypted key. (The other import function, sshcom_read(), already
got this right.) Thanks to David Wedderwille for the report.

This is more than just an error-reporting mistake; it actually causes
Windows PuTTYgen to tight-loop on attempting to load a corrupt OpenSSH
key, because the 'wrong passphrase' return value causes the caller to
loop round and try again, but of course it knows the key is
unencrypted so it doesn't prompt for a different passphrase and just
tries again with no change...

[originally from svn r9643]
2012-08-30 18:44:34 +00:00
Simon Tatham e2a48fe9b1 Avoid leaking file handles in load_openssh_key(), as reported by David
Wedderwille.

[originally from svn r9642]
2012-08-30 18:44:33 +00:00
Simon Tatham ddfca43402 Fix a controlling-terminal bug reported by Anthony Heading: Cygwin
doesn't have TIOCSCTTY, so my attempt to set the ctty of the child
process isn't doing anything, and only works by chance when you run
bash because bash does the thing that _will_ set the ctty, namely
opening the terminal file again without O_NOCTTY. So now we do that
too.

[originally from svn r9638]
2012-08-28 17:42:47 +00:00
Simon Tatham 03ebc74b9f Partially revert r9636. It is true that we can directly return the
result of memcmp, but untrue that we can do so _unconditionally_: if
memcmp returns zero, we still need to fall through to the next
comparison.

[originally from svn r9637]
[r9636 == 538090ede4]
2012-08-28 17:41:10 +00:00
Ben Harris 538090ede4 Clang, like LCC, objects to using '<' and '>' on function pointers.
I'm not entirely sure that using memcmp() is any more defined by the C
standard, but at least Clang doesn't complain about it.  While I'm
here, tree234 doesn't require that comparison functions return
precisely +1 or -1, so we can use the return value of memcmp()
directly.

[originally from svn r9636]
2012-08-27 23:16:49 +00:00
Ben Harris e27ce2017e Change return type of do_ssh2_transport() to void.
Nothing pays attention to it any more, anyway.

[originally from svn r9635]
2012-08-27 22:02:17 +00:00
Ben Harris 3cc03d85e7 Make bombout() less of a macro and more of a function.
This gives GCC slightly fewer opportunities to gratuitously inflate
its output.

[originally from svn r9634]
2012-08-27 21:55:45 +00:00
Ben Harris df83634e21 Fix a memory leak in parse_ttymodes() (found by Memcheck/Valgrind).
[originally from svn r9633]
2012-08-27 19:11:39 +00:00
Ben Harris 475507e978 Slightly simplify crFinishFree{,V}.
They're only likely to be useful for freeing a coroutine state
structure, in which case there's no need to reset the line number
(since all such coroutines keep their line number in the state
structure) and the state structure pointer is always called "s".

[originally from svn r9632]
2012-08-27 18:44:06 +00:00
Ben Harris 0768c8557d Don't close SSH-2 channels with outstanding channel requests on local error.
In sshfwd_unclean_close(), get ssh2_check_close() to handle sending
SSH_MSG_CHANNEL_CLOSE.  That way, it can hold off doing so until any
outstanding channel requests are processed.

Also add event log message for unclean channel closures.

[originally from svn r9631]
2012-08-27 17:37:44 +00:00
Simon Tatham 3fa95b2a7f It's not legal to free a coroutine's state structure before invoking
crFinish or crFinishV, since they will attempt to write to the
coroutine state variable contained in that structure. Introduced some
new all-in-one macros crFinishFree and crFinishFreeV, and used those
instead. Should fix today's report of a crash just after authentication.

[originally from svn r9630]
2012-08-27 14:34:41 +00:00
Jacob Nevins 85c95e30e4 Fix markup error introduced in r9626.
[originally from svn r9627]
[r9626 == 92fc25c6cd]
2012-08-26 09:50:57 +00:00
Ben Harris 92fc25c6cd Remove documentation for "Out of space for port forwardings" error.
It no longer exists in the code, and should have been obsoleted by
r9214 at the latest.

[originally from svn r9626]
[r9214 == a1f3b7a358]
2012-08-26 09:19:34 +00:00
Ben Harris 3fad1f402b Improve window-size handling in Unix Plink.
Unconditionally override the configured terminal size with the one
from stdin if it's available.  This avoids the silliness whereby if
Default Settings had a terminal size set, Plink used this and thus
caused the server to use the wrong size.

[originally from svn r9624]
2012-08-25 22:57:39 +00:00
Ben Harris 3d466aec90 Better handling of outstanding CHANNEL_REQUESTS on channel destruction.
Part the first: make sure that all structures describing channel
requests are freed when the SSH connection is freed.  This involves
adding a means to ask a response handler to free any memory it holds.

Part the second: in ssh_channel_try_eof(), call
ssh2_channel_check_close() rather than emitting an SSH_MSG_CHANNEL_EOF
directly.  This avoids the possibility of closing the channel while a
CHANNEL_REQUEST is outstanding.

Also add some assertions that helped with tracking down the latter
problem.

[originally from svn r9623]
2012-08-25 21:06:48 +00:00
Ben Harris 4e623f5b23 Factor out common code to construct CHANNEL_REQUESTS.
This reduces code size a little and also makes it harder to
accidentally request a reply without putting in place a handler for
it or vice versa.

[originally from svn r9620]
2012-08-25 15:57:05 +00:00
Ben Harris ab6d966f91 Simplify handling of responses to channel requests.
The various setup routines can only receive CHANNEL_SUCCESS or
CHANNEL_FAILURE, so there's no need for the to worry about receiving
anything else.  Strange packets will end up in do_ssh2_authconn
instead.

[originally from svn r9619]
2012-08-25 15:04:29 +00:00
Ben Harris 1c4eac5fa3 Add some kind of window tracking to logparse.pl.
[originally from svn r9618]
2012-08-25 14:34:20 +00:00
Ben Harris 8387897d90 Fix matching of channel and global requests with replies in logparse.pl.
In each case, want_reply was being treated as true even when it wasn't,
because it got decoded into "yes"/"no", both of which are true in
Perl.

[originally from svn r9617]
2012-08-25 13:54:56 +00:00
Ben Harris 30e43ba2a3 Handle all replies to CHANNEL_REQUESTs through the per-channel queue.
Each of the minor start-of-session requests is now dealt with by its own 
little co-routine, while the shell/command is done in do_ssh2_authconn() 
itself.  This eliminates one more round-trip in session setup: PuTTY gets
all the way up to sending a shell request before worrying about any
replies.

[originally from svn r9616]
2012-08-25 13:39:32 +00:00
Ben Harris 57945a753f Generalise SSH_MSG_CHANNEL_{SUCCESS,FAILURE} handling.
Now each channel has a queue of arbitrary handlers for those messages, 
with anything that sends a CHANNEL_REQUEST with want_reply true pushing 
a new entry onto the queue, and a shared handler that dispatches 
responses appropriately.

Currently, this is only used for winadj@putty.projects.tartarus.org, but 
extending it to cover the initial requests as well shouldn't be too 
painful.

[originally from svn r9615]
2012-08-25 11:12:14 +00:00
Simon Tatham 5ebf74d103 Fix a bug in the PSFTP command parser which would cause it to
hallucinate an extra empty argument word at the end of a line if the
line ended in more than one whitespace character.

[originally from svn r9613]
2012-08-22 18:36:44 +00:00
Simon Tatham f796f2d2d3 Enhance logparse.pl so that it detects channels running SFTP and
decodes the SFTP message layer in addition to the underlying SSH.
Requests and responses are matched up via their ids.

[originally from svn r9612]
2012-08-22 18:25:28 +00:00
Ben Harris f071feb9a6 Fix recently-introduced memory leak in ssh2_msg_unexpected().
[originally from svn r9611]
2012-08-21 23:04:22 +00:00
Ben Harris e148dd97e3 De-duplicate code in KEXINIT generation.
There's no need to have identical code generating server-to-client and
client-to-server versions of the cipher and MAC lists; a couple of
twice-around loops will do fine.

[originally from svn r9610]
2012-08-21 22:33:31 +00:00
Ben Harris 8e0ab8be59 Reworking of packet delivery to coroutines in SSH-2.
Before, NULL in the dispatch table meant "send to the appropriate one of 
do_ssh2_transport() and do_ssh2_authconn()".  Now those (via small 
shims) are specified directly in the dispatch table, so ssh2_protocol() 
is much simpler.

In the process, this has somewhat centralised the handling of gross 
server protocol violations.  PuTTY will now disconnect with a rude 
message when (e.g.) OpenSSH sends us an SSH_MSG_UNIMPLEMENTED when we 
try to KEXINIT during authentication.

[originally from svn r9609]
2012-08-21 22:04:56 +00:00
Ben Harris 4e5012aeda Fix an erroneous "case" fallthrough in ssh1_msg_channel_close, which was
causing assertion failures when closing X11 channels in SSH-1.  Also fix 
another pasto.

[originally from svn r9608]
2012-08-19 11:35:26 +00:00
Ben Harris e570820c74 Tweak to SSH coroutine code: put line number in the coroutine state
structure, which is consistent with Simon's canonical version of the
macros.

[originally from svn r9607]
2012-08-18 09:30:01 +00:00
Simon Tatham 1ac65ff017 Use a single sftp_senddata() to send each SFTP packet, rather than
using one for the length field and one for the rest of the packet
contents. Since sftp_senddata() has no queuing or deferral mechanism
but instead constructs and sends an SSH2_MSG_CHANNEL_DATA message
immediately, this change has the effect of ceasing to split every SFTP
packet across two SSH messages.

[originally from svn r9603]
2012-08-12 20:17:13 +00:00
Ben Harris b599e77ada Rework bufchain code to allow for variable-sized granules.
bufchain_add() now allocates at most one new granule.  Granules still 
have a minimum size, so small adds still get coalesced.

The main practical consequence of this is that PSCP and PSFTP now 
generate 4K SSH packets rather than 512-byte ones.  Also, the compiled 
code (on my Ubuntu box) is fractionally smaller.

[originally from svn r9602]
2012-08-11 09:10:31 +00:00
Ben Harris 37ea0f4541 Reduce the number of round-trips involved in opening an SSH-2 session
by sending most of the initial SSH_MSG_CHANNEL_REQUEST messages before
waiting for any replies.  The initial version of this code was a clever
thing with a two-pass loop, but that got hairy so I went for the simpler
approach of separating the request and reply code and having flags to
keep track of which requests have been sent.

[originally from svn r9599]
2012-08-02 22:18:18 +00:00
Simon Tatham 8ae3278d0c Add a missing \define I accidentally assumed was there in r9592.
[originally from svn r9593]
[r9592 == 71f0c7546d]
2012-07-29 13:38:31 +00:00
Simon Tatham 71f0c7546d Add a bug-compatibility flag to disable the
winadj@putty.projects.tartarus.org request. Not currently enabled
automatically, but should be usable as a manual workaround.

[originally from svn r9592]
2012-07-28 19:30:12 +00:00