serve ftp: check --passive-port arguments are correct
See: https://forum.rclone.org/t/serve-ftp-passive-port-validity-check/27458
This commit is contained in:
parent
a6ca4b3817
commit
7d3648dc46
1 changed files with 8 additions and 0 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -128,6 +129,8 @@ type server struct {
|
||||||
useTLS bool
|
useTLS bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var passivePortsRe = regexp.MustCompile(`^\s*\d+\s*-\s*\d+\s*$`)
|
||||||
|
|
||||||
// Make a new FTP to serve the remote
|
// Make a new FTP to serve the remote
|
||||||
func newServer(ctx context.Context, f fs.Fs, opt *Options) (*server, error) {
|
func newServer(ctx context.Context, f fs.Fs, opt *Options) (*server, error) {
|
||||||
host, port, err := net.SplitHostPort(opt.ListenAddr)
|
host, port, err := net.SplitHostPort(opt.ListenAddr)
|
||||||
|
@ -151,6 +154,11 @@ func newServer(ctx context.Context, f fs.Fs, opt *Options) (*server, error) {
|
||||||
}
|
}
|
||||||
s.useTLS = s.opt.TLSKey != ""
|
s.useTLS = s.opt.TLSKey != ""
|
||||||
|
|
||||||
|
// Check PassivePorts format since the the server library doesn't!
|
||||||
|
if !passivePortsRe.MatchString(opt.PassivePorts) {
|
||||||
|
return nil, fmt.Errorf("invalid format for passive ports %q", opt.PassivePorts)
|
||||||
|
}
|
||||||
|
|
||||||
ftpopt := &ftp.ServerOpts{
|
ftpopt := &ftp.ServerOpts{
|
||||||
Name: "Rclone FTP Server",
|
Name: "Rclone FTP Server",
|
||||||
WelcomeMessage: "Welcome to Rclone " + fs.Version + " FTP Server",
|
WelcomeMessage: "Welcome to Rclone " + fs.Version + " FTP Server",
|
||||||
|
|
Loading…
Reference in a new issue