2021-09-17 04:44:35 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ValidateNTP validates and update NTP configuration.
|
2022-02-28 03:15:01 +00:00
|
|
|
func ValidateNTP(config *schema.Configuration, validator *schema.StructValidator) {
|
|
|
|
if config.NTP == nil {
|
|
|
|
config.NTP = &schema.DefaultNTPConfiguration
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.NTP.Address == "" {
|
|
|
|
config.NTP.Address = schema.DefaultNTPConfiguration.Address
|
2021-09-17 04:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
if config.NTP.Version == 0 {
|
|
|
|
config.NTP.Version = schema.DefaultNTPConfiguration.Version
|
|
|
|
} else if config.NTP.Version < 3 || config.NTP.Version > 4 {
|
|
|
|
validator.Push(fmt.Errorf(errFmtNTPVersion, config.NTP.Version))
|
2021-09-17 04:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
if config.NTP.MaximumDesync == "" {
|
|
|
|
config.NTP.MaximumDesync = schema.DefaultNTPConfiguration.MaximumDesync
|
2021-09-17 04:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
_, err := utils.ParseDurationString(config.NTP.MaximumDesync)
|
2021-09-17 04:44:35 +00:00
|
|
|
if err != nil {
|
2022-02-28 03:15:01 +00:00
|
|
|
validator.Push(fmt.Errorf(errFmtNTPMaxDesync, err))
|
2021-09-17 04:44:35 +00:00
|
|
|
}
|
|
|
|
}
|