[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-04-06 Thread Marcin Kozakiewicz (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15958438#comment-15958438
 ] 

Marcin Kozakiewicz commented on SSHD-733:
-

I checked it and it is working fine for my test cases, i.e.
- directory symlinks are displayed correctly , 
- symlinks follow to correct locations and proper files are downloaded,
- ls displays symlinks with destination they point to.
Thank you.

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Assignee: Goldstein Lyor
>Priority: Minor
> Fix For: 1.5.0
>
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-04-04 Thread Goldstein Lyor (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15955620#comment-15955620
 ] 

Goldstein Lyor commented on SSHD-733:
-

I have made a slight adjustment so that symlinks as *not* followed on listed 
children of a folder - please see if this improves the result.

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Assignee: Goldstein Lyor
>Priority: Minor
> Fix For: 1.5.0
>
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-04-03 Thread Piotr Praszmo (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15953917#comment-15953917
 ] 

Piotr Praszmo commented on SSHD-733:


I think this path might be going to far. open and read dir now follow symlinks 
but so does listing the actual contents - which is not consistent with OpenSSH.
Output from ls via sftp:

OpenSSH:
{code}
drwxr-xr-x 2 piotr piotr   4096 Apr  3 19:51 a
lrwxrwxrwx 1 piotr piotr  1 Apr  3 19:51 b -> a
{code}

mina:
{code}
drwxr-xr-x   2 piotrpiotr4096 Apr  3 19:51 a
drwxr-xr-x   2 piotrpiotr4096 Apr  3 19:51 b
{code}

I will try to debug this further if I find the time.

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Assignee: Goldstein Lyor
>Priority: Minor
> Fix For: 1.5.0
>
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-29 Thread Goldstein Lyor (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15947529#comment-15947529
 ] 

Goldstein Lyor commented on SSHD-733:
-

Please note that according to [SFTP draft 
13|https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13]
{quote}
SSH_FXP_STAT and SSH_FXP_LSTAT only differ in that SSH_FXP_STAT follows 
symbolic links on the server, whereas SSH_FXP_LSTAT does not
{quote}
I.e., the configured value will *not* apply to these commands.

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Assignee: Goldstein Lyor
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-29 Thread Goldstein Lyor (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15947411#comment-15947411
 ] 

Goldstein Lyor commented on SSHD-733:
-

I am inclined to agree, I will therefore add it as a *configurable* option (in 
case someone encounters an error and needs to restore the current 
implementation) with the default set to follow links,

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-28 Thread Piotr Praszmo (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15945849#comment-15945849
 ] 

Piotr Praszmo commented on SSHD-733:


RFC just says:
{quote}
This will return an error if the path does not specify a directory or if the 
directory is not readable.
{quote}
but it's not really clear, if path to symlink to directory specifies a 
directory.

I'm not sure about the "spirit" but SFTP commands seem to mimic POSIX calls. 
opendir() does follow symlinks. Following symlinks also makes "sftp" command 
behave like a local shell. I.e. you can "ls /path/to/symlink/"

I've tested this on OpenSSH, dropbear and lsh. They all follow symlinks in this 
case. So does apache-sshd-0.9.0. It would be great to get the same behavior 
everywhere.

Configurable option would work but I don't really see any benefits or current 
behavior. It just makes interchangeability with other servers harder.
Theoretically someone might rely on current behavior to detect symlinks but 
their code is broken on all those other servers. It's much more likely that 
someone will face regression moving to current Mina version.



> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-28 Thread Goldstein Lyor (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15945481#comment-15945481
 ] 

Goldstein Lyor commented on SSHD-733:
-

I do not doubt that it solved *your* problem, but the question remains whether 
this fix is good for everybody...

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-28 Thread Marcin Kozakiewicz (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15945068#comment-15945068
 ] 

Marcin Kozakiewicz commented on SSHD-733:
-

[~ppraszmo] after applying these changes server works as expected:

{code}
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
 
b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
index 120f0c0..1e70f13 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
@@ -1804,7 +1804,7 @@ public class SftpSubsystem
 }

 Path file = dh.getFile();
