[ https://issues.apache.org/jira/browse/SSHD-1308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17623373#comment-17623373 ]
Thomas Wolf commented on SSHD-1308: ----------------------------------- {quote}client application must be notified by a message such as _setting environment variable is not allowed_ instead of success. {quote} That's not part of the SSH RFC's. As I wrote, you'd have to program that yourself. And in fact, there are SSH clients that do expect the "silently ignore" behavior (for instance, git using SSH for cloning or fetching). Most SSH servers restrict the environment variables that can be set via the SSH "env" channel command anyway. It depends on the server configuration; see [AcceptEnv|https://man.openbsd.org/sshd_config#AcceptEnv] in the OpenSSH server configuration. If you want the "throw an exception" behavior, here's one approach how you could implement this in your client: with enough overriding and custom subclassing, you could implement a custom {{ChannelExec}} that would send the "env" channel requests with {{{}want-reply = true{}}}. A correct server must send back an {{SSH_MSG_CHANNEL_FAILURE}} if it doesn't set an environment variable. You would also need a queue (per channel) of sent "env" requests without reply yet, and fulfill the OpenFuture only once all requests have been positively acknowledged. If any of them receives a failure reply, close the channel and fulfill the OpenFuture with an exception. But implementing this correctly is not easy. In the Apache MINA sshd library we will not do this. We follow the OpenSSH behavior here, which is to send the "env" requests with {{{}want-reply = false{}}}. Which means the client silently ignores the fact that the server may not have set an environment variable. A well-designed application protocol between the command you invoke on the server and your client can recognize and deal with both cases, whether or not the server set the environment variable. Again, git is such an example. Your work-around of using {{sh -c}} and setting the variables inside the command is valid, and much easier than implementing the "throw exception" behavior. > No exception is thrown if setting environment variable is ignored by SSH > server > ------------------------------------------------------------------------------- > > Key: SSHD-1308 > URL: https://issues.apache.org/jira/browse/SSHD-1308 > Project: MINA SSHD > Issue Type: Improvement > Affects Versions: 2.9.1 > Environment: Java 8 > Reporter: dgü > Priority: Major > > Hello! > If an environment variable set by > _org.apache.sshd.client.session.ClientSession#createExecChannel(command,null,env)_ > is ignored by SSH server and exit code returns 0, then this may cause > unexpected behaviour in client application. > For example, client application may do different tasks when an environment > variable is set and not set. In both cases, client application may return 0. > Client application may assume that it worked successfully. But, indeed its > environment variable is ignored and worked as if environment variable is not > set. > is it possible throw an exception if setting environment variable is ignored > by SSH server ? > Thanks in advance... > > -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org For additional commands, e-mail: dev-h...@mina.apache.org