Commit Graph

77 Commits

Author SHA1 Message Date
Georg Müller 9183e7fd79 request-server: Introduce ReadlinkFileLister
ReadlinkFileLister with its Readlink method allows returning paths without
misusing the os.FileInfo interface, whose Name() method should only return
the base name of a file.

By implementing ReadlinkFileLister, it is possible to easily return
symlinks of any kind (absolute, relative, multiple directory levels)
2022-10-14 17:17:08 +02:00
Georg Müller eb2fffbb98 request server: fix symlink handling for relative links 2022-10-14 17:16:43 +02:00
Nicola Murino 51a5aa4e04 RealPathFileLister: allow to return an error
added legacyRealPathFileLister for backward compatibility

Fixes #512
2022-07-16 09:55:51 +02:00
Nicola Murino 0b43101c5b fix as per review 2021-04-27 18:06:39 +02:00
Nicola Murino db2d41339c request server: add an optional RealpathFileLister interface
This allow to customize the responses for SSH_FXP_REALPATH requests
and so implementing features like a start directory
2021-04-27 11:08:29 +02:00
Nicola Murino 5dbfeffd12 request-server: add StatVFS support 2021-02-10 19:13:19 +01:00
Cassondra Foesch c46216738b symlink loop testing 2020-09-29 17:39:30 +00:00
Cassondra Foesch 78524b582a more specification polishing, document specification points better 2020-09-25 16:13:10 +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 12db74fbb4 move endpoint symlink resolution to openfile rather than newfile 2020-09-25 13:34:03 +00:00
Cassondra Foesch 4e715d5625 rename vs PosixRename 2020-09-25 12:35:15 +00:00
Cassondra Foesch 8ae3feeb9f add NOTEs everywhere symlink target/linkpath vs sftp.Request.Filepath and sfftp.Request.Target come up 2020-09-24 15:20:10 +00:00
Cassondra Foesch 42f3825de9 corner-cases, better spec conformance 2020-09-24 15:03:10 +00:00
Cassondra Foesch f1495003d3 github not showing any diff of changes for move and change of file 2020-09-24 14:52:30 +00:00
Cassondra Foesch 48a22c540b since this code is exported, it should not be called 'example' anymore 2020-09-21 12:02:41 +00:00
Cassondra Foesch e7c9755368 split remove and rmdir 2020-09-17 15:53:23 +00:00
Cassondra Foesch 6d302dbb16 use openfile for Fileread as well 2020-09-17 15:32:57 +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 cd54350fbe ListerAt polishing 2020-09-17 12:14:59 +00:00
Cassondra Foesch 115b73076b refactor ListerAt functionality 2020-09-17 12:03:39 +00:00
Cassondra Foesch dc4f208617 fetch follows symlinks, lfetch does not 2020-09-17 11:47:19 +00:00
Cassondra Foesch 82f3e48fbd refactor memFile 2020-09-17 09:53:13 +00: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 f70d440af3 memory handler: use POSIX paths 2020-09-02 19:26:46 +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 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
Tobias Klauser 7d8a855595 Revert PR #370
This reverts commit 3cda2a1c6b / PR #370.

Reason for revert: this broke the Travis CI build, see
https://github.com/pkg/sftp/pull/370#issuecomment-678610816
2020-08-24 11:22:05 +02:00
Tobias Klauser 3cda2a1c6b Exclude test/example code in non-test builds
The fakeFileInfoSys and testOsSys funcs are only used in tests, so
rename the files they are defined in to request_*_test.go to exclude
them from non-test builds.

Also rename request-example.go to request_example_test.go to exclude it
as well, since it uses said funcs in example code.
2020-08-10 14:14:59 +02:00
John Eikenberry 5a3a7572f5
Revert "Bug: windows specific issue on request-server.go" 2019-11-02 21:04:45 +00:00
Daniel Fletcher 313f3c181d Bug: InMemoryHandler() mimics a linux file system. When build for
windows filepath.Dir(), more specifically the clean function preforms
incorrectly in our situation. As the filesystem is constant we can do a
simplified dir() function to resolve the issue.
2019-10-23 10:45:52 +01:00
Daniel Fletcher e9514f4967 Removed some unnecessary logging, and previous merge duplicated some code 2019-10-21 12:43:45 +01:00
Daniel Fletcher 4adf56b4e4 Merge branch 'master' of https://github.com/danfletcher1/sftp 2019-10-21 11:54:57 +01:00
Daniel Fletcher 67f906c100 When removing or renaming a folder, subfiles/folders of the path was not being updated 2019-10-21 11:52:48 +01:00
Daniel Fletcher b4e1be7c5d When removing or renaming a folder, subfiles/folders of the path was not being updated 2019-10-09 16:40:31 +01:00
John Eikenberry dcef9e0d4a
Merge pull request #304 from drakkan/lint
fix lint issues and update to be more idiomatic
2019-09-29 13:12:10 -07:00
Nicola Murino c5d967b3f6 notify errors to readerAt and writerAt
Add an optional interface that readerAt and writerAt can implement
to be notified about the error causing Serve() to exit with the
request still open.

Implement the TransferError interface in request-example.
This way we can run the request server example in debug mode, for example:

cd examples/request-server
go run -tags debug main.go

simulate a connection error killing an sftp client while uploading/downloading
and see the debug log that shows that the error is correctly notifyed

Fixes #306
2019-09-12 08:17:32 +02: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 05f7f0a92c add comment about purpose of context use in example/tests 2019-02-04 13:22:46 -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 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
John Eikenberry 91a21603c9 add WithContext() calls to each test handler
Want to catch issues with using Context objects in tests. Instigated by
a deadlock bug (#280) when calling WithContext(). This triggers that
bug.
2019-01-29 14:49:05 -08:00