ftpd: add basic wildcard support

this is the minimal implementation to allow mget and similar commands with
wildcards.

We only support wildcard for the last path level, for example:

- mget *.xml is supported
- mget dir/*.xml is supported
- mget */*.xml is not supported

Removed . and .. from FTP directory listing

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-05-04 19:32:02 +02:00
parent 9a37e3d159
commit 61947e67ae
6 changed files with 225 additions and 41 deletions

View File

@@ -1002,3 +1002,28 @@ func TestPassiveIPResolver(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, b.ForcePassiveIP, passiveIP)
}
func TestRelativePath(t *testing.T) {
rel := getPathRelativeTo("/testpath", "/testpath")
assert.Empty(t, rel)
rel = getPathRelativeTo("/", "/")
assert.Empty(t, rel)
rel = getPathRelativeTo("/", "/dir/sub")
assert.Equal(t, "dir/sub", rel)
rel = getPathRelativeTo("./", "/dir/sub")
assert.Equal(t, "/dir/sub", rel)
rel = getPathRelativeTo("/sub", "/dir/sub")
assert.Equal(t, "../dir/sub", rel)
rel = getPathRelativeTo("/dir", "/dir/sub")
assert.Equal(t, "sub", rel)
rel = getPathRelativeTo("/dir/sub", "/dir")
assert.Equal(t, "../", rel)
rel = getPathRelativeTo("dir", "/dir1")
assert.Equal(t, "/dir1", rel)
rel = getPathRelativeTo("", "/dir2")
assert.Equal(t, "dir2", rel)
rel = getPathRelativeTo(".", "/dir2")
assert.Equal(t, "/dir2", rel)
rel = getPathRelativeTo("/dir3", "dir3")
assert.Equal(t, "dir3", rel)
}