Skip to content

Commit

Permalink
add settings to disable server STAT and SYST (#204)
Browse files Browse the repository at this point in the history
Co-authored-by: Florent Clairambault <[email protected]>
  • Loading branch information
drakkan and fclairamb authored Dec 18, 2020
1 parent 695e05f commit 6678256
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,7 @@ type Settings struct {
DisableSite bool // Disable SITE command
DisableActiveMode bool // Disable Active FTP
EnableHASH bool // Enable support for calculating hash value of files
DisableSTAT bool // Disable Server STATUS, STAT on files and directories will still work
DisableSYST bool // Disable SYST
EnableCOMB bool // Enable COMB support
}
5 changes: 5 additions & 0 deletions handle_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func TestLoginSuccess(t *testing.T) {
require.NoError(t, err)
require.Equal(t, StatusSystemType, rc)
require.Equal(t, "UNIX Type: L8", response)

s.settings.DisableSYST = true
rc, response, err = raw.SendCommand("SYST")
require.NoError(t, err)
require.Equal(t, StatusCommandNotImplemented, rc, response)
}

func TestLoginFailure(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions handle_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ func (c *clientHandler) handlePBSZ() error {
}

func (c *clientHandler) handleSYST() error {
if c.server.settings.DisableSYST {
c.writeMessage(StatusCommandNotImplemented, "SYST is disabled")
return nil
}

c.writeMessage(StatusSystemType, "UNIX Type: L8")

return nil
}

Expand Down Expand Up @@ -80,6 +86,14 @@ func (c *clientHandler) handleSITE() error {
}

func (c *clientHandler) handleSTATServer() error {
if c.server.settings.DisableSTAT {
c.writeMessage(StatusCommandNotImplemented, "STAT is disabled")
return nil
}

// drakkan(2020-12-17): we don't handle STAT properly,
// we should return the status for all the transfers and we should allow
// stat while a transfer is in progress, see RFC 959
defer c.multilineAnswer(StatusSystemStatus, "Server status")()

duration := time.Now().UTC().Sub(c.connectedAt)
Expand Down
6 changes: 6 additions & 0 deletions handle_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func TestStat(t *testing.T) {
count := strings.Count(str, "\n")
require.GreaterOrEqual(t, count, 4)
require.NotEqual(t, ' ', str[0])

s.settings.DisableSTAT = true

rc, str, err = raw.SendCommand("STAT")
require.NoError(t, err)
require.Equal(t, StatusCommandNotImplemented, rc, str)
}

func TestCLNT(t *testing.T) {
Expand Down

0 comments on commit 6678256

Please sign in to comment.