FTPD: make sure that the passive ip, if provided, is valid

The server will refuse to start if the provided passive ip is not a
valid IPv4 address.

Fixes #376
This commit is contained in:
Nicola Murino
2021-04-16 15:08:10 +02:00
parent 683ba6cd5b
commit 124c471a2b
5 changed files with 46 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package ftpd
import (
"fmt"
"net"
"path/filepath"
ftpserver "github.com/fclairamb/ftpserverlib"
@@ -74,6 +75,21 @@ func (b *Binding) IsValid() bool {
return b.Port > 0
}
func (b *Binding) checkPassiveIP() error {
if b.ForcePassiveIP != "" {
ip := net.ParseIP(b.ForcePassiveIP)
if ip == nil {
return fmt.Errorf("the provided passive IP %#v is not valid", b.ForcePassiveIP)
}
ip = ip.To4()
if ip == nil {
return fmt.Errorf("the provided passive IP %#v is not a valid IPv4 address", b.ForcePassiveIP)
}
b.ForcePassiveIP = ip.String()
}
return nil
}
// HasProxy returns true if the proxy protocol is active for this binding
func (b *Binding) HasProxy() bool {
return b.ApplyProxyConfig && common.Config.ProxyProtocol > 0