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

147 Коммитов

Автор SHA1 Сообщение Дата
Ben Harris 5c42f97b68 Switch to flow-control-based SFTP uploading.
Formerly PuTTY's SFTP code would transmit (or buffer) a megabyte of data
before even starting to look for acknowledgements, but wouldn't allow
there to be more than a megabyte of unacknowledged data at a time.  Now,
instead, it pays attention to whether the transmit path is blocked, and
transmits iff it isn't.

This should mean that SFTP goes faster over long fat pipes, and also
doesn't end up buffering so much over thin ones.

I practice, I tend to run into other performance limitations (such as
TCP or SSH-2 windows) before this enhancement looks particularly good,
but with an artificial lag of 250 ms on the loopback interface this
patch almost doubles my upload speed, so I think it's worthwhile.
2016-04-09 17:20:07 +01:00
Simon Tatham b0b5d5fbe6 Extend ACL-restriction to all Windows tools.
Protecting our processes from outside interference need not be limited
to just PuTTY: there's no reason why the other SSH-speaking tools
shouldn't have the same treatment (PSFTP, PSCP, Plink), and PuTTYgen
and Pageant which handle private key material.
2016-04-02 08:00:07 +01:00
Jacob Nevins a454399ec8 Rationalise and document log options somewhat.
TOOLTYPE_NONNETWORK (i.e. pterm) already has "-log" (as does Unix
PuTTY), so there's no sense suppressing the synonym "-sessionlog".

Undocumented lacunae that remain:

plink accepts -sessionlog, but does nothing with it. Arguably it should.

puttytel accepts -sshlog/-sshrawlog (and happily logs e.g. Telnet
negotiation, as does PuTTY proper).
2015-11-08 11:58:45 +00:00
Simon Tatham 5c5ca116db Centralise stripslashes() and make it OS-sensitive.
I noticed that Unix PSCP was unwantedly renaming downloaded files
which had a backslash in their names, because pscp.c's stripslashes()
treated \ as a path component separator, since it hadn't been modified
since PSCP ran on Windows only.

It also turns out that pscp.c, psftp.c and winsftp.c all had a
stripslashes(), and they didn't all have quite the same prototype. So
now there's one in winsftp.c and one in uxsftp.c, with appropriate
OS-dependent behaviour, and the ones in pscp.c and psftp.c are gone.
2015-09-24 17:47:10 +01:00
Ben Harris 9e20c81bc9 Merge branch 'pre-0.65' 2015-06-25 23:38:41 +01:00
Ben Harris 95501a148c When PSFTP exits in batch mode due to a command failure, set exit status != 0.
There are possibly other circumstances when PSFTP should also return
failure, but that one seems particularly obvious.
2015-06-25 23:36:17 +01:00
Simon Tatham 89da2ddf56 Giant const-correctness patch of doom!
Having found a lot of unfixed constness issues in recent development,
I thought perhaps it was time to get proactive, so I compiled the
whole codebase with -Wwrite-strings. That turned up a huge load of
const problems, which I've fixed in this commit: the Unix build now
goes cleanly through with -Wwrite-strings, and the Windows build is as
close as I could get it (there are some lingering issues due to
occasional Windows API functions like AcquireCredentialsHandle not
having the right constness).

Notable fallout beyond the purely mechanical changing of types:
 - the stuff saved by cmdline_save_param() is now explicitly
   dupstr()ed, and freed in cmdline_run_saved.
 - I couldn't make both string arguments to cmdline_process_param()
   const, because it intentionally writes to one of them in the case
   where it's the argument to -pw (in the vain hope of being at least
   slightly friendly to 'ps'), so elsewhere I had to temporarily
   dupstr() something for the sake of passing it to that function
 - I had to invent a silly parallel version of const_cmp() so I could
   pass const string literals in to lookup functions.
 - stripslashes() in pscp.c and psftp.c has the annoying strchr nature
