summaryrefslogtreecommitdiff
path: root/source3/libads
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-08-30 04:40:03 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:38:59 -0500
commit2abab7ee6d04a62017d99578c274244a1cdd27b2 (patch)
treecaba5392b1f1ba24f7af17b94cb2d85f643b874b /source3/libads
parent3bc4fd1bb9bfbd0e0efd89d47c50bf798e5a1481 (diff)
downloadsamba-2abab7ee6d04a62017d99578c274244a1cdd27b2.tar.gz
samba-2abab7ee6d04a62017d99578c274244a1cdd27b2.tar.bz2
samba-2abab7ee6d04a62017d99578c274244a1cdd27b2.zip
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)
Diffstat (limited to 'source3/libads')
-rw-r--r--source3/libads/cldap.c4
-rw-r--r--source3/libads/dns.c99
-rw-r--r--source3/libads/ldap.c3
3 files changed, 99 insertions, 7 deletions
diff --git a/source3/libads/cldap.c b/source3/libads/cldap.c
index 2e96270e90..3a6083558f 100644
--- a/source3/libads/cldap.c
+++ b/source3/libads/cldap.c
@@ -260,8 +260,8 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply)
*reply->user_name = 0;
}
- p += pull_netlogon_string(reply->site_name, p, (const char *)os3.data);
- p += pull_netlogon_string(reply->site_name_2, p, (const char *)os3.data);
+ p += pull_netlogon_string(reply->server_site_name, p, (const char *)os3.data);
+ p += pull_netlogon_string(reply->client_site_name, p, (const char *)os3.data);
reply->version = IVAL(p, 0);
reply->lmnt_token = SVAL(p, 4);
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;
+}
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index c6d1fc9c60..c943558bd3 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -173,6 +173,9 @@ BOOL ads_try_connect(ADS_STRUCT *ads, const char *server )
saf_store( ads->server.workgroup, server );
+ /* Store our site name. */
+ sitename_store( cldap_reply.client_site_name );
+
return True;
}