Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions sftp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"

"emperror.dev/errors"
"github.com/apex/log"
Expand Down Expand Up @@ -125,6 +126,7 @@ func (c *SFTPServer) AcceptInbound(conn net.Conn, config *ssh.ServerConfig) erro
defer sconn.Close()
go ssh.DiscardRequests(reqs)

var wg sync.WaitGroup
for ch := range chans {
// If its not a session channel we just move on because its not something we
// know how to handle at this point.
Expand All @@ -147,13 +149,22 @@ func (c *SFTPServer) AcceptInbound(conn net.Conn, config *ssh.ServerConfig) erro
}
}(requests)

if srv, ok := c.manager.Get(sconn.Permissions.Extensions["uuid"]); ok {
srv, ok := c.manager.Get(sconn.Permissions.Extensions["uuid"])
if !ok {
_ = channel.Close()
continue
}

wg.Add(1)
go func(srv *server.Server, channel ssh.Channel) {
defer wg.Done()
if err := c.Handle(sconn, srv, channel); err != nil {
return err
log.WithField("error", err).WithField("user", sconn.User()).Error("sftp: failed to handle session")
}
}
}(srv, channel)
}

wg.Wait()
return nil
}

Expand Down