2015-05-15 12:47:44 +01:00
Simon Tatham 23208779e7 Merge branch 'pre-0.64' 2014-12-20 18:52:40 +00:00
Simon Tatham dd0f1e5cc7 Close the remote file handle if sftp_put_file's fstat fails.
Instead of abruptly returning from sftp_put_file in that situation, we
now send an FXP_CLOSE instead. Patch due to Tim Kosse.
2014-12-20 16:59:55 +00:00
Simon Tatham c269dd0135 Move echo/edit state change functionality out of ldisc_send.
I'm not actually sure why we've always had back ends notify ldisc of
changes to echo/edit settings by giving ldisc_send(ldisc,NULL,0,0) a
special meaning, instead of by having a separate dedicated notify
function with its own prototype and parameter set. Coverity's recent
observation that the two kinds of call don't even have the same
requirements on the ldisc (particularly, whether ldisc->term can be
NULL) makes me realise that it's really high time I separated the two
conceptually different operations into actually different functions.

While I'm here, I've renamed the confusing ldisc_update() function
which that special operation ends up feeding to, because it's not
actually a function applying to an ldisc - it applies to a front end.
So ldisc_send(ldisc,NULL,0,0) is now ldisc_echoedit_update(ldisc), and
that in turn figures out the current echo/edit settings before passing
them on to frontend_echoedit_update(). I think that should be clearer.
2014-11-22 16:18:00 +00:00
Jacob Nevins addf6219bd Update command-line help and man pages for -hostkey.
[originally from svn r10229]
2014-09-20 22:49:47 +00:00
Simon Tatham bb78583ad2 Implement connection sharing between instances of PuTTY.
The basic strategy is described at the top of the new source file
sshshare.c. In very brief: an 'upstream' PuTTY opens a Unix-domain
socket or Windows named pipe, and listens for connections from other
PuTTYs wanting to run sessions on the same server. The protocol spoken
down that socket/pipe is essentially the bare ssh-connection protocol,
using a trivial binary packet protocol with no encryption, and the
upstream has to do some fiddly transformations that I've been
referring to as 'channel-number NAT' to avoid resource clashes between
the sessions it's managing.

This is quite different from OpenSSH's approach of using the Unix-
domain socket as a means of passing file descriptors around; the main
reason for that is that fd-passing is Unix-specific but this system
has to work on Windows too. However, there are additional advantages,
such as making it easy for each downstream PuTTY to run its own
independent set of port and X11 forwardings (though the method for
making the latter work is quite painful).

Sharing is off by default, but configuration is intended to be very
easy in the normal case - just tick one box in the SSH config panel
and everything else happens automatically.

[originally from svn r10083]
2013-11-17 14:05:41 +00:00
Simon Tatham eb19a35a3d Fix a few more memory and resource leaks.
[originally from svn r9968]
2013-07-22 19:55:55 +00:00
Simon Tatham acf38797eb Add a nonfatal() function everywhere, to be used for reporting things
that the user really ought to know but that are not actually fatal to
continued operation of PuTTY or a single network connection.

[originally from svn r9932]
2013-07-19 17:44:28 +00:00
Simon Tatham ea301bdd9b Fix another giant batch of resource leaks. (Mostly memory, but there's
one missing fclose too.)

[originally from svn r9919]
2013-07-14 10:46:07 +00:00
Simon Tatham cc4f38df14 Add an assortment of missing frees, and one missing file close. Mostly
on error paths, although the one in PSFTP's wildcard_iterate will come
up in normal usage.

[originally from svn r9916]
2013-07-11 17:43:41 +00:00
Simon Tatham c925526e3f xfer_{up,down}load_gotpkt free their input sftp_packet as a side
effect of handling it, but they do not free it if it isn't a packet
they recognise as part of their upload/download. Invent a return value
that specifically signals this, and consistently free pktin at every
call site if that return value comes back. Also, ensure that that
return value also always comes with something meaningful in fxp_error.

[originally from svn r9915]
2013-07-11 17:24:53 +00:00
Simon Tatham f78c9165a1 Fix a couple of code paths on which, if fxp_readdir returned an error,
we would return without first closing the directory handle we had used
as an argument.

