2 Unix SMB/CIFS implementation.
4 Copyright (C) Gerald (Jerry) Carter 2006.
5 Copyright (C) Jeremy Allison 2007.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libads/dns.h"
23 #include "../librpc/ndr/libndr.h"
25 /* AIX resolv.h uses 'class' in struct ns_rr */
33 /* resolver headers */
35 #include <sys/types.h>
36 #include <netinet/in.h>
37 #include <arpa/nameser.h>
41 #define MAX_DNS_PACKET_SIZE 0xffff
43 #ifdef NS_HFIXEDSZ /* Bind 8/9 interface */
44 #if !defined(C_IN) /* AIX 5.3 already defines C_IN */
47 #if !defined(T_A) /* AIX 5.3 already defines T_A */
51 #if defined(HAVE_IPV6)
53 # define T_AAAA ns_t_aaaa
57 # define T_SRV ns_t_srv
58 #if !defined(T_NS) /* AIX 5.3 already defines T_NS */
63 # define NS_HFIXEDSZ HFIXEDSZ
65 # define NS_HFIXEDSZ sizeof(HEADER)
66 # endif /* HFIXEDSZ */
68 # define NS_PACKETSZ PACKETSZ
69 # else /* 512 is usually the default */
70 # define NS_PACKETSZ 512
71 # endif /* PACKETSZ */
75 /*********************************************************************
76 *********************************************************************/
78 static bool ads_dns_parse_query( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
79 uint8
**ptr
, struct dns_query
*q
)
82 char hostname
[MAX_DNS_NAME_LENGTH
];
87 if ( !start
|| !end
|| !q
|| !*ptr
)
90 /* See RFC 1035 for details. If this fails, then return. */
92 namelen
= dn_expand( start
, end
, p
, hostname
, sizeof(hostname
) );
97 q
->hostname
= talloc_strdup( ctx
, hostname
);
99 /* check that we have space remaining */
101 if ( PTR_DIFF(p
+4, end
) > 0 )
104 q
->type
= RSVAL( p
, 0 );
105 q
->in_class
= RSVAL( p
, 2 );
113 /*********************************************************************
114 *********************************************************************/
116 static bool ads_dns_parse_rr( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
117 uint8
**ptr
, struct dns_rr
*rr
)
120 char hostname
[MAX_DNS_NAME_LENGTH
];
123 if ( !start
|| !end
|| !rr
|| !*ptr
)
127 /* pull the name from the answer */
129 namelen
= dn_expand( start
, end
, p
, hostname
, sizeof(hostname
) );
134 rr
->hostname
= talloc_strdup( ctx
, hostname
);
136 /* check that we have space remaining */
138 if ( PTR_DIFF(p
+10, end
) > 0 )
141 /* pull some values and then skip onto the string */
143 rr
->type
= RSVAL(p
, 0);
144 rr
->in_class
= RSVAL(p
, 2);
145 rr
->ttl
= RIVAL(p
, 4);
146 rr
->rdatalen
= RSVAL(p
, 8);
150 /* sanity check the available space */
152 if ( PTR_DIFF(p
+rr
->rdatalen
, end
) > 0 ) {
157 /* save a point to the rdata for this section */
167 /*********************************************************************
168 *********************************************************************/
170 static bool ads_dns_parse_rr_srv( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
171 uint8
**ptr
, struct dns_rr_srv
*srv
)
175 char dcname
[MAX_DNS_NAME_LENGTH
];
178 if ( !start
|| !end
|| !srv
|| !*ptr
)
181 /* Parse the RR entry. Coming out of the this, ptr is at the beginning
182 of the next record */
184 if ( !ads_dns_parse_rr( ctx
, start
, end
, ptr
, &rr
) ) {
185 DEBUG(1,("ads_dns_parse_rr_srv: Failed to parse RR record\n"));
189 if ( rr
.type
!= T_SRV
) {
190 DEBUG(1,("ads_dns_parse_rr_srv: Bad answer type (%d)\n",
197 srv
->priority
= RSVAL(p
, 0);
198 srv
->weight
= RSVAL(p
, 2);
199 srv
->port
= RSVAL(p
, 4);
203 namelen
= dn_expand( start
, end
, p
, dcname
, sizeof(dcname
) );
205 DEBUG(1,("ads_dns_parse_rr_srv: Failed to uncompress name!\n"));
209 srv
->hostname
= talloc_strdup( ctx
, dcname
);
211 DEBUG(10,("ads_dns_parse_rr_srv: Parsed %s [%u, %u, %u]\n",
220 /*********************************************************************
221 *********************************************************************/
223 static bool ads_dns_parse_rr_ns( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
224 uint8
**ptr
, struct dns_rr_ns
*nsrec
)
228 char nsname
[MAX_DNS_NAME_LENGTH
];
231 if ( !start
|| !end
|| !nsrec
|| !*ptr
)
234 /* Parse the RR entry. Coming out of the this, ptr is at the beginning
235 of the next record */
237 if ( !ads_dns_parse_rr( ctx
, start
, end
, ptr
, &rr
) ) {
238 DEBUG(1,("ads_dns_parse_rr_ns: Failed to parse RR record\n"));
242 if ( rr
.type
!= T_NS
) {
243 DEBUG(1,("ads_dns_parse_rr_ns: Bad answer type (%d)\n",
250 /* ame server hostname */
252 namelen
= dn_expand( start
, end
, p
, nsname
, sizeof(nsname
) );
254 DEBUG(1,("ads_dns_parse_rr_ns: Failed to uncompress name!\n"));
257 nsrec
->hostname
= talloc_strdup( ctx
, nsname
);
262 /*********************************************************************
263 Sort SRV record list based on weight and priority. See RFC 2782.
264 *********************************************************************/
266 static int dnssrvcmp( struct dns_rr_srv
*a
, struct dns_rr_srv
*b
)
268 if ( a
->priority
== b
->priority
) {
270 /* randomize entries with an equal weight and priority */
271 if ( a
->weight
== b
->weight
)
274 /* higher weights should be sorted lower */
275 if ( a
->weight
> b
->weight
)
281 if ( a
->priority
< b
->priority
)
287 /*********************************************************************
288 Simple wrapper for a DNS query
289 *********************************************************************/
291 #define DNS_FAILED_WAITTIME 30
293 static NTSTATUS
dns_send_req( TALLOC_CTX
*ctx
, const char *name
, int q_type
,
294 uint8
**buf
, int *resp_length
)
296 uint8
*buffer
= NULL
;
298 int resp_len
= NS_PACKETSZ
;
299 static time_t last_dns_check
= 0;
300 static NTSTATUS last_dns_status
= NT_STATUS_OK
;
301 time_t now
= time_mono(NULL
);
303 /* Try to prevent bursts of DNS lookups if the server is down */
305 /* Protect against large clock changes */
307 if ( last_dns_check
> now
)
310 /* IF we had a DNS timeout or a bad server and we are still
311 in the 30 second cache window, just return the previous
312 status and save the network timeout. */
314 if ( (NT_STATUS_EQUAL(last_dns_status
,NT_STATUS_IO_TIMEOUT
) ||
315 NT_STATUS_EQUAL(last_dns_status
,NT_STATUS_CONNECTION_REFUSED
)) &&
316 (last_dns_check
+DNS_FAILED_WAITTIME
) > now
)
318 DEBUG(10,("last_dns_check: Returning cached status (%s)\n",
319 nt_errstr(last_dns_status
) ));
320 return last_dns_status
;
326 TALLOC_FREE( buffer
);
328 buf_len
= resp_len
* sizeof(uint8
);
331 if ((buffer
= TALLOC_ARRAY(ctx
, uint8
, buf_len
))
333 DEBUG(0,("ads_dns_lookup_srv: "
334 "talloc() failed!\n"));
335 last_dns_status
= NT_STATUS_NO_MEMORY
;
336 last_dns_check
= time_mono(NULL
);
337 return last_dns_status
;
341 if ((resp_len
= res_query(name
, C_IN
, q_type
, buffer
, buf_len
))
343 DEBUG(3,("ads_dns_lookup_srv: "
344 "Failed to resolve %s (%s)\n",
345 name
, strerror(errno
)));
346 TALLOC_FREE( buffer
);
347 last_dns_status
= NT_STATUS_UNSUCCESSFUL
;
349 if (errno
== ETIMEDOUT
) {
350 last_dns_status
= NT_STATUS_IO_TIMEOUT
;
352 if (errno
== ECONNREFUSED
) {
353 last_dns_status
= NT_STATUS_CONNECTION_REFUSED
;
355 last_dns_check
= time_mono(NULL
);
356 return last_dns_status
;
359 /* On AIX, Solaris, and possibly some older glibc systems (e.g. SLES8)
360 truncated replies never give back a resp_len > buflen
361 which ends up causing DNS resolve failures on large tcp DNS replies */
363 if (buf_len
== resp_len
) {
364 if (resp_len
== MAX_DNS_PACKET_SIZE
) {
365 DEBUG(1,("dns_send_req: DNS reply too large when resolving %s\n",
367 TALLOC_FREE( buffer
);
368 last_dns_status
= NT_STATUS_BUFFER_TOO_SMALL
;
369 last_dns_check
= time_mono(NULL
);
370 return last_dns_status
;
373 resp_len
= MIN(resp_len
*2, MAX_DNS_PACKET_SIZE
);
377 } while ( buf_len
< resp_len
&& resp_len
<= MAX_DNS_PACKET_SIZE
);
380 *resp_length
= resp_len
;
382 last_dns_check
= time_mono(NULL
);
383 last_dns_status
= NT_STATUS_OK
;
384 return last_dns_status
;
387 /*********************************************************************
388 Simple wrapper for a DNS SRV query
389 *********************************************************************/
391 static NTSTATUS
ads_dns_lookup_srv( TALLOC_CTX
*ctx
,
393 struct dns_rr_srv
**dclist
,
396 uint8
*buffer
= NULL
;
398 struct dns_rr_srv
*dcs
= NULL
;
399 int query_count
, answer_count
, auth_count
, additional_count
;
405 if ( !ctx
|| !name
|| !dclist
) {
406 return NT_STATUS_INVALID_PARAMETER
;
409 /* Send the request. May have to loop several times in case
412 status
= dns_send_req( ctx
, name
, T_SRV
, &buffer
, &resp_len
);
413 if ( !NT_STATUS_IS_OK(status
) ) {
414 DEBUG(3,("ads_dns_lookup_srv: Failed to send DNS query (%s)\n",
420 /* For some insane reason, the ns_initparse() et. al. routines are only
421 available in libresolv.a, and not the shared lib. Who knows why....
422 So we have to parse the DNS reply ourselves */
424 /* Pull the answer RR's count from the header.
425 * Use the NMB ordering macros */
427 query_count
= RSVAL( p
, 4 );
428 answer_count
= RSVAL( p
, 6 );
429 auth_count
= RSVAL( p
, 8 );
430 additional_count
= RSVAL( p
, 10 );
432 DEBUG(4,("ads_dns_lookup_srv: "
433 "%d records returned in the answer section.\n",
437 if ((dcs
= TALLOC_ZERO_ARRAY(ctx
, struct dns_rr_srv
,
438 answer_count
)) == NULL
) {
439 DEBUG(0,("ads_dns_lookup_srv: "
440 "talloc() failure for %d char*'s\n",
442 return NT_STATUS_NO_MEMORY
;
448 /* now skip the header */
452 /* parse the query section */
454 for ( rrnum
=0; rrnum
<query_count
; rrnum
++ ) {
457 if (!ads_dns_parse_query(ctx
, buffer
,
458 buffer
+resp_len
, &p
, &q
)) {
459 DEBUG(1,("ads_dns_lookup_srv: "
460 "Failed to parse query record [%d]!\n", rrnum
));
461 return NT_STATUS_UNSUCCESSFUL
;
465 /* now we are at the answer section */
467 for ( rrnum
=0; rrnum
<answer_count
; rrnum
++ ) {
468 if (!ads_dns_parse_rr_srv(ctx
, buffer
, buffer
+resp_len
,
470 DEBUG(1,("ads_dns_lookup_srv: "
471 "Failed to parse answer recordi [%d]!\n", rrnum
));
472 return NT_STATUS_UNSUCCESSFUL
;
477 /* Parse the authority section */
478 /* just skip these for now */
480 for ( rrnum
=0; rrnum
<auth_count
; rrnum
++ ) {
483 if (!ads_dns_parse_rr( ctx
, buffer
,
484 buffer
+resp_len
, &p
, &rr
)) {
485 DEBUG(1,("ads_dns_lookup_srv: "
486 "Failed to parse authority record! [%d]\n", rrnum
));
487 return NT_STATUS_UNSUCCESSFUL
;
491 /* Parse the additional records section */
493 for ( rrnum
=0; rrnum
<additional_count
; rrnum
++ ) {
497 if (!ads_dns_parse_rr(ctx
, buffer
, buffer
+resp_len
,
499 DEBUG(1,("ads_dns_lookup_srv: Failed "
500 "to parse additional records section! [%d]\n", rrnum
));
501 return NT_STATUS_UNSUCCESSFUL
;
504 /* Only interested in A or AAAA records as a shortcut for having
505 * to come back later and lookup the name. For multi-homed
506 * hosts, the number of additional records and exceed the
507 * number of answer records. */
509 if (rr
.type
!= T_A
|| rr
.rdatalen
!= 4) {
510 #if defined(HAVE_IPV6)
511 /* RFC2874 defines A6 records. This
512 * requires recusive and horribly complex lookups.
513 * Bastards. Ignore this for now.... JRA.
514 * Luckily RFC3363 reprecates A6 records.
516 if (rr
.type
!= T_AAAA
|| rr
.rdatalen
!= 16)
521 for ( i
=0; i
<idx
; i
++ ) {
522 if ( strcmp( rr
.hostname
, dcs
[i
].hostname
) == 0 ) {
523 int num_ips
= dcs
[i
].num_ips
;
524 struct sockaddr_storage
*tmp_ss_s
;
526 /* allocate new memory */
528 if (dcs
[i
].num_ips
== 0) {
529 if ((dcs
[i
].ss_s
= TALLOC_ARRAY(dcs
,
530 struct sockaddr_storage
, 1 ))
532 return NT_STATUS_NO_MEMORY
;
535 if ((tmp_ss_s
= TALLOC_REALLOC_ARRAY(dcs
,
537 struct sockaddr_storage
,
540 return NT_STATUS_NO_MEMORY
;
543 dcs
[i
].ss_s
= tmp_ss_s
;
547 /* copy the new IP address */
548 if (rr
.type
== T_A
) {
550 memcpy(&ip
, rr
.rdata
, 4);
551 in_addr_to_sockaddr_storage(
552 &dcs
[i
].ss_s
[num_ips
],
555 #if defined(HAVE_IPV6)
556 if (rr
.type
== T_AAAA
) {
558 memcpy(&ip6
, rr
.rdata
, rr
.rdatalen
);
559 in6_addr_to_sockaddr_storage(
560 &dcs
[i
].ss_s
[num_ips
],
568 TYPESAFE_QSORT(dcs
, idx
, dnssrvcmp
);
576 /*********************************************************************
577 Simple wrapper for a DNS NS query
578 *********************************************************************/
580 NTSTATUS
ads_dns_lookup_ns(TALLOC_CTX
*ctx
,
581 const char *dnsdomain
,
582 struct dns_rr_ns
**nslist
,
585 uint8
*buffer
= NULL
;
587 struct dns_rr_ns
*nsarray
= NULL
;
588 int query_count
, answer_count
, auth_count
, additional_count
;
594 if ( !ctx
|| !dnsdomain
|| !nslist
) {
595 return NT_STATUS_INVALID_PARAMETER
;
598 /* Send the request. May have to loop several times in case
601 status
= dns_send_req( ctx
, dnsdomain
, T_NS
, &buffer
, &resp_len
);
602 if ( !NT_STATUS_IS_OK(status
) ) {
603 DEBUG(3,("ads_dns_lookup_ns: Failed to send DNS query (%s)\n",
609 /* For some insane reason, the ns_initparse() et. al. routines are only
610 available in libresolv.a, and not the shared lib. Who knows why....
611 So we have to parse the DNS reply ourselves */
613 /* Pull the answer RR's count from the header.
614 * Use the NMB ordering macros */
616 query_count
= RSVAL( p
, 4 );
617 answer_count
= RSVAL( p
, 6 );
618 auth_count
= RSVAL( p
, 8 );
619 additional_count
= RSVAL( p
, 10 );
621 DEBUG(4,("ads_dns_lookup_ns: "
622 "%d records returned in the answer section.\n",
626 if ((nsarray
= TALLOC_ARRAY(ctx
, struct dns_rr_ns
,
627 answer_count
)) == NULL
) {
628 DEBUG(0,("ads_dns_lookup_ns: "
629 "talloc() failure for %d char*'s\n",
631 return NT_STATUS_NO_MEMORY
;
637 /* now skip the header */
641 /* parse the query section */
643 for ( rrnum
=0; rrnum
<query_count
; rrnum
++ ) {
646 if (!ads_dns_parse_query(ctx
, buffer
, buffer
+resp_len
,
648 DEBUG(1,("ads_dns_lookup_ns: "
649 " Failed to parse query record!\n"));
650 return NT_STATUS_UNSUCCESSFUL
;
654 /* now we are at the answer section */
656 for ( rrnum
=0; rrnum
<answer_count
; rrnum
++ ) {
657 if (!ads_dns_parse_rr_ns(ctx
, buffer
, buffer
+resp_len
,
658 &p
, &nsarray
[rrnum
])) {
659 DEBUG(1,("ads_dns_lookup_ns: "
660 "Failed to parse answer record!\n"));
661 return NT_STATUS_UNSUCCESSFUL
;
666 /* Parse the authority section */
667 /* just skip these for now */
669 for ( rrnum
=0; rrnum
<auth_count
; rrnum
++ ) {
672 if ( !ads_dns_parse_rr(ctx
, buffer
, buffer
+resp_len
,
674 DEBUG(1,("ads_dns_lookup_ns: "
675 "Failed to parse authority record!\n"));
676 return NT_STATUS_UNSUCCESSFUL
;
680 /* Parse the additional records section */
682 for ( rrnum
=0; rrnum
<additional_count
; rrnum
++ ) {
686 if (!ads_dns_parse_rr(ctx
, buffer
, buffer
+resp_len
,
688 DEBUG(1,("ads_dns_lookup_ns: Failed "
689 "to parse additional records section!\n"));
690 return NT_STATUS_UNSUCCESSFUL
;
693 /* only interested in A records as a shortcut for having to come
694 back later and lookup the name */
696 if (rr
.type
!= T_A
|| rr
.rdatalen
!= 4) {
697 #if defined(HAVE_IPV6)
698 if (rr
.type
!= T_AAAA
|| rr
.rdatalen
!= 16)
703 for ( i
=0; i
<idx
; i
++ ) {
704 if (strcmp(rr
.hostname
, nsarray
[i
].hostname
) == 0) {
705 if (rr
.type
== T_A
) {
707 memcpy(&ip
, rr
.rdata
, 4);
708 in_addr_to_sockaddr_storage(
712 #if defined(HAVE_IPV6)
713 if (rr
.type
== T_AAAA
) {
715 memcpy(&ip6
, rr
.rdata
, rr
.rdatalen
);
716 in6_addr_to_sockaddr_storage(
731 /********************************************************************
732 Query with optional sitename.
733 ********************************************************************/
735 static NTSTATUS
ads_dns_query_internal(TALLOC_CTX
*ctx
,
736 const char *servicename
,
737 const char *dc_pdc_gc_domains
,
739 const char *sitename
,
740 struct dns_rr_srv
**dclist
,
745 name
= talloc_asprintf(ctx
, "%s._tcp.%s._sites.%s._msdcs.%s",
746 servicename
, sitename
,
747 dc_pdc_gc_domains
, realm
);
749 name
= talloc_asprintf(ctx
, "%s._tcp.%s._msdcs.%s",
750 servicename
, dc_pdc_gc_domains
, realm
);
753 return NT_STATUS_NO_MEMORY
;
755 return ads_dns_lookup_srv( ctx
, name
, dclist
, numdcs
);
758 /********************************************************************
760 ********************************************************************/
762 NTSTATUS
ads_dns_query_dcs(TALLOC_CTX
*ctx
,
764 const char *sitename
,
765 struct dns_rr_srv
**dclist
,
770 status
= ads_dns_query_internal(ctx
, "_ldap", "dc", realm
, sitename
,
773 if (NT_STATUS_EQUAL(status
, NT_STATUS_IO_TIMEOUT
) ||
774 NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_REFUSED
)) {
779 ((!NT_STATUS_IS_OK(status
)) ||
780 (NT_STATUS_IS_OK(status
) && (numdcs
== 0)))) {
781 /* Sitename DNS query may have failed. Try without. */
782 status
= ads_dns_query_internal(ctx
, "_ldap", "dc", realm
,
783 NULL
, dclist
, numdcs
);
788 /********************************************************************
790 ********************************************************************/
792 NTSTATUS
ads_dns_query_gcs(TALLOC_CTX
*ctx
,
794 const char *sitename
,
795 struct dns_rr_srv
**dclist
,
800 status
= ads_dns_query_internal(ctx
, "_ldap", "gc", realm
, sitename
,
803 if (NT_STATUS_EQUAL(status
, NT_STATUS_IO_TIMEOUT
) ||
804 NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_REFUSED
)) {
809 ((!NT_STATUS_IS_OK(status
)) ||
810 (NT_STATUS_IS_OK(status
) && (numdcs
== 0)))) {
811 /* Sitename DNS query may have failed. Try without. */
812 status
= ads_dns_query_internal(ctx
, "_ldap", "gc", realm
,
813 NULL
, dclist
, numdcs
);
818 /********************************************************************
820 Even if our underlying kerberos libraries are UDP only, this
821 is pretty safe as it's unlikely that a KDC supports TCP and not UDP.
822 ********************************************************************/
824 NTSTATUS
ads_dns_query_kdcs(TALLOC_CTX
*ctx
,
825 const char *dns_forest_name
,
826 const char *sitename
,
827 struct dns_rr_srv
**dclist
,
832 status
= ads_dns_query_internal(ctx
, "_kerberos", "dc",
833 dns_forest_name
, sitename
, dclist
,
836 if (NT_STATUS_EQUAL(status
, NT_STATUS_IO_TIMEOUT
) ||
837 NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_REFUSED
)) {
842 ((!NT_STATUS_IS_OK(status
)) ||
843 (NT_STATUS_IS_OK(status
) && (numdcs
== 0)))) {
844 /* Sitename DNS query may have failed. Try without. */
845 status
= ads_dns_query_internal(ctx
, "_kerberos", "dc",
846 dns_forest_name
, NULL
,
852 /********************************************************************
853 Query for AD PDC. Sitename is obsolete here.
854 ********************************************************************/
856 NTSTATUS
ads_dns_query_pdc(TALLOC_CTX
*ctx
,
857 const char *dns_domain_name
,
858 struct dns_rr_srv
**dclist
,
861 return ads_dns_query_internal(ctx
, "_ldap", "pdc", dns_domain_name
,
862 NULL
, dclist
, numdcs
);
865 /********************************************************************
866 Query for AD DC by guid. Sitename is obsolete here.
867 ********************************************************************/
869 NTSTATUS
ads_dns_query_dcs_guid(TALLOC_CTX
*ctx
,
870 const char *dns_forest_name
,
871 const struct GUID
*domain_guid
,
872 struct dns_rr_srv
**dclist
,
875 /*_ldap._tcp.DomainGuid.domains._msdcs.DnsForestName */
880 guid_string
= GUID_string(ctx
, domain_guid
);
882 return NT_STATUS_NO_MEMORY
;
886 domains
= talloc_asprintf(ctx
, "%s.domains", guid_string
);
888 return NT_STATUS_NO_MEMORY
;
890 TALLOC_FREE(guid_string
);
892 return ads_dns_query_internal(ctx
, "_ldap", domains
, dns_forest_name
,
893 NULL
, dclist
, numdcs
);