@@ -210,8 +210,10 @@ func populateNameserverPorts(servers []string) {
210
210
}
211
211
}
212
212
213
- // checkDNSPropagation checks if the expected TXT record has been propagated to all authoritative nameservers.
214
- func checkDNSPropagation (fqdn , value string , resolvers []string ) (bool , error ) {
213
+ // checkDNSPropagation checks if the expected TXT record has been propagated.
214
+ // If checkAuthoritativeServers is true, the authoritative nameservers are checked directly,
215
+ // otherwise only the given resolvers are checked.
216
+ func checkDNSPropagation (fqdn , value string , resolvers []string , checkAuthoritativeServers bool ) (bool , error ) {
215
217
if ! strings .HasSuffix (fqdn , "." ) {
216
218
fqdn += "."
217
219
}
@@ -226,18 +228,22 @@ func checkDNSPropagation(fqdn, value string, resolvers []string) (bool, error) {
226
228
fqdn = updateDomainWithCName (r , fqdn )
227
229
}
228
230
229
- authoritativeNss , err := lookupNameservers (fqdn , resolvers )
230
- if err != nil {
231
- return false , err
231
+ if checkAuthoritativeServers {
232
+ authoritativeServers , err := lookupNameservers (fqdn , resolvers )
233
+ if err != nil {
234
+ return false , err
235
+ }
236
+ populateNameserverPorts (authoritativeServers )
237
+ resolvers = authoritativeServers
232
238
}
233
239
234
- return checkAuthoritativeNss (fqdn , value , authoritativeNss )
240
+ return checkNameservers (fqdn , value , resolvers )
235
241
}
236
242
237
- // checkAuthoritativeNss queries each of the given nameservers for the expected TXT record.
238
- func checkAuthoritativeNss (fqdn , value string , nameservers []string ) (bool , error ) {
243
+ // checkNameservers checks if any of the given nameservers has the expected TXT record.
244
+ func checkNameservers (fqdn , value string , nameservers []string ) (bool , error ) {
239
245
for _ , ns := range nameservers {
240
- r , err := dnsQuery (fqdn , dns .TypeTXT , []string {net . JoinHostPort ( ns , "53" ) }, true )
246
+ r , err := dnsQuery (fqdn , dns .TypeTXT , []string {ns }, true )
241
247
if err != nil {
242
248
return false , err
243
249
}
@@ -252,23 +258,17 @@ func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, erro
252
258
return false , fmt .Errorf ("NS %s returned %s for %s" , ns , dns .RcodeToString [r .Rcode ], fqdn )
253
259
}
254
260
255
- var found bool
256
261
for _ , rr := range r .Answer {
257
262
if txt , ok := rr .(* dns.TXT ); ok {
258
263
record := strings .Join (txt .Txt , "" )
259
264
if record == value {
260
- found = true
261
- break
265
+ return true , nil
262
266
}
263
267
}
264
268
}
265
-
266
- if ! found {
267
- return false , nil
268
- }
269
269
}
270
270
271
- return true , nil
271
+ return false , nil
272
272
}
273
273
274
274
// lookupNameservers returns the authoritative nameservers for the given fqdn.
0 commit comments