pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.51k stars 380 forks source link

Question about sshFxpOpendirPacket packet #585

Open ior308 opened 5 months ago

ior308 commented 5 months ago

Dear, I noticed that the SFTP server bundle in the library uses an sshFxpOpenPacket to respond to an sshFxpOpendirPacket. Since I need to handle files and directories differently, I replaced the response packet with sshFxpOpenDPacket.

It seems to be working well, but I would like to ask you if this change could cause any issues.

Regards

puellanivis commented 5 months ago

This package has two separate server implementations. I’m confused about which precisely you’re talking about.

Maybe if you give an example of the code you changed, I could give you some feedback.

ior308 commented 5 months ago

Dear,

I changed a line in the server.go:

case *sshFxpOpendirPacket: lp := s.toLocalPath(p.Path)

              s.logQueue <- logmodel.LogMsg{
                      Level: "INFO",
                      Stdo:  false,
                      Uuid:  s.cUuid,
                      Msg:   fmt.Sprintf("BROWSE folder: %s", lp)}

              if stat, err := os.Stat(lp); err != nil {
                      rpkt = statusFromError(p.ID, err)
              } else if !stat.IsDir() {
                      rpkt = statusFromError(p.ID, &os.PathError{
                              Path: lp, Err: syscall.ENOTDIR,
                      })
              } else {
                      //rpkt = (&sshFxpOpenPacket{  <========= Original line
                      rpkt = (&sshFxpOpenDPacket{
                              ID:     p.ID,
                              Path:   p.Path,
                              Pflags: sshFxfRead,
                      }).respond(s)
              }

Regards

puellanivis commented 5 months ago

This is where my confusion is coming from: there is not defined an OpenDPacket. No less, the corresponding packet name SSH_FXP_OPEN_D_PACKET does not exist in the standard: https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-3

This code also appears to be in the server.go which is the direct local-filesystem implementation, where ReadDir operates on the *os.File type https://pkg.go.dev/os@go1.22.2#File.ReadDir and therefore, its functionality should be properly performed by sshFxpOpenPacket

ior308 commented 5 months ago

uhm, certainly my mistake. I'll check the code better. Thanks for the quick reply.

Regards

Il giorno lun 29 apr 2024 alle ore 11:19 Cassondra Foesch < @.***> ha scritto:

This is where my confusion is coming from: there is not defined an OpenDPacket. No less, the corresponding packet name SSH_FXP_OPEN_D_PACKET does not exist in the standard: https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02#section-3

This code also appears to be in the server.go which is the direct local-filesystem implementation, where ReadDir operates on the *os.File type @.***#File.ReadDir and therefore, its functionality should be properly performed by sshFxpOpenPacket

— Reply to this email directly, view it on GitHub https://github.com/pkg/sftp/issues/585#issuecomment-2082240483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL7ZDKD2XNNBLTC6FBL3LJLY7YGA5AVCNFSM6AAAAABG25MYUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBSGI2DANBYGM . You are receiving this because you authored the thread.Message ID: @.***>

--

Quando cambi il modo di guardare le cose, le cose che guardi cambieranno !! (Max Planck)