Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request server: add an optional RealpathFileLister interface #437

Merged
merged 2 commits into from
Apr 28, 2021

Conversation

drakkan
Copy link
Collaborator

@drakkan drakkan commented Apr 27, 2021

This allow to customize the responses for SSH_FXP_REALPATH requests
and so implementing features like a start directory.

I'm not sure if this is the best way to add this feature, maybe we could consider a server option too

This allow to customize the responses for SSH_FXP_REALPATH requests
and so implementing features like a start directory
@puellanivis
Copy link
Collaborator

I’m kind of hesitant to add yet more behaviors exposed through these interfaces… I’m not sure what a better solution would look like, but I feel like this path is unsustainable and overly complicated.

request-interfaces.go Outdated Show resolved Hide resolved
request-server.go Outdated Show resolved Hide resolved
request-server_test.go Outdated Show resolved Hide resolved
request-example.go Outdated Show resolved Hide resolved
@drakkan
Copy link
Collaborator Author

drakkan commented Apr 27, 2021

Thank you for the review, I tryed to fix the code based on your comments. Other libraries that I use within SFTPGo have a similar structure, for example:

In this case we could also add a server option that allows to set the start directory and use this value instead of / in cleanPath.
An optional interface allows full control to the caller but I'm not sure that this is required.

Do you have better ideas?

@puellanivis
Copy link
Collaborator

Yeah, following up on my concern about the ReadPathLister this is direction that we’re wanting to go towards: extensible interfaces. I just had a knee-jerk reaction to it. 😆

@puellanivis puellanivis merged commit ba12343 into pkg:master Apr 28, 2021
@drakkan
Copy link
Collaborator Author

drakkan commented Apr 28, 2021

Thank you

@drakkan
Copy link
Collaborator Author

drakkan commented Feb 23, 2022

Hi @puellanivis,

I'm trying to add a start directory feature to SFTPGo, see drakkan/sftpgo#705.

I implemented the RealPathLister interface and with smart clients like sftp CLI or FileZilla this is enough. These clients request the current directory when they connect and then send absolute paths.

I started to write the test cases, take a look here:

currentDir, err := client.Getwd()
assert.NoError(t, err)
assert.Equal(t, startDir, currentDir)

entries, err := client.ReadDir(".")

client.Getwd and client.RealPath are ok, but if I do client.ReadDir(".") I get the / contents: our client sends a relative path and it is converted server side as absolute in our cleanPath method. I think this happen only for the request server.

I think it would be better to avoid path normalization server side and delegate them to the request server implementation but it would be a backward incompatible change at this point.

Add a check for relative path and call the RealPathLister could do the trick but it seems quite ugly and I don't want to add something like this.
Do you have better suggestions? Thanks

@puellanivis
Copy link
Collaborator

🤔 Hm. It seems the standard never really required all paths to be absolute. Although, it specifies only that relative paths be from a rooted point (the user’s home directory), and provides no way to change that directory once set. The fact that the relative directory support does not have any way to traverse directories is precisely the reason why requiring all paths be absolute has worked for so long, client have to do that relative path tracking almost entirely themselves already, so why not also do it for the user directory as well.

I think is a case where we’re slightly out of spec, and should be doing different behavior, but also… the assumptions made lead to a design that is going to be difficult to “fix” now.

@drakkan drakkan deleted the realpath branch July 15, 2022 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants