From 66782562d4fdd27dd61362ae280abb2aa8d7bc77 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Fri, 18 Dec 2020 02:10:54 +0100 Subject: [PATCH] add settings to disable server STAT and SYST (#204) Co-authored-by: Florent Clairambault --- driver.go | 2 ++ handle_auth_test.go | 5 +++++ handle_misc.go | 14 ++++++++++++++ handle_misc_test.go | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/driver.go b/driver.go index d7c9aa7c..479d9c9d 100644 --- a/driver.go +++ b/driver.go @@ -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 } diff --git a/handle_auth_test.go b/handle_auth_test.go index c39db549..27cfc529 100644 --- a/handle_auth_test.go +++ b/handle_auth_test.go @@ -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) { diff --git a/handle_misc.go b/handle_misc.go index 1093e02b..461584e4 100644 --- a/handle_misc.go +++ b/handle_misc.go @@ -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 } @@ -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) diff --git a/handle_misc_test.go b/handle_misc_test.go index 98fc1039..c92a3e8a 100644 --- a/handle_misc_test.go +++ b/handle_misc_test.go @@ -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) {