[originally from svn r9913]
2013-07-11 17:24:44 +00:00
Simon Tatham 779466f0b0 It's not actually legal by the C standard to call qsort with a null
array pointer, _even_ if you're asking it to sort zero elements so
that in principle it should never dereference that pointer. Fix the
four instances in PSCP/PSFTP where this was previously occurring.

[originally from svn r9912]
2013-07-11 17:24:39 +00:00
Simon Tatham 8201e7d22d Remove redundant null checks for arguments to sftp_{get,put}_file
which are (a) never NULL anyway, and (b) have already been
dereferenced by the time we make those checks so it would be too late
if they were.

[originally from svn r9906]
2013-07-11 17:24:10 +00:00
Simon Tatham 2c586ee2cd Clean up handling of the return value from sftp_find_request. In many
places we simply enforce by assertion that it will match the request
we sent out a moment ago: in fact it can also return NULL, so it makes
more sense to report a proper error message if it doesn't return the
expected value, and while we're at it, have that error message
whatever message was helpfully left in fxp_error() by
sftp_find_request when it failed.

To do this, I've written a centralised function in psftp.c called
sftp_wait_for_reply, which is handed a request that's just been sent
out and deals with the mechanics of waiting for its reply, returning
the reply when it arrives, and aborting with a sensible error if
anything else arrives instead. The numerous sites in psftp.c which
called sftp_find_request have all been rewritten to do this instead,
and as a side effect they now look more sensible. The only other uses
of sftp_find_request were in xfer_*load_gotpkt, which had to be
tweaked in its own way.

While I'm here, also fix memory management in sftp_find_request, which
was freeing its input packet on some but not all error return paths.

[originally from svn r9894]
2013-07-06 20:43:21 +00:00
Simon Tatham 5db48dcddb Make --help and --version work consistently across all tools.
Well, at least across all command-line tools on both Windows and Unix,
and the GTK apps on Unix too. The Windows GUI apps fundamentally can't
write to standard output and it doesn't seem sensible to use message
boxes for these purposes :-)

[originally from svn r9673]
2012-09-19 17:08:15 +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 a580c22c24 John Hartnup reports that Apache SSHD's SFTP server responds to
FXP_READDIR on an empty directory by returning a zero-length list of
filenames, instead of the more common response of a list containing
just "." and "..". Stop PSFTP failing an assertion when that happens.

[originally from svn r9569]
2012-06-20 17:39:32 +00:00
Simon Tatham 947962e0b9 Revamp of EOF handling in all network connections, pipes and other
data channels. Should comprehensively fix 'half-closed', in principle,
though it's a big and complicated change and so there's a good chance
I've made at least one mistake somewhere.

All connections should now be rigorous about propagating end-of-file
(or end-of-data-stream, or socket shutdown, or whatever) independently
in both directions, except in frontends with no mechanism for sending
explicit EOF (e.g. interactive terminal windows) or backends which are
basically always used for interactive sessions so it's unlikely that
an application would be depending on independent EOF (telnet, rlogin).

EOF should now never accidentally be sent while there's still buffered
data to go out before it. (May help fix 'portfwd-corrupt', and also I
noticed recently that the ssh main session channel can accidentally
have MSG_EOF sent before the output bufchain is clear, leading to
embarrassment when it subsequently does send the output).

[originally from svn r9279]
2011-09-13 11:44:03 +00:00
Simon Tatham 5c00b581c8 Propagate file permissions in both directions in Unix pscp and psftp.
I think I have to consider this to be a separate but related change to
the wishlist item 'pscp-filemodes'; that was written before the Unix
port existed, and referred to the ability to configure the permissions
used for files copied from Windows to Unix - which is still not done.

[originally from svn r9260]
2011-08-11 17:59:30 +00:00
Simon Tatham a1f3b7a358 Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.

User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).

One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.

