r22928: Use better success error code.
[Samba/gebeck_regimport.git] / source / libads / dns.c
blobe0e696c99c97c822be95b0c589982d05f18c595e
1 /*
2 Unix SMB/CIFS implementation.
3 DNS utility library
4 Copyright (C) Gerald (Jerry) Carter 2006.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 /* AIX resolv.h uses 'class' in struct ns_rr */
25 #if defined(AIX)
26 # if defined(class)
27 # undef class
28 # endif
29 #endif /* AIX */
31 /* resolver headers */
33 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <arpa/nameser.h>
36 #include <resolv.h>
37 #include <netdb.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 */
43 # define C_IN ns_c_in
44 #endif
45 #if !defined(T_A) /* AIX 5.3 already defines T_A */
46 # define T_A ns_t_a
47 #endif
48 # define T_SRV ns_t_srv
49 #if !defined(T_NS) /* AIX 5.3 already defines T_NS */
50 # define T_NS ns_t_ns
51 #endif
52 #else
53 # ifdef HFIXEDSZ
54 # define NS_HFIXEDSZ HFIXEDSZ
55 # else
56 # define NS_HFIXEDSZ sizeof(HEADER)
57 # endif /* HFIXEDSZ */
58 # ifdef PACKETSZ
59 # define NS_PACKETSZ PACKETSZ
60 # else /* 512 is usually the default */
61 # define NS_PACKETSZ 512
62 # endif /* PACKETSZ */
63 # define T_SRV 33
64 #endif
66 /*********************************************************************
67 *********************************************************************/
69 static BOOL ads_dns_parse_query( TALLOC_CTX *ctx, uint8 *start, uint8 *end,
70 uint8 **ptr, struct dns_query *q )
72 uint8 *p = *ptr;
73 pstring hostname;
74 int namelen;
76 ZERO_STRUCTP( q );
78 if ( !start || !end || !q || !*ptr)
79 return False;
81 /* See RFC 1035 for details. If this fails, then return. */
83 namelen = dn_expand( start, end, p, hostname, sizeof(hostname) );
84 if ( namelen < 0 ) {
85 return False;
87 p += namelen;
88 q->hostname = talloc_strdup( ctx, hostname );
90 /* check that we have space remaining */
92 if ( PTR_DIFF(p+4, end) > 0 )
93 return False;
95 q->type = RSVAL( p, 0 );
96 q->in_class = RSVAL( p, 2 );
97 p += 4;
99 *ptr = p;
101 return True;
104 /*********************************************************************
105 *********************************************************************/
107 static BOOL ads_dns_parse_rr( TALLOC_CTX *ctx, uint8 *start, uint8 *end,
108 uint8 **ptr, struct dns_rr *rr )
110 uint8 *p = *ptr;
111 pstring hostname;
112 int namelen;
114 if ( !start || !end || !rr || !*ptr)
115 return -1;
117 ZERO_STRUCTP( rr );
118 /* pull the name from the answer */
120 namelen = dn_expand( start, end, p, hostname, sizeof(hostname) );
121 if ( namelen < 0 ) {
122 return -1;
124 p += namelen;
125 rr->hostname = talloc_strdup( ctx, hostname );
127 /* check that we have space remaining */
129 if ( PTR_DIFF(p+10, end) > 0 )
130 return False;
132 /* pull some values and then skip onto the string */
134 rr->type = RSVAL(p, 0);
135 rr->in_class = RSVAL(p, 2);
136 rr->ttl = RIVAL(p, 4);
137 rr->rdatalen = RSVAL(p, 8);
139 p += 10;
141 /* sanity check the available space */
143 if ( PTR_DIFF(p+rr->rdatalen, end ) > 0 ) {
144 return False;
148 /* save a point to the rdata for this section */
150 rr->rdata = p;
151 p += rr->rdatalen;
153 *ptr = p;
155 return True;
158 /*********************************************************************
159 *********************************************************************/
161 static BOOL ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end,
162 uint8 **ptr, struct dns_rr_srv *srv )
164 struct dns_rr rr;
165 uint8 *p;
166 pstring dcname;
167 int namelen;
169 if ( !start || !end || !srv || !*ptr)
170 return -1;
172 /* Parse the RR entry. Coming out of the this, ptr is at the beginning
173 of the next record */
175 if ( !ads_dns_parse_rr( ctx, start, end, ptr, &rr ) ) {
176 DEBUG(1,("ads_dns_parse_rr_srv: Failed to parse RR record\n"));
177 return False;
180 if ( rr.type != T_SRV ) {
181 DEBUG(1,("ads_dns_parse_rr_srv: Bad answer type (%d)\n", rr.type));
182 return False;
185 p = rr.rdata;
187 srv->priority = RSVAL(p, 0);
188 srv->weight = RSVAL(p, 2);
189 srv->port = RSVAL(p, 4);
191 p += 6;
193 namelen = dn_expand( start, end, p, dcname, sizeof(dcname) );
194 if ( namelen < 0 ) {
195 DEBUG(1,("ads_dns_parse_rr_srv: Failed to uncompress name!\n"));
196 return False;
198 srv->hostname = talloc_strdup( ctx, dcname );
200 return True;
203 /*********************************************************************
204 *********************************************************************/
206 static BOOL ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end,
207 uint8 **ptr, struct dns_rr_ns *nsrec )
209 struct dns_rr rr;
210 uint8 *p;
211 pstring nsname;
212 int namelen;
214 if ( !start || !end || !nsrec || !*ptr)
215 return -1;
217 /* Parse the RR entry. Coming out of the this, ptr is at the beginning
218 of the next record */
220 if ( !ads_dns_parse_rr( ctx, start, end, ptr, &rr ) ) {
221 DEBUG(1,("ads_dns_parse_rr_ns: Failed to parse RR record\n"));
222 return False;
225 if ( rr.type != T_NS ) {
226 DEBUG(1,("ads_dns_parse_rr_ns: Bad answer type (%d)\n", rr.type));
227 return False;
230 p = rr.rdata;
232 /* ame server hostname */
234 namelen = dn_expand( start, end, p, nsname, sizeof(nsname) );
235 if ( namelen < 0 ) {
236 DEBUG(1,("ads_dns_parse_rr_ns: Failed to uncompress name!\n"));
237 return False;
239 nsrec->hostname = talloc_strdup( ctx, nsname );
241 return True;
244 /*********************************************************************
245 Sort SRV record list based on weight and priority. See RFC 2782.
246 *********************************************************************/
248 static int dnssrvcmp( struct dns_rr_srv *a, struct dns_rr_srv *b )
250 if ( a->priority == b->priority ) {
252 /* randomize entries with an equal weight and priority */
253 if ( a->weight == b->weight )
254 return 0;
256 /* higher weights should be sorted lower */
257 if ( a->weight > b->weight )
258 return -1;
259 else
260 return 1;
263 if ( a->priority < b->priority )
264 return -1;
266 return 1;
269 /*********************************************************************
270 Simple wrapper for a DNS query
271 *********************************************************************/
273 #define DNS_FAILED_WAITTIME 30
275 static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type,
276 uint8 **buf, int *resp_length )
278 uint8 *buffer = NULL;
279 size_t buf_len;
280 int resp_len = NS_PACKETSZ;
281 static time_t last_dns_check = 0;
282 static NTSTATUS last_dns_status = NT_STATUS_OK;
283 time_t now = time(NULL);
285 /* Try to prevent bursts of DNS lookups if the server is down */
287 /* Protect against large clock changes */
289 if ( last_dns_check > now )
290 last_dns_check = 0;
292 /* IF we had a DNS timeout or a bad server and we are still
293 in the 30 second cache window, just return the previous
294 status and save the network timeout. */
296 if ( (NT_STATUS_EQUAL(last_dns_status,NT_STATUS_IO_TIMEOUT) ||
297 NT_STATUS_EQUAL(last_dns_status,NT_STATUS_CONNECTION_REFUSED)) &&
298 (last_dns_check+DNS_FAILED_WAITTIME) > now )
300 DEBUG(10,("last_dns_check: Returning cached status (%s)\n",
301 nt_errstr(last_dns_status) ));
302 return last_dns_status;
305 /* Send the Query */
306 do {
307 if ( buffer )
308 TALLOC_FREE( buffer );
310 buf_len = resp_len * sizeof(uint8);
312 if (buf_len) {
313 if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) {
314 DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n"));
315 last_dns_status = NT_STATUS_NO_MEMORY;
316 last_dns_check = time(NULL);
317 return last_dns_status;
321 if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) {
322 DEBUG(3,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno)));
323 TALLOC_FREE( buffer );
324 last_dns_status = NT_STATUS_UNSUCCESSFUL;
326 if (errno == ETIMEDOUT) {
327 last_dns_status = NT_STATUS_IO_TIMEOUT;
329 if (errno == ECONNREFUSED) {
330 last_dns_status = NT_STATUS_CONNECTION_REFUSED;
332 last_dns_check = time(NULL);
333 return last_dns_status;
335 } while ( buf_len < resp_len && resp_len < MAX_DNS_PACKET_SIZE );
337 *buf = buffer;
338 *resp_length = resp_len;
340 last_dns_check = time(NULL);
341 last_dns_status = NT_STATUS_OK;
342 return last_dns_status;
345 /*********************************************************************
346 Simple wrapper for a DNS SRV query
347 *********************************************************************/
349 static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_srv **dclist, int *numdcs )
351 uint8 *buffer = NULL;
352 int resp_len = 0;
353 struct dns_rr_srv *dcs = NULL;
354 int query_count, answer_count, auth_count, additional_count;
355 uint8 *p = buffer;
356 int rrnum;
357 int idx = 0;
358 NTSTATUS status;
360 if ( !ctx || !name || !dclist ) {
361 return NT_STATUS_INVALID_PARAMETER;
364 /* Send the request. May have to loop several times in case
365 of large replies */
367 status = dns_send_req( ctx, name, T_SRV, &buffer, &resp_len );
368 if ( !NT_STATUS_IS_OK(status) ) {
369 DEBUG(3,("ads_dns_lookup_srv: Failed to send DNS query (%s)\n",
370 nt_errstr(status)));
371 return status;
373 p = buffer;
375 /* For some insane reason, the ns_initparse() et. al. routines are only
376 available in libresolv.a, and not the shared lib. Who knows why....
377 So we have to parse the DNS reply ourselves */
379 /* Pull the answer RR's count from the header. Use the NMB ordering macros */
381 query_count = RSVAL( p, 4 );
382 answer_count = RSVAL( p, 6 );
383 auth_count = RSVAL( p, 8 );
384 additional_count = RSVAL( p, 10 );
386 DEBUG(4,("ads_dns_lookup_srv: %d records returned in the answer section.\n",
387 answer_count));
389 if (answer_count) {
390 if ( (dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) {
391 DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n",
392 answer_count));
393 return NT_STATUS_NO_MEMORY;
395 } else {
396 dcs = NULL;
399 /* now skip the header */
401 p += NS_HFIXEDSZ;
403 /* parse the query section */
405 for ( rrnum=0; rrnum<query_count; rrnum++ ) {
406 struct dns_query q;
408 if ( !ads_dns_parse_query( ctx, buffer, buffer+resp_len, &p, &q ) ) {
409 DEBUG(1,("ads_dns_lookup_srv: Failed to parse query record!\n"));
410 return NT_STATUS_UNSUCCESSFUL;
414 /* now we are at the answer section */
416 for ( rrnum=0; rrnum<answer_count; rrnum++ ) {
417 if ( !ads_dns_parse_rr_srv( ctx, buffer, buffer+resp_len, &p, &dcs[rrnum] ) ) {
418 DEBUG(1,("ads_dns_lookup_srv: Failed to parse answer record!\n"));
419 return NT_STATUS_UNSUCCESSFUL;
422 idx = rrnum;
424 /* Parse the authority section */
425 /* just skip these for now */
427 for ( rrnum=0; rrnum<auth_count; rrnum++ ) {
428 struct dns_rr rr;
430 if ( !ads_dns_parse_rr( ctx, buffer, buffer+resp_len, &p, &rr ) ) {
431 DEBUG(1,("ads_dns_lookup_srv: Failed to parse authority record!\n"));
432 return NT_STATUS_UNSUCCESSFUL;
436 /* Parse the additional records section */
438 for ( rrnum=0; rrnum<additional_count; rrnum++ ) {
439 struct dns_rr rr;
440 int i;
442 if ( !ads_dns_parse_rr( ctx, buffer, buffer+resp_len, &p, &rr ) ) {
443 DEBUG(1,("ads_dns_lookup_srv: Failed to parse additional records section!\n"));
444 return NT_STATUS_UNSUCCESSFUL;
447 /* only interested in A records as a shortcut for having to come
448 back later and lookup the name. For multi-homed hosts, the
449 number of additional records and exceed the number of answer
450 records. */
453 if ( (rr.type != T_A) || (rr.rdatalen != 4) )
454 continue;
456 for ( i=0; i<idx; i++ ) {
457 if ( strcmp( rr.hostname, dcs[i].hostname ) == 0 ) {
458 int num_ips = dcs[i].num_ips;
459 uint8 *buf;
460 struct in_addr *tmp_ips;
462 /* allocate new memory */
464 if ( dcs[i].num_ips == 0 ) {
465 if ( (dcs[i].ips = TALLOC_ARRAY( dcs,
466 struct in_addr, 1 )) == NULL )
468 return NT_STATUS_NO_MEMORY;
470 } else {
471 if ( (tmp_ips = TALLOC_REALLOC_ARRAY( dcs, dcs[i].ips,
472 struct in_addr, dcs[i].num_ips+1)) == NULL )
474 return NT_STATUS_NO_MEMORY;
477 dcs[i].ips = tmp_ips;
479 dcs[i].num_ips++;
481 /* copy the new IP address */
483 buf = (uint8*)&dcs[i].ips[num_ips].s_addr;
484 memcpy( buf, rr.rdata, 4 );
489 qsort( dcs, idx, sizeof(struct dns_rr_srv), QSORT_CAST dnssrvcmp );
491 *dclist = dcs;
492 *numdcs = idx;
494 return NT_STATUS_OK;
497 /*********************************************************************
498 Simple wrapper for a DNS NS query
499 *********************************************************************/
501 NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_rr_ns **nslist, int *numns )
503 uint8 *buffer = NULL;
504 int resp_len = 0;
505 struct dns_rr_ns *nsarray = NULL;
506 int query_count, answer_count, auth_count, additional_count;
507 uint8 *p;
508 int rrnum;
509 int idx = 0;
510 NTSTATUS status;
512 if ( !ctx || !dnsdomain || !nslist ) {
513 return NT_STATUS_INVALID_PARAMETER;
516 /* Send the request. May have to loop several times in case
517 of large replies */
519 status = dns_send_req( ctx, dnsdomain, T_NS, &buffer, &resp_len );
520 if ( !NT_STATUS_IS_OK(status) ) {
521 DEBUG(3,("ads_dns_lookup_ns: Failed to send DNS query (%s)\n",
522 nt_errstr(status)));
523 return status;
525 p = buffer;
527 /* For some insane reason, the ns_initparse() et. al. routines are only
528 available in libresolv.a, and not the shared lib. Who knows why....
529 So we have to parse the DNS reply ourselves */
531 /* Pull the answer RR's count from the header. Use the NMB ordering macros */
533 query_count = RSVAL( p, 4 );
534 answer_count = RSVAL( p, 6 );
535 auth_count = RSVAL( p, 8 );
536 additional_count = RSVAL( p, 10 );
538 DEBUG(4,("ads_dns_lookup_ns: %d records returned in the answer section.\n",
539 answer_count));
541 if (answer_count) {
542 if ( (nsarray = TALLOC_ARRAY(ctx, struct dns_rr_ns, answer_count)) == NULL ) {
543 DEBUG(0,("ads_dns_lookup_ns: talloc() failure for %d char*'s\n",
544 answer_count));
545 return NT_STATUS_NO_MEMORY;
547 } else {
548 nsarray = NULL;
551 /* now skip the header */
553 p += NS_HFIXEDSZ;
555 /* parse the query section */
557 for ( rrnum=0; rrnum<query_count; rrnum++ ) {
558 struct dns_query q;
560 if ( !ads_dns_parse_query( ctx, buffer, buffer+resp_len, &p, &q ) ) {
561 DEBUG(1,("ads_dns_lookup_ns: Failed to parse query record!\n"));
562 return NT_STATUS_UNSUCCESSFUL;
566 /* now we are at the answer section */
568 for ( rrnum=0; rrnum<answer_count; rrnum++ ) {
569 if ( !ads_dns_parse_rr_ns( ctx, buffer, buffer+resp_len, &p, &nsarray[rrnum] ) ) {
570 DEBUG(1,("ads_dns_lookup_ns: Failed to parse answer record!\n"));
571 return NT_STATUS_UNSUCCESSFUL;
574 idx = rrnum;
576 /* Parse the authority section */
577 /* just skip these for now */
579 for ( rrnum=0; rrnum<auth_count; rrnum++ ) {
580 struct dns_rr rr;
582 if ( !ads_dns_parse_rr( ctx, buffer, buffer+resp_len, &p, &rr ) ) {
583 DEBUG(1,("ads_dns_lookup_ns: Failed to parse authority record!\n"));
584 return NT_STATUS_UNSUCCESSFUL;
588 /* Parse the additional records section */
590 for ( rrnum=0; rrnum<additional_count; rrnum++ ) {
591 struct dns_rr rr;
592 int i;
594 if ( !ads_dns_parse_rr( ctx, buffer, buffer+resp_len, &p, &rr ) ) {
595 DEBUG(1,("ads_dns_lookup_ns: Failed to parse additional records section!\n"));
596 return NT_STATUS_UNSUCCESSFUL;
599 /* only interested in A records as a shortcut for having to come
600 back later and lookup the name */
602 if ( (rr.type != T_A) || (rr.rdatalen != 4) )
603 continue;
605 for ( i=0; i<idx; i++ ) {
606 if ( strcmp( rr.hostname, nsarray[i].hostname ) == 0 ) {
607 uint8 *buf = (uint8*)&nsarray[i].ip.s_addr;
608 memcpy( buf, rr.rdata, 4 );
613 *nslist = nsarray;
614 *numns = idx;
616 return NT_STATUS_OK;
619 /****************************************************************************
620 Store and fetch the AD client sitename.
621 ****************************************************************************/
623 #define SITENAME_KEY "AD_SITENAME/DOMAIN/%s"
625 static char *sitename_key(const char *realm)
627 char *keystr;
629 if (asprintf(&keystr, SITENAME_KEY, strupper_static(realm)) == -1) {
630 return NULL;
633 return keystr;
637 /****************************************************************************
638 Store the AD client sitename.
639 We store indefinately as every new CLDAP query will re-write this.
640 If the sitename is "Default-First-Site-Name" we don't store it
641 as this isn't a valid DNS name.
642 ****************************************************************************/
644 BOOL sitename_store(const char *realm, const char *sitename)
646 time_t expire;
647 BOOL ret = False;
648 char *key;
650 if (!gencache_init()) {
651 return False;
654 if (!realm || (strlen(realm) == 0)) {
655 DEBUG(0,("no realm\n"));
656 return False;
659 key = sitename_key(realm);
661 if (!sitename || (sitename && !*sitename)) {
662 DEBUG(5,("sitename_store: deleting empty sitename!\n"));
663 ret = gencache_del(key);
664 SAFE_FREE(key);
665 return ret;
668 expire = get_time_t_max(); /* Store indefinately. */
670 DEBUG(10,("sitename_store: realm = [%s], sitename = [%s], expire = [%u]\n",
671 realm, sitename, (unsigned int)expire ));
673 ret = gencache_set( key, sitename, expire );
674 SAFE_FREE(key);
675 return ret;
678 /****************************************************************************
679 Fetch the AD client sitename.
680 Caller must free.
681 ****************************************************************************/
683 char *sitename_fetch(const char *realm)
685 char *sitename = NULL;
686 time_t timeout;
687 BOOL ret = False;
688 const char *query_realm;
689 char *key;
691 if (!gencache_init()) {
692 return False;
695 if (!realm || (strlen(realm) == 0)) {
696 query_realm = lp_realm();
697 } else {
698 query_realm = realm;
701 key = sitename_key(query_realm);
703 ret = gencache_get( key, &sitename, &timeout );
704 SAFE_FREE(key);
705 if ( !ret ) {
706 DEBUG(5,("sitename_fetch: No stored sitename for %s\n",
707 query_realm));
708 } else {
709 DEBUG(5,("sitename_fetch: Returning sitename for %s: \"%s\"\n",
710 query_realm, sitename ));
712 return sitename;
715 /****************************************************************************
716 Did the sitename change ?
717 ****************************************************************************/
719 BOOL stored_sitename_changed(const char *realm, const char *sitename)
721 BOOL ret = False;
723 char *new_sitename;
725 if (!realm || (strlen(realm) == 0)) {
726 DEBUG(0,("no realm\n"));
727 return False;
730 new_sitename = sitename_fetch(realm);
732 if (sitename && new_sitename && !strequal(sitename, new_sitename)) {
733 ret = True;
734 } else if ((sitename && !new_sitename) ||
735 (!sitename && new_sitename)) {
736 ret = True;
738 SAFE_FREE(new_sitename);
739 return ret;
742 /********************************************************************
743 Query with optional sitename.
744 ********************************************************************/
746 NTSTATUS ads_dns_query_internal(TALLOC_CTX *ctx,
747 const char *servicename,
748 const char *realm,
749 const char *sitename,
750 struct dns_rr_srv **dclist,
751 int *numdcs )
753 char *name;
754 if (sitename) {
755 name = talloc_asprintf(ctx, "%s._tcp.%s._sites.dc._msdcs.%s",
756 servicename, sitename, realm );
757 } else {
758 name = talloc_asprintf(ctx, "%s._tcp.dc._msdcs.%s",
759 servicename, realm );
761 if (!name) {
762 return NT_STATUS_NO_MEMORY;
764 return ads_dns_lookup_srv( ctx, name, dclist, numdcs );
767 /********************************************************************
768 Query for AD DC's.
769 ********************************************************************/
771 NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx,
772 const char *realm,
773 const char *sitename,
774 struct dns_rr_srv **dclist,
775 int *numdcs )
777 NTSTATUS status;
779 status = ads_dns_query_internal(ctx, "_ldap", realm, sitename,
780 dclist, numdcs);
782 if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) ||
783 NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_REFUSED)) {
784 return status;
787 if (sitename && !NT_STATUS_IS_OK(status)) {
788 /* Sitename DNS query may have failed. Try without. */
789 status = ads_dns_query_internal(ctx, "_ldap", realm, NULL,
790 dclist, numdcs);
792 return status;
795 /********************************************************************
796 Query for AD KDC's.
797 Even if our underlying kerberos libraries are UDP only, this
798 is pretty safe as it's unlikely that a KDC supports TCP and not UDP.
799 ********************************************************************/
801 NTSTATUS ads_dns_query_kdcs(TALLOC_CTX *ctx,
802 const char *realm,
803 const char *sitename,
804 struct dns_rr_srv **dclist,
805 int *numdcs )
807 NTSTATUS status;
809 status = ads_dns_query_internal(ctx, "_kerberos", realm, sitename,
810 dclist, numdcs);
812 if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) ||
813 NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_REFUSED)) {
814 return status;
817 if (sitename && !NT_STATUS_IS_OK(status)) {
818 /* Sitename DNS query may have failed. Try without. */
819 status = ads_dns_query_internal(ctx, "_kerberos", realm, NULL,
820 dclist, numdcs);
822 return status;