Skip to content

Commit 872ba20

Browse files
committed
Return exit code 0(success) to ssh client
1 parent d8a3112 commit 872ba20

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ssh-server.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func startSshServer() {
8181
}
8282

8383
// Seems next can some time. Not block listening loop
84-
go handleChannels(sshConn, channels)
84+
go handleChannels(*sshConn, channels)
8585
}
8686
}
8787

@@ -116,12 +116,12 @@ func publicKeyCallback(sshConn ssh.ConnMetadata, remoteKey ssh.PublicKey) (*ssh.
116116
log.Printf("Public key math: %s", username)
117117
return nil, nil
118118
}
119-
return nil, errors.New("Not authorized key")
119+
return nil, errors.New("not authorized key")
120120
}
121121

122122
// This is called for already authenticated(via publicKeyCallback) users
123123
// Handles receiving a token from the user
124-
func handleChannels(sshConn ssh.ConnMetadata, channels <-chan ssh.NewChannel) {
124+
func handleChannels(sshConn ssh.ServerConn, channels <-chan ssh.NewChannel) {
125125
for newChannel := range channels {
126126
// Channels have a type, depending on the application level protocol intended.
127127
// In the case of a shell, the type is "session" and ServerShell may be used
@@ -196,7 +196,11 @@ func handleChannels(sshConn ssh.ConnMetadata, channels <-chan ssh.NewChannel) {
196196
break
197197
}
198198
}
199+
// Send exit code: 0 - success
200+
// 4 zeros because answer must be uint32 (4 bytes)
201+
channel.SendRequest("exit-status", false, []byte{0,0,0,0})
199202
channel.Close()
203+
sshConn.Close()
200204
// Lock and modify global var
201205
ssh_tokens_mutex.Lock()
202206
delete(ssh_tokens, sshToken)

0 commit comments

Comments
 (0)