summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2002-08-22 22:50:57 +0000
committerAndrew Tridgell <tridge@samba.org>2002-08-22 22:50:57 +0000
commit84b4e79227c4e5ad7f03c3fbc289465fa913cb39 (patch)
treead9ec553c43526aedaba490edb37cd489eb9f7e4
parent2a505d023f95457f63a3975e386b95e8658928f4 (diff)
downloadsamba-84b4e79227c4e5ad7f03c3fbc289465fa913cb39.tar.gz
samba-84b4e79227c4e5ad7f03c3fbc289465fa913cb39.tar.bz2
samba-84b4e79227c4e5ad7f03c3fbc289465fa913cb39.zip
a few minor cleanups in the cldap request
(This used to be commit 228fc518da0404fe770175d5277fe5f5b08f9c67)
-rw-r--r--source3/utils/net_ads_cldap.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/source3/utils/net_ads_cldap.c b/source3/utils/net_ads_cldap.c
index 1bf96fc5d5..6821a5902e 100644
--- a/source3/utils/net_ads_cldap.c
+++ b/source3/utils/net_ads_cldap.c
@@ -45,7 +45,7 @@ static unsigned pull_len_string(char **ret, const char *p)
unsigned len = *p;
(*ret) = NULL;
if (len == 0) return 1;
- (*ret) = strndup(p+1, len);
+ (*ret) = smb_xstrndup(p+1, len);
return len+1;
}
@@ -156,8 +156,9 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply)
blob = data_blob(NULL, 8192);
ret = read(sock, blob.data, blob.length);
+
if (ret <= 0) {
- d_printf("no reply to cldap netlogon\n");
+ d_printf("no reply received to cldap netlogon\n");
return -1;
}
blob.length = ret;
@@ -180,6 +181,11 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply)
asn1_end_tag(&data);
asn1_end_tag(&data);
+ if (data.has_error) {
+ d_printf("Failed to parse cldap reply\n");
+ return -1;
+ }
+
file_save("cldap_reply_core.dat", os3.data, os3.length);
p = os3.data;
@@ -208,6 +214,18 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply)
/*
+ free a cldap reply packet
+*/
+static void cldap_reply_free(struct cldap_netlogon_reply *reply)
+{
+ SAFE_FREE(reply->domain);
+ SAFE_FREE(reply->server_name);
+ SAFE_FREE(reply->domain_flatname);
+ SAFE_FREE(reply->server_flatname);
+ SAFE_FREE(reply->dns_name);
+}
+
+/*
do a cldap netlogon query
*/
int ads_cldap_netlogon(ADS_STRUCT *ads)
@@ -233,6 +251,10 @@ int ads_cldap_netlogon(ADS_STRUCT *ads)
ret = recv_cldap_netlogon(sock, &reply);
close(sock);
+ if (ret == -1) {
+ return -1;
+ }
+
d_printf("Version: 0x%x\n", reply.version);
d_printf("GUID: ");
print_guid(&reply.guid);
@@ -242,6 +264,8 @@ int ads_cldap_netlogon(ADS_STRUCT *ads)
d_printf("Flatname: %s\n", reply.domain_flatname);
d_printf("Server Name2: %s\n", reply.server_flatname);
d_printf("DNS Name: %s\n", reply.dns_name);
+
+ cldap_reply_free(&reply);
return ret;
}