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/utils/net_ads.c | 6 +++- source3/utils/net_lookup.c | 72 +++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 30 deletions(-) (limited to 'source3/utils') diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index cca8dd63d0..8076860569 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -72,8 +72,12 @@ static int net_ads_lookup(int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; + const char *realm = NULL; - ads = ads_init(NULL, opt_target_workgroup, opt_host); + if ( strequal(lp_workgroup(), opt_target_workgroup ) ) + realm = lp_realm(); + + ads = ads_init(realm, opt_target_workgroup, opt_host); if (ads) { ads->auth.flags |= ADS_AUTH_NO_BIND; } diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c index dd2d666d5a..68097aa9f7 100644 --- a/source3/utils/net_lookup.c +++ b/source3/utils/net_lookup.c @@ -62,71 +62,85 @@ static int net_lookup_host(int argc, const char **argv) return 0; } -#ifdef HAVE_LDAP -static void print_ldap_srvlist(char *srvlist) +#ifdef HAVE_ADS +static void print_ldap_srvlist(struct dns_rr_srv *dclist, int numdcs ) { - char *cur, *next; struct in_addr ip; - BOOL printit; - - cur = srvlist; - do { - next = strchr(cur,':'); - if (next) *next++='\0'; - printit = resolve_name(cur, &ip, 0x20); - cur=next; - next=cur ? strchr(cur,' ') :NULL; - if (next) - *next++='\0'; - if (printit) - d_printf("%s:%s\n", inet_ntoa(ip), cur?cur:""); - cur = next; - } while (next); + int i; + + for ( i=0; i 0) domain = argv[0]; else domain = opt_target_workgroup; + if ( (ctx = talloc_init("net_lookup_ldap")) == NULL ) { + d_fprintf(stderr, "net_lookup_ldap: talloc_inti() failed!\n"); + return -1; + } + DEBUG(9, ("Lookup up ldap for domain %s\n", domain)); - rc = ldap_domain2hostlist(domain, &srvlist); - if ((rc == LDAP_SUCCESS) && srvlist) { - print_ldap_srvlist(srvlist); + + status = ads_dns_query_dcs( ctx, domain, &dcs, &numdcs ); + if ( NT_STATUS_IS_OK(status) && numdcs ) { + print_ldap_srvlist(dcs, numdcs); + TALLOC_FREE( ctx ); + return 0; } DEBUG(9, ("Looking up DC for domain %s\n", domain)); - if (!get_pdc_ip(domain, &addr)) + if (!get_pdc_ip(domain, &addr)) { + TALLOC_FREE( ctx ); return -1; + } hostent = gethostbyaddr((char *) &addr.s_addr, sizeof(addr.s_addr), AF_INET); - if (!hostent) + if (!hostent) { + TALLOC_FREE( ctx ); return -1; + } DEBUG(9, ("Found DC with DNS name %s\n", hostent->h_name)); domain = strchr(hostent->h_name, '.'); - if (!domain) + if (!domain) { + TALLOC_FREE( ctx ); return -1; + } domain++; DEBUG(9, ("Looking up ldap for domain %s\n", domain)); - rc = ldap_domain2hostlist(domain, &srvlist); - if ((rc == LDAP_SUCCESS) && srvlist) { - print_ldap_srvlist(srvlist); + + status = ads_dns_query_dcs( ctx, domain, &dcs, &numdcs ); + if ( NT_STATUS_IS_OK(status) && numdcs ) { + print_ldap_srvlist(dcs, numdcs); + TALLOC_FREE( ctx ); + return 0; } + + TALLOC_FREE( ctx ); + + return -1; #endif DEBUG(1,("No ADS support\n")); -- cgit