From 5be1d1be699cd0cbe97218a42d1b011197df900f Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Thu, 14 Nov 2019 16:49:42 +0100 Subject: [PATCH] sftpd: send exit-status message on close this fix restic compatibility --- sftpd/scp.go | 4 ---- sftpd/server.go | 11 ++++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sftpd/scp.go b/sftpd/scp.go index 50e631e2..a3190384 100644 --- a/sftpd/scp.go +++ b/sftpd/scp.go @@ -28,10 +28,6 @@ type execMsg struct { Command string } -type exitStatusMsg struct { - Status uint32 -} - type scpCommand struct { connection Connection args []string diff --git a/sftpd/server.go b/sftpd/server.go index 6716283f..bbb236ed 100644 --- a/sftpd/server.go +++ b/sftpd/server.go @@ -30,6 +30,10 @@ const defaultPrivateKeyName = "id_rsa" var sftpExtensions = []string{"posix-rename@openssh.com"} +type exitStatusMsg struct { + Status uint32 +} + // Configuration for the SFTP server type Configuration struct { // Identification string used by the server @@ -329,7 +333,12 @@ func (c Configuration) handleSftpConnection(channel ssh.Channel, connection Conn server := sftp.NewRequestServer(channel, handler) if err := server.Serve(); err == io.EOF { - connection.Log(logger.LevelDebug, logSender, "connection closed") + connection.Log(logger.LevelDebug, logSender, "connection closed, sending exit-status") + ex := exitStatusMsg{ + Status: 0, + } + _, err = channel.SendRequest("exit-status", false, ssh.Marshal(&ex)) + connection.Log(logger.LevelDebug, logSender, "send exit status error: %v", err) server.Close() } else if err != nil { connection.Log(logger.LevelWarn, logSender, "connection closed with error: %v", err)