check if the ip range is valid
This commit is contained in:
parent
24544a6260
commit
657f92a3df
9
ldap.go
9
ldap.go
|
@ -34,11 +34,12 @@ func (l *ldapConfig) addIPRange(s string) error {
|
|||
if len(ips) != 2 {
|
||||
return errors.New("invalid IPs")
|
||||
}
|
||||
if ip := net.ParseIP(ips[0]); ip != nil {
|
||||
l.ipMin = ip
|
||||
for k, v := range []*net.IP{&(l.ipMin), &(l.ipMax)} {
|
||||
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
|
||||
}
|
||||
|
|
5
main.go
5
main.go
|
@ -76,7 +76,10 @@ func main() {
|
|||
certAuth: config.GetString(profile+".cert", "optionnal"),
|
||||
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 {
|
||||
log.Println("valud ldap configuration must have 2 attributes")
|
||||
|
|
Loading…
Reference in New Issue