summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/libads/cldap.c13
-rw-r--r--source3/libads/ldap.c31
-rw-r--r--source3/libsmb/dsgetdcname.c4
-rw-r--r--source3/utils/net_ads.c4
4 files changed, 34 insertions, 18 deletions
diff --git a/source3/libads/cldap.c b/source3/libads/cldap.c
index 6068ca4faf..be084c9df6 100644
--- a/source3/libads/cldap.c
+++ b/source3/libads/cldap.c
@@ -116,7 +116,9 @@ static void gotalarm_sig(void)
/*
receive a cldap netlogon reply
*/
-static int recv_cldap_netlogon(int sock, struct nbt_cldap_netlogon_5 *reply)
+static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
+ int sock,
+ struct nbt_cldap_netlogon_5 *reply)
{
int ret;
ASN1_DATA data;
@@ -182,7 +184,7 @@ static int recv_cldap_netlogon(int sock, struct nbt_cldap_netlogon_5 *reply)
return -1;
}
- ndr_err = ndr_pull_union_blob_all(&os3, talloc_tos(), &p, 5,
+ ndr_err = ndr_pull_union_blob_all(&os3, mem_ctx, &p, 5,
(ndr_pull_flags_fn_t)ndr_pull_nbt_cldap_netlogon);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
return -1;
@@ -208,7 +210,10 @@ static int recv_cldap_netlogon(int sock, struct nbt_cldap_netlogon_5 *reply)
do a cldap netlogon query. Always 389/udp
*******************************************************************/
-bool ads_cldap_netlogon(const char *server, const char *realm, struct nbt_cldap_netlogon_5 *reply)
+bool ads_cldap_netlogon(TALLOC_CTX *mem_ctx,
+ const char *server,
+ const char *realm,
+ struct nbt_cldap_netlogon_5 *reply)
{
int sock;
int ret;
@@ -225,7 +230,7 @@ bool ads_cldap_netlogon(const char *server, const char *realm, struct nbt_cldap
close(sock);
return False;
}
- ret = recv_cldap_netlogon(sock, reply);
+ ret = recv_cldap_netlogon(mem_ctx, sock, reply);
close(sock);
if (ret == -1) {
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index b4a977056e..99df4ed8a3 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -177,6 +177,8 @@ bool ads_try_connect(ADS_STRUCT *ads, const char *server )
{
char *srv;
struct nbt_cldap_netlogon_5 cldap_reply;
+ TALLOC_CTX *mem_ctx = NULL;
+ bool ret = false;
if (!server || !*server) {
return False;
@@ -185,16 +187,22 @@ bool ads_try_connect(ADS_STRUCT *ads, const char *server )
DEBUG(5,("ads_try_connect: sending CLDAP request to %s (realm: %s)\n",
server, ads->server.realm));
+ mem_ctx = talloc_init("ads_try_connect");
+ if (!mem_ctx) {
+ DEBUG(0,("out of memory\n"));
+ return false;
+ }
+
/* this copes with inet_ntoa brokenness */
srv = SMB_STRDUP(server);
ZERO_STRUCT( cldap_reply );
- if ( !ads_cldap_netlogon( srv, ads->server.realm, &cldap_reply ) ) {
+ if ( !ads_cldap_netlogon(mem_ctx, srv, ads->server.realm, &cldap_reply ) ) {
DEBUG(3,("ads_try_connect: CLDAP request %s failed.\n", srv));
- SAFE_FREE( srv );
- return False;
+ ret = false;
+ goto out;
}
/* Check the CLDAP reply flags */
@@ -202,8 +210,8 @@ bool ads_try_connect(ADS_STRUCT *ads, const char *server )
if ( !(cldap_reply.server_type & ADS_LDAP) ) {
DEBUG(1,("ads_try_connect: %s's CLDAP reply says it is not an LDAP server!\n",
srv));
- SAFE_FREE( srv );
- return False;
+ ret = false;
+ goto out;
}
/* Fill in the ads->config values */
@@ -235,16 +243,19 @@ bool ads_try_connect(ADS_STRUCT *ads, const char *server )
DEBUG(1,("ads_try_connect: unable to convert %s "
"to an address\n",
srv));
- SAFE_FREE( srv );
- return False;
+ ret = false;
+ goto out;
}
- SAFE_FREE(srv);
-
/* Store our site name. */
sitename_store( cldap_reply.domain, cldap_reply.client_site);
- return True;
+ ret = true;
+ out:
+ SAFE_FREE(srv);
+ TALLOC_FREE(mem_ctx);
+
+ return ret;
}
/**********************************************************************
diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c
index 531ab11622..0b3b3d9bbf 100644
--- a/source3/libsmb/dsgetdcname.c
+++ b/source3/libsmb/dsgetdcname.c
@@ -203,7 +203,7 @@ static NTSTATUS dsgetdcname_cache_refresh(TALLOC_CTX *mem_ctx,
ZERO_STRUCT(r);
- if (ads_cldap_netlogon(info->dc_unc,
+ if (ads_cldap_netlogon(mem_ctx, info->dc_unc,
info->domain_name, &r)) {
dsgetdcname_cache_delete(mem_ctx, domain_name);
@@ -618,7 +618,7 @@ static NTSTATUS process_dc_dns(TALLOC_CTX *mem_ctx,
DEBUG(10,("LDAP ping to %s\n", dclist[i].hostname));
- if ((ads_cldap_netlogon(dclist[i].hostname,
+ if ((ads_cldap_netlogon(mem_ctx, dclist[i].hostname,
domain_name, &r)) &&
(check_cldap_reply_required_flags(r.server_type, flags))) {
valid_dc = true;
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
index af55430fac..dbdd3e3c59 100644
--- a/source3/utils/net_ads.c
+++ b/source3/utils/net_ads.c
@@ -84,7 +84,7 @@ static int net_ads_cldap_netlogon(ADS_STRUCT *ads)
struct nbt_cldap_netlogon_5 reply;
print_sockaddr(addr, sizeof(addr), &ads->ldap.ss);
- if ( !ads_cldap_netlogon(addr, ads->server.realm, &reply ) ) {
+ if ( !ads_cldap_netlogon(talloc_tos(), addr, ads->server.realm, &reply ) ) {
d_fprintf(stderr, "CLDAP query failed!\n");
return -1;
}
@@ -389,7 +389,7 @@ static int net_ads_workgroup(int argc, const char **argv)
}
print_sockaddr(addr, sizeof(addr), &ads->ldap.ss);
- if ( !ads_cldap_netlogon(addr, ads->server.realm, &reply ) ) {
+ if ( !ads_cldap_netlogon(talloc_tos(), addr, ads->server.realm, &reply ) ) {
d_fprintf(stderr, "CLDAP query failed!\n");
return -1;
}