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

Channel always forces close when sending SSH_MSG_CHANNEL_CLOSE #25

Open
xucito opened this issue Oct 30, 2019 · 0 comments
Open

Channel always forces close when sending SSH_MSG_CHANNEL_CLOSE #25

xucito opened this issue Oct 30, 2019 · 0 comments

Comments

@xucito
Copy link

xucito commented Oct 30, 2019

As per ssh documentation

The close message can be non-violently to return exit-statuses and acknowledgement of commands.

" When the command running at the other end terminates, the following
message can be sent to return the exit status of the command.
Returning the status is RECOMMENDED. No acknowledgement is sent for
this message. The channel needs to be closed with
SSH_MSG_CHANNEL_CLOSE after this message.

The client MAY ignore these messages.

  byte      SSH_MSG_CHANNEL_REQUEST
  uint32    recipient channel
  string    "exit-status"
  boolean   FALSE
  uint32    exit_status

The remote command may also terminate violently due to a signal.
Such a condition can be indicated by the following message. A zero
'exit_status' usually means that the command terminated successfully.
"

Suggested fix is to allow for optional parameter in SendClose(uint? exitCode = null) in Channel.cs that dictates whether to "CheckBothClosed()" which will default to true to prevent any breaking change for other projects.

        public void SendClose(uint? exitCode = null, bool forceClose = true)
        {
            if (ServerClosed)
                return;

            ServerClosed = true;
            if (exitCode.HasValue)
                _connectionService._session.SendMessage(new ExitStatusMessage { RecipientChannel = ClientChannelId, ExitStatus = exitCode.Value });
            _connectionService._session.SendMessage(new ChannelCloseMessage { RecipientChannel = ClientChannelId });

            if (forceClose)
            {
                CheckBothClosed();
            }
        }

I will submit a PR with the suggested fix.

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

No branches or pull requests

1 participant