summaryrefslogtreecommitdiff
path: root/source4/torture/ldap/common.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-30 07:22:16 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:09:23 -0500
commita0ab1f7afda62964d480af9dc26e60a38d1350e0 (patch)
treec078770b99b8a2972ff71cd090acb2ebfe0d7a60 /source4/torture/ldap/common.c
parent003fbe7f6472ed433bc5495b422f3e6d5278da17 (diff)
downloadsamba-a0ab1f7afda62964d480af9dc26e60a38d1350e0.tar.gz
samba-a0ab1f7afda62964d480af9dc26e60a38d1350e0.tar.bz2
samba-a0ab1f7afda62964d480af9dc26e60a38d1350e0.zip
r5107: moved the horrible ldap socket code, and the even worse
asn1-tied-to-blocking-sockets code into the ldap client and torture suite, and out of the generic libs, so nobody else is tempted to use it for any new code. (This used to be commit 39d1ced21baeca40d1fca62ba65243ca8f15757e)
Diffstat (limited to 'source4/torture/ldap/common.c')
-rw-r--r--source4/torture/ldap/common.c65
1 files changed, 59 insertions, 6 deletions
diff --git a/source4/torture/ldap/common.c b/source4/torture/ldap/common.c
index 162934a38d..b9f0f5c655 100644
--- a/source4/torture/ldap/common.c
+++ b/source4/torture/ldap/common.c
@@ -103,6 +103,61 @@ NTSTATUS torture_ldap_close(struct ldap_connection *conn)
return NT_STATUS_OK;
}
+
+/*
+ Write data to a fd
+*/
+static ssize_t write_data(int fd, char *buffer, size_t N)
+{
+ size_t total=0;
+ ssize_t ret;
+
+ while (total < N) {
+ ret = sys_write(fd,buffer + total,N - total);
+
+ if (ret == -1) {
+ DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno) ));
+ return -1;
+ }
+ if (ret == 0)
+ return total;
+
+ total += ret;
+ }
+
+ return (ssize_t)total;
+}
+
+
+/*
+ Read data from the client, reading exactly N bytes
+*/
+static ssize_t read_data(int fd, char *buffer, size_t N)
+{
+ ssize_t ret;
+ size_t total=0;
+
+ while (total < N) {
+
+ ret = sys_read(fd,buffer + total,N - total);
+
+ if (ret == 0) {
+ DEBUG(10,("read_data: read of %d returned 0. Error = %s\n",
+ (int)(N - total), strerror(errno) ));
+ return 0;
+ }
+
+ if (ret == -1) {
+ DEBUG(0,("read_data: read failure for %d. Error = %s\n",
+ (int)(N - total), strerror(errno) ));
+ return -1;
+ }
+ total += ret;
+ }
+
+ return (ssize_t)total;
+}
+
BOOL ldap_sasl_send_msg(struct ldap_connection *conn, struct ldap_message *msg,
const struct timeval *endtime)
{
@@ -131,26 +186,24 @@ BOOL ldap_sasl_send_msg(struct ldap_connection *conn, struct ldap_message *msg,
RSIVAL(length, 0, wrapped.length);
- result = (write_data_until(conn->sock, length, 4,
- endtime) == 4);
+ result = (write_data(conn->sock, length, 4) == 4);
if (!result)
return result;
- result = (write_data_until(conn->sock, wrapped.data, wrapped.length,
- endtime) == wrapped.length);
+ result = (write_data(conn->sock, wrapped.data, wrapped.length) == wrapped.length);
if (!result)
return result;
wrapped = data_blob(NULL, 0x4000);
data_blob_clear(&wrapped);
- result = (read_data_until(conn->sock, length, 4, NULL) == 4);
+ result = (read_data(conn->sock, length, 4) == 4);
if (!result)
return result;
len = RIVAL(length,0);
- result = (read_data_until(conn->sock, wrapped.data, MIN(wrapped.length,len), NULL) == len);
+ result = (read_data(conn->sock, wrapped.data, MIN(wrapped.length,len)) == len);
if (!result)
return result;