check if the ip range is valid

This commit is contained in:
Xavier Henner 2019-07-14 05:12:28 +02:00
parent 24544a6260
commit 657f92a3df
2 changed files with 10 additions and 6 deletions

View File

@ -34,11 +34,12 @@ func (l *ldapConfig) addIPRange(s string) error {
if len(ips) != 2 { if len(ips) != 2 {
return errors.New("invalid IPs") return errors.New("invalid IPs")
} }
if ip := net.ParseIP(ips[0]); ip != nil { for k, v := range []*net.IP{&(l.ipMin), &(l.ipMax)} {
l.ipMin = ip if ip := net.ParseIP(strings.Trim(ips[k], " ")); ip == nil {
return errors.New(fmt.Sprintf("invalid IP '%s'", ips[k]))
} else {
*v = ip
} }
if ip := net.ParseIP(ips[1]); ip != nil {
l.ipMax = ip
} }
return nil return nil
} }

View File

@ -76,7 +76,10 @@ func main() {
certAuth: config.GetString(profile+".cert", "optionnal"), certAuth: config.GetString(profile+".cert", "optionnal"),
upgradeFrom: config.GetString(profile+".upgradeFrom", ""), upgradeFrom: config.GetString(profile+".upgradeFrom", ""),
} }
ldapConf.addIPRange(config.GetString(profile+".IPRange", "")) if err := ldapConf.addIPRange(config.GetString(profile+".IPRange", "")); err != nil {
log.Println(err)
os.Exit(1)
}
if len(ldapConf.servers) > 0 && len(ldapConf.attributes) < 2 { if len(ldapConf.servers) > 0 && len(ldapConf.attributes) < 2 {
log.Println("valud ldap configuration must have 2 attributes") log.Println("valud ldap configuration must have 2 attributes")