summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2006-05-05 19:24:48 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:16:49 -0500
commitaf086da4ec19de83717820de85d8e672850ed4b2 (patch)
treeae285c5d92f19b4ce6cdc362cbca79f6232e7e99 /source3/utils
parent3bff11407e721a4a01b67881862d2a466ec5d103 (diff)
downloadsamba-af086da4ec19de83717820de85d8e672850ed4b2.tar.gz
samba-af086da4ec19de83717820de85d8e672850ed4b2.tar.bz2
samba-af086da4ec19de83717820de85d8e672850ed4b2.zip
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)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_ads.c6
-rw-r--r--source3/utils/net_lookup.c72
2 files changed, 48 insertions, 30 deletions
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<numdcs; i++ ) {
+ if ( resolve_name(dclist[i].hostname, &ip, 0x20) ) {
+ d_printf("%s:%d\n", inet_ntoa(ip), dclist[i].port);
+ }
+ }
}
#endif
static int net_lookup_ldap(int argc, const char **argv)
{
#ifdef HAVE_ADS
- char *srvlist;
const char *domain;
- int rc;
struct in_addr addr;
struct hostent *hostent;
+ struct dns_rr_srv *dcs = NULL;
+ int numdcs = 0;
+ TALLOC_CTX *ctx;
+ NTSTATUS status;
if (argc > 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"));