summaryrefslogtreecommitdiff
path: root/source3/libads
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-04-26 17:03:32 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-04-28 05:30:20 +0200
commit818ec32d0c4dde545199b4462da30b49a19ecc87 (patch)
treeb9ef927164f792e495ffb768448e47a206f9f6a6 /source3/libads
parentaa8406cadf62ea676ffb7a6239a8b3f4fe71abbf (diff)
downloadsamba-818ec32d0c4dde545199b4462da30b49a19ecc87.tar.gz
samba-818ec32d0c4dde545199b4462da30b49a19ecc87.tar.bz2
samba-818ec32d0c4dde545199b4462da30b49a19ecc87.zip
s3-libads Pass a struct sockaddr_storage to cldap routines
This avoids these routines doing a DNS lookup that has already been done, and ensures that the emulated DNS lookup isn't thrown away. Andrew Bartlett
Diffstat (limited to 'source3/libads')
-rw-r--r--source3/libads/cldap.c14
-rw-r--r--source3/libads/cldap.h4
-rw-r--r--source3/libads/ldap.c41
3 files changed, 17 insertions, 42 deletions
diff --git a/source3/libads/cldap.c b/source3/libads/cldap.c
index 5d2e900c05..03fa17c26f 100644
--- a/source3/libads/cldap.c
+++ b/source3/libads/cldap.c
@@ -30,7 +30,7 @@
*******************************************************************/
bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx,
- const char *server,
+ struct sockaddr_storage *ss,
const char *realm,
uint32_t nt_version,
struct netlogon_samlogon_response **_reply)
@@ -39,18 +39,12 @@ bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx,
struct cldap_netlogon io;
struct netlogon_samlogon_response *reply;
NTSTATUS status;
- struct sockaddr_storage ss;
char addrstr[INET6_ADDRSTRLEN];
const char *dest_str;
int ret;
struct tsocket_address *dest_addr;
- if (!interpret_string_addr_prefer_ipv4(&ss, server, 0)) {
- DEBUG(2,("Failed to resolve[%s] into an address for cldap\n",
- server));
- return false;
- }
- dest_str = print_sockaddr(addrstr, sizeof(addrstr), &ss);
+ dest_str = print_sockaddr(addrstr, sizeof(addrstr), ss);
ret = tsocket_address_inet_from_strings(mem_ctx, "ip",
dest_str, LDAP_PORT,
@@ -113,7 +107,7 @@ failed:
*******************************************************************/
bool ads_cldap_netlogon_5(TALLOC_CTX *mem_ctx,
- const char *server,
+ struct sockaddr_storage *ss,
const char *realm,
struct NETLOGON_SAM_LOGON_RESPONSE_EX *reply5)
{
@@ -121,7 +115,7 @@ bool ads_cldap_netlogon_5(TALLOC_CTX *mem_ctx,
struct netlogon_samlogon_response *reply = NULL;
bool ret;
- ret = ads_cldap_netlogon(mem_ctx, server, realm, nt_version, &reply);
+ ret = ads_cldap_netlogon(mem_ctx, ss, realm, nt_version, &reply);
if (!ret) {
return false;
}
diff --git a/source3/libads/cldap.h b/source3/libads/cldap.h
index e2d05ce731..36f4588939 100644
--- a/source3/libads/cldap.h
+++ b/source3/libads/cldap.h
@@ -2,11 +2,11 @@
/* The following definitions come from libads/cldap.c */
bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx,
- const char *server,
+ struct sockaddr_storage *ss,
const char *realm,
uint32_t nt_version,
struct netlogon_samlogon_response **reply);
bool ads_cldap_netlogon_5(TALLOC_CTX *mem_ctx,
- const char *server,
+ struct sockaddr_storage *ss,
const char *realm,
struct NETLOGON_SAM_LOGON_RESPONSE_EX *reply5);
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index d65e53ee19..793b689361 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -196,45 +196,32 @@ bool ads_closest_dc(ADS_STRUCT *ads)
*/
static bool ads_try_connect(ADS_STRUCT *ads, const char *server, bool gc)
{
- char *srv;
struct NETLOGON_SAM_LOGON_RESPONSE_EX cldap_reply;
TALLOC_CTX *frame = talloc_stackframe();
bool ret = false;
+ struct sockaddr_storage ss;
+ char addr[INET6_ADDRSTRLEN];
if (!server || !*server) {
TALLOC_FREE(frame);
return False;
}
- if (!is_ipaddress(server)) {
- struct sockaddr_storage ss;
- char addr[INET6_ADDRSTRLEN];
-
- if (!resolve_name(server, &ss, 0x20, true)) {
- DEBUG(5,("ads_try_connect: unable to resolve name %s\n",
- server ));
- TALLOC_FREE(frame);
- return false;
- }
- print_sockaddr(addr, sizeof(addr), &ss);
- srv = talloc_strdup(frame, addr);
- } else {
- /* this copes with inet_ntoa brokenness */
- srv = talloc_strdup(frame, server);
- }
-
- if (!srv) {
+ if (!resolve_name(server, &ss, 0x20, true)) {
+ DEBUG(5,("ads_try_connect: unable to resolve name %s\n",
+ server ));
TALLOC_FREE(frame);
return false;
}
+ print_sockaddr(addr, sizeof(addr), &ss);
DEBUG(5,("ads_try_connect: sending CLDAP request to %s (realm: %s)\n",
- srv, ads->server.realm));
+ addr, ads->server.realm));
ZERO_STRUCT( cldap_reply );
- if ( !ads_cldap_netlogon_5(frame, srv, ads->server.realm, &cldap_reply ) ) {
- DEBUG(3,("ads_try_connect: CLDAP request %s failed.\n", srv));
+ if ( !ads_cldap_netlogon_5(frame, &ss, ads->server.realm, &cldap_reply ) ) {
+ DEBUG(3,("ads_try_connect: CLDAP request %s failed.\n", addr));
ret = false;
goto out;
}
@@ -243,7 +230,7 @@ static bool ads_try_connect(ADS_STRUCT *ads, const char *server, bool gc)
if ( !(cldap_reply.server_type & NBT_SERVER_LDAP) ) {
DEBUG(1,("ads_try_connect: %s's CLDAP reply says it is not an LDAP server!\n",
- srv));
+ addr));
ret = false;
goto out;
}
@@ -273,13 +260,7 @@ static bool ads_try_connect(ADS_STRUCT *ads, const char *server, bool gc)
ads->server.workgroup = SMB_STRDUP(cldap_reply.domain_name);
ads->ldap.port = gc ? LDAP_GC_PORT : LDAP_PORT;
- if (!interpret_string_addr(&ads->ldap.ss, srv, 0)) {
- DEBUG(1,("ads_try_connect: unable to convert %s "
- "to an address\n",
- srv));
- ret = false;
- goto out;
- }
+ ads->ldap.ss = ss;
/* Store our site name. */
sitename_store( cldap_reply.domain_name, cldap_reply.client_site);