Commit Graph

38 Commits

Author SHA1 Message Date
Cassondra Foesch 00dc491201 refactor ls formatting work 2021-08-11 15:09:43 +00:00
Cassondra Foesch e683b3b6ed cleanup request mutex usage 2021-08-02 11:23:37 +00:00
Sebastien Rosset (serosset) 3b8042dfc0 Use go errors instead of github.com/pkg/errors 2021-06-04 14:18:41 -07:00
Cassondra Foesch 861a8eaf5c pointer receivers and statusFromError(uint32, error) 2021-02-22 12:11:42 +00:00
Cassondra Foesch ac6027de63 numerous subtle race conditions resolved in clientConn 2021-02-22 12:04:43 +00:00
Cassondra Foesch a66e205b29 chan is already available via closure 2021-02-22 12:04:43 +00:00
Cassondra Foesch 5e8f9f4960 MarshalBinary now gives a 4-byte header for length, marshalPacket gives a two-stage write 2021-02-22 12:04:43 +00:00
Cassondra Foesch 0314349ddc more data to debug test failure 2021-02-22 12:04:43 +00:00
greatroar cb1556337d Don't crash when the packet length is zero 2020-11-02 17:07:10 +01:00
Fazlul Shahriar bbd5cf2737
Merge branch 'master' into plan9 2020-09-15 12:06:10 -04:00
Will Norris 8df2eb9876 server: better handle IsNotExist errors
Return early from statusFromError if os.IsNotExist is true.
2020-09-14 07:58:12 -07:00
Will Norris 28f6fd9187 server: use os.IsNotExist to map sshFxNoSuchFile
Always use os.IsNotExist to identify any OS specific error types that
represent missing files or directories.  This resolves an issue on
Windows where some system errors (ENOTDIR) were not being identified as
'not found' errors and mapped to sshFxNoSuchFile.

fixes #381
2020-09-13 21:38:21 -07:00
Fazlul Shahriar 6120cae121
Fix build on Plan 9
All test are passing on Plan 9, and I've also verified
`examples/go-sftp-server` is working.
2020-09-10 18:18:22 -04:00
Nicola Murino 1acb74f50a remove redundant types declaration 2020-07-25 10:17:41 +02:00
Nicola Murino 1f178f9671 the allocator can now be enabled per request
Other minor changes as per review comments
2020-03-18 09:36:07 +01:00
Nicola Murino 3f969fcd59 add optional AllocationModeOptimized
after processing a packet we keep in memory the allocated slices and we reuse
them for new packets.
Slices are allocated in:

- recvPacket
- when we receive a sshFxpReadPacket (downloads)

The allocated slices have a fixed size = maxMsgLength.

Allocated slices are referenced to the request order id and are marked for reuse
after a request is served in maybeSendPackets.

The allocator is added to the packetManager struct and it is cleaned at the end
of the Serve() function.

This allocation mode is optional and disabled by default
2020-03-14 19:42:19 +01:00
Nicola Murino b4ea0fd6f6 fix lint issues
These lint issues remain:

- request-errors.go, aliases for new error types
- request-attrs.go, UidGid. Changing this will break compatibility
2019-08-30 17:04:37 +02:00
Daniel Theophanes d8ec5de5ee sftp: update tests to finish and not panic on windows
Many Unix assuptions have been made when testing.
Previously running tests on windows threw a panic
part way through the tests. After these changes
many more tests pass when the fix was isolated
to the test itself, and none panic.

Some tests are skipped because they do make sense
on windows (chmod, chown), while others are skipped
just to how the test was implemented.

Lastly, some of the external executables were hard coded.
Change these to look paths in TestMain first. This is done
to better support windows, where openssh may be installed and
sftp and sftp-server may both be in the PATH.
2019-01-18 16:29:07 -08:00
John Eikenberry b0f20f999f fix race w/ open packet and stat
An Open packet would trigger the use of a worker pool, then the Stat
packet would come in go to the pool and return faster than the Open
(returning a file-not-found error). This fixes that be eliminating the
pool/non-pool state switching.

The include test doesn't really exercise it fully as it cannot inject
a delay in the right place to trigger the race. I plan on adding a means
to inject some logic into the packet handling in the future once I
rewrite the old filesystem server code as a request-server backend.

Fixes #265
2018-08-22 13:11:00 -07:00
Allan Feid 820ccceeef Send unsupported error on extended packets.
Following the rules outlined here:

https://tools.ietf.org/html/draft-ietf-secsh-filexfer-extensions-00

Return an SSH_FXP_STATUS with appropriate status error for extended
packets that we do not support.
2018-03-19 10:32:22 -04:00
John Eikenberry 738e088bbd support handlers returning explicit error codes
Add errors for all the SSH_FXP_STATUS codes to give the developer
implementing request server handlers greater control over the returned
codes. Most helpful in cases where nothing currently would work (eg.
unsupported).

Fixes #223
2018-01-26 17:26:44 -08:00
andreas 4d7bb970c4 Resolved conflict with SftpServerWorkerCount
Splitted cleanPath into cleanPacketPath and cleanPath for better handling of slashes in file paths
Added test for cleanPath func
Removed code duplication => filepath.ToSlash(filepath.Clean(...)) => cleanPath(...)
Fixed tests for runLs to match year or time
Renamed constants to fit hound rules
2017-08-13 14:00:08 +02:00
Andreas 9b58814641 Fixed time.Parse in runLs tests
Fixed runLs tests on Windows
2017-08-10 07:49:14 +02:00
andreas f7ea598f7f Added os independent test for runLs function 2017-08-10 07:12:50 +02:00
Andreas 11608a1d31 Added initial test setup for runLs 2017-08-09 19:43:14 +02:00
John Eikenberry 5024cb048c Move packer ordering code into packet-manager
The worker/packet mangement code needs to be in the packet manager so
the request-server can utilize it as well. This also improves the
encapsulation of the method as it relied on internal data that should be
better isolated inside the file/struct.
2017-04-23 13:47:05 -07:00
John Eikenberry 447b7fabc1 small naming and output tweaks for tests 2017-04-23 11:32:22 -07:00
John Eikenberry 693e43ceb6 add a test to replicate close happening out of order 2017-04-17 17:24:15 -07:00
Pavel Borzenkov 1d032678cc test: add new test to verify concurrent requests handling
The tests issues several requests in parallel to verify that the server
can handle concurrent requests correctly. Right now the test fails with
race detector enabled. This will be fixed by the following patch.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
2017-04-05 14:15:57 -07:00
Pavel Borzenkov ee0946f83b test: close the server to avoid goroutine leak
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
2017-04-05 14:15:57 -07:00
Dave Cheney e3fac22d8a remove debugging dreg from fc30a3e 2016-06-15 20:15:49 +10:00
Dave Cheney 9d52a809ce Always close client conn when clientConn.recv exits (#117)
If recv has exited then nobody will retrive the response, so
make sure we cannot send anything by shutting down the Write side of the
connection.
2016-06-15 20:04:26 +10:00
Dave Cheney 1a25dc501f rename sendRequest to sendPacket
clientConn.sendPacket now obscures clientConn.conn.sendPacket with a
diferent signature.
2016-06-15 18:57:05 +10:00
Dave Cheney c5050bbe83 removed unused code 2016-06-15 11:33:39 +10:00
Dave Cheney 530345cb99 client: use a waitgroup rather than a close channel (#112) 2016-06-13 22:40:12 +10:00
Dave Cheney aca140bc99 Revert "Fix sendRequest"
This reverts commit 7500207056.
2016-06-13 21:37:38 +10:00
Dave Cheney 7500207056 Fix sendRequest
sendRequest was not returning a value to the channel if there was
_not_ an error. How did this even work ?!?

Also remove server_test.go because it was wrong, it was testing that
sending a properly formed, but invalid (ie, requested wrong extended
packet) packet would cause an error during send ... which is wrong.
sendRequest will only return an error if the client connection was
closed.
2016-06-13 21:29:13 +10:00
Mark Sheahan 9ff4de5c31 add serverside StatVFS function, implemented for darwin and linux (#89) 2016-06-13 14:45:13 +10:00