token-validator: fix IP assignation when > 254 (there is a lot of student this year)

This commit is contained in:
nemunaire 2021-02-20 19:13:33 +01:00
parent cc7e738932
commit 060831d9c2
3 changed files with 24 additions and 7 deletions

View file

@ -37,12 +37,16 @@ func registerUser(tplPath string, filename string, username string, ip net.IP) e
pkey := hmac.New(sha512.New512_224, []byte(loginSalt))
if len(ip.To4()) != 4 {
return fmt.Errorf("Unable to assign a protected IP.")
}
if pxeTmpl, err := template.New("pxeUser").Parse(string(pxeTplCnt)); err != nil {
return err
} else if err := pxeTmpl.Execute(userfd, map[string]string{
"username": username,
"pkey": fmt.Sprintf("%x", pkey.Sum([]byte(username))),
"ip": fmt.Sprintf("%d.%d.%d.%d", ip.To4()[0], ip.To4()[1], ip.To4()[2], ip.To4()[3]),
"ip": ip.String(),
}); err != nil {
return err
}