package configimport ()// GetKDCs returns the count of KDCs available and a map of KDC host names keyed on preference order.func ( *Config) ( string, bool) (int, map[int]string, error) {if == "" { = .LibDefaults.DefaultRealm } := make(map[int]string)varint// Get the KDCs from the krb5.conf.var []stringfor , := range .Realms {if .Realm != {continue } = .KDC } = len()if > 0 {// Order the kdcs randomly for preference. = randServOrder()return , , nil }if !.LibDefaults.DNSLookupKDC {return , , fmt.Errorf("no KDCs defined in configuration for realm %s", ) }// Use DNS to resolve kerberos SRV records. := "udp"if { = "tcp" } , , := dnsutils.OrderedSRV("kerberos", , )if != nil {return , , }iflen() < 1 {return , , fmt.Errorf("no KDC SRV records found for realm %s", ) } = for , := range { [] = strings.TrimRight(.Target, ".") + ":" + strconv.Itoa(int(.Port)) }return , , nil}// GetKpasswdServers returns the count of kpasswd servers available and a map of kpasswd host names keyed on preference order.// https://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html#realms - see kpasswd_server sectionfunc ( *Config) ( string, bool) (int, map[int]string, error) { := make(map[int]string)varint// Use DNS to resolve kerberos SRV records if configured to do so in krb5.conf.if .LibDefaults.DNSLookupKDC { := "udp"if { = "tcp" } , , := dnsutils.OrderedSRV("kpasswd", , )if != nil {return , , }if < 1 { , , = dnsutils.OrderedSRV("kerberos-adm", , )if != nil {return , , } }iflen() < 1 {return , , fmt.Errorf("no kpasswd or kadmin SRV records found for realm %s", ) } = for , := range { [] = strings.TrimRight(.Target, ".") + ":" + strconv.Itoa(int(.Port)) } } else {// Get the KDCs from the krb5.conf an order them randomly for preference.var []stringvar []stringfor , := range .Realms {if .Realm == { = .KPasswdServer = .AdminServerbreak } }iflen() < 1 {for , := range { , , := net.SplitHostPort()if != nil {continue } = append(, +":464") } } = len()if < 1 {return , , fmt.Errorf("no kpasswd or kadmin defined in configuration for realm %s", ) } = randServOrder() }return , , nil}func randServOrder( []string) map[int]string { := make(map[int]string) := len() := 1if > 1 { := len()for > 0 { := rand.Intn() [] = []if > 1 {// Remove the entry from the source slice by swapping with the last entry and truncating [len()-1], [] = [], [len()-1] = [:len()-1] = len() } else { = 0 } ++ } } else { [] = [0] }return}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.