@@ -36,7 +36,7 @@ func asHandlers(handlers interface {
3636 return sftp.Handlers {handlers , handlers , handlers , handlers }
3737}
3838
39- func (s * Server ) HandleChannel (ctx context.Context , bucket * S3Bucket , sshCh ssh.Channel , reqs <- chan * ssh.Request ) {
39+ func (s * Server ) HandleChannel (ctx context.Context , bucket * S3Bucket , sshCh ssh.Channel , reqs <- chan * ssh.Request , userInfo * UserInfo ) {
4040 defer s .Log .Debug ("HandleChannel ended" )
4141 server := sftp .NewRequestServer (
4242 sshCh ,
@@ -52,6 +52,7 @@ func (s *Server) HandleChannel(ctx context.Context, bucket *S3Bucket, sshCh ssh.
5252 Perms : bucket .Perms ,
5353 ServerSideEncryption : & bucket .ServerSideEncryption ,
5454 Now : s .Now ,
55+ UserInfo : userInfo ,
5556 },
5657 ),
5758 )
@@ -106,6 +107,10 @@ func (s *Server) HandleClient(ctx context.Context, conn *net.TCPConn) error {
106107 F (s .Log .Info , "connection from client %s closed" , conn .RemoteAddr ().String ())
107108 conn .Close ()
108109 }()
110+
111+ var userInfo * UserInfo = new (UserInfo )
112+ userInfo .Addr = conn .RemoteAddr ()
113+
109114 F (s .Log .Info , "connected from client %s" , conn .RemoteAddr ().String ())
110115
111116 innerCtx , cancel := context .WithCancel (ctx )
@@ -122,6 +127,7 @@ func (s *Server) HandleClient(ctx context.Context, conn *net.TCPConn) error {
122127 return err
123128 }
124129
130+ userInfo .User = sconn .User ()
125131 F (s .Log .Info , "user %s logged in" , sconn .User ())
126132 bucket , ok := s .UserToBucketMap [sconn .User ()]
127133 if ! ok {
@@ -160,7 +166,7 @@ func (s *Server) HandleClient(ctx context.Context, conn *net.TCPConn) error {
160166 wg .Add (1 )
161167 go func () {
162168 defer wg .Done ()
163- s .HandleChannel (innerCtx , bucket , sshCh , reqs )
169+ s .HandleChannel (innerCtx , bucket , sshCh , reqs , userInfo )
164170 }()
165171 }
166172 }(chans )
0 commit comments