Skip to content

Commit 83ec1c4

Browse files
committed
add settings to disable server STAT and SYST
1 parent fdb9611 commit 83ec1c4

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,6 @@ type Settings struct {
186186
DisableSite bool // Disable SITE command
187187
DisableActiveMode bool // Disable Active FTP
188188
EnableHASH bool // Enable support for calculating hash value of files
189+
DisableSTAT bool // Disable Server STATUS, STAT on files and directories will still work
190+
DisableSYST bool // Disable SYST
189191
}

handle_auth_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func TestLoginSuccess(t *testing.T) {
6464
require.NoError(t, err)
6565
require.Equal(t, StatusSystemType, rc)
6666
require.Equal(t, "UNIX Type: L8", response)
67+
68+
s.settings.DisableSYST = true
69+
rc, response, err = raw.SendCommand("SYST")
70+
require.NoError(t, err)
71+
require.Equal(t, StatusCommandNotImplemented, rc, response)
6772
}
6873

6974
func TestLoginFailure(t *testing.T) {

handle_misc.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ func (c *clientHandler) handlePBSZ() error {
4040
}
4141

4242
func (c *clientHandler) handleSYST() error {
43+
if c.server.settings.DisableSYST {
44+
c.writeMessage(StatusCommandNotImplemented, "SYST is disabled")
45+
return nil
46+
}
47+
4348
c.writeMessage(StatusSystemType, "UNIX Type: L8")
49+
4450
return nil
4551
}
4652

@@ -80,6 +86,14 @@ func (c *clientHandler) handleSITE() error {
8086
}
8187

8288
func (c *clientHandler) handleSTATServer() error {
89+
if c.server.settings.DisableSTAT {
90+
c.writeMessage(StatusCommandNotImplemented, "STAT is disabled")
91+
return nil
92+
}
93+
94+
// drakkan(2020-12-17): we don't handle STAT properly,
95+
// we should return the status for all the transfers and we should allow
96+
// stat while a transfer is in progress, see RFC 959
8397
defer c.multilineAnswer(StatusSystemStatus, "Server status")()
8498

8599
duration := time.Now().UTC().Sub(c.connectedAt)

handle_misc_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func TestStat(t *testing.T) {
8888
count := strings.Count(str, "\n")
8989
require.GreaterOrEqual(t, count, 4)
9090
require.NotEqual(t, ' ', str[0])
91+
92+
s.settings.DisableSTAT = true
93+
94+
rc, str, err = raw.SendCommand("STAT")
95+
require.NoError(t, err)
96+
require.Equal(t, StatusCommandNotImplemented, rc, str)
9197
}
9298

9399
func TestCLNT(t *testing.T) {

0 commit comments

Comments
 (0)