Commit Graph

107 Commits

Author SHA1 Message Date
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 98b35dcfc3 request server: add WithStartDirectory option 2022-03-02 18:33:41 +01:00
Cassondra Foesch 68f4ca6663 linting 2021-08-11 11:12:34 +00:00
Nicola Murino eaa697cc21
Merge pull request #441 from CiscoM31/migrate_to_go_errors
Use go errors instead of github.com/pkg/errors
2021-07-05 21:28:12 +02:00
Cassondra Foesch 71618243c4 deconvert encoded paths on windows servers 2021-06-29 15:16:15 +00:00
Sebastien Rosset (serosset) 3b8042dfc0 Use go errors instead of github.com/pkg/errors 2021-06-04 14:18:41 -07: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 a88961882e remove some redundant types 2021-02-22 22:29:35 +01:00
Cassondra Foesch 861a8eaf5c pointer receivers and statusFromError(uint32, error) 2021-02-22 12:11:42 +00:00
Nicola Murino 5dbfeffd12 request-server: add StatVFS support 2021-02-10 19:13:19 +01:00
Nicola Murino 6af3f0a271 request-server: don't return EOF if there is an unexpected error
io.EOF means no error so convert to ErrUnexpectedEOF if we detect
a transfer error
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 d696bdb2ff add PosixRename optional support same as Lstat 2020-09-25 16:16:01 +00: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 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 161b43cdfc this makes more sense as cleanup of serveLoop() 2020-07-18 20:02:25 +00:00
Cassondra Foesch e56b4ff6ad Additional bug-fixes found looking at PR-361 2020-07-18 19:45:27 +00:00
Nicola Murino 118ca57204 cleanPath: use path.IsAbs after converting ToSlash
we need a POSIX path filepath.IsAbs can give unexpected results on Windows
2020-07-05 22:18:13 +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
Daniel Fletcher 5df8e92923 request-server: fix posixrename 2019-10-27 06:59:47 +01:00
Eric 3f23d5935f fix nil panic error when sshFxpExtendedPacket could not UnmarshalBinary ExtendedRequest 2019-10-11 14:31:08 +08: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
Nicola Murino b519cb8db9 define supported extensions in one place and use for both server and request-server 2019-08-27 09:18:15 +02:00
John Eikenberry 5a2fe52342 Merge branch 'soopsio-master' into test 2019-08-25 20:32:04 -07:00
John Eikenberry 5d724974df Merge branch 'kardianos-kardianos-server-ext' into test 2019-08-25 20:24:06 -07:00
soopsio 55133952b5 gracefully handle unknown extended packets
Fixed a problem that caused secureFX to crash when
errUnknownExtendedPacket in SFTP server mode
2019-08-25 20:19:45 -07:00
Daniel Theophanes e5ded3a9d1 sftp: support rename extension for server
Previously if a client makes an unsupported operation,
like a POSIX rename, it would exit the server.

Both support POSIX rename, and do not abort the connection
if there is an unsupported operation is made by the client.
2019-08-25 20:17:08 -07: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 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
John Eikenberry 7f7e75b40d ensure packet responses in same order as requests
Previous code used the request ids to do ordering. This worked until a
client came along that used un-ordered request ids. This reworks the
ordering to use an internal counter (per session) to order all packets
ensuring that responses are sent in the same order as the requests were
received.

Fixes #260
2018-08-01 13:18:57 -07:00
John Eikenberry 048358fb96 use correct param type instead of asserting
Instead of accepting a more general type and then asserting it to the
proper type, just take the proper type as the argument.
Also clean up some of the use of it where it checked old direct sending
code's return error (error is now always nil).
2018-07-23 15:53:41 -07:00
John Eikenberry 4cad28be43 eliminate bare values in composite literals
Using key-value pairs is much more future proof.
2018-07-23 14:49:12 -07:00
John Eikenberry d0a1c8098b remove unnecessary type
Added to shorten code text, but not used enough to be worth the extra type.
2018-07-23 12:18:00 -07:00
John Eikenberry 57673e38ea no longer need new request after opendir stat
PR #257 fixes the issue with running Stat and Readdir on the same
Request. Thus we no longer need to close and recreate the Request
when handling an Opendir call.
2018-06-10 18:16:20 -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
Allan Feid 7d7ee5c869 Handle RequestServer the same 2018-03-19 11:53:13 -04: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 68e5d2f242 better/clearer function name 2018-03-10 12:51:41 -08:00
John Eikenberry 50d15dd2c8 remove some unused/unnecessary code 2018-02-15 11:46:17 -08:00
John Eikenberry 353daee2bc better request copy code
With state's lock as a pointer, we can use the `*r = *r2` statement for
copying which is much more concise and future proof.
2018-02-06 12:22:08 -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
John Eikenberry 36cbb62432 make sure request is always closed properly 2018-02-05 12:46:27 -08:00
John Eikenberry 30b632cf56 handle errors in file creation from open packet
open packet w/ the create flag would create the file but was ignoring
any errors from that. this fixes that and adds a test for it.
2018-01-07 18:30:26 -08:00