[originally from svn r9214]
2011-07-14 18:52:21 +00:00
Jacob Nevins 5eb70af8b1 Remove an unused variable (should shut up a warning from GCC 4.6).
[originally from svn r9111]
2011-03-01 23:04:37 +00:00
Jacob Nevins 4bddcc2b5d Workarounds for compiling with -D_FORTIFY_SOURCE=2 (as Ubuntu does), which
doesn't like you to ignore the return value from read()/write()/etc (and
apparently can't be shut up with a cast to void).

[originally from svn r8614]
2009-08-07 00:19:04 +00:00
Simon Tatham c7ac5745ab When giving authorisation errors from the proxy code in x11fwd.c,
name the proxy using the global 'appname' variable, instead of
statically calling it PuTTY.

(Knock-on effect is that PSCP and PSFTP have to declare that
variable, though of course they shouldn't ever actually _use_ the X
forwarding code. Probably I ought to replace it with a stub
nox11fwd.c for those applications.)

[originally from svn r8501]
2009-04-23 17:39:36 +00:00
Jacob Nevins a6cbfd974d Treat lines starting with '#' as comments in PSFTP.
[originally from svn r8325]
2008-11-24 18:19:55 +00:00
Simon Tatham 2a0cf16c33 Tim Kosse points out that xfer_upload_gotpkt can return a negative
value on error, so the check at the call site shouldn't test for
exactly zero.

[originally from svn r8183]
2008-09-16 12:48:38 +00:00
Simon Tatham e01df1da9f Patch from Tim Kosse: check back->exitcode() in both loops on
ssh_sftp_loop_iteration(), not just one. Fixes exiting on a negative
response to the host key confirmation prompt on Windows (because
winsftp.c doesn't have the equivalent of uxsftp.c's no_fds_ok); on
Unix it worked already but gave a suboptimal error message, which is
fixed too by this patch.

[originally from svn r8110]
2008-07-06 12:24:56 +00:00
Simon Tatham 7edbe42d12 Patch from Tim Kosse to make PSFTP remember to close files on
various error conditions.

[originally from svn r8109]
2008-07-06 12:11:34 +00:00
Ben Harris a3ea90c0e8 In the file-transfer applications, which only ever use the main
channel, arrange to set the SSH-2 window size to something very
large.  This prevents the connection stalling when the window fills
up, and means that PSCP receives data _much_ faster.

[originally from svn r7672]
2007-08-04 22:14:19 +00:00
Ben Harris 7df108f2fd When we get an error writing to a local file, stop the download rather than
pretending we just got -1 bytes.  Not actually tested, but it looks pretty
obvious.
Bug reported by dking wang.

[originally from svn r7459]
2007-04-10 21:46:44 +00:00
Simon Tatham 0a3c07d15e When the comments say `if we're in restart mode', the code in
question should actually be conditional on restart mode!

[originally from svn r7438]
2007-04-02 08:44:00 +00:00
Jacob Nevins cc28093380 Spotted by Tim Kosse: we were returning an incorrect path in canonify() when
we couldn't get any sense out of the server.

[originally from svn r6877]
2006-10-22 20:19:55 +00:00
Simon Tatham c353c3cc97 The `socket' function in the backends is only ever checked to see if
it's NULL. Since we already have one back end (uxpty) which doesn't
in fact talk to a network socket, and may well have more soon, I'm
replacing this TCP/IP-centric function with a nice neutral
`connected' function returning a boolean. Nothing else about its
semantics has currently changed.

[originally from svn r6810]
2006-08-27 08:03:19 +00:00
Simon Tatham 5765f8ceb9 On cleanup, PSCP and PSFTP should explicitly check that the back end
is still running rather than relying on ssh_sftp_loop_iteration() to
return a bogus value.

[originally from svn r6803]
2006-08-26 10:17:39 +00:00
Owen Dunn 33b7caa590 Large file support for psftp and pscp on both Windows and Unix. On Unix
we set _FILE_OFFSET_BITS to 64 on the compiler command line (via mkfiles.pl),
and on Windows we use SetFilePointer and GetFileSize to cope with 64-bit sizes
where possible.  Not tested on Win9x.

[originally from svn r6783]
2006-08-12 15:20:19 +00:00
Jacob Nevins f3be6ab7ab Everywhere we print an fxp_error(), try to make it clear what we were trying
to do at the time.
(A lot of these say just "canonify:". This isn't a nice thing to show to a
user, but I don't believe canonify() will ever return failure due to a server
error, so users shouldn't actually see it, and it means we have a chance of
tracing it if reported.)

[originally from svn r6636]
2006-04-13 21:18:09 +00:00
Jacob Nevins 1d6f8ae824 Remove login name prompt from PSFTP.
ssh.c will prompt for a login name as required, and doing so in psftp.c
before we've even made a connection is incorrect wrt `bypass-ssh2-userauth'.

