2019-07-30 18:51:29 +00:00
|
|
|
// Package sftpd implements the SSH File Transfer Protocol as described in https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02.
|
|
|
|
// It uses pkg/sftp library:
|
|
|
|
// https://github.com/pkg/sftp
|
2019-07-20 10:26:52 +00:00
|
|
|
package sftpd
|
|
|
|
|
|
|
|
import (
|
2021-01-18 12:24:38 +00:00
|
|
|
"strings"
|
2019-07-20 10:26:52 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-07-24 21:39:38 +00:00
|
|
|
logSender = "sftpd"
|
|
|
|
handshakeTimeout = 2 * time.Minute
|
2019-10-09 15:33:30 +00:00
|
|
|
)
|
|
|
|
|
2019-07-20 10:26:52 +00:00
|
|
|
var (
|
2020-07-24 21:39:38 +00:00
|
|
|
supportedSSHCommands = []string{"scp", "md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum", "cd", "pwd",
|
2020-06-13 20:48:51 +00:00
|
|
|
"git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync", "sftpgo-copy", "sftpgo-remove"}
|
2022-03-14 09:42:14 +00:00
|
|
|
defaultSSHCommands = []string{"md5sum", "sha1sum", "sha256sum", "cd", "pwd", "scp"}
|
2020-07-24 21:39:38 +00:00
|
|
|
sshHashCommands = []string{"md5sum", "sha1sum", "sha256sum", "sha384sum", "sha512sum"}
|
|
|
|
systemCommands = []string{"git-receive-pack", "git-upload-pack", "git-upload-archive", "rsync"}
|
2020-12-08 10:18:34 +00:00
|
|
|
serviceStatus ServiceStatus
|
2019-07-20 10:26:52 +00:00
|
|
|
)
|
|
|
|
|
2019-11-15 11:15:07 +00:00
|
|
|
type sshSubsystemExitStatus struct {
|
|
|
|
Status uint32
|
|
|
|
}
|
|
|
|
|
2019-11-18 22:30:37 +00:00
|
|
|
type sshSubsystemExecMsg struct {
|
|
|
|
Command string
|
|
|
|
}
|
|
|
|
|
2020-12-08 10:18:34 +00:00
|
|
|
// HostKey defines the details for a used host key
|
|
|
|
type HostKey struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Fingerprint string `json:"fingerprint"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceStatus defines the service status
|
|
|
|
type ServiceStatus struct {
|
2022-02-26 15:43:29 +00:00
|
|
|
IsActive bool `json:"is_active"`
|
|
|
|
Bindings []Binding `json:"bindings"`
|
|
|
|
SSHCommands []string `json:"ssh_commands"`
|
|
|
|
HostKeys []HostKey `json:"host_keys"`
|
|
|
|
Authentications []string `json:"authentications"`
|
2020-12-08 10:18:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 12:24:38 +00:00
|
|
|
// GetSSHCommandsAsString returns enabled SSH commands as comma separated string
|
2022-02-26 15:43:29 +00:00
|
|
|
func (s *ServiceStatus) GetSSHCommandsAsString() string {
|
2021-01-18 12:24:38 +00:00
|
|
|
return strings.Join(s.SSHCommands, ", ")
|
|
|
|
}
|
|
|
|
|
2022-02-26 15:43:29 +00:00
|
|
|
// GetSupportedAuthsAsString returns the supported authentications as comma separated string
|
|
|
|
func (s *ServiceStatus) GetSupportedAuthsAsString() string {
|
|
|
|
return strings.Join(s.Authentications, ", ")
|
|
|
|
}
|
|
|
|
|
2020-12-08 10:18:34 +00:00
|
|
|
// GetStatus returns the server status
|
|
|
|
func GetStatus() ServiceStatus {
|
|
|
|
return serviceStatus
|
|
|
|
}
|
|
|
|
|
2019-11-18 22:30:37 +00:00
|
|
|
// GetDefaultSSHCommands returns the SSH commands enabled as default
|
|
|
|
func GetDefaultSSHCommands() []string {
|
|
|
|
result := make([]string, len(defaultSSHCommands))
|
|
|
|
copy(result, defaultSSHCommands)
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSupportedSSHCommands returns the supported SSH commands
|
|
|
|
func GetSupportedSSHCommands() []string {
|
|
|
|
result := make([]string, len(supportedSSHCommands))
|
|
|
|
copy(result, supportedSSHCommands)
|
|
|
|
return result
|
|
|
|
}
|