From af086da4ec19de83717820de85d8e672850ed4b2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 5 May 2006 19:24:48 +0000 Subject: r15462: replace the use of OpenLDAP's ldap_domain2hostlist() for locating AD DC's with out own DNS SRV queries. Testing on Linux and Solaris. (This used to be commit cf71f88a3cdcabf99c0798ef4cf8c978397a57eb) --- source3/libads/dns.c | 353 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 source3/libads/dns.c (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c new file mode 100644 index 0000000000..0119ae9130 --- /dev/null +++ b/source3/libads/dns.c @@ -0,0 +1,353 @@ +/* + Unix SMB/CIFS implementation. + DNS utility library + Copyright (C) Gerald (Jerry) Carter 2006. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* AIX resolv.h uses 'class' in struct ns_rr */ + +#if defined(AIX) +# if defined(class) +# undef class +# endif +#endif /* AIX */ + +/* resolver headers */ + +#include +#include +#include +#include +#include + +#define MAX_DNS_PACKET_SIZE 0xffff + +/********************************************************************* +*********************************************************************/ + +static BOOL ads_dns_parse_query( TALLOC_CTX *ctx, uint8 *start, uint8 *end, + uint8 **ptr, struct dns_query *q ) +{ + uint8 *p = *ptr; + pstring hostname; + int namelen; + + ZERO_STRUCTP( q ); + + if ( !start || !end || !q || !*ptr) + return False; + + /* See RFC 1035 for details. If this fails, then return. */ + + namelen = dn_expand( start, end, p, hostname, sizeof(hostname) ); + if ( namelen < 0 ) { + return False; + } + p += namelen; + q->hostname = talloc_strdup( ctx, hostname ); + + /* check that we have space remaining */ + + if ( PTR_DIFF(p+4, end) > 0 ) + return False; + + q->type = RSVAL( p, 0 ); + q->in_class = RSVAL( p, 2 ); + p += 4; + + *ptr = p; + + return True; +} + +/********************************************************************* +*********************************************************************/ + +static BOOL ads_dns_parse_rr( TALLOC_CTX *ctx, uint8 *start, uint8 *end, + uint8 **ptr, struct dns_rr *rr ) +{ + uint8 *p = *ptr; + pstring hostname; + int namelen; + + if ( !start || !end || !rr || !*ptr) + return -1; + + ZERO_STRUCTP( rr ); + /* pull the name from the answer */ + + namelen = dn_expand( start, end, p, hostname, sizeof(hostname) ); + if ( namelen < 0 ) { + return -1; + } + p += namelen; + rr->hostname = talloc_strdup( ctx, hostname ); + + /* check that we have space remaining */ + + if ( PTR_DIFF(p+10, end) > 0 ) + return False; + + /* pull some values and then skip onto the string */ + + rr->type = RSVAL(p, 0); + rr->in_class = RSVAL(p, 2); + rr->ttl = RIVAL(p, 4); + rr->rdatalen = RSVAL(p, 8); + + p += 10; + + /* sanity check the available space */ + + if ( PTR_DIFF(p+rr->rdatalen, end ) > 0 ) { + return False; + + } + + /* save a point to the rdata for this section */ + + rr->rdata = p; + p += rr->rdatalen; + + *ptr = p; + + return True; +} + +/********************************************************************* +*********************************************************************/ + +static BOOL ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, + uint8 **ptr, struct dns_rr_srv *srv ) +{ + struct dns_rr rr; + uint8 *p; + pstring dcname; + int namelen; + + if ( !start || !end || !srv || !*ptr) + return -1; + + /* Parse the RR entry. Coming out of the this, ptr is at the beginning + of the next record */ + + if ( !ads_dns_parse_rr( ctx, start, end, ptr, &rr ) ) { + DEBUG(1,("ads_dns_parse_rr_srv: Failed to parse RR record\n")); + return False; + } + + if ( rr.type != ns_t_srv ) { + DEBUG(1,("ads_dns_parse_rr_srv: Bad answer type (%d)\n", rr.type)); + return False; + } + + p = rr.rdata; + + srv->priority = RSVAL(p, 0); + srv->weight = RSVAL(p, 2); + srv->port = RSVAL(p, 4); + + p += 6; + + namelen = dn_expand( start, end, p, dcname, sizeof(dcname) ); + if ( namelen < 0 ) { + DEBUG(1,("ads_dns_parse_rr_srv: Failed to uncompress name!\n")); + return False; + } + srv->hostname = talloc_strdup( ctx, dcname ); + + return True; +} + + +/********************************************************************* + Sort SRV record list based on weight and priority. See RFC 2782. +*********************************************************************/ + +static int dnssrvcmp( struct dns_rr_srv *a, struct dns_rr_srv *b ) +{ + BOOL init = False; + + if ( !init ) { + srand( (uint32)time(NULL) ); + } + + if ( a->priority == b->priority ) { + + /* randomize entries with an equal weight and priority */ + if ( a->weight == b->weight ) + return rand() % 2 ? -1 : 1; + + /* higher weights should be sorted lower */ + if ( a->weight > b->weight ) + return -1; + else + return 1; + } + + if ( a->priority < b->priority ) + return -1; + + return 1; +} + +/********************************************************************* + Simple wrapper for a DNS SRV query +*********************************************************************/ + +NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_srv **dclist, int *numdcs ) +{ + uint8 *buffer = NULL; + size_t buf_len; + int resp_len = NS_PACKETSZ; + struct dns_rr_srv *dcs = NULL; + int query_count, answer_count, auth_count, additional_count; + uint8 *p = buffer; + int rrnum; + int idx = 0; + + if ( !ctx || !name || !dclist ) { + return NT_STATUS_INVALID_PARAMETER; + } + + /* Send the request. May have to loop several times in case + of large replies */ + + do { + if ( buffer ) + TALLOC_FREE( buffer ); + + buf_len = resp_len * sizeof(uint8); + + if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) { + DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n")); + return NT_STATUS_NO_MEMORY; + } + + if ( (resp_len = res_query(name, ns_c_in, ns_t_srv, buffer, buf_len)) < 0 ) { + DEBUG(1,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); + TALLOC_FREE( buffer ); + return NT_STATUS_UNSUCCESSFUL; + } + } while ( buf_len < resp_len && resp_len < MAX_DNS_PACKET_SIZE ); + + p = buffer; + + /* For some insane reason, the ns_initparse() et. al. routines are only + available in libresolv.a, and not the shared lib. Who knows why.... + So we have to parse the DNS reply ourselves */ + + /* Pull the answer RR's count from the header. Use the NMB ordering macros */ + + query_count = RSVAL( p, 4 ); + answer_count = RSVAL( p, 6 ); + auth_count = RSVAL( p, 8 ); + additional_count = RSVAL( p, 10 ); + + DEBUG(4,("ads_dns_lookup_srv: %d records returned in the answer section.\n", + answer_count)); + + if ( (dcs = TALLOC_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { + DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n", + answer_count)); + return NT_STATUS_NO_MEMORY; + } + + /* now skip the header */ + + p += NS_HFIXEDSZ; + + /* parse the query section */ + + for ( rrnum=0; rrnum Date: Fri, 5 May 2006 20:18:50 +0000 Subject: r15463: compile fix for new DNS code for machine using Bind 4 libs (old IRIX host) (This used to be commit b0160f893393a446927c751961d101ddbcba4db4) --- source3/libads/dns.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 0119ae9130..678124a5e9 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -38,6 +38,14 @@ #define MAX_DNS_PACKET_SIZE 0xffff +#ifndef NS_HFIXEDSZ +# ifdef HFIXEDSZ +# define NS_HFIXEDSZ HFIXEDSZ +# else +# define NS_HFIXEDSZ 12 +# endif +#endif + /********************************************************************* *********************************************************************/ -- cgit From b62f60d736ebc99ca688d577d5f4987100744f2a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 5 May 2006 21:19:25 +0000 Subject: r15464: fix dns build breakage on IRIX and OpenBSD (This used to be commit 43f5d09a164ae111807222bdcbef949206766097) --- source3/libads/dns.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 678124a5e9..7eeb915ecf 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -38,12 +38,17 @@ #define MAX_DNS_PACKET_SIZE 0xffff -#ifndef NS_HFIXEDSZ +#ifdef NS_HFIXEDSZ /* Bind 8/9 interface */ +# define C_IN ns_c_in +# define T_A ns_t_a +# define T_SRV ns_t_srv +#else # ifdef HFIXEDSZ # define NS_HFIXEDSZ HFIXEDSZ # else -# define NS_HFIXEDSZ 12 +# define NS_HFIXEDSZ sizeof(HEADER) # endif +# define T_SRV 33 #endif /********************************************************************* @@ -160,7 +165,7 @@ static BOOL ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, return False; } - if ( rr.type != ns_t_srv ) { + if ( rr.type != T_SRV ) { DEBUG(1,("ads_dns_parse_rr_srv: Bad answer type (%d)\n", rr.type)); return False; } @@ -248,7 +253,7 @@ NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_sr return NT_STATUS_NO_MEMORY; } - if ( (resp_len = res_query(name, ns_c_in, ns_t_srv, buffer, buf_len)) < 0 ) { + if ( (resp_len = res_query(name, C_IN, T_SRV, buffer, buf_len)) < 0 ) { DEBUG(1,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); TALLOC_FREE( buffer ); return NT_STATUS_UNSUCCESSFUL; @@ -328,7 +333,7 @@ NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_sr /* only interested in A records as a shortcut for having to come back later and lookup the name */ - if ( (rr.type != ns_t_a) || (rr.rdatalen != 4) ) + if ( (rr.type != T_A) || (rr.rdatalen != 4) ) continue; for ( i=0; i Date: Fri, 12 May 2006 16:38:51 +0000 Subject: r15544: make sure to define NS_PACKETSZ for Bind 4 interfaces (fix build on us4) (This used to be commit 18f2e1a4e19a83afec6573a020f3a913f07d19dc) --- source3/libads/dns.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 7eeb915ecf..d2e263a9d1 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -47,7 +47,12 @@ # define NS_HFIXEDSZ HFIXEDSZ # else # define NS_HFIXEDSZ sizeof(HEADER) -# endif +# endif /* HFIXEDSZ */ +# ifdef PACKETSZ +# define NS_PACKETSZ PACKETSZ +# else /* 512 is usually the default */ +# define NS_PACKETSZ 512 +# endif /* PACKETSZ */ # define T_SRV 33 #endif -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/libads/dns.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index d2e263a9d1..321b435527 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -39,8 +39,12 @@ #define MAX_DNS_PACKET_SIZE 0xffff #ifdef NS_HFIXEDSZ /* Bind 8/9 interface */ +#if !defined(C_IN) /* AIX 5.3 already defines C_IN */ # define C_IN ns_c_in +#endif +#if !defined(T_A) /* AIX 5.3 already defines T_A */ # define T_A ns_t_a +#endif # define T_SRV ns_t_srv #else # ifdef HFIXEDSZ -- cgit From f3550d82a76840d23be9fe2fa6739a81d426bf5f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 19 Jul 2006 20:53:10 +0000 Subject: r17146: Starting to cleanout my local tree some * add code to lookup NS records (in prep for later coe that does DNS updates as part of the net ads join) (This used to be commit 36d4970646638a2719ebb05a091c951183535987) --- source3/libads/dns.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 199 insertions(+), 16 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 321b435527..570f9583f0 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -46,6 +46,7 @@ # define T_A ns_t_a #endif # define T_SRV ns_t_srv +# define T_NS ns_t_ns #else # ifdef HFIXEDSZ # define NS_HFIXEDSZ HFIXEDSZ @@ -197,6 +198,46 @@ static BOOL ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, return True; } +/********************************************************************* +*********************************************************************/ + +static BOOL ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end, + uint8 **ptr, struct dns_rr_ns *nsrec ) +{ + struct dns_rr rr; + uint8 *p; + pstring nsname; + int namelen; + + if ( !start || !end || !nsrec || !*ptr) + return -1; + + /* Parse the RR entry. Coming out of the this, ptr is at the beginning + of the next record */ + + if ( !ads_dns_parse_rr( ctx, start, end, ptr, &rr ) ) { + DEBUG(1,("ads_dns_parse_rr_ns: Failed to parse RR record\n")); + return False; + } + + if ( rr.type != T_NS ) { + DEBUG(1,("ads_dns_parse_rr_ns: Bad answer type (%d)\n", rr.type)); + return False; + } + + p = rr.rdata; + + /* ame server hostname */ + + namelen = dn_expand( start, end, p, nsname, sizeof(nsname) ); + if ( namelen < 0 ) { + DEBUG(1,("ads_dns_parse_rr_ns: Failed to uncompress name!\n")); + return False; + } + nsrec->hostname = talloc_strdup( ctx, nsname ); + + return True; +} /********************************************************************* Sort SRV record list based on weight and priority. See RFC 2782. @@ -230,27 +271,16 @@ static int dnssrvcmp( struct dns_rr_srv *a, struct dns_rr_srv *b ) } /********************************************************************* - Simple wrapper for a DNS SRV query + Simple wrapper for a DNS query *********************************************************************/ -NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_srv **dclist, int *numdcs ) +static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, + uint8 **buf, int *resp_length ) { uint8 *buffer = NULL; size_t buf_len; - int resp_len = NS_PACKETSZ; - struct dns_rr_srv *dcs = NULL; - int query_count, answer_count, auth_count, additional_count; - uint8 *p = buffer; - int rrnum; - int idx = 0; - - if ( !ctx || !name || !dclist ) { - return NT_STATUS_INVALID_PARAMETER; - } + int resp_len = NS_PACKETSZ; - /* Send the request. May have to loop several times in case - of large replies */ - do { if ( buffer ) TALLOC_FREE( buffer ); @@ -262,13 +292,47 @@ NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_sr return NT_STATUS_NO_MEMORY; } - if ( (resp_len = res_query(name, C_IN, T_SRV, buffer, buf_len)) < 0 ) { + if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) { DEBUG(1,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); TALLOC_FREE( buffer ); return NT_STATUS_UNSUCCESSFUL; } } while ( buf_len < resp_len && resp_len < MAX_DNS_PACKET_SIZE ); + + *buf = buffer; + *resp_length = resp_len; + + return NT_STATUS_OK; +} + +/********************************************************************* + Simple wrapper for a DNS SRV query +*********************************************************************/ + +static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_srv **dclist, int *numdcs ) +{ + uint8 *buffer = NULL; + int resp_len = 0; + struct dns_rr_srv *dcs = NULL; + int query_count, answer_count, auth_count, additional_count; + uint8 *p = buffer; + int rrnum; + int idx = 0; + NTSTATUS status; + + if ( !ctx || !name || !dclist ) { + return NT_STATUS_INVALID_PARAMETER; + } + + /* Send the request. May have to loop several times in case + of large replies */ + status = dns_send_req( ctx, name, T_SRV, &buffer, &resp_len ); + if ( !NT_STATUS_IS_OK(status) ) { + DEBUG(0,("ads_dns_lookup_srv: Failed to send DNS query (%s)\n", + nt_errstr(status))); + return status; + } p = buffer; /* For some insane reason, the ns_initparse() et. al. routines are only @@ -361,6 +425,125 @@ NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_sr return NT_STATUS_OK; } +/********************************************************************* + Simple wrapper for a DNS NS query +*********************************************************************/ + +NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_rr_ns **nslist, int *numns ) +{ + uint8 *buffer = NULL; + int resp_len = 0; + struct dns_rr_ns *nsarray = NULL; + int query_count, answer_count, auth_count, additional_count; + uint8 *p; + int rrnum; + int idx = 0; + NTSTATUS status; + + if ( !ctx || !dnsdomain || !nslist ) { + return NT_STATUS_INVALID_PARAMETER; + } + + /* Send the request. May have to loop several times in case + of large replies */ + + status = dns_send_req( ctx, dnsdomain, T_NS, &buffer, &resp_len ); + if ( !NT_STATUS_IS_OK(status) ) { + DEBUG(0,("ads_dns_lookup_ns: Failed to send DNS query (%s)\n", + nt_errstr(status))); + return status; + } + p = buffer; + + /* For some insane reason, the ns_initparse() et. al. routines are only + available in libresolv.a, and not the shared lib. Who knows why.... + So we have to parse the DNS reply ourselves */ + + /* Pull the answer RR's count from the header. Use the NMB ordering macros */ + + query_count = RSVAL( p, 4 ); + answer_count = RSVAL( p, 6 ); + auth_count = RSVAL( p, 8 ); + additional_count = RSVAL( p, 10 ); + + DEBUG(4,("ads_dns_lookup_ns: %d records returned in the answer section.\n", + answer_count)); + + if ( (nsarray = TALLOC_ARRAY(ctx, struct dns_rr_ns, answer_count)) == NULL ) { + DEBUG(0,("ads_dns_lookup_ns: talloc() failure for %d char*'s\n", + answer_count)); + return NT_STATUS_NO_MEMORY; + } + + /* now skip the header */ + + p += NS_HFIXEDSZ; + + /* parse the query section */ + + for ( rrnum=0; rrnum Date: Tue, 25 Jul 2006 19:59:35 +0000 Subject: r17239: BUG 3959: patch from William Charles to fix a segv in the DNS SRV lookups dur to calling rand() (This used to be commit be12519fd8a7ccd8400fd298e05921eda56b4e16) --- source3/libads/dns.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 570f9583f0..558c7f75ba 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -245,17 +245,11 @@ static BOOL ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end, static int dnssrvcmp( struct dns_rr_srv *a, struct dns_rr_srv *b ) { - BOOL init = False; - - if ( !init ) { - srand( (uint32)time(NULL) ); - } - if ( a->priority == b->priority ) { /* randomize entries with an equal weight and priority */ if ( a->weight == b->weight ) - return rand() % 2 ? -1 : 1; + return 0; /* higher weights should be sorted lower */ if ( a->weight > b->weight ) -- cgit From 1a0b57b5f523bdf787a8024303b661ea9004215f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 25 Jul 2006 20:11:03 +0000 Subject: r17242: BUG 3957: make sure to zero memory in the SRV hostlist in case there is not an A record for each SRV name (This used to be commit 42608b8bb974e1bd88cf2105bf1774622c045458) --- source3/libads/dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 558c7f75ba..903d19b753 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -343,7 +343,7 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn DEBUG(4,("ads_dns_lookup_srv: %d records returned in the answer section.\n", answer_count)); - if ( (dcs = TALLOC_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { + if ( (dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n", answer_count)); return NT_STATUS_NO_MEMORY; -- cgit From 8cac7c139908eff0124a4a6f9d25f3b3fe10a254 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 24 Aug 2006 12:13:57 +0000 Subject: r17795: Finally track down the "ads_connect: Interrupted system call" error. Fix our DNS SRV lookup code to deal with multi-homed hosts. We were noly remembering one IP address per host from the Additional records section in the SRV response which could have been an unreachable address. (This used to be commit 899179d2b9fba13cc6f4dab6efc3c22e44e062bc) --- source3/libads/dns.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 903d19b753..c946ab0bdd 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -398,14 +398,45 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn } /* only interested in A records as a shortcut for having to come - back later and lookup the name */ + back later and lookup the name. For multi-homed hosts, the + number of additional records and exceed the number of answer + records. */ + if ( (rr.type != T_A) || (rr.rdatalen != 4) ) continue; + /* FIX ME!!! Should this be a list of IP addresses for + each host? */ + for ( i=0; i Date: Tue, 29 Aug 2006 15:43:15 +0000 Subject: r17910: remove incorrect comment (code has already been fixed) (This used to be commit 9810d74e171542408eea3ec22a0ebb57a9e1e87e) --- source3/libads/dns.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index c946ab0bdd..8cc68a0c14 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -406,9 +406,6 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn if ( (rr.type != T_A) || (rr.rdatalen != 4) ) continue; - /* FIX ME!!! Should this be a list of IP addresses for - each host? */ - for ( i=0; i Date: Wed, 30 Aug 2006 04:40:03 +0000 Subject: r17928: Implement the basic store for CLDAP sitename support when looking up DC's. On every CLDAP call store the returned client sitename (if present, delete store if not) in gencache with infinate timeout. On AD DNS DC lookup, try looking for sitename DC's first, only try generic if sitename DNS lookup failed. I still haven't figured out yet how to ensure we fetch the sitename with a CLDAP query before doing the generic DC list lookup. This code is difficult to understand. I'll do some experiments and backtraces tomorrow to try and work out where to force a CLDAP site query first. Jeremy. (This used to be commit ab3f0c5b1e9c5fd192c5514cbe9451b938f9cd5d) --- source3/libads/dns.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 5 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 8cc68a0c14..937cd9213f 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -565,16 +565,105 @@ NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_r return NT_STATUS_OK; } +/**************************************************************************** + Store and fetch the AD client sitename. +****************************************************************************/ -/******************************************************************** -********************************************************************/ +#define SITENAME_KEY "AD_SITENAME" + +/**************************************************************************** + Store the AD client sitename. + We store indefinately as every new CLDAP query will re-write this. +****************************************************************************/ -NTSTATUS ads_dns_query_dcs( TALLOC_CTX *ctx, const char *domain, struct dns_rr_srv **dclist, int *numdcs ) +BOOL sitename_store(const char *sitename) { - pstring name; + time_t expire; + BOOL ret = False; + + if ( !sitename || (sitename && !*sitename)) { + DEBUG(2,("sitename_store: deleting empty sitename!\n")); + return gencache_del(SITENAME_KEY); + } + + if (!gencache_init()) { + return False; + } + + expire = get_time_t_max(); /* Store indefinately. */ + + DEBUG(10,("sitename_store: sitename = [%s], expire = [%u]\n", + sitename, (unsigned int)expire )); + + ret = gencache_set( SITENAME_KEY, sitename, expire ); + return ret; +} - snprintf( name, sizeof(name), "_ldap._tcp.dc._msdcs.%s", domain ); +/**************************************************************************** + Fetch the AD client sitename. + Caller must free. +****************************************************************************/ +static char *sitename_fetch(void) +{ + char *sitename = NULL; + time_t timeout; + BOOL ret = False; + + if (!gencache_init()) { + return False; + } + + ret = gencache_get( SITENAME_KEY, &sitename, &timeout ); + if ( !ret ) { + DEBUG(5,("sitename_fetch: No stored sitename\n")); + } else { + DEBUG(5,("sitename_fetch: Returning sitename \"%s\"\n", + sitename )); + } + return sitename; +} + +/******************************************************************** + Query with optional sitename. +********************************************************************/ + +NTSTATUS ads_dns_query_dcs_internal(TALLOC_CTX *ctx, + const char *domain, + const char *sitename, + struct dns_rr_srv **dclist, + int *numdcs ) +{ + char *name; + if (sitename) { + name = talloc_asprintf(ctx, "_ldap._tcp.%s._sites.dc._msdcs.%s", + sitename, domain ); + } else { + name = talloc_asprintf(ctx, "_ldap._tcp.dc._msdcs.%s", domain ); + } + if (!name) { + return NT_STATUS_NO_MEMORY; + } return ads_dns_lookup_srv( ctx, name, dclist, numdcs ); } +/******************************************************************** + Query for AD DC's. Transparently use sitename. +********************************************************************/ + +NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, + const char *domain, + struct dns_rr_srv **dclist, + int *numdcs ) +{ + NTSTATUS status; + char *sitename = sitename_fetch(); + + status = ads_dns_query_dcs_internal(ctx, domain, sitename, dclist, numdcs); + if (sitename && !NT_STATUS_IS_OK(status)) { + /* Sitename DNS query may have failed. Try without. */ + status = ads_dns_query_dcs_internal(ctx, domain, NULL, dclist, numdcs); + } + SAFE_FREE(sitename); + return status; +} -- cgit From 7b7ce43b40888af7d2663e77d8a9e83c383c6b2d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Aug 2006 05:52:31 +0000 Subject: r17929: Ok, I think I finally figured out where to put the code to redo the CLDAP query to restrict DC DNS lookups to the sitename. Jerry, please check to stop me going insane :-). Jeremy. (This used to be commit 8d22cc111579c57aec65be8884b41564b79b133a) --- source3/libads/dns.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 937cd9213f..430486741d 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -604,7 +604,7 @@ BOOL sitename_store(const char *sitename) Caller must free. ****************************************************************************/ -static char *sitename_fetch(void) +char *sitename_fetch(void) { char *sitename = NULL; time_t timeout; @@ -624,6 +624,25 @@ static char *sitename_fetch(void) return sitename; } +/**************************************************************************** + Did the sitename change ? +****************************************************************************/ + +BOOL sitename_changed(const char *sitename) +{ + BOOL ret = False; + char *new_sitename = sitename_fetch(); + + if (sitename && new_sitename && !strequal(sitename, new_sitename)) { + ret = True; + } else if ((sitename && !new_sitename) || + (!sitename && new_sitename)) { + ret = True; + } + SAFE_FREE(new_sitename); + return ret; +} + /******************************************************************** Query with optional sitename. ********************************************************************/ -- cgit From 256172f7d6dd384ea95457dd6322e0289057ac56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 31 Aug 2006 00:07:24 +0000 Subject: r17942: Jerry is right - when no site support is enabled the client sitename is "Default-First-Site-Name". Treat this as a blank site (no site configured). Jeremy. (This used to be commit 5c46381bd7dd1b3f11f427d111ded0b76fc1bec8) --- source3/libads/dns.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 430486741d..4d935c1b6e 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -574,22 +574,27 @@ NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_r /**************************************************************************** Store the AD client sitename. We store indefinately as every new CLDAP query will re-write this. + If the sitename is "Default-First-Site-Name" we don't store it + as this isn't a valid DNS name. ****************************************************************************/ BOOL sitename_store(const char *sitename) { time_t expire; BOOL ret = False; - - if ( !sitename || (sitename && !*sitename)) { - DEBUG(2,("sitename_store: deleting empty sitename!\n")); - return gencache_del(SITENAME_KEY); - } - + if (!gencache_init()) { return False; } + if (!sitename || (sitename && !*sitename)) { + DEBUG(5,("sitename_store: deleting empty sitename!\n")); + return gencache_del(SITENAME_KEY); + } else if (sitename && strequal(sitename, "Default-First-Site-Name")) { + DEBUG(5,("sitename_store: delete default sitename Default-First-Site-Name\n")); + return gencache_del(SITENAME_KEY); + } + expire = get_time_t_max(); /* Store indefinately. */ DEBUG(10,("sitename_store: sitename = [%s], expire = [%u]\n", -- cgit From 2fcd113f5507f643fcf80d5a9770ce72aa121ba8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 31 Aug 2006 04:14:08 +0000 Subject: r17945: Store the server and client sitenames in the ADS struct so we can see when they match - only create the ugly krb5 hack when they do. Jeremy. (This used to be commit 9be4ecf24b6b5dacf4c2891bddb072fa7543753f) --- source3/libads/dns.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 4d935c1b6e..3f99a73a33 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -590,8 +590,9 @@ BOOL sitename_store(const char *sitename) if (!sitename || (sitename && !*sitename)) { DEBUG(5,("sitename_store: deleting empty sitename!\n")); return gencache_del(SITENAME_KEY); - } else if (sitename && strequal(sitename, "Default-First-Site-Name")) { - DEBUG(5,("sitename_store: delete default sitename Default-First-Site-Name\n")); + } else if (sitename && strequal(sitename, DEFAULT_SITE_NAME)) { + DEBUG(5,("sitename_store: delete default sitename %s\n", + DEFAULT_SITE_NAME)); return gencache_del(SITENAME_KEY); } @@ -633,11 +634,16 @@ char *sitename_fetch(void) Did the sitename change ? ****************************************************************************/ -BOOL sitename_changed(const char *sitename) +BOOL stored_sitename_changed(const char *sitename) { BOOL ret = False; char *new_sitename = sitename_fetch(); + /* Treat default site as no name. */ + if (strequal(sitename, DEFAULT_SITE_NAME)) { + sitename = NULL; + } + if (sitename && new_sitename && !strequal(sitename, new_sitename)) { ret = True; } else if ((sitename && !new_sitename) || -- cgit From 305ceade3905dad45eac2f407dd8f56a9979cf1c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 31 Aug 2006 16:26:32 +0000 Subject: r17970: Add missing include-guards around ads.h and ads_cldap.h. Remove all reference to "Default-First-Site-Name" and treat it like any other site. Jeremy. (This used to be commit 5ae3564d6844f44a6943b2028917bd457371af1e) --- source3/libads/dns.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 3f99a73a33..579296ea1f 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -590,10 +590,6 @@ BOOL sitename_store(const char *sitename) if (!sitename || (sitename && !*sitename)) { DEBUG(5,("sitename_store: deleting empty sitename!\n")); return gencache_del(SITENAME_KEY); - } else if (sitename && strequal(sitename, DEFAULT_SITE_NAME)) { - DEBUG(5,("sitename_store: delete default sitename %s\n", - DEFAULT_SITE_NAME)); - return gencache_del(SITENAME_KEY); } expire = get_time_t_max(); /* Store indefinately. */ @@ -639,11 +635,6 @@ BOOL stored_sitename_changed(const char *sitename) BOOL ret = False; char *new_sitename = sitename_fetch(); - /* Treat default site as no name. */ - if (strequal(sitename, DEFAULT_SITE_NAME)) { - sitename = NULL; - } - if (sitename && new_sitename && !strequal(sitename, new_sitename)) { ret = True; } else if ((sitename && !new_sitename) || -- cgit From 0f1bc28744d8c7cae2fe2774b50fc4336408a74d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 2 Sep 2006 19:27:44 +0000 Subject: r18006: Actually a smaller change than it looks. Leverage the get_dc_list code to get the _kerberos. names for site support. This way we don't depend on one KDC to do ticket refresh. Even though we know it's up when we add it, it may go down when we're trying to refresh. Jeremy. (This used to be commit 77fe2a3d7418012a8dbfb6aaeb2a8dd57c6e1a5d) --- source3/libads/dns.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 579296ea1f..d5c851d5ca 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -649,18 +649,20 @@ BOOL stored_sitename_changed(const char *sitename) Query with optional sitename. ********************************************************************/ -NTSTATUS ads_dns_query_dcs_internal(TALLOC_CTX *ctx, - const char *domain, +NTSTATUS ads_dns_query_internal(TALLOC_CTX *ctx, + const char *servicename, + const char *realm, const char *sitename, struct dns_rr_srv **dclist, int *numdcs ) { char *name; if (sitename) { - name = talloc_asprintf(ctx, "_ldap._tcp.%s._sites.dc._msdcs.%s", - sitename, domain ); + name = talloc_asprintf(ctx, "%s._tcp.%s._sites.dc._msdcs.%s", + servicename, sitename, realm ); } else { - name = talloc_asprintf(ctx, "_ldap._tcp.dc._msdcs.%s", domain ); + name = talloc_asprintf(ctx, "%s._tcp.dc._msdcs.%s", + servicename, realm ); } if (!name) { return NT_STATUS_NO_MEMORY; @@ -673,17 +675,44 @@ NTSTATUS ads_dns_query_dcs_internal(TALLOC_CTX *ctx, ********************************************************************/ NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, - const char *domain, + const char *realm, struct dns_rr_srv **dclist, int *numdcs ) { NTSTATUS status; char *sitename = sitename_fetch(); - status = ads_dns_query_dcs_internal(ctx, domain, sitename, dclist, numdcs); + status = ads_dns_query_internal(ctx, "_ldap", realm, sitename, + dclist, numdcs); if (sitename && !NT_STATUS_IS_OK(status)) { /* Sitename DNS query may have failed. Try without. */ - status = ads_dns_query_dcs_internal(ctx, domain, NULL, dclist, numdcs); + status = ads_dns_query_internal(ctx, "_ldap", realm, NULL, + dclist, numdcs); + } + SAFE_FREE(sitename); + return status; +} + +/******************************************************************** + Query for AD KDC's. Transparently use sitename. + Even if our underlying kerberos libraries are UDP only, this + is pretty safe as it's unlikely that a KDC supports TCP and not UDP. +********************************************************************/ + +NTSTATUS ads_dns_query_kdcs(TALLOC_CTX *ctx, + const char *realm, + struct dns_rr_srv **dclist, + int *numdcs ) +{ + NTSTATUS status; + char *sitename = sitename_fetch(); + + status = ads_dns_query_internal(ctx, "_kerberos", realm, sitename, + dclist, numdcs); + if (sitename && !NT_STATUS_IS_OK(status)) { + /* Sitename DNS query may have failed. Try without. */ + status = ads_dns_query_internal(ctx, "_kerberos", realm, NULL, + dclist, numdcs); } SAFE_FREE(sitename); return status; -- cgit From ed0274433c438a65468238f1f97c1e809fec7bab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Sep 2006 21:08:29 +0000 Subject: r18234: DNS failures are too common to log at level zero or 1. Jeremy. (This used to be commit 943e21d5da2a8aadab1b2c3d700a9b8b880582f2) --- source3/libads/dns.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index d5c851d5ca..063665d136 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -287,7 +287,7 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, } if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) { - DEBUG(1,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); + DEBUG(3,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); TALLOC_FREE( buffer ); return NT_STATUS_UNSUCCESSFUL; } @@ -323,7 +323,7 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn status = dns_send_req( ctx, name, T_SRV, &buffer, &resp_len ); if ( !NT_STATUS_IS_OK(status) ) { - DEBUG(0,("ads_dns_lookup_srv: Failed to send DNS query (%s)\n", + DEBUG(3,("ads_dns_lookup_srv: Failed to send DNS query (%s)\n", nt_errstr(status))); return status; } @@ -471,7 +471,7 @@ NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_r status = dns_send_req( ctx, dnsdomain, T_NS, &buffer, &resp_len ); if ( !NT_STATUS_IS_OK(status) ) { - DEBUG(0,("ads_dns_lookup_ns: Failed to send DNS query (%s)\n", + DEBUG(3,("ads_dns_lookup_ns: Failed to send DNS query (%s)\n", nt_errstr(status))); return status; } -- cgit From 6b3c42b1a17956f69ea4a0c345a6b6fcd1429a81 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 13 Sep 2006 13:02:51 +0000 Subject: r18466: Attempt to fix the AIX build (This used to be commit 1398425067d77d90ecf2ed4c17a12d643f7f5a88) --- source3/libads/dns.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 063665d136..c8b3f29507 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -46,7 +46,9 @@ # define T_A ns_t_a #endif # define T_SRV ns_t_srv +#if !defined(T_NS) /* AIX 5.3 already defines T_NS */ # define T_NS ns_t_ns +#endif #else # ifdef HFIXEDSZ # define NS_HFIXEDSZ HFIXEDSZ -- cgit From bfd099e148ed97394bc858e746a1a998a71ac43c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 17 Jan 2007 18:25:35 +0000 Subject: r20857: Silence gives assent :-). Checking in the fix for site support in a network where many DC's are down. I heard via Volker there is still a bug w.r.t the wrong site being chosen with trusted domains but we'll have to layer that fix on top of this. Gd - complain if this doesn't work for you. Jeremy. (This used to be commit 97e248f89ac6548274f03f2ae7583a255da5ddb3) --- source3/libads/dns.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index c8b3f29507..b67d802bdc 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -673,16 +673,16 @@ NTSTATUS ads_dns_query_internal(TALLOC_CTX *ctx, } /******************************************************************** - Query for AD DC's. Transparently use sitename. + Query for AD DC's. ********************************************************************/ NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, const char *realm, + const char *sitename, struct dns_rr_srv **dclist, int *numdcs ) { NTSTATUS status; - char *sitename = sitename_fetch(); status = ads_dns_query_internal(ctx, "_ldap", realm, sitename, dclist, numdcs); @@ -691,23 +691,22 @@ NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, status = ads_dns_query_internal(ctx, "_ldap", realm, NULL, dclist, numdcs); } - SAFE_FREE(sitename); return status; } /******************************************************************** - Query for AD KDC's. Transparently use sitename. + Query for AD KDC's. Even if our underlying kerberos libraries are UDP only, this is pretty safe as it's unlikely that a KDC supports TCP and not UDP. ********************************************************************/ NTSTATUS ads_dns_query_kdcs(TALLOC_CTX *ctx, const char *realm, + const char *sitename, struct dns_rr_srv **dclist, int *numdcs ) { NTSTATUS status; - char *sitename = sitename_fetch(); status = ads_dns_query_internal(ctx, "_kerberos", realm, sitename, dclist, numdcs); @@ -716,6 +715,5 @@ NTSTATUS ads_dns_query_kdcs(TALLOC_CTX *ctx, status = ads_dns_query_internal(ctx, "_kerberos", realm, NULL, dclist, numdcs); } - SAFE_FREE(sitename); return status; } -- cgit From a99840e59ee4bd27fd4f2cf8b465dd0f215ea067 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 17 Jan 2007 19:20:11 +0000 Subject: r20862: When in disconnected mode there is no need to try a fallback to a site less DNS query. This speeds up offline detection slightly. Guenther (This used to be commit eda76ecf07a4d2f9bb5544e2c031cfad14d93e85) --- source3/libads/dns.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index b67d802bdc..bd280fea62 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -291,6 +291,12 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) { DEBUG(3,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); TALLOC_FREE( buffer ); + if (errno == ETIMEDOUT) { + return NT_STATUS_IO_TIMEOUT; + } + if (errno == ECONNREFUSED) { + return NT_STATUS_CONNECTION_REFUSED; + } return NT_STATUS_UNSUCCESSFUL; } } while ( buf_len < resp_len && resp_len < MAX_DNS_PACKET_SIZE ); @@ -686,6 +692,12 @@ NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, status = ads_dns_query_internal(ctx, "_ldap", realm, sitename, dclist, numdcs); + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) || + NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_REFUSED)) { + return status; + } + if (sitename && !NT_STATUS_IS_OK(status)) { /* Sitename DNS query may have failed. Try without. */ status = ads_dns_query_internal(ctx, "_ldap", realm, NULL, @@ -710,6 +722,12 @@ NTSTATUS ads_dns_query_kdcs(TALLOC_CTX *ctx, status = ads_dns_query_internal(ctx, "_kerberos", realm, sitename, dclist, numdcs); + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) || + NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_REFUSED)) { + return status; + } + if (sitename && !NT_STATUS_IS_OK(status)) { /* Sitename DNS query may have failed. Try without. */ status = ads_dns_query_internal(ctx, "_kerberos", realm, NULL, -- cgit From e9c294b926c0b831fd936194342ec0564f935798 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 18 Jan 2007 09:58:57 +0000 Subject: r20874: We need to distinguish client sitenames per realm. We were overwriting the stored client sitename with the sitename from each sucessfull CLDAP connection. Guenther (This used to be commit 6a13e878b5d299cb3b3d7cb33ee0d51089d9228d) --- source3/libads/dns.c | 71 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 14 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index bd280fea62..b405d29d96 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -577,7 +577,19 @@ NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_r Store and fetch the AD client sitename. ****************************************************************************/ -#define SITENAME_KEY "AD_SITENAME" +#define SITENAME_KEY "AD_SITENAME/DOMAIN/%s" + +static char *sitename_key(const char *realm) +{ + char *keystr; + + if (asprintf(&keystr, SITENAME_KEY, strupper_static(realm)) == -1) { + return NULL; + } + + return keystr; +} + /**************************************************************************** Store the AD client sitename. @@ -586,26 +598,37 @@ NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_r as this isn't a valid DNS name. ****************************************************************************/ -BOOL sitename_store(const char *sitename) +BOOL sitename_store(const char *realm, const char *sitename) { time_t expire; BOOL ret = False; + char *key; if (!gencache_init()) { return False; } + + if (!realm || (strlen(realm) == 0)) { + DEBUG(0,("no realm\n")); + return False; + } + key = sitename_key(realm); + if (!sitename || (sitename && !*sitename)) { DEBUG(5,("sitename_store: deleting empty sitename!\n")); - return gencache_del(SITENAME_KEY); + ret = gencache_del(sitename_key(realm)); + SAFE_FREE(key); + return ret; } expire = get_time_t_max(); /* Store indefinately. */ - DEBUG(10,("sitename_store: sitename = [%s], expire = [%u]\n", - sitename, (unsigned int)expire )); + DEBUG(10,("sitename_store: realm = [%s], sitename = [%s], expire = [%u]\n", + realm, sitename, (unsigned int)expire )); - ret = gencache_set( SITENAME_KEY, sitename, expire ); + ret = gencache_set( key, sitename, expire ); + SAFE_FREE(key); return ret; } @@ -614,22 +637,34 @@ BOOL sitename_store(const char *sitename) Caller must free. ****************************************************************************/ -char *sitename_fetch(void) +char *sitename_fetch(const char *realm) { char *sitename = NULL; time_t timeout; BOOL ret = False; + const char *query_realm; + char *key; if (!gencache_init()) { return False; } - - ret = gencache_get( SITENAME_KEY, &sitename, &timeout ); + + if (!realm || (strlen(realm) == 0)) { + query_realm = lp_realm(); + } else { + query_realm = realm; + } + + key = sitename_key(query_realm); + + ret = gencache_get( key, &sitename, &timeout ); + SAFE_FREE(key); if ( !ret ) { - DEBUG(5,("sitename_fetch: No stored sitename\n")); + DEBUG(5,("sitename_fetch: No stored sitename for %s\n", + query_realm)); } else { - DEBUG(5,("sitename_fetch: Returning sitename \"%s\"\n", - sitename )); + DEBUG(5,("sitename_fetch: Returning sitename for %s: \"%s\"\n", + query_realm, sitename )); } return sitename; } @@ -638,10 +673,18 @@ char *sitename_fetch(void) Did the sitename change ? ****************************************************************************/ -BOOL stored_sitename_changed(const char *sitename) +BOOL stored_sitename_changed(const char *realm, const char *sitename) { BOOL ret = False; - char *new_sitename = sitename_fetch(); + + char *new_sitename; + + if (!realm || (strlen(realm) == 0)) { + DEBUG(0,("no realm\n")); + return False; + } + + new_sitename = sitename_fetch(realm); if (sitename && new_sitename && !strequal(sitename, new_sitename)) { ret = True; -- cgit From 9d19e5294042e4de2c0eb70ee8b17993ebce211d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Jan 2007 19:18:43 +0000 Subject: r20880: Fix memory leak in new sitename code. You got *really* close Guenther, then you forgot to use "key" :-) :-). Jeremy. (This used to be commit 56842b59d00d531b0c9c22639603dc721eab50b4) --- source3/libads/dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index b405d29d96..008266ea0b 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -617,7 +617,7 @@ BOOL sitename_store(const char *realm, const char *sitename) if (!sitename || (sitename && !*sitename)) { DEBUG(5,("sitename_store: deleting empty sitename!\n")); - ret = gencache_del(sitename_key(realm)); + ret = gencache_del(key); SAFE_FREE(key); return ret; } -- cgit From be8b0685a55700c6bce3681734800ec6434b0364 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Apr 2007 02:39:34 +0000 Subject: r22589: Make TALLOC_ARRAY consistent across all uses. Jeremy. (This used to be commit 8968808c3b5b0208cbad9ac92eaf948f2c546dd9) --- source3/libads/dns.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 008266ea0b..8b031b0e3a 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -283,9 +283,13 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, buf_len = resp_len * sizeof(uint8); - if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) { - DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n")); - return NT_STATUS_NO_MEMORY; + if (buf_len) { + if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) { + DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n")); + return NT_STATUS_NO_MEMORY; + } + } else { + buffer = NULL; } if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) { @@ -499,10 +503,14 @@ NTSTATUS ads_dns_lookup_ns( TALLOC_CTX *ctx, const char *dnsdomain, struct dns_r DEBUG(4,("ads_dns_lookup_ns: %d records returned in the answer section.\n", answer_count)); - if ( (nsarray = TALLOC_ARRAY(ctx, struct dns_rr_ns, answer_count)) == NULL ) { - DEBUG(0,("ads_dns_lookup_ns: talloc() failure for %d char*'s\n", - answer_count)); - return NT_STATUS_NO_MEMORY; + if (answer_count) { + if ( (nsarray = TALLOC_ARRAY(ctx, struct dns_rr_ns, answer_count)) == NULL ) { + DEBUG(0,("ads_dns_lookup_ns: talloc() failure for %d char*'s\n", + answer_count)); + return NT_STATUS_NO_MEMORY; + } + } else { + nsarray = NULL; } /* now skip the header */ -- cgit From 56a5d05b8b285250bdc0e9cc3c8f3c3d8af80382 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Apr 2007 02:51:26 +0000 Subject: r22590: Make TALLOC_ARRAY consistent across all uses. That should be it.... Jeremy. (This used to be commit 603233a98bbf65467c8b4f04719d771c70b3b4c9) --- source3/libads/dns.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 8b031b0e3a..f16cea2555 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -355,10 +355,14 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn DEBUG(4,("ads_dns_lookup_srv: %d records returned in the answer section.\n", answer_count)); - if ( (dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { - DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n", - answer_count)); - return NT_STATUS_NO_MEMORY; + if (answer_count) { + if ( (dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { + DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n", + answer_count)); + return NT_STATUS_NO_MEMORY; + } + } else { + dcs = NULL; } /* now skip the header */ -- cgit From 89fd4444aff2c858605f71d46715e3b366e82749 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 6 May 2007 21:06:55 +0000 Subject: r22714: Prevent DNS lookup storms when the DNS servers are unreachable. Helps when transitioning from offline to online mode. Note that this is a quick hack and a better solution would be to start the DNS server's state between processes (similar to the namecache entries). (This used to be commit 4f05c6fe26f4abd7ca71eac339fee2ef5e254369) --- source3/libads/dns.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index f16cea2555..e0e696c99c 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -270,45 +270,76 @@ static int dnssrvcmp( struct dns_rr_srv *a, struct dns_rr_srv *b ) Simple wrapper for a DNS query *********************************************************************/ +#define DNS_FAILED_WAITTIME 30 + static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, uint8 **buf, int *resp_length ) { uint8 *buffer = NULL; size_t buf_len; int resp_len = NS_PACKETSZ; - + static time_t last_dns_check = 0; + static NTSTATUS last_dns_status = NT_STATUS_OK; + time_t now = time(NULL); + + /* Try to prevent bursts of DNS lookups if the server is down */ + + /* Protect against large clock changes */ + + if ( last_dns_check > now ) + last_dns_check = 0; + + /* IF we had a DNS timeout or a bad server and we are still + in the 30 second cache window, just return the previous + status and save the network timeout. */ + + if ( (NT_STATUS_EQUAL(last_dns_status,NT_STATUS_IO_TIMEOUT) || + NT_STATUS_EQUAL(last_dns_status,NT_STATUS_CONNECTION_REFUSED)) && + (last_dns_check+DNS_FAILED_WAITTIME) > now ) + { + DEBUG(10,("last_dns_check: Returning cached status (%s)\n", + nt_errstr(last_dns_status) )); + return last_dns_status; + } + + /* Send the Query */ do { if ( buffer ) TALLOC_FREE( buffer ); buf_len = resp_len * sizeof(uint8); - if (buf_len) { + if (buf_len) { if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) { DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n")); - return NT_STATUS_NO_MEMORY; + last_dns_status = NT_STATUS_NO_MEMORY; + last_dns_check = time(NULL); + return last_dns_status; } - } else { - buffer = NULL; } if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) { DEBUG(3,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); TALLOC_FREE( buffer ); + last_dns_status = NT_STATUS_UNSUCCESSFUL; + if (errno == ETIMEDOUT) { - return NT_STATUS_IO_TIMEOUT; + last_dns_status = NT_STATUS_IO_TIMEOUT; } if (errno == ECONNREFUSED) { - return NT_STATUS_CONNECTION_REFUSED; + last_dns_status = NT_STATUS_CONNECTION_REFUSED; } - return NT_STATUS_UNSUCCESSFUL; + last_dns_check = time(NULL); + return last_dns_status; } } while ( buf_len < resp_len && resp_len < MAX_DNS_PACKET_SIZE ); *buf = buffer; *resp_length = resp_len; - return NT_STATUS_OK; + last_dns_check = time(NULL); + last_dns_status = NT_STATUS_OK; + return last_dns_status; } /********************************************************************* -- cgit From 8ead92f06d11ae1cbedf2b700bdbf96da5602a1d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 29 Jun 2007 11:54:29 +0000 Subject: r23654: Remove misleading inline comment. Guenther (This used to be commit a3441c22b342e2802bd9766b7046073db3895a29) --- source3/libads/dns.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index e0e696c99c..c0d8d61e36 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -637,8 +637,6 @@ static char *sitename_key(const char *realm) /**************************************************************************** Store the AD client sitename. We store indefinately as every new CLDAP query will re-write this. - If the sitename is "Default-First-Site-Name" we don't store it - as this isn't a valid DNS name. ****************************************************************************/ BOOL sitename_store(const char *realm, const char *sitename) @@ -652,7 +650,7 @@ BOOL sitename_store(const char *realm, const char *sitename) } if (!realm || (strlen(realm) == 0)) { - DEBUG(0,("no realm\n")); + DEBUG(0,("sitename_store: no realm\n")); return False; } @@ -723,7 +721,7 @@ BOOL stored_sitename_changed(const char *realm, const char *sitename) char *new_sitename; if (!realm || (strlen(realm) == 0)) { - DEBUG(0,("no realm\n")); + DEBUG(0,("stored_sitename_changed: no realm\n")); return False; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/libads/dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index c0d8d61e36..d2f2c12522 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/libads/dns.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index d2f2c12522..96cd54af06 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 22cf5a3f8086b8f823fa5c45bce4432df825b92c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 28 Aug 2007 14:27:48 +0000 Subject: r24739: With resolve_ads() allow to query for PDCs as well. Also add dns query functions to find GCs and DCs by GUID. Guenther (This used to be commit cc469157f6684ec507bf1c3a659fc36a53d304a1) --- source3/libads/dns.c | 137 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 109 insertions(+), 28 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 96cd54af06..02baec78fb 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -740,21 +740,23 @@ BOOL stored_sitename_changed(const char *realm, const char *sitename) Query with optional sitename. ********************************************************************/ -NTSTATUS ads_dns_query_internal(TALLOC_CTX *ctx, - const char *servicename, - const char *realm, - const char *sitename, - struct dns_rr_srv **dclist, - int *numdcs ) +static NTSTATUS ads_dns_query_internal(TALLOC_CTX *ctx, + const char *servicename, + const char *dc_pdc_gc_domains, + const char *realm, + const char *sitename, + struct dns_rr_srv **dclist, + int *numdcs ) { char *name; if (sitename) { - name = talloc_asprintf(ctx, "%s._tcp.%s._sites.dc._msdcs.%s", - servicename, sitename, realm ); - } else { - name = talloc_asprintf(ctx, "%s._tcp.dc._msdcs.%s", - servicename, realm ); - } + name = talloc_asprintf(ctx, "%s._tcp.%s._sites.%s._msdcs.%s", + servicename, sitename, + dc_pdc_gc_domains, realm); + } else { + name = talloc_asprintf(ctx, "%s._tcp.%s._msdcs.%s", + servicename, dc_pdc_gc_domains, realm); + } if (!name) { return NT_STATUS_NO_MEMORY; } @@ -766,14 +768,14 @@ NTSTATUS ads_dns_query_internal(TALLOC_CTX *ctx, ********************************************************************/ NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, - const char *realm, - const char *sitename, - struct dns_rr_srv **dclist, - int *numdcs ) + const char *realm, + const char *sitename, + struct dns_rr_srv **dclist, + int *numdcs ) { NTSTATUS status; - status = ads_dns_query_internal(ctx, "_ldap", realm, sitename, + status = ads_dns_query_internal(ctx, "_ldap", "dc", realm, sitename, dclist, numdcs); if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) || @@ -781,10 +783,42 @@ NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, return status; } - if (sitename && !NT_STATUS_IS_OK(status)) { + if (sitename && + ((!NT_STATUS_IS_OK(status)) || + (NT_STATUS_IS_OK(status) && (numdcs == 0)))) { /* Sitename DNS query may have failed. Try without. */ - status = ads_dns_query_internal(ctx, "_ldap", realm, NULL, - dclist, numdcs); + status = ads_dns_query_internal(ctx, "_ldap", "dc", realm, + NULL, dclist, numdcs); + } + return status; +} + +/******************************************************************** + Query for AD GC's. +********************************************************************/ + +NTSTATUS ads_dns_query_gcs(TALLOC_CTX *ctx, + const char *realm, + const char *sitename, + struct dns_rr_srv **dclist, + int *numdcs ) +{ + NTSTATUS status; + + status = ads_dns_query_internal(ctx, "_ldap", "gc", realm, sitename, + dclist, numdcs); + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) || + NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_REFUSED)) { + return status; + } + + if (sitename && + ((!NT_STATUS_IS_OK(status)) || + (NT_STATUS_IS_OK(status) && (numdcs == 0)))) { + /* Sitename DNS query may have failed. Try without. */ + status = ads_dns_query_internal(ctx, "_ldap", "gc", realm, + NULL, dclist, numdcs); } return status; } @@ -796,25 +830,72 @@ NTSTATUS ads_dns_query_dcs(TALLOC_CTX *ctx, ********************************************************************/ NTSTATUS ads_dns_query_kdcs(TALLOC_CTX *ctx, - const char *realm, - const char *sitename, - struct dns_rr_srv **dclist, - int *numdcs ) + const char *dns_forest_name, + const char *sitename, + struct dns_rr_srv **dclist, + int *numdcs ) { NTSTATUS status; - status = ads_dns_query_internal(ctx, "_kerberos", realm, sitename, - dclist, numdcs); + status = ads_dns_query_internal(ctx, "_kerberos", "dc", + dns_forest_name, sitename, dclist, + numdcs); if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) || NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_REFUSED)) { return status; } - if (sitename && !NT_STATUS_IS_OK(status)) { + if (sitename && + ((!NT_STATUS_IS_OK(status)) || + (NT_STATUS_IS_OK(status) && (numdcs == 0)))) { /* Sitename DNS query may have failed. Try without. */ - status = ads_dns_query_internal(ctx, "_kerberos", realm, NULL, + status = ads_dns_query_internal(ctx, "_kerberos", "dc", + dns_forest_name, NULL, dclist, numdcs); } return status; } + +/******************************************************************** + Query for AD PDC. Sitename is obsolete here. +********************************************************************/ + +NTSTATUS ads_dns_query_pdc(TALLOC_CTX *ctx, + const char *dns_domain_name, + struct dns_rr_srv **dclist, + int *numdcs ) +{ + return ads_dns_query_internal(ctx, "_ldap", "pdc", dns_domain_name, + NULL, dclist, numdcs); +} + +/******************************************************************** + Query for AD DC by guid. Sitename is obsolete here. +********************************************************************/ + +NTSTATUS ads_dns_query_dcs_guid(TALLOC_CTX *ctx, + const char *dns_forest_name, + const struct GUID *domain_guid, + struct dns_rr_srv **dclist, + int *numdcs ) +{ + /*_ldap._tcp.DomainGuid.domains._msdcs.DnsForestName */ + + const char *domains; + const char *guid_string; + + guid_string = GUID_string(ctx, domain_guid); + if (!guid_string) { + return NT_STATUS_NO_MEMORY; + } + + /* little hack */ + domains = talloc_asprintf(ctx, "%s.domains", guid_string); + if (!domains) { + return NT_STATUS_NO_MEMORY; + } + + return ads_dns_query_internal(ctx, "_ldap", domains, dns_forest_name, + NULL, dclist, numdcs); +} -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/libads/dns.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 02baec78fb..7959e910a8 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -65,7 +65,7 @@ /********************************************************************* *********************************************************************/ -static BOOL ads_dns_parse_query( TALLOC_CTX *ctx, uint8 *start, uint8 *end, +static bool ads_dns_parse_query( TALLOC_CTX *ctx, uint8 *start, uint8 *end, uint8 **ptr, struct dns_query *q ) { uint8 *p = *ptr; @@ -103,7 +103,7 @@ static BOOL ads_dns_parse_query( TALLOC_CTX *ctx, uint8 *start, uint8 *end, /********************************************************************* *********************************************************************/ -static BOOL ads_dns_parse_rr( TALLOC_CTX *ctx, uint8 *start, uint8 *end, +static bool ads_dns_parse_rr( TALLOC_CTX *ctx, uint8 *start, uint8 *end, uint8 **ptr, struct dns_rr *rr ) { uint8 *p = *ptr; @@ -157,7 +157,7 @@ static BOOL ads_dns_parse_rr( TALLOC_CTX *ctx, uint8 *start, uint8 *end, /********************************************************************* *********************************************************************/ -static BOOL ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, +static bool ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, uint8 **ptr, struct dns_rr_srv *srv ) { struct dns_rr rr; @@ -202,7 +202,7 @@ static BOOL ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, /********************************************************************* *********************************************************************/ -static BOOL ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end, +static bool ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end, uint8 **ptr, struct dns_rr_ns *nsrec ) { struct dns_rr rr; @@ -638,10 +638,10 @@ static char *sitename_key(const char *realm) We store indefinately as every new CLDAP query will re-write this. ****************************************************************************/ -BOOL sitename_store(const char *realm, const char *sitename) +bool sitename_store(const char *realm, const char *sitename) { time_t expire; - BOOL ret = False; + bool ret = False; char *key; if (!gencache_init()) { @@ -681,7 +681,7 @@ char *sitename_fetch(const char *realm) { char *sitename = NULL; time_t timeout; - BOOL ret = False; + bool ret = False; const char *query_realm; char *key; @@ -713,9 +713,9 @@ char *sitename_fetch(const char *realm) Did the sitename change ? ****************************************************************************/ -BOOL stored_sitename_changed(const char *realm, const char *sitename) +bool stored_sitename_changed(const char *realm, const char *sitename) { - BOOL ret = False; + bool ret = False; char *new_sitename; -- cgit From e2d0526c9799a75f87bbbe24f2e5a268df89fea9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 29 Oct 2007 13:34:00 -0700 Subject: Change our DNS code to cope with AAAA records. A6 records look like a nightmare to use, so ignore them for now. Jeremy. (This used to be commit 814daded90781dc5a5bdd522ea8cfe5d47e6d7a7) --- source3/libads/dns.c | 294 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 189 insertions(+), 105 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 7959e910a8..8aca5b083e 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -1,18 +1,19 @@ -/* +/* Unix SMB/CIFS implementation. DNS utility library Copyright (C) Gerald (Jerry) Carter 2006. + Copyright (C) Jeremy Allison 2007. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -44,6 +45,13 @@ #if !defined(T_A) /* AIX 5.3 already defines T_A */ # define T_A ns_t_a #endif + +#if defined(HAVE_IPV6) +#if !defined(T_AAAA) +# define T_AAAA ns_t_aaaa +#endif +#endif + # define T_SRV ns_t_srv #if !defined(T_NS) /* AIX 5.3 already defines T_NS */ # define T_NS ns_t_ns @@ -73,7 +81,7 @@ static bool ads_dns_parse_query( TALLOC_CTX *ctx, uint8 *start, uint8 *end, int namelen; ZERO_STRUCTP( q ); - + if ( !start || !end || !q || !*ptr) return False; @@ -134,7 +142,7 @@ static bool ads_dns_parse_rr( TALLOC_CTX *ctx, uint8 *start, uint8 *end, rr->in_class = RSVAL(p, 2); rr->ttl = RIVAL(p, 4); rr->rdatalen = RSVAL(p, 8); - + p += 10; /* sanity check the available space */ @@ -168,7 +176,7 @@ static bool ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, if ( !start || !end || !srv || !*ptr) return -1; - /* Parse the RR entry. Coming out of the this, ptr is at the beginning + /* Parse the RR entry. Coming out of the this, ptr is at the beginning of the next record */ if ( !ads_dns_parse_rr( ctx, start, end, ptr, &rr ) ) { @@ -177,7 +185,8 @@ static bool ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, } if ( rr.type != T_SRV ) { - DEBUG(1,("ads_dns_parse_rr_srv: Bad answer type (%d)\n", rr.type)); + DEBUG(1,("ads_dns_parse_rr_srv: Bad answer type (%d)\n", + rr.type)); return False; } @@ -213,7 +222,7 @@ static bool ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end, if ( !start || !end || !nsrec || !*ptr) return -1; - /* Parse the RR entry. Coming out of the this, ptr is at the beginning + /* Parse the RR entry. Coming out of the this, ptr is at the beginning of the next record */ if ( !ads_dns_parse_rr( ctx, start, end, ptr, &rr ) ) { @@ -222,14 +231,15 @@ static bool ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end, } if ( rr.type != T_NS ) { - DEBUG(1,("ads_dns_parse_rr_ns: Bad answer type (%d)\n", rr.type)); + DEBUG(1,("ads_dns_parse_rr_ns: Bad answer type (%d)\n", + rr.type)); return False; } p = rr.rdata; /* ame server hostname */ - + namelen = dn_expand( start, end, p, nsname, sizeof(nsname) ); if ( namelen < 0 ) { DEBUG(1,("ads_dns_parse_rr_ns: Failed to uncompress name!\n")); @@ -249,16 +259,16 @@ static int dnssrvcmp( struct dns_rr_srv *a, struct dns_rr_srv *b ) if ( a->priority == b->priority ) { /* randomize entries with an equal weight and priority */ - if ( a->weight == b->weight ) + if ( a->weight == b->weight ) return 0; - /* higher weights should be sorted lower */ + /* higher weights should be sorted lower */ if ( a->weight > b->weight ) return -1; else return 1; } - + if ( a->priority < b->priority ) return -1; @@ -271,14 +281,14 @@ static int dnssrvcmp( struct dns_rr_srv *a, struct dns_rr_srv *b ) #define DNS_FAILED_WAITTIME 30 -static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, +static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, uint8 **buf, int *resp_length ) { uint8 *buffer = NULL; size_t buf_len; - int resp_len = NS_PACKETSZ; + int resp_len = NS_PACKETSZ; static time_t last_dns_check = 0; - static NTSTATUS last_dns_status = NT_STATUS_OK; + static NTSTATUS last_dns_status = NT_STATUS_OK; time_t now = time(NULL); /* Try to prevent bursts of DNS lookups if the server is down */ @@ -288,13 +298,13 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, if ( last_dns_check > now ) last_dns_check = 0; - /* IF we had a DNS timeout or a bad server and we are still - in the 30 second cache window, just return the previous + /* IF we had a DNS timeout or a bad server and we are still + in the 30 second cache window, just return the previous status and save the network timeout. */ if ( (NT_STATUS_EQUAL(last_dns_status,NT_STATUS_IO_TIMEOUT) || NT_STATUS_EQUAL(last_dns_status,NT_STATUS_CONNECTION_REFUSED)) && - (last_dns_check+DNS_FAILED_WAITTIME) > now ) + (last_dns_check+DNS_FAILED_WAITTIME) > now ) { DEBUG(10,("last_dns_check: Returning cached status (%s)\n", nt_errstr(last_dns_status) )); @@ -305,39 +315,44 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, do { if ( buffer ) TALLOC_FREE( buffer ); - + buf_len = resp_len * sizeof(uint8); - if (buf_len) { - if ( (buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) == NULL ) { - DEBUG(0,("ads_dns_lookup_srv: talloc() failed!\n")); + if (buf_len) { + if ((buffer = TALLOC_ARRAY(ctx, uint8, buf_len)) + == NULL ) { + DEBUG(0,("ads_dns_lookup_srv: " + "talloc() failed!\n")); last_dns_status = NT_STATUS_NO_MEMORY; last_dns_check = time(NULL); - return last_dns_status; + return last_dns_status; } } - if ( (resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) < 0 ) { - DEBUG(3,("ads_dns_lookup_srv: Failed to resolve %s (%s)\n", name, strerror(errno))); + if ((resp_len = res_query(name, C_IN, q_type, buffer, buf_len)) + < 0 ) { + DEBUG(3,("ads_dns_lookup_srv: " + "Failed to resolve %s (%s)\n", + name, strerror(errno))); TALLOC_FREE( buffer ); last_dns_status = NT_STATUS_UNSUCCESSFUL; - + if (errno == ETIMEDOUT) { - last_dns_status = NT_STATUS_IO_TIMEOUT; + last_dns_status = NT_STATUS_IO_TIMEOUT; } if (errno == ECONNREFUSED) { - last_dns_status = NT_STATUS_CONNECTION_REFUSED; + last_dns_status = NT_STATUS_CONNECTION_REFUSED; } last_dns_check = time(NULL); return last_dns_status; } } while ( buf_len < resp_len && resp_len < MAX_DNS_PACKET_SIZE ); - + *buf = buffer; *resp_length = resp_len; last_dns_check = time(NULL); - last_dns_status = NT_STATUS_OK; + last_dns_status = NT_STATUS_OK; return last_dns_status; } @@ -345,7 +360,10 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, Simple wrapper for a DNS SRV query *********************************************************************/ -static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dns_rr_srv **dclist, int *numdcs ) +static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, + const char *name, + struct dns_rr_srv **dclist, + int *numdcs) { uint8 *buffer = NULL; int resp_len = 0; @@ -359,8 +377,8 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn if ( !ctx || !name || !dclist ) { return NT_STATUS_INVALID_PARAMETER; } - - /* Send the request. May have to loop several times in case + + /* Send the request. May have to loop several times in case of large replies */ status = dns_send_req( ctx, name, T_SRV, &buffer, &resp_len ); @@ -375,19 +393,23 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn available in libresolv.a, and not the shared lib. Who knows why.... So we have to parse the DNS reply ourselves */ - /* Pull the answer RR's count from the header. Use the NMB ordering macros */ + /* Pull the answer RR's count from the header. + * Use the NMB ordering macros */ query_count = RSVAL( p, 4 ); answer_count = RSVAL( p, 6 ); auth_count = RSVAL( p, 8 ); additional_count = RSVAL( p, 10 ); - DEBUG(4,("ads_dns_lookup_srv: %d records returned in the answer section.\n", + DEBUG(4,("ads_dns_lookup_srv: " + "%d records returned in the answer section.\n", answer_count)); - + if (answer_count) { - if ( (dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, answer_count)) == NULL ) { - DEBUG(0,("ads_dns_lookup_srv: talloc() failure for %d char*'s\n", + if ((dcs = TALLOC_ZERO_ARRAY(ctx, struct dns_rr_srv, + answer_count)) == NULL ) { + DEBUG(0,("ads_dns_lookup_srv: " + "talloc() failure for %d char*'s\n", answer_count)); return NT_STATUS_NO_MEMORY; } @@ -404,8 +426,10 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, const char *name, struct dn for ( rrnum=0; rrnum Date: Thu, 15 Nov 2007 18:27:26 -0800 Subject: Add MAX_DNS_NAME_LENGTH, remove more pstrings. Jeremy. (This used to be commit a1725f4ff7ed375808c78ac661b539557748d0a5) --- source3/libads/dns.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 8aca5b083e..cdc4b448cf 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -77,7 +77,7 @@ static bool ads_dns_parse_query( TALLOC_CTX *ctx, uint8 *start, uint8 *end, uint8 **ptr, struct dns_query *q ) { uint8 *p = *ptr; - pstring hostname; + char hostname[MAX_DNS_NAME_LENGTH]; int namelen; ZERO_STRUCTP( q ); @@ -115,7 +115,7 @@ static bool ads_dns_parse_rr( TALLOC_CTX *ctx, uint8 *start, uint8 *end, uint8 **ptr, struct dns_rr *rr ) { uint8 *p = *ptr; - pstring hostname; + char hostname[MAX_DNS_NAME_LENGTH]; int namelen; if ( !start || !end || !rr || !*ptr) @@ -170,7 +170,7 @@ static bool ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, { struct dns_rr rr; uint8 *p; - pstring dcname; + char dcname[MAX_DNS_NAME_LENGTH]; int namelen; if ( !start || !end || !srv || !*ptr) @@ -216,7 +216,7 @@ static bool ads_dns_parse_rr_ns( TALLOC_CTX *ctx, uint8 *start, uint8 *end, { struct dns_rr rr; uint8 *p; - pstring nsname; + char nsname[MAX_DNS_NAME_LENGTH]; int namelen; if ( !start || !end || !nsrec || !*ptr) -- cgit From 78c6ee0090f4122bc25baaacb5546517ad4b7bc6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Nov 2007 17:27:54 +0100 Subject: Remove some globals (This used to be commit 31d0a846db08d845e6cdfd85def4ac1c34031e02) --- source3/libads/dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index cdc4b448cf..3239892814 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -709,7 +709,7 @@ static char *sitename_key(const char *realm) { char *keystr; - if (asprintf(&keystr, SITENAME_KEY, strupper_static(realm)) == -1) { + if (asprintf_strupper_m(&keystr, SITENAME_KEY, realm) == -1) { return NULL; } -- cgit From 43c079ef26b6c5c1ee3c22c72d800d6131396993 Mon Sep 17 00:00:00 2001 From: "Gerald W. Carter" Date: Wed, 30 Apr 2008 09:57:15 -0500 Subject: BUG 5107: Fix handling of large DNS replies on AIX and Solaris. On AIX, Solaris, and possibly some older glibc systems (e.g. SLES8) truncated replies never give back a resp_len > buflen which ends up causing DNS resolve failures on large tcp DNS replies. Also add more debug lines about processing the DNS reply. (This used to be commit 5ed9b92097460cd8180db806a08213e97cfb8daa) --- source3/libads/dns.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 3239892814..fe0e6d3e86 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -203,8 +203,15 @@ static bool ads_dns_parse_rr_srv( TALLOC_CTX *ctx, uint8 *start, uint8 *end, DEBUG(1,("ads_dns_parse_rr_srv: Failed to uncompress name!\n")); return False; } + srv->hostname = talloc_strdup( ctx, dcname ); + DEBUG(10,("ads_dns_parse_rr_srv: Parsed %s [%u, %u, %u]\n", + srv->hostname, + srv->priority, + srv->weight, + srv->port)); + return True; } @@ -285,7 +292,7 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, uint8 **buf, int *resp_length ) { uint8 *buffer = NULL; - size_t buf_len; + size_t buf_len = 0; int resp_len = NS_PACKETSZ; static time_t last_dns_check = 0; static NTSTATUS last_dns_status = NT_STATUS_OK; @@ -346,7 +353,26 @@ static NTSTATUS dns_send_req( TALLOC_CTX *ctx, const char *name, int q_type, last_dns_check = time(NULL); return last_dns_status; } - } while ( buf_len < resp_len && resp_len < MAX_DNS_PACKET_SIZE ); + + /* On AIX, Solaris, and possibly some older glibc systems (e.g. SLES8) + truncated replies never give back a resp_len > buflen + which ends up causing DNS resolve failures on large tcp DNS replies */ + + if (buf_len == resp_len) { + if (resp_len == MAX_DNS_PACKET_SIZE) { + DEBUG(1,("dns_send_req: DNS reply too large when resolving %s\n", + name)); + TALLOC_FREE( buffer ); + last_dns_status = NT_STATUS_BUFFER_TOO_SMALL; + last_dns_check = time(NULL); + return last_dns_status; + } + + resp_len = MIN(resp_len*2, MAX_DNS_PACKET_SIZE); + } + + + } while ( buf_len < resp_len && resp_len <= MAX_DNS_PACKET_SIZE ); *buf = buffer; *resp_length = resp_len; @@ -429,7 +455,7 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, if (!ads_dns_parse_query(ctx, buffer, buffer+resp_len, &p, &q)) { DEBUG(1,("ads_dns_lookup_srv: " - "Failed to parse query record!\n")); + "Failed to parse query record [%d]!\n", rrnum)); return NT_STATUS_UNSUCCESSFUL; } } @@ -440,7 +466,7 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, if (!ads_dns_parse_rr_srv(ctx, buffer, buffer+resp_len, &p, &dcs[rrnum])) { DEBUG(1,("ads_dns_lookup_srv: " - "Failed to parse answer record!\n")); + "Failed to parse answer recordi [%d]!\n", rrnum)); return NT_STATUS_UNSUCCESSFUL; } } @@ -455,7 +481,7 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, if (!ads_dns_parse_rr( ctx, buffer, buffer+resp_len, &p, &rr)) { DEBUG(1,("ads_dns_lookup_srv: " - "Failed to parse authority record!\n")); + "Failed to parse authority record! [%d]\n", rrnum)); return NT_STATUS_UNSUCCESSFUL; } } @@ -469,7 +495,7 @@ static NTSTATUS ads_dns_lookup_srv( TALLOC_CTX *ctx, if (!ads_dns_parse_rr(ctx, buffer, buffer+resp_len, &p, &rr)) { DEBUG(1,("ads_dns_lookup_srv: Failed " - "to parse additional records section!\n")); + "to parse additional records section! [%d]\n", rrnum)); return NT_STATUS_UNSUCCESSFUL; } -- cgit From 893e3522fc9a9cb1ef677ce1232525f51a8cc95e Mon Sep 17 00:00:00 2001 From: "Gerald W. Carter" Date: Sat, 28 Jun 2008 09:35:07 -0400 Subject: Return NULL in sitename_fetch() if gencache_init() fails. Not false (This used to be commit 8704c2ab37479236788c0a99465d73643d3d555a) --- source3/libads/dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index fe0e6d3e86..3a9e849668 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -796,7 +796,7 @@ char *sitename_fetch(const char *realm) char *key; if (!gencache_init()) { - return False; + return NULL; } if (!realm || (strlen(realm) == 0)) { -- cgit From 962beb287239b525ed4828ae13b85de31448d256 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 3 Jul 2008 15:15:57 +0200 Subject: Pass NULL to gencache_get when we are not interested in the timeout value (This used to be commit 16062dfc3dcc8f1ca0024a3ae21effb889c7ffc0) --- source3/libads/dns.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index 3a9e849668..a8825d32e6 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -790,7 +790,6 @@ bool sitename_store(const char *realm, const char *sitename) char *sitename_fetch(const char *realm) { char *sitename = NULL; - time_t timeout; bool ret = False; const char *query_realm; char *key; @@ -807,7 +806,7 @@ char *sitename_fetch(const char *realm) key = sitename_key(query_realm); - ret = gencache_get( key, &sitename, &timeout ); + ret = gencache_get( key, &sitename, NULL ); SAFE_FREE(key); if ( !ret ) { DEBUG(5,("sitename_fetch: No stored sitename for %s\n", -- cgit From d3def9a18cc701573530154ed420278f007f06a3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 11 Jul 2008 17:44:25 +0200 Subject: Revert "Pass NULL to gencache_get when we are not interested in the timeout value" This reverts commit 16062dfc3dcc8f1ca0024a3ae21effb889c7ffc0. (This used to be commit 114ca8577568cdb5a81d8734f1d1d096f1b36c36) --- source3/libads/dns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/libads/dns.c') diff --git a/source3/libads/dns.c b/source3/libads/dns.c index a8825d32e6..3a9e849668 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -790,6 +790,7 @@ bool sitename_store(const char *realm, const char *sitename) char *sitename_fetch(const char *realm) { char *sitename = NULL; + time_t timeout; bool ret = False; const char *query_realm; char *key; @@ -806,7 +807,7 @@ char *sitename_fetch(const char *realm) key = sitename_key(query_realm); - ret = gencache_get( key, &sitename, NULL ); + ret = gencache_get( key, &sitename, &timeout ); SAFE_FREE(key); if ( !ret ) { DEBUG(5,("sitename_fetch: No stored sitename for %s\n", -- cgit