diff options
Diffstat (limited to 'source3/libads')
-rw-r--r-- | source3/libads/cldap.c | 4 | ||||
-rw-r--r-- | source3/libads/dns.c | 99 | ||||
-rw-r--r-- | source3/libads/ldap.c | 3 |
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; } |