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/>.
23 /* AIX resolv.h uses 'class' in struct ns_rr */
31 /* resolver headers */
33 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <arpa/nameser.h>
39 #define MAX_DNS_PACKET_SIZE 0xffff
41 #ifdef NS_HFIXEDSZ /* Bind 8/9 interface */
42 #if !defined(C_IN) /* AIX 5.3 already defines C_IN */
45 #if !defined(T_A) /* AIX 5.3 already defines T_A */
49 #if defined(HAVE_IPV6)
51 # define T_AAAA ns_t_aaaa
55 # define T_SRV ns_t_srv
56 #if !defined(T_NS) /* AIX 5.3 already defines T_NS */
61 # define NS_HFIXEDSZ HFIXEDSZ
63 # define NS_HFIXEDSZ sizeof(HEADER)
64 # endif /* HFIXEDSZ */
66 # define NS_PACKETSZ PACKETSZ
67 # else /* 512 is usually the default */
68 # define NS_PACKETSZ 512
69 # endif /* PACKETSZ */
73 /*********************************************************************
74 *********************************************************************/
76 static bool ads_dns_parse_query( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
77 uint8
**ptr
, struct dns_query
*q
)
80 char hostname
[MAX_DNS_NAME_LENGTH
];
85 if ( !start
|| !end
|| !q
|| !*ptr
)
88 /* See RFC 1035 for details. If this fails, then return. */
90 namelen
= dn_expand( start
, end
, p
, hostname
, sizeof(hostname
) );
95 q
->hostname
= talloc_strdup( ctx
, hostname
);
97 /* check that we have space remaining */
99 if ( PTR_DIFF(p
+4, end
) > 0 )
102 q
->type
= RSVAL( p
, 0 );
103 q
->in_class
= RSVAL( p
, 2 );
111 /*********************************************************************
112 *********************************************************************/
114 static bool ads_dns_parse_rr( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
115 uint8
**ptr
, struct dns_rr
*rr
)
118 char hostname
[MAX_DNS_NAME_LENGTH
];
121 if ( !start
|| !end
|| !rr
|| !*ptr
)
125 /* pull the name from the answer */
127 namelen
= dn_expand( start
, end
, p
, hostname
, sizeof(hostname
) );
132 rr
->hostname
= talloc_strdup( ctx
, hostname
);
134 /* check that we have space remaining */
136 if ( PTR_DIFF(p
+10, end
) > 0 )
139 /* pull some values and then skip onto the string */
141 rr
->type
= RSVAL(p
, 0);
142 rr
->in_class
= RSVAL(p
, 2);
143 rr
->ttl
= RIVAL(p
, 4);
144 rr
->rdatalen
= RSVAL(p
, 8);
148 /* sanity check the available space */
150 if ( PTR_DIFF(p
+rr
->rdatalen
, end
) > 0 ) {
155 /* save a point to the rdata for this section */
165 /*********************************************************************
166 *********************************************************************/
168 static bool ads_dns_parse_rr_srv( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
169 uint8
**ptr
, struct dns_rr_srv
*srv
)
173 char dcname
[MAX_DNS_NAME_LENGTH
];
176 if ( !start
|| !end
|| !srv
|| !*ptr
)
179 /* Parse the RR entry. Coming out of the this, ptr is at the beginning
180 of the next record */
182 if ( !ads_dns_parse_rr( ctx
, start
, end
, ptr
, &rr
) ) {
183 DEBUG(1,("ads_dns_parse_rr_srv: Failed to parse RR record\n"));
187 if ( rr
.type
!= T_SRV
) {
188 DEBUG(1,("ads_dns_parse_rr_srv: Bad answer type (%d)\n",
195 srv
->priority
= RSVAL(p
, 0);
196 srv
->weight
= RSVAL(p
, 2);
197 srv
->port
= RSVAL(p
, 4);
201 namelen
= dn_expand( start
, end
, p
, dcname
, sizeof(dcname
) );
203 DEBUG(1,("ads_dns_parse_rr_srv: Failed to uncompress name!\n"));
207 srv
->hostname
= talloc_strdup( ctx
, dcname
);
209 DEBUG(10,("ads_dns_parse_rr_srv: Parsed %s [%u, %u, %u]\n",
218 /*********************************************************************
219 *********************************************************************/
221 static bool ads_dns_parse_rr_ns( TALLOC_CTX
*ctx
, uint8
*start
, uint8
*end
,
222 uint8
**ptr
, struct dns_rr_ns
*nsrec
)
226 char nsname
[MAX_DNS_NAME_LENGTH
];
229 if ( !start
|| !end
|| !nsrec
|| !*ptr
)
232 /* Parse the RR entry. Coming out of the this, ptr is at the beginning
233 of the next record */
235 if ( !ads_dns_parse_rr( ctx
, start
, end
, ptr
, &rr
) ) {
236 DEBUG(1,("ads_dns_parse_rr_ns: Failed to parse RR record\n"));
240 if ( rr
.type
!= T_NS
) {
241 DEBUG(1,("ads_dns_parse_rr_ns: Bad answer type (%d)\n",
248 /* ame server hostname */
250 namelen
= dn_expand( start
, end
, p
, nsname
, sizeof(nsname
) );
252 DEBUG(1,("ads_dns_parse_rr_ns: Failed to uncompress name!\n"));
255 nsrec
->hostname
= talloc_strdup( ctx
, nsname
);
260 /*********************************************************************
261 Sort SRV record list based on weight and priority. See RFC 2782.
262 *********************************************************************/
264 static int dnssrvcmp( struct dns_rr_srv
*a
, struct dns_rr_srv
*b
)
266 if ( a
->priority
== b
->priority
) {
268 /* randomize entries with an equal weight and priority */
269 if ( a
->weight
== b
->weight
)
272 /* higher weights should be sorted lower */
273 if ( a
->weight
> b
->weight
)
279 if ( a
->priority
< b
->priority
)
285 /*********************************************************************
286 Simple wrapper for a DNS query
287 *********************************************************************/
289 #define DNS_FAILED_WAITTIME 30
291 static NTSTATUS
dns_send_req( TALLOC_CTX
*ctx
, const char *name
, int q_type
,
292 uint8
**buf
, int *resp_length
)
294 uint8
*buffer
= NULL
;
296 int resp_len
= NS_PACKETSZ
;
297 static time_t last_dns_check
= 0;
298 static NTSTATUS last_dns_status
= NT_STATUS_OK
;
299 time_t now
= time(NULL
);
301 /* Try to prevent bursts of DNS lookups if the server is down */
303 /* Protect against large clock changes */
305 if ( last_dns_check
> now
)
308 /* IF we had a DNS timeout or a bad server and we are still
309 in the 30 second cache window, just return the previous
310 status and save the network timeout. */
312 if ( (NT_STATUS_EQUAL(last_dns_status
,NT_STATUS_IO_TIMEOUT
) ||
313 NT_STATUS_EQUAL(last_dns_status
,NT_STATUS_CONNECTION_REFUSED
)) &&
314 (last_dns_check
+DNS_FAILED_WAITTIME
) > now
)
316 DEBUG(10,("last_dns_check: Returning cached status (%s)\n",
317 nt_errstr(last_dns_status
) ));
318 return last_dns_status
;
324 TALLOC_FREE( buffer
);
326 buf_len
= resp_len
* sizeof(uint8
);
329 if ((buffer
= TALLOC_ARRAY(ctx
, uint8
, buf_len
))
331 DEBUG(0,("ads_dns_lookup_srv: "
332 "talloc() failed!\n"));
333 last_dns_status
= NT_STATUS_NO_MEMORY
;
334 last_dns_check
= time(NULL
);
335 return last_dns_status
;
339 if ((resp_len
= res_query(name
, C_IN
, q_type
, buffer
, buf_len
))
341 DEBUG(3,("ads_dns_lookup_srv: "
342 "Failed to resolve %s (%s)\n",
343 name
, strerror(errno
)));
344 TALLOC_FREE( buffer
);
345 last_dns_status
= NT_STATUS_UNSUCCESSFUL
;
347 if (errno
== ETIMEDOUT
) {
348 last_dns_status
= NT_STATUS_IO_TIMEOUT
;
350 if (errno
== ECONNREFUSED
) {
351 last_dns_status
= NT_STATUS_CONNECTION_REFUSED
;
353 last_dns_check
= time(NULL
);
354 return last_dns_status
;
357 /* On AIX, Solaris, and possibly some older glibc systems (e.g. SLES8)
358 truncated replies never give back a resp_len > buflen
359 which ends up causing DNS resolve failures on large tcp DNS replies */
361 if (buf_len
== resp_len
) {
362 if (resp_len
== MAX_DNS_PACKET_SIZE
) {
363 DEBUG(1,("dns_send_req: DNS reply too large when resolving %s\n",
365 TALLOC_FREE( buffer
);
366 last_dns_status
= NT_STATUS_BUFFER_TOO_SMALL
;
367 last_dns_check
= time(NULL
);
368 return last_dns_status
;
371 resp_len
= MIN(resp_len
*2, MAX_DNS_PACKET_SIZE
);
375 } while ( buf_len
< resp_len
&& resp_len
<= MAX_DNS_PACKET_SIZE
);
378 *resp_length
= resp_len
;
380 last_dns_check
= time(NULL
);
381 last_dns_status
= NT_STATUS_OK
;
382 return last_dns_status
;
385 /*********************************************************************
386 Simple wrapper for a DNS SRV query
387 *********************************************************************/
389 static NTSTATUS
ads_dns_lookup_srv( TALLOC_CTX
*ctx
,
391 struct dns_rr_srv
**dclist
,
394 uint8
*buffer
= NULL
;
396 struct dns_rr_srv
*dcs
= NULL
;
397 int query_count
, answer_count
, auth_count
, additional_count
;
403 if ( !ctx
|| !name
|| !dclist
) {
404 return NT_STATUS_INVALID_PARAMETER
;
407 /* Send the request. May have to loop several times in case
410 status
= dns_send_req( ctx
, name
, T_SRV
, &buffer
, &resp_len
);
411 if ( !NT_STATUS_IS_OK(status
) ) {
412 DEBUG(3,("ads_dns_lookup_srv: Failed to send DNS query (%s)\n",
418 /* For some insane reason, the ns_initparse() et. al. routines are only
419 available in libresolv.a, and not the shared lib. Who knows why....
420 So we have to parse the DNS reply ourselves */
422 /* Pull the answer RR's count from the header.
423 * Use the NMB ordering macros */
425 query_count
= RSVAL( p
, 4 );
426 answer_count
= RSVAL( p
, 6 );
427 auth_count
= RSVAL( p
, 8 );
428 additional_count
= RSVAL( p
, 10 );
430 DEBUG(4,("ads_dns_lookup_srv: "
431 "%d records returned in the answer section.\n",
435 if ((dcs
= TALLOC_ZERO_ARRAY(ctx
, struct dns_rr_srv
,
436 answer_count
)) == NULL
) {
437 DEBUG(0,("ads_dns_lookup_srv: "
438 "talloc() failure for %d char*'s\n",
440 return NT_STATUS_NO_MEMORY
;
446 /* now skip the header */
450 /* parse the query section */
452 for ( rrnum
=0; rrnum
<query_count
; rrnum
++ ) {
455 if (!ads_dns_parse_query(ctx
, buffer
,
456 buffer
+resp_len
, &p
, &q
)) {
457 DEBUG(1,("ads_dns_lookup_srv: "
458 "Failed to parse query record [%d]!\n", rrnum
));
459 return NT_STATUS_UNSUCCESSFUL
;
463 /* now we are at the answer section */
465 for ( rrnum
=0; rrnum
<answer_count
; rrnum
++ ) {
466 if (!ads_dns_parse_rr_srv(ctx
, buffer
, buffer
+resp_len
,
468 DEBUG(1,("ads_dns_lookup_srv: "
469 "Failed to parse answer recordi [%d]!\n", rrnum
));
470 return NT_STATUS_UNSUCCESSFUL
;
475 /* Parse the authority section */
476 /* just skip these for now */
478 for ( rrnum
=0; rrnum
<auth_count
; rrnum
++ ) {
481 if (!ads_dns_parse_rr( ctx
, buffer
,
482 buffer
+resp_len
, &p
, &rr
)) {
483 DEBUG(1,("ads_dns_lookup_srv: "
484 "Failed to parse authority record! [%d]\n", rrnum
));
485 return NT_STATUS_UNSUCCESSFUL
;
489 /* Parse the additional records section */
491 for ( rrnum
=0; rrnum
<additional_count
; rrnum
++ ) {
495 if (!ads_dns_parse_rr(ctx
, buffer
, buffer
+resp_len
,
497 DEBUG(1,("ads_dns_lookup_srv: Failed "
498 "to parse additional records section! [%d]\n", rrnum
));
499 return NT_STATUS_UNSUCCESSFUL
;
502 /* Only interested in A or AAAA records as a shortcut for having
503 * to come back later and lookup the name. For multi-homed
504 * hosts, the number of additional records and exceed the
505 * number of answer records. */
507 if (rr
.type
!= T_A
|| rr
.rdatalen
!= 4) {
508 #if defined(HAVE_IPV6)
509 /* FIXME. RFC2874 defines A6 records. This
510 * requires recusive and horribly complex lookups.
511 * Bastards. Ignore this for now.... JRA.
513 if (rr
.type
!= T_AAAA
|| rr
.rdatalen
!= 16)
518 for ( i
=0; i
<idx
; i
++ ) {
519 if ( strcmp( rr
.hostname
, dcs
[i
].hostname
) == 0 ) {
520 int num_ips
= dcs
[i
].num_ips
;
521 struct sockaddr_storage
*tmp_ss_s
;
523 /* allocate new memory */
525 if (dcs
[i
].num_ips
== 0) {
526 if ((dcs
[i
].ss_s
= TALLOC_ARRAY(dcs
,
527 struct sockaddr_storage
, 1 ))
529 return NT_STATUS_NO_MEMORY
;
532 if ((tmp_ss_s
= TALLOC_REALLOC_ARRAY(dcs
,
534 struct sockaddr_storage
,
537 return NT_STATUS_NO_MEMORY
;
540 dcs
[i
].ss_s
= tmp_ss_s
;
544 /* copy the new IP address */
545 if (rr
.type
== T_A
) {
547 memcpy(&ip
, rr
.rdata
, 4);
548 in_addr_to_sockaddr_storage(
549 &dcs
[i
].ss_s
[num_ips
],
552 #if defined(HAVE_IPV6)
553 if (rr
.type
== T_AAAA
) {
555 memcpy(&ip6
, rr
.rdata
, rr
.rdatalen
);
556 in6_addr_to_sockaddr_storage(
557 &dcs
[i
].ss_s
[num_ips
],
565 qsort( dcs
, idx
, sizeof(struct dns_rr_srv
), QSORT_CAST dnssrvcmp
);
573 /*********************************************************************
574 Simple wrapper for a DNS NS query
575 *********************************************************************/
577 NTSTATUS
ads_dns_lookup_ns(TALLOC_CTX
*ctx
,
578 const char *dnsdomain
,
579 struct dns_rr_ns
**nslist
,
582 uint8
*buffer
= NULL
;
584 struct dns_rr_ns
*nsarray
= NULL
;
585 int query_count
, answer_count
, auth_count
, additional_count
;
591 if ( !ctx
|| !dnsdomain
|| !nslist
) {
592 return NT_STATUS_INVALID_PARAMETER
;
595 /* Send the request. May have to loop several times in case
598 status
= dns_send_req( ctx
, dnsdomain
, T_NS
, &buffer
, &resp_len
);
599 if ( !NT_STATUS_IS_OK(status
) ) {
600 DEBUG(3,("ads_dns_lookup_ns: Failed to send DNS query (%s)\n",
606 /* For some insane reason, the ns_initparse() et. al. routines are only
607 available in libresolv.a, and not the shared lib. Who knows why....
608 So we have to parse the DNS reply ourselves */
610 /* Pull the answer RR's count from the header.
611 * Use the NMB ordering macros */
613 query_count
= RSVAL( p
, 4 );
614 answer_count
= RSVAL( p
, 6 );
615 auth_count
= RSVAL( p
, 8 );
616 additional_count
= RSVAL( p
, 10 );
618 DEBUG(4,("ads_dns_lookup_ns: "
619 "%d records returned in the answer section.\n",
623 if ((nsarray
= TALLOC_ARRAY(ctx
, struct dns_rr_ns
,
624 answer_count
)) == NULL
) {
625 DEBUG(0,("ads_dns_lookup_ns: "
626 "talloc() failure for %d char*'s\n",
628 return NT_STATUS_NO_MEMORY
;
634 /* now skip the header */
638 /* parse the query section */
640 for ( rrnum
=0; rrnum
<query_count
; rrnum
++ ) {
643 if (!ads_dns_parse_query(ctx
, buffer
, buffer
+resp_len
,
645 DEBUG(1,("ads_dns_lookup_ns: "
646 " Failed to parse query record!\n"));
647 return NT_STATUS_UNSUCCESSFUL
;
651 /* now we are at the answer section */
653 for ( rrnum
=0; rrnum
<answer_count
; rrnum
++ ) {
654 if (!ads_dns_parse_rr_ns(ctx
, buffer
, buffer
+resp_len
,
655 &p
, &nsarray
[rrnum
])) {
656 DEBUG(1,("ads_dns_lookup_ns: "
657 "Failed to parse answer record!\n"));
658 return NT_STATUS_UNSUCCESSFUL
;
663 /* Parse the authority section */
664 /* just skip these for now */
666 for ( rrnum
=0; rrnum
<auth_count
; rrnum
++ ) {
669 if ( !ads_dns_parse_rr(ctx
, buffer
, buffer
+resp_len
,
671 DEBUG(1,("ads_dns_lookup_ns: "
672 "Failed to parse authority record!\n"));
673 return NT_STATUS_UNSUCCESSFUL
;
677 /* Parse the additional records section */
679 for ( rrnum
=0; rrnum
<additional_count
; rrnum
++ ) {
683 if (!ads_dns_parse_rr(ctx
, buffer
, buffer
+resp_len
,
685 DEBUG(1,("ads_dns_lookup_ns: Failed "
686 "to parse additional records section!\n"));
687 return NT_STATUS_UNSUCCESSFUL
;
690 /* only interested in A records as a shortcut for having to come
691 back later and lookup the name */
693 if (rr
.type
!= T_A
|| rr
.rdatalen
!= 4) {
694 #if defined(HAVE_IPV6)
695 if (rr
.type
!= T_AAAA
|| rr
.rdatalen
!= 16)
700 for ( i
=0; i
<idx
; i
++ ) {
701 if (strcmp(rr
.hostname
, nsarray
[i
].hostname
) == 0) {
702 if (rr
.type
== T_A
) {
704 memcpy(&ip
, rr
.rdata
, 4);
705 in_addr_to_sockaddr_storage(
709 #if defined(HAVE_IPV6)
710 if (rr
.type
== T_AAAA
) {
712 memcpy(&ip6
, rr
.rdata
, rr
.rdatalen
);
713 in6_addr_to_sockaddr_storage(
728 /****************************************************************************
729 Store and fetch the AD client sitename.
730 ****************************************************************************/
732 #define SITENAME_KEY "AD_SITENAME/DOMAIN/%s"
734 static char *sitename_key(const char *realm
)
738 if (asprintf_strupper_m(&keystr
, SITENAME_KEY
, realm
) == -1) {
746 /****************************************************************************
747 Store the AD client sitename.
748 We store indefinately as every new CLDAP query will re-write this.
749 ****************************************************************************/
751 bool sitename_store(const char *realm
, const char *sitename
)
757 if (!realm
|| (strlen(realm
) == 0)) {
758 DEBUG(0,("sitename_store: no realm\n"));
762 key
= sitename_key(realm
);
764 if (!sitename
|| (sitename
&& !*sitename
)) {
765 DEBUG(5,("sitename_store: deleting empty sitename!\n"));
766 ret
= gencache_del(key
);
771 expire
= get_time_t_max(); /* Store indefinately. */
773 DEBUG(10,("sitename_store: realm = [%s], sitename = [%s], expire = [%u]\n",
774 realm
, sitename
, (unsigned int)expire
));
776 ret
= gencache_set( key
, sitename
, expire
);
781 /****************************************************************************
782 Fetch the AD client sitename.
784 ****************************************************************************/
786 char *sitename_fetch(const char *realm
)
788 char *sitename
= NULL
;
791 const char *query_realm
;
794 if (!realm
|| (strlen(realm
) == 0)) {
795 query_realm
= lp_realm();
800 key
= sitename_key(query_realm
);
802 ret
= gencache_get( key
, &sitename
, &timeout
);
805 DEBUG(5,("sitename_fetch: No stored sitename for %s\n",
808 DEBUG(5,("sitename_fetch: Returning sitename for %s: \"%s\"\n",
809 query_realm
, sitename
));
814 /****************************************************************************
815 Did the sitename change ?
816 ****************************************************************************/
818 bool stored_sitename_changed(const char *realm
, const char *sitename
)
824 if (!realm
|| (strlen(realm
) == 0)) {
825 DEBUG(0,("stored_sitename_changed: no realm\n"));
829 new_sitename
= sitename_fetch(realm
);
831 if (sitename
&& new_sitename
&& !strequal(sitename
, new_sitename
)) {
833 } else if ((sitename
&& !new_sitename
) ||
834 (!sitename
&& new_sitename
)) {
837 SAFE_FREE(new_sitename
);
841 /********************************************************************
842 Query with optional sitename.
843 ********************************************************************/
845 static NTSTATUS
ads_dns_query_internal(TALLOC_CTX
*ctx
,
846 const char *servicename
,
847 const char *dc_pdc_gc_domains
,
849 const char *sitename
,
850 struct dns_rr_srv
**dclist
,
855 name
= talloc_asprintf(ctx
, "%s._tcp.%s._sites.%s._msdcs.%s",
856 servicename
, sitename
,
857 dc_pdc_gc_domains
, realm
);
859 name
= talloc_asprintf(ctx
, "%s._tcp.%s._msdcs.%s",
860 servicename
, dc_pdc_gc_domains
, realm
);
863 return NT_STATUS_NO_MEMORY
;
865 return ads_dns_lookup_srv( ctx
, name
, dclist
, numdcs
);
868 /********************************************************************
870 ********************************************************************/
872 NTSTATUS
ads_dns_query_dcs(TALLOC_CTX
*ctx
,
874 const char *sitename
,
875 struct dns_rr_srv
**dclist
,
880 status
= ads_dns_query_internal(ctx
, "_ldap", "dc", realm
, sitename
,
883 if (NT_STATUS_EQUAL(status
, NT_STATUS_IO_TIMEOUT
) ||
884 NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_REFUSED
)) {
889 ((!NT_STATUS_IS_OK(status
)) ||
890 (NT_STATUS_IS_OK(status
) && (numdcs
== 0)))) {
891 /* Sitename DNS query may have failed. Try without. */
892 status
= ads_dns_query_internal(ctx
, "_ldap", "dc", realm
,
893 NULL
, dclist
, numdcs
);
898 /********************************************************************
900 ********************************************************************/
902 NTSTATUS
ads_dns_query_gcs(TALLOC_CTX
*ctx
,
904 const char *sitename
,
905 struct dns_rr_srv
**dclist
,
910 status
= ads_dns_query_internal(ctx
, "_ldap", "gc", realm
, sitename
,
913 if (NT_STATUS_EQUAL(status
, NT_STATUS_IO_TIMEOUT
) ||
914 NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_REFUSED
)) {
919 ((!NT_STATUS_IS_OK(status
)) ||
920 (NT_STATUS_IS_OK(status
) && (numdcs
== 0)))) {
921 /* Sitename DNS query may have failed. Try without. */
922 status
= ads_dns_query_internal(ctx
, "_ldap", "gc", realm
,
923 NULL
, dclist
, numdcs
);
928 /********************************************************************
930 Even if our underlying kerberos libraries are UDP only, this
931 is pretty safe as it's unlikely that a KDC supports TCP and not UDP.
932 ********************************************************************/
934 NTSTATUS
ads_dns_query_kdcs(TALLOC_CTX
*ctx
,
935 const char *dns_forest_name
,
936 const char *sitename
,
937 struct dns_rr_srv
**dclist
,
942 status
= ads_dns_query_internal(ctx
, "_kerberos", "dc",
943 dns_forest_name
, sitename
, dclist
,
946 if (NT_STATUS_EQUAL(status
, NT_STATUS_IO_TIMEOUT
) ||
947 NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_REFUSED
)) {
952 ((!NT_STATUS_IS_OK(status
)) ||
953 (NT_STATUS_IS_OK(status
) && (numdcs
== 0)))) {
954 /* Sitename DNS query may have failed. Try without. */
955 status
= ads_dns_query_internal(ctx
, "_kerberos", "dc",
956 dns_forest_name
, NULL
,
962 /********************************************************************
963 Query for AD PDC. Sitename is obsolete here.
964 ********************************************************************/
966 NTSTATUS
ads_dns_query_pdc(TALLOC_CTX
*ctx
,
967 const char *dns_domain_name
,
968 struct dns_rr_srv
**dclist
,
971 return ads_dns_query_internal(ctx
, "_ldap", "pdc", dns_domain_name
,
972 NULL
, dclist
, numdcs
);
975 /********************************************************************
976 Query for AD DC by guid. Sitename is obsolete here.
977 ********************************************************************/
979 NTSTATUS
ads_dns_query_dcs_guid(TALLOC_CTX
*ctx
,
980 const char *dns_forest_name
,
981 const struct GUID
*domain_guid
,
982 struct dns_rr_srv
**dclist
,
985 /*_ldap._tcp.DomainGuid.domains._msdcs.DnsForestName */
990 guid_string
= GUID_string(ctx
, domain_guid
);
992 return NT_STATUS_NO_MEMORY
;
996 domains
= talloc_asprintf(ctx
, "%s.domains", guid_string
);
998 return NT_STATUS_NO_MEMORY
;
1000 TALLOC_FREE(guid_string
);
1002 return ads_dns_query_internal(ctx
, "_ldap", domains
, dns_forest_name
,
1003 NULL
, dclist
, numdcs
);