Commit Graph

84 Commits

Author SHA1 Message Date
Cassondra Foesch fef2628887 remove write/read race condition 2021-02-22 12:04:43 +00:00
Cassondra Foesch e3d9bf1123 early return error, happy path straight 2021-02-22 12:04:43 +00:00
Cassondra Foesch c6aaae51f9 cleanup a t.Fatalf 2021-02-22 12:04:43 +00:00
Nicola Murino 14bb577288 client statVFS: normalize the returned error
added a test case for the request server to check os.IsNotExist error
2021-02-10 19:35:30 +01:00
Nicola Murino 5dbfeffd12 request-server: add StatVFS support 2021-02-10 19:13:19 +01:00
Nicola Murino 75eca30139 request-server test: set size for the error channel to 1
This way even if we do not read from this channel, there is not a
blocked goroutine left hanging
2020-11-18 08:57:15 +01:00
Nicola Murino 863783342b request-server: add test cases for server errors 2020-11-16 17:38:12 +01:00
Nicola Murino 732b2a30fb request server: fix handles leak in error case
For open/opendir requests we create a new handle and close it
when the client sends an SSH_FXP_CLOSE but if we return an error the
client will never send the close packet so we have to close the handle
ourselves
2020-11-16 14:34:09 +01:00
Cassondra Foesch c46216738b symlink loop testing 2020-09-29 17:39:30 +00:00
Cassondra Foesch a0a2273fde Test that Rename does not overwrite, and PosixRename does 2020-09-25 16:13:45 +00:00
Cassondra Foesch 6f2abc6af1 O_CREAT|O_EXCL can go through a directory symlink, but cannot create a dangling symlink target 2020-09-25 14:01:02 +00:00
Cassondra Foesch 8279444a65 oops mkdir on a dangling symlink SHOULD NOT work 2020-09-25 13:33:06 +00:00
Cassondra Foesch 2ac0d4ad11 more require over assert found during coding 2020-09-21 14:29:50 +00:00
Cassondra Foesch 99283be930 extract newfile creation to normalize how files/dirs/symlinks are made 2020-09-17 15:31:22 +00:00
Cassondra Foesch ffc579dce4 test parent directory before making a symlink 2020-09-17 14:48:19 +00:00
Cassondra Foesch 5b7cbe6684 creating a file at a dangling symlink should make the target filename 2020-09-17 14:23:59 +00:00
Cassondra Foesch d4a89094dc dangling links ok, but overwriting is not 2020-09-17 14:05:55 +00:00
Cassondra Foesch 18c9a7a273 support for O_EXCL 2020-09-17 13:46:13 +00:00
Cassondra Foesch 72a9e15fa5 handle O_EXCL|O_CREATE 2020-09-17 12:58:38 +00:00
Cassondra Foesch f05f53fcbb handle when os.O_CREATE not set 2020-09-17 12:56:04 +00:00
Cassondra Foesch 5471c643dd replace assert.Nil with {assert,require}.NoError 2020-09-17 12:52:54 +00:00
Cassondra Foesch dc4f208617 fetch follows symlinks, lfetch does not 2020-09-17 11:47:19 +00:00
Cassondra Foesch d96ad30fc5 test: symlinks should be followed recursively 2020-09-17 11:40:22 +00:00
Fazlul Shahriar bbd5cf2737
Merge branch 'master' into plan9 2020-09-15 12:06:10 -04: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 ba3e280524 request-server: add lstat support
Add LstatFileLister, an optional interface for FileLister, if this
interface is implemented Lstat requests will call it otherwirse they
will be handled in the same way as Stat, as before
2020-09-06 08:26:58 +02:00
Nicola Murino 703dd9827c request-server: set request state only if there is no error 2020-09-03 16:40:14 +02:00
Nicola Murino 9284f1d6ac only check OpenFileWriter interface if Read flags is true
Improve memory handler and some test case
Improve nil check for Close and TransferError interfaces
2020-09-02 19:21:12 +02:00
Nicola Murino ea67d57ce5 request-server: implement Open method
add an optional interface to FileWriter to allow to open a file for both
writing and reading