[originally from svn r6634]
2006-04-07 21:42:30 +00:00
Jacob Nevins 5e59d81947 Fix up documentation/usage messages for r6572.
[originally from svn r6574]
[r6572 == c2b2d9c539]
2006-02-19 12:52:28 +00:00
Jacob Nevins 8719f92c14 Revamp SSH authentication code so that user interaction is more
abstracted out; replace loops structured around a single interaction
per loop with less tortuous code (fixes: `ki-multiprompt-crash',
`ssh1-bad-passphrase-crash'; makes `ssh2-password-expiry' and
`proxy-password-prompt' easier).

The new interaction abstraction has a lot of fields that are unused in
the current code (things like window captions); this is groundwork for
`gui-auth'. However, ssh.c still writes directly to stderr; that may
want to be fixed.

In the GUI apps, user interaction is moved to terminal.c. This should
make it easier to fix things like UTF-8 username entry, although I
haven't attempted to do so. Also, control character filtering can be
tailored to be appropriate for individual front-ends; so far I don't
promise anything other than not having made it any worse.

I've tried to test this fairly exhaustively (although Mac stuff is
untested, as usual). It all seems to basically work, but I bet there
are new bugs. (One I know about is that you can no longer make the
PuTTY window go away with a ^D at the password prompt; this should be
fixed.)

[originally from svn r6437]
[this svn revision also touched putty-wishlist]
2005-10-30 20:24:09 +00:00
Jacob Nevins 9565f4f550 Double-free on mkdir error, spotted by Brian Hartsock.
[originally from svn r5929]
2005-06-08 15:14:47 +00:00
Jacob Nevins 36fc6c0a76 Try to make our PGP signing more useful:
* All the PuTTY tools for Windows and Unix now contain the fingerprints of
   the Master Keys. The method for accessing them is crude but universal:
   a new "-pgpfp" command-line option. (Except Unix PuTTYgen, which takes
   "--pgpfp" just to be awkward.)

 * Move the key policy discussion from putty-website/keys.html to
   putty/doc/pgpkeys.but, and autogenerate the former from the latter.
   Also tweak the text somewhat and include the fingerprints of the
   Master Keys themselves.
   (I've merged the existing autogeneration scripts into a single new
   one; I've left the old scripts and keys.html around until such time
   as the webmonster reviews the changes and plumbs in the new script;
   he should remove the old files then.)

[originally from svn r5524]
[this svn revision also touched putty-website]
2005-03-19 02:26:58 +00:00
Jacob Nevins 5aa719d16e Consistently use a single notation to refer to SSH protocol versions, as
discussed. Use Barrett and Silverman's convention of "SSH-1" for SSH protocol
version 1 and "SSH-2" for protocol 2 ("SSH1"/"SSH2" refer to ssh.com
implementations in this scheme). <http://www.snailbook.com/terms.html>

[originally from svn r5480]
2005-03-10 16:36:05 +00:00
Jacob Nevins a00b7e746f Localise "not connected to a host" messages.
[originally from svn r5060]
2005-01-01 16:43:19 +00:00
Jacob Nevins e5f13ceee5 Now that rm, mkdir, and rmdir can operate on lots of files, make them more
chatty like the other multiple-file commands.

[originally from svn r5059]
2005-01-01 16:35:57 +00:00