-LinkOption[] options = IoUtils.getLinkOptions(false);
+LinkOption[] options = IoUtils.getLinkOptions(true);
 Boolean status = IoUtils.checkFileExists(file, options);
 if (status == null) {
 throw new AccessDeniedException("Cannot determine existence of 
read-dir for " + file);
@@ -1862,7 +1862,7 @@ public class SftpSubsystem
 String handle;

 try {
-handle = doOpenDir(id, path, IoUtils.getLinkOptions(false));
+handle = doOpenDir(id, path, IoUtils.getLinkOptions(true));
 } catch (IOException | RuntimeException e) {
 sendStatus(BufferUtils.clear(buffer), id, e);
 return;
{code}

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-27 Thread Goldstein Lyor (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15943532#comment-15943532
 ] 

Goldstein Lyor commented on SSHD-733:
-

We could flip it back, but the question is whether it is the *right* thing to 
do. I am not so sure that we always want to follow symbolic links, nor that it 
is in accordance with the letter or spirit of SFTP. Perhaps a configurable 
behavior or sub-classed one would be more appropriate.

Any thoughts ?

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-27 Thread Piotr Praszmo (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15943140#comment-15943140
 ] 

Piotr Praszmo commented on SSHD-733:


It looks like symlink following is explicitly disabled here. options is passed 
from IoUtils.getLinkOptions:
{code}
handle = doOpenDir(id, path, IoUtils.getLinkOptions(false));
{code}
which returns:
{code}
new LinkOption[]{LinkOption.NOFOLLOW_LINKS}
{code}

It looks like this changed in: 
https://github.com/apache/mina-sshd/commit/cccec812bf9a0571da7bffee651e9c741c402e39

Maybe we can just flip it back?

[~kozzakko] can you check, if it would help in your case? You can also try 
providing your own FileSystem which will disregard this option.

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-25 Thread Goldstein Lyor (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15941638#comment-15941638
 ] 

Goldstein Lyor commented on SSHD-733:
-

The code can be easly debugged by looking at {{SftpSubsystem#doOpenDir}}:
{code:java}
protected String doOpenDir(int id, String path, LinkOption... options) throws 
IOException {
Path p = resolveNormalizedLocation(path);
if (log.isDebugEnabled()) {
log.debug("doOpenDir({})[id={}] SSH_FXP_OPENDIR (path={})[{}]",
  getServerSession(), id, path, p);
}

Boolean status = IoUtils.checkFileExists(p, options);
if (status == null) {
throw new AccessDeniedException("Cannot determine open-dir 
existence for " + p);
}

if (!status) {
throw new FileNotFoundException(path);
} else if (!Files.isDirectory(p, options)) {
throw new NotDirectoryException(path);
} else if (!Files.isReadable(p)) {
throw new AccessDeniedException("Not readable: " + p);
} else {
String handle = generateFileHandle(p);
DirectoryHandle dirHandle = new DirectoryHandle(this, p, handle);
handles.put(handle, dirHandle);
return handle;
}
}
{code}
Seems that {{Files.isDirectory(p, options}} returns {{false}}, so I don't see 
what else SSHD can do...

> SSHD server displays file symlinks instead of dir symlinks
> --
>
> Key: SSHD-733
> URL: https://issues.apache.org/jira/browse/SSHD-733
> Project: MINA SSHD
>  Issue Type: Wish
>Affects Versions: 1.2.0
> Environment: Windows/Linux
>Reporter: Marcin Kozakiewicz
>Priority: Minor
>
> We use sshd for junit testing of sftp file transfers. 
> Scenario:
> 1.create filesystem:
> {code}
> ├── mem0
> │   └── mem0.txt
> ├── run -> mem0
> └── run2 -> mem0
> {code}
> 2. Start SSh server with given file system.
> code snippet from out project:
> {code}
> _server = SshServer.setUpDefaultServer();
> _server.setHost("localhost");
> _server.setPort(PORT);
> _server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
> _server.setPasswordAuthenticator(new PasswordAuthenticator() {
> @Override
> public boolean authenticate(final String username, final String 
> password, final ServerSession session) {
> return USERNAME.equals(username) && PASSWORD.equals(password);
> }
> });
> _server.setSubsystemFactories(singletonList(new 
> SftpSubsystemFactory()));
> _server.setFileSystemFactory(new 
> VirtualFileSystemFactory(fileSystemPath));
> _server.start();
> {code}
> 3. Connect to server with sftp client.
> Result:
> run and run2 symlinks are presented as file symlinks instead of directory 
> symlinks.
> Expected result:
> run and run2 are presented as directory symlinks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (SSHD-733) SSHD server displays file symlinks instead of dir symlinks

2017-03-24 Thread Piotr Praszmo (JIRA)

[ 
https://issues.apache.org/jira/browse/SSHD-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15941023#comment-15941023
 ] 

Piotr Praszmo commented on SSHD-733:


I'm having similar (probably the same) issue:

{code}
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;

import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.subsystem.sftp.SftpClient;
import org.apache.sshd.client.subsystem.sftp.SftpClient.CloseableHandle;
import org.apache.sshd.client.subsystem.sftp.SftpClient.DirEntry;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;

public class Main {

private static final String USERNAME = "my username";
private static final String PASSWORD = "my password";

public static void main(final String[] args) throws Exception {

Files.delete(Paths.get("my_link"));
final Path link = 
Files.createSymbolicLink(Paths.get("my_link"), Paths.get("/")).toAbsolutePath();

final SshServer server = SshServer.setUpDefaultServer();
server.setHost("localhost");
server.setPort(0);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
server.setPasswordAuthenticator(
(username, password, session) -> 
USERNAME.equals(username) && PASSWORD.equals(password));

server.setSubsystemFactories(Collections.singletonList(new 
SftpSubsystemFactory()));
server.setFileSystemFactory(new 
VirtualFileSystemFactory(Paths.get("/")));
server.start();

System.out.println("openssh:");
test(22, link);

System.out.println("mina:");
test(server.getPort(), link);
}

private static void test(final int port, final Path path) throws 
IOException {
try (final SshClient client = SshClient.setUpDefaultClient()) {
client.setHostConfigEntryResolver((h, p, u) -> null);
client.start();
try (ClientSession session = client.connect(USERNAME, 
"localhost", port).verify().getSession()) {
session.addPasswordIdentity(PASSWORD);
session.auth().verify();
final SftpClient sftp = 
session.createSftpClient();
try {
try (CloseableHandle dir = 
sftp.openDir(path.toString())) {
for (final DirEntry entry : 
sftp.listDir(dir)) {

System.out.print(entry.getFilename() + " ");
}
System.out.println();
}
} catch (final Exception e) {
e.printStackTrace();
}
}
}
}
}
{code}

Produces following output:

{code}
openssh:
vmlinuz libx32 usr srv sbin tmp lost+found dev initrd.img.old var etc home 
media . opt initrd.img sys run proc lib root lib64 boot bin vmlinuz.old mnt 
lib32 .. 
mina:
SFTP error (SSH_FX_NOT_A_DIRECTORY): Internal NotDirectoryException: 
/tmp/workspace/test/my_link
at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.throwStatusException(AbstractSftpClient.java:169)
at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.checkHandleResponse(AbstractSftpClient.java:204)
at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.checkHandle(AbstractSftpClient.java:184)
at 
org.apache.sshd.client.subsystem.sftp.AbstractSftpClient.openDir(AbstractSftpClient.java:853)
at test.Main.test(Main.java:57)
at test.Main.main(Main.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.lang.Thread.run(Thread.java:745)
{code}

`/tmp/workspace/test/my_link` is a symlink to directory (created at the start 
of main).
On port 22 I'm running:
{code}
SSH-2.0-OpenSSH_7.4p1 Debian-6
{code}
OpenSSH lists the