Fixes #374
2020-08-30 10:40:22 +02:00
Nicola Murino 07229f28f5 Improve Fsetstat test case 2020-08-25 14:39:22 +02:00
Nicola Murino b6bdd772b5 truncate should not change offset
improved Fsetstat test case
2020-08-25 07:46:42 +02:00
Nicola Murino a011842257 request server: add support for SSH_FXP_FSETSTAT
we need to add a case for this packet inside the packet worker otherwise
it will be handled in hasHandle case and it will become a "Put" request.

Client side if a Truncate request is called on the open file we should
send a FSETSTAT packet, the request is on the handle, and not a SETSTAT
packet that should be used for paths and not for handle.
2020-08-24 15:00:36 +02:00
Cassondra Foesch 97b9df616e
Merge pull request #355 from drakkan/path
cleanPath: use path.IsAbs after converting ToSlash
2020-07-16 19:17:56 +00:00
Nicola Murino abc70d5950 improve test cases for cleanPath 2020-06-29 18:27:11 +02:00
Nicola Murino 2fc68482d2 remove NewRequestServerWithOptions
we can keep compatibility removing the error return value from
RequestServerOption
2020-03-19 13:20:22 +01: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 f9e61c9b8f request-server: add test case for posixrename 2019-10-28 10:34:49 +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
Tommie Gannert 2c24eaad1c Implement the hardlink@openssh.com extension.
Both client and server. This is documented in

  https://github.com/openssh/openssh-portable/blob/master/PROTOCOL

Draft 7 of SFTP added support for SSH_FXP_LINK which supports both
symlinks and hardlinks, but unfortunately OpenSSH doesn't support
that:

  https://tools.ietf.org/html/draft-ietf-secsh-filexfer-07#section-7.7

Adding support for this as an option would be a nice extension to
this.
2019-08-25 20:16:37 -07:00
John Eikenberry c35a03098c
Merge pull request #282 from kardianos/kardianos-fixup-tests
sftp: update tests to finish and not panic on windows
2019-02-05 12:26:05 -08:00
John Eikenberry fdad088de8 small fixes suggested in code review
needless use of empty byte slice (left over from earlier work)
plus a couple tweaks to tests/asserts

thanks @puellanivis for the review
2019-02-04 13:21:47 -08:00
John Eikenberry 7f106a3327 change fstat to not reuse request object
When fstat is called it now uses the handle to get the opened request,
pulls the filepath from that and creates a new request for the fstat
call. This eliminates the need to change the Method on the request
object and furthers the goal of eliminating post-creation mutation of
the request object to open up the possibility to eliminate or at least
reduce the use of the global request lock.
2019-01-29 14:49:22 -08:00
John Eikenberry c71cbb17d3 'open' directory on opendir packet
Just like with files, the call to the hander to create the Lister is
done when the OPENDIR packet is received. This eliminates the need for
the lock in the filelist() method and opens the path for eliminating
more locks.
2019-01-29 14:49:22 -08:00
John Eikenberry 0a96e0de8a initial test of opening 'file' on open packet
Testing feasibility of creating the reader/writer when first receiving
the Open packet instead of waiting for the Get/Put.

This work is meant to make the Request locks easier to manage and
ultimately reducing/eliminating them as much as possible.
2019-01-29 14:49:22 -08: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 fe93131e0a fix example request filesystem's file renaming
also added a test for the issue

Fixes #264
2018-08-17 11:59:53 -07:00
John Eikenberry 218c0d4148 Opendir return an error status when not found
The initial Opendir packet is supposed to repond with an error status if
the directory wasn't found. It was just returning a handle without
checking, now it does a Stat on the path and only returns the handle if
the Stat is successful and it indicates it is a directory, otherwise it
returns an error.
2018-05-26 13:59:55 -07:00
John Eikenberry 66107b5f08 unused variables in tests 2018-02-15 10:28:06 -08:00
John Eikenberry b00841bcd7 create master/parent context in the server session
Create a master Context in the per-session ReqeustServer.Serve method
that is then used as the parent for all Context's created in that
server. Its cancelFunc is then always called when Serve exits. This is
in line which out the http.serve code works.

Each Request gets a child WithCancel context created in the
requestFromPacket call. This Context is still closed on request.close().
2018-02-05 14:10:05 -08:00