StefanBruens
1ff6dda616
Correctly parse v4 subsecond timestamps
...
All subsecond timestamps are only in the packets if both the
SUBSECOND_TIMES flag and the timestamp flag, e.g. ATTR_ACCESSTIME
are set.
SUBSECOND_TIMES are not very common across server implementations
(e.g. openssh does not include it, nor does libssh's sftpserver
implementation), but this interpretation of the SFTP protocol draft
is used by WinSCP and lftp.
Fixes T219.
Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2020-04-15 13:21:28 +02:00
Andreas Schneider
8542f675f4
sftp: Replace PRIdS with ANSI C99 %zu
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2020-02-12 09:39:06 +01:00
Andreas Schneider
4cae57c581
sftp: Use SSH_BUFFER_FREE()
...
Fixes T183
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
9384a18e91
sftp: Use SSH_STRING_FREE()
...
Fixes T183
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
af2aeba838
SSH-01-006: Add missing NULL check in sftp_open()
...
Fixes T193
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
d672b1d7c4
sftp: Avoid comparison of integers of different sizes
...
This casts ssize_t len to size_t.
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
d40f33c400
sftp: Cast sftp version to int
...
This is a public struct and the version should be unsigned there.
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
c29840060b
sftp: Use uint32_t for sftp extension count
...
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
98824d6e11
sftp: Fix integer types in sftp_extension_supported()
...
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
839fab6df4
sftp: Fix integer types in sftp_read()
...
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
6b105624bf
sftp: Fix integer types in sftp_write() and sftp_packet_write()
...
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Andreas Schneider
db4345fb36
sftp: Remove internal function from sftp.h
...
Those are not marked as LIBSSH_API so not part of the public API and the
symbols aren't exported!
Fixes T188
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-12-09 16:08:03 +01:00
Anderson Toshiyuki Sasaki
0280ff12a5
sftp: Do not mix integer types
...
Don't use long unsigned int as equivalent as uint32_t. Use macros to
correctly print the values independently of the architecture.
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2019-06-14 15:22:45 +02:00
David Wedderwille
32eec7b418
SSH_LOG: Adjust log level from SSH_LOG_WARNING to SSH_LOG_PROTOCOL
...
Fixes T149
Signed-off-by: David Wedderwille <davidwe@posteo.de >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2019-06-13 16:43:44 +02:00
raminfp
9b1772ecbd
sftp: Remove the break statements
...
They aren't needed and perhaps some compilers will issue "Unreachable
code" warnings.
Signed-off-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2019-05-22 15:35:29 +02:00
David Wedderwille
cc536377f9
sftp server: Implementation of sftp_server_free() as counterpart to sftp_server_new()
...
Fixes T143
Signed-off-by: David Wedderwille <davidwe@posteo.de >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-04-29 13:17:24 +02:00
Andreas Schneider
c4348c7b3c
sftp: Check if the channel is still valid
...
Fixes T138
Reported-by: Jan Pazdziora <jpazdziora@redhat.com >
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2019-04-29 13:17:16 +02:00
Anderson Toshiyuki Sasaki
8ddbe7bec6
sftp: Add NULL check in sftp_ext_free()
...
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2019-01-26 13:56:25 +01:00
Anderson Toshiyuki Sasaki
61ad276a87
sftp: Reformat sftp_ext_free()
...
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2019-01-26 13:56:22 +01:00
Andreas Schneider
9f1718e159
Revert "sftp: Set error if invalid session pointer is passed to sftp_new()"
...
This reverts commit d011b780c3 .
2019-01-05 13:17:32 +01:00
Andreas Schneider
d011b780c3
sftp: Set error if invalid session pointer is passed to sftp_new()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2019-01-04 13:31:34 +01:00
Anderson Toshiyuki Sasaki
f05717d23e
sftp: Add NULL check in sftp_fstat()
...
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
2018-12-07 17:47:22 +01:00
Anderson Toshiyuki Sasaki
eaa97d2062
sftp: Add NULL check in sftp_xstat()
...
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-12-07 17:47:18 +01:00
Anderson Toshiyuki Sasaki
bda2cc69af
sftp: Add NULL check in sftp_opendir()
...
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-12-07 17:47:11 +01:00
Anderson Toshiyuki Sasaki
83d827d7dd
sftp: Set sftp error when received unexpected message
...
Set sftp error to SSH_FX_BAD_MESSAGE if an unexpected message is
received.
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-12-07 17:47:00 +01:00
Anderson Toshiyuki Sasaki
0f95295966
sftp: Set sftp error code when fail occurs
...
When an operation fails in sftp subsystem, set the sftp error, so that
it can be obtained by sftp_get_error().
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-12-07 17:44:52 +01:00
Anderson Toshiyuki Sasaki
d78a29eb79
sftp: Set error when EOF is received in sftp_packet_read()
...
When reading a sftp packet and an EOF is received before all requested
bytes are read, set the session and sftp error codes.
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-12-07 17:43:08 +01:00
Andreas Schneider
3784226fd8
sftp: Do not overwrite errors set by channel functions
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-11-30 18:52:40 +01:00
Andreas Schneider
3245b50795
sftp: Only prepend header data once
...
This reduces memory moving.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2018-10-08 09:27:06 +02:00
Andreas Schneider
508dfc5251
sftp: Reformat sftp_packet_write()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2018-10-08 09:26:59 +02:00
Andreas Schneider
aec9fa4442
sftp: Use bytearray macros
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
Reviewed-by: Jakub Jelen <jjelen@redhat.com >
2018-10-05 14:38:43 +02:00
Alberto Aguirre
14f5624ff5
sftpserver: allocate packet on sftp_server_new
...
Ensure sftp_server_new allocates the packet and payload as
sftp_packet_read now expects the packet and payload to be
pre-allocated.
Similarly, ensure sftp_get_client_message does not free the packet.
Signed-off-by: Alberto Aguirre <albaguirre@gmail.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-25 16:41:54 +02:00
Chris Townsend
6c56c1e0d7
sftpserver: Support some openssh extensions
...
Add support for "hardlink@openssh.com " and
"posix-rename@openssh.com " extensions.
Signed-off-by: Chris Townsend <christopher.townsend@canonical.com >
Signed-off-by: Alberto Aguirre <albaguirre@gmail.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-20 16:35:13 +02:00
Andreas Schneider
a30d542207
sftp: Include stdint.h
...
Thanks to Apex Liu
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-19 12:25:03 +02:00
Harald Sitter
97cb302c0e
sftp: fix buffer_unpack argument to be char** rather than char*
...
Summary:
buffer variable 's' gets unpacked as char**, the previous code was passing
a char* causing segfaults on all readlink calls inside the unpacking code
Test Plan:
- without patchy examples/samplesftp segfaults in readlink
- with patchy it doesn't
Reviewers: asn
Differential Revision: https://bugs.libssh.org/D14
Signed-off-by: Harald Sitter <sitter@kde.org >
2018-09-19 11:18:12 +02:00
Andreas Schneider
cc83b463ce
sftp: Fix a possible null pointer dereference
...
CID 1395721
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-18 10:19:59 +02:00
Andreas Schneider
0762057eb9
sftp: Move the packet payload to the message
...
This reduces memory allocations and copying.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
57153f6481
sftp: Use SSH_BUFFER_FREE in sftp_message_free()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
4c32befd93
sftp: Reformat sftp_message_free()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
be8302e2f3
sftp: Allocate a new buffer in sftp_packet_read() if needed
...
We will move the buffer to the message instead of duplicating the
memory.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
97d2e1f4cb
sftp: Reformat sftp_read_and_dispatch()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
12fc0ea1bf
sftp: Validate the packet handle before we allocate memory
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
573eab0d51
sftp: Reformat sftp_get_message()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
0e317e612f
sftp: Use bool for is_eof in sftp_packet_read()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
01135703a3
sftp: Use 's' only in the scope it is needed
...
This revaled a bug when reading the packet type.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
c070414309
sftp: Use 16K for the transfer buffer size
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
d2cc4eccc7
sftp: Get the packet type directly from the buffer
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
38781f69b0
sftp: Limit packet size to 256 MB
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
dc4faf9952
sftp: Directly read and validate the packet size from the bufffer
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
cbbc6ddcb6
sftp: Use read_packet from sftp handle
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00