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

42 Коммитов

Автор SHA1 Сообщение Дата
Simon Tatham 2cb4d89135 Replace sftp_pkt_get* with BinarySource.
This is the first major piece of code converted to the new
unmarshalling system, and allows me to remove all the sftp_pkt_get*
functions in sftp.c that were previously duplicating standard decode
logic.
2018-06-02 17:43:54 +01:00
Simon Tatham 9e96af59ce Introduce a new 'ptrlen' type.
This wraps up a (pointer, length) pair into a convenient struct that
lets me return it by value from a function, and also pass it through
to other functions in one go.

Ideally quite a lot of this code base could be switched over to using
ptrlen in place of separate pointer and length variables or function
parameters. (In fact, in my personal ideal conception of C, the usual
string type would be of this form, and all the string.h functions
would operate on ptrlens instead of zero-terminated 'char *'.)

For the moment, I'm just introducing it to make some upcoming
refactoring less inconvenient. Bulk migration of existing code to
ptrlen is a project for another time.

Along with the type itself, I've provided a convenient system of
including the contents of a ptrlen in a printf; a constructor function
that wraps up a pointer and length so you can make a ptrlen on the fly
in mid-expression; a function to compare a ptrlen against an ordinary
C string (which I mostly expect to use with string literals); and a
function 'mkstr' to make a dynamically allocated C string out of one.
That last function replaces a function of the same name in sftp.c,
which I'm promoting to a whole-codebase facility and adjusting its
API.
2018-06-02 17:33:23 +01:00
Simon Tatham 7babe66a83 Make lots of generic data parameters into 'void *'.
This is a cleanup I started to notice a need for during the BinarySink
work. It removes a lot of faffing about casting things to char * or
unsigned char * so that some API will accept them, even though lots of
such APIs really take a plain 'block of raw binary data' argument and
don't care what C thinks the signedness of that data might be - they
may well reinterpret it back and forth internally.

So I've tried to arrange for all the function call APIs that ought to
have a void * (or const void *) to have one, and those that need to do
pointer arithmetic on the parameter internally can cast it back at the
top of the function. That saves endless ad-hoc casts at the call
sites.
2018-05-26 09:22:43 +01:00
Simon Tatham 81a04c4fe6 Remove the sftp_pkt_add* functions.
Another set of duplicated marshalling bites the dust, replaced with
the same generic functions I'm using everywhere else.
2018-05-25 14:36:16 +01:00
Simon Tatham 5d852585a1 scp_recv_filedata: handle EOF more sensibly.
xfer_download_data could return actuallen as either 0 or -1 to
indicate EOF. Now it's always 0, and scp_recv_filedata actually checks
for that case and reports an error.
2017-02-15 21:39:23 +00:00
Tim Kosse 6f871e3d22 Handle failed SSH_FXP_CLOSE requests in sftp_put_file.
It is possible for SSH_FXP_CLOSE requests to fail. This can happen if the
server buffers writes and an error occurs flushing the data to disk while
processing the SSH_FXP_CLOSE request. If the close fails, sftp_put_file now
returns an error as well.
2016-12-29 11:18:03 +00:00
Tim Kosse 09b74971c7 Fix type mismatch in sftp_find_request
The id member of the sftp_request structure is of type unsigned int.
This type is also used in the sftp_reqfind callback. In
sftp_find_request we thus need to pass a pointer to unsigned int to
find234. Before this commit, sftp_find_request was passing a pointer
to unsigned long to find234, which causes the lookup to fail on
big-endian platforms where sizeof(unsigned int) != sizeof(unsigned
long), e.g. ppc64.
2016-11-19 07:27:24 +00:00
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 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 896bb7c74d Tighten up a lot of casts from unsigned to int which are read by one
of the GET_32BIT macros and then used as length fields. Missing bounds
checks against zero have been added, and also I've introduced a helper
function toint() which casts from unsigned to int in such a way as to
avoid C undefined behaviour, since I'm not sure I trust compilers any
more to do the obviously sensible thing.

[originally from svn r9918]
2013-07-14 10:45:54 +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 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 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
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 42801b7e9e Get rid of all the MSVC warnings.
[originally from svn r7086]
2007-01-09 18:24:07 +00:00
Simon Tatham bbec032476 Lionel Fourquaux offers this very simple patch to speed up SFTP,
simply by upping the packet sizes and maximum in-flight packet
count. Got to be worth a try, I think!

[originally from svn r6722]
2006-06-02 08:46:34 +00:00
Jacob Nevins 6eec320f0b Unify GET_32BIT()/PUT_32BIT() et al from numerous source files into misc.h.
I've done a bit of testing (not exhaustive), and I don't _think_ I've broken
anything...

[originally from svn r5632]
2005-04-12 20:04:56 +00:00
Simon Tatham e902c235ad Per Gunnar Floe spotted a reversed test in sftp_cleanup_requests().
[originally from svn r5394]
2005-02-25 09:59:24 +00:00
Simon Tatham 893d187b81 Additional robustness to SFTP packet parsing and memory allocation.
[originally from svn r5358]
2005-02-20 10:30:05 +00:00
Simon Tatham d649075539 The xfer mechanism wasn't gracefully terminating when an error was
encountered part way through transfer. In particular, this caused
psftp to hang (waiting for FXP_READ replies which had already
arrived) if you try `get' (without -r) on a remote directory.

[originally from svn r5005]
2004-12-17 13:39:41 +00:00
Simon Tatham 7a1eae7ff2 Joe Yates's memory leak patches.
[originally from svn r3650]
2003-12-19 12:44:46 +00:00
Simon Tatham 77cc301862 Uploads turn out to be much easier than downloads, so here's faster
upload support in PSFTP as well.

[originally from svn r3470]
2003-09-28 14:24:01 +00:00
Simon Tatham bc83c59aa7 First cut at speeding up SFTP. Generic download-management code in
sftp.c, and psftp.c now uses that instead of going it alone. Should
in principle be easily installed in PSCP as well, but I haven't done
it yet; also it only handles downloads, not uploads, and finally it
doesn't yet properly calculate the correct number of parallel
requests to queue. Still, it's a start, and in my own tests it
seemed to perform as expected (download speed suddenly became
roughly what you'd expect from the available bandwidth, and
decreased by roughly the expected number of round-trip times).

[originally from svn r3468]
2003-09-27 17:52:34 +00:00
Simon Tatham 66fa6f320e And just to prove that psftp.c really is now platform-independent
... here's a Unix port of PSFTP. Woo. (Oddly PSCP looks to be
somewhat harder; there's more Windows code interleaved than there
was in PSFTP.)

[originally from svn r3419]
2003-08-24 13:22:17 +00:00
Simon Tatham 5bd604f53f Phase 1a of SFTP re-engineering: fix the glaring memory and request
ID leak in the previous checkin. Oops :-)

[originally from svn r3319]
2003-06-29 14:47:14 +00:00
Simon Tatham 3e44064f32 First phase of SFTP re-engineering. Each base-level fxp_* function
has been split into a send half and a receive half, so that callers
can set several requests in motion at a time and deal with the
responses in whatever order they arrive.

[originally from svn r3318]
2003-06-29 14:26:09 +00:00
Simon Tatham d36a4c3685 Introduced wrapper macros snew(), snewn() and sresize() for the
malloc functions, which automatically cast to the same type they're
allocating the size of. Should prevent any future errors involving
mallocing the size of the wrong structure type, and will also make
life easier if we ever need to turn the PuTTY core code from real C
into C++-friendly C. I haven't touched the Mac frontend in this
checkin because I couldn't compile or test it.

[originally from svn r3014]
2003-03-29 16:14:26 +00:00
Simon Tatham 4756c15fc9 Yet more global-removal. The static variables in logging.c are now
absent, and also (I think) all the frontend request functions (such
as request_resize) take a context pointer, so that multiple windows
can be handled sensibly. I wouldn't swear to this, but I _think_
that only leaves the Unicode stuff as the last stubborn holdout.

[originally from svn r2147]
2002-10-26 12:58:13 +00:00
Simon Tatham ae2599845c Fix major memory leak in sftp_cmd_ls (thanks to Hans-Juergen Petrich
for pointing it out).

[originally from svn r1612]
2002-03-31 16:26:13 +00:00
Simon Tatham 0b61ac21c2 Memory leak fix: repair endemic failure to call sftp_pkt_free().
[originally from svn r1570]
2002-03-01 13:16:25 +00:00
Simon Tatham 211bad80f0 Remove ghastly hack involving fxp_error_message.
[originally from svn r1484]
2001-12-14 10:12:53 +00:00
Simon Tatham 382ffaf026 Fix error handling in sftp (the sftp_recv return value was being
checked for NULL almost nowhere).

[originally from svn r1472]
2001-12-11 20:08:12 +00:00
Simon Tatham f176cbe70f Yikes! sftp.c wasn't using the misc.h wrappered malloc functions,
meaning that PSFTP couldn't meaningfully be debugged using
Minefield. That's what I get for developing it under Unix and
forgetting to port it properly :-/

[originally from svn r1383]
2001-11-14 12:58:42 +00:00
Simon Tatham ff9a038cdd PSCP now uses the modern SFTP protocol if it can, and falls back to
scp1 if it can't. Currently not very tested - I checked it in as
soon as it completed a successful recursive copy in both directions.
Also, one known bug: you can't specify a remote wildcard, because by
the nature of SFTP we'll need to implement the wildcard engine on
the client side. I do intend to do this (and use the same wildcard
engine in PSFTP as well) but I haven't got round to it yet.

[originally from svn r1208]
2001-08-26 18:32:28 +00:00
Simon Tatham 9c5951ed35 More upgrades to psftp: it now supports mv, chmod, reget and reput.
[originally from svn r1203]
2001-08-26 11:35:11 +00:00
Simon Tatham 4a0fb28883 Patch to PSFTP: implement mkdir, rmdir, rm and scripting. Still to
do: wildcards, chmod, mv, probably other things.

[originally from svn r1168]
2001-08-04 14:19:51 +00:00
Simon Tatham 3730ada5ce Run entire source base through GNU indent to tidy up the varying
coding styles of the various contributors! Woohoo!

[originally from svn r1098]
2001-05-06 14:35:20 +00:00
Simon Tatham 6b58ab6ad4 Fix various trivial compiler warnings
[originally from svn r983]
2001-03-05 17:31:36 +00:00
Simon Tatham 2b8ab6082f Patches to prevent a couple of silly crashes
[originally from svn r954]
2001-02-27 09:11:42 +00:00
Simon Tatham 39cf689fd6 psftp now works as part of the PuTTY suite
[originally from svn r940]
2001-02-24 16:08:56 +00:00
Simon Tatham 094dd30d95 SFTP client now successfully handles cd, ls, get and put.
[originally from svn r939]
2001-02-24 12:02:35 +00:00
Simon Tatham 48b988b439 First stab at an SFTP client. Currently a Unixland testing app, not
integrated into PuTTY.

[originally from svn r938]
2001-02-23 18:21:44 +00:00