From 30484578cda303099e6b36d7d1e6999522232b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 3 Jul 2022 14:20:26 +0200 Subject: [PATCH] Add openssh sftp-server path detection for windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unfortunately LookPath doesn't handle DOS extensions. But it was already confused by the / location anyway. Signed-off-by: Anders F Björklund --- pkg/reversesshfs/reversesshfs.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/reversesshfs/reversesshfs.go b/pkg/reversesshfs/reversesshfs.go index 323528d..93bf295 100644 --- a/pkg/reversesshfs/reversesshfs.go +++ b/pkg/reversesshfs/reversesshfs.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strconv" "strings" @@ -79,6 +80,17 @@ func DetectOpensshSftpServerBinary() string { return exe } } + if runtime.GOOS == "windows" { + // unix path is like "/usr/lib/ssh/sftp-server" + cygpathCmd := exec.Command("cygpath", "-w", "/usr/lib/ssh/sftp-server") + // windows path is like `C:\msys64\usr\lib\ssh\sftp-server.exe` + if out, err := cygpathCmd.Output(); err == nil { + sftpServer := strings.TrimSpace(string(out)) + if exe, err := exec.LookPath(sftpServer); err == nil { + return exe + } + } + } candidates := []string{ "/usr/libexec/sftp-server", // macOS, OpenWrt "/usr/libexec/openssh/sftp-server", // Fedora