diff --git a/checker/checker.go b/checker/checker.go index 909a498..b45aaf5 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -53,11 +53,12 @@ func check_ping(ip string, cb func(pkt *ping.Packet)) (err error) { // PORT 53 -func get_GLUE(domain string) (aaaa net.IP, err error) { +func get_GLUE(student *adlin.Student) (aaaa net.IP, err error) { client := dns.Client{Net: "tcp", Timeout: time.Second * 5} + domain := student.MyDelegatedDomain() dnssrv := "[2a01:e0a:2b:2250::b]:53" - if strings.HasSuffix(domain, adlin.DelegatedDomainSuffix) { + if strings.HasSuffix(domain, student.MyDelegatedDomainSuffix()) { dnssrv = "[2a01:e0a:2b:2250::b]:53" } else if v, ok := domainsHostingMap[domain]; ok { dnssrv = v @@ -607,7 +608,7 @@ func studentChecker(std *adlin.Student, also_check_matrix bool) { dnsIP := stdIP var glueErr error // Is GLUE defined? - if glueIP, err := get_GLUE(std.MyDelegatedDomain()); glueIP != nil { + if glueIP, err := get_GLUE(std); glueIP != nil { dnsIP = glueIP.String() if verbose { diff --git a/libadlin/domain.go b/libadlin/domain.go index 4553012..3ef086b 100644 --- a/libadlin/domain.go +++ b/libadlin/domain.go @@ -5,21 +5,29 @@ import ( "strings" ) -const ( - AssociatedDomainSuffix = "adlin2022.p0m.fr." - DelegatedDomainSuffix = "srs.p0m.fr." +var ( + AssociatedDomainSuffixes = []string{"adlin2023.p0m.fr."} + DelegatedDomainSuffixes = []string{"srs.p0m.fr."} ) +func (student *Student) MyDelegatedDomainSuffix() string { + return DelegatedDomainSuffixes[int(student.Id)%len(DelegatedDomainSuffixes)] +} + func (student *Student) MyDelegatedDomain() string { if student.DelegatedDomain != nil { return *student.DelegatedDomain } else { - return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), DelegatedDomainSuffix) + return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), student.MyDelegatedDomainSuffix()) } } +func (student *Student) MyAssociatedDomainSuffix() string { + return AssociatedDomainSuffixes[int(student.Id)%len(AssociatedDomainSuffixes)] +} + func (student *Student) DefaultAssociatedDomain() string { - return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), AssociatedDomainSuffix) + return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), student.MyAssociatedDomainSuffix()) } func (student *Student) MyAssociatedDomain() string { diff --git a/token-validator/domain.go b/token-validator/domain.go index 3874b5e..ea463de 100644 --- a/token-validator/domain.go +++ b/token-validator/domain.go @@ -236,7 +236,7 @@ func GetAssociatedDomain(student *adlin.Student, dn string) (rrs []Entry, err er err = errors.New(fmt.Sprintf("Unable to find domain %q.", dn)) } - if entries, errr := parseZoneRead(adlin.AssociatedDomainSuffix, dn); err != nil { + if entries, errr := parseZoneRead(student.MyAssociatedDomainSuffix(), dn); err != nil { return nil, errr } else { for _, e := range entries { @@ -260,7 +260,7 @@ func delAssociatedDomains(student *adlin.Student, dn string) (err error) { m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{Name: adlin.AssociatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m1.Question[0] = dns.Question{Name: student.MyAssociatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var rrs []dns.RR for _, domain := range adomains { @@ -302,7 +302,7 @@ func AddAssociatedDomains(student *adlin.Student, aaaa net.IP) (err error) { m2.Id = dns.Id() m2.Opcode = dns.OpcodeUpdate m2.Question = make([]dns.Question, 1) - m2.Question[0] = dns.Question{Name: adlin.AssociatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m2.Question[0] = dns.Question{Name: student.MyAssociatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrA := new(dns.A) rrA.Hdr = dns.RR_Header{Name: student.DefaultAssociatedDomain(), Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600} @@ -335,7 +335,7 @@ func getRRDelegatedDomain(student *adlin.Student, dn string, rr string) (rrs []E err = errors.New(fmt.Sprintf("Unable to find domain %q.", dn)) } - if entries, errr := parseZoneRead(adlin.DelegatedDomainSuffix, dn); err != nil { + if entries, errr := parseZoneRead(student.MyDelegatedDomainSuffix(), dn); err != nil { return nil, errr } else { for _, e := range entries { @@ -354,7 +354,7 @@ func AddNSDelegatedDomain(student *adlin.Student, dn string, ttl uint32, ns stri m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m1.Question[0] = dns.Question{Name: student.MyDelegatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrNS := new(dns.NS) rrNS.Hdr = dns.RR_Header{Name: d, Rrtype: dns.TypeNS, Class: dns.ClassINET, Ttl: ttl} @@ -377,7 +377,7 @@ func UpdateNSDelegatedDomain(student *adlin.Student, dn string, ttl uint32, oldn m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m1.Question[0] = dns.Question{Name: student.MyDelegatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrOldNS := new(dns.NS) rrOldNS.Hdr = dns.RR_Header{Name: d, Rrtype: dns.TypeNS, Class: dns.ClassINET} @@ -417,7 +417,7 @@ func AddGLUEDelegatedDomain(student *adlin.Student, dn string, ttl uint32, aaaa m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m1.Question[0] = dns.Question{Name: student.MyDelegatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var rr dns.RR rr, err = dns.NewRR(fmt.Sprintf("%s %d IN AAAA %s", dn, ttl, aaaa)) @@ -453,7 +453,7 @@ func UpdateGLUEDelegatedDomain(student *adlin.Student, dn string, ttl uint32, ol m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m1.Question[0] = dns.Question{Name: student.MyDelegatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var rr dns.RR @@ -509,7 +509,7 @@ func AddDSDelegatedDomain(student *adlin.Student, dn string, ttl uint32, rdata s m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m1.Question[0] = dns.Question{Name: student.MyDelegatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} var ds *dns.DS ds = dnskey.ToDS(dns.SHA256) @@ -545,7 +545,7 @@ func DeleteRRDelegatedDomain(student *adlin.Student, dn string, rr string, value m1.Id = dns.Id() m1.Opcode = dns.OpcodeUpdate m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{Name: adlin.DelegatedDomainSuffix, Qtype: dns.TypeSOA, Qclass: dns.ClassINET} + m1.Question[0] = dns.Question{Name: student.MyDelegatedDomainSuffix(), Qtype: dns.TypeSOA, Qclass: dns.ClassINET} rrr, errr := dns.NewRR(fmt.Sprintf("%s %s %s", dn, rr, strings.Join(values, " "))) if errr != nil {