mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 23:00:55 +03:00
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:
16
ftpd/ftpd.go
16
ftpd/ftpd.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user