r3507: - added deferred replies on sharing violation in pvfs open. The
[jelmer/samba4-debian.git] / source / ldap_server / ldap_server.c
index 6ce2dfdd79fd8a542c888a0b4c19c55f1e40260f..9338baa165f8597fc76be44c62676587445fc3d8 100644 (file)
 */
 
 #include "includes.h"
+#include "events.h"
+#include "auth/auth.h"
+#include "dlinklist.h"
+#include "asn_1.h"
+#include "ldap_server/ldap_server.h"
 
 /*
   close the socket and shutdown a server_context
@@ -34,11 +39,11 @@ static void ldapsrv_terminate_connection(struct ldapsrv_connection *ldap_conn, c
 */
 static void add_socket(struct server_service *service, 
                       const struct model_ops *model_ops, 
-                      struct in_addr *ifip)
+                      struct ipv4_addr *ifip)
 {
        struct server_socket *srv_sock;
        uint16_t port = 389;
-       char *ip_str = talloc_strdup(service, inet_ntoa(*ifip));
+       char *ip_str = talloc_strdup(service, sys_inet_ntoa(*ifip));
 
        srv_sock = service_setup_socket(service, model_ops, "ipv4", ip_str, &port);
 
@@ -99,7 +104,7 @@ static void ldapsrv_init(struct server_service *service,
                   socket per interface and bind to only these.
                */
                for(i = 0; i < num_interfaces; i++) {
-                       struct in_addr *ifip = iface_n_ip(i);
+                       struct ipv4_addr *ifip = iface_n_ip(i);
 
                        if (ifip == NULL) {
                                DEBUG(0,("ldapsrv_init: interface %d has NULL "
@@ -110,7 +115,7 @@ static void ldapsrv_init(struct server_service *service,
                        add_socket(service, model_ops, ifip);
                }
        } else {
-               struct in_addr ifip;
+               struct ipv4_addr ifip;
 
                /* Just bind to lp_socket_address() (usually 0.0.0.0) */
                ifip = interpret_addr2(lp_socket_address());
@@ -155,10 +160,17 @@ static BOOL read_into_buf(struct socket_context *sock, struct rw_buffer *buf)
        NTSTATUS status;
        DATA_BLOB tmp_blob;
        BOOL ret;
+       size_t nread;
 
-       status = socket_recv(sock, sock, &tmp_blob, 1024, 0);
-       if (!NT_STATUS_IS_OK(status)) {
+       tmp_blob = data_blob_talloc(sock, NULL, 1024);
+       if (tmp_blob.data == NULL) {
+               return False;
+       }
+
+       status = socket_recv(sock, tmp_blob.data, tmp_blob.length, &nread, 0);
+       if (NT_STATUS_IS_ERR(status)) {
                DEBUG(10,("socket_recv: %s\n",nt_errstr(status)));
+               talloc_free(tmp_blob.data);
                return False;
        }
 
@@ -179,6 +191,7 @@ static BOOL ldapsrv_read_buf(struct ldapsrv_connection *conn)
        int buf_length, sasl_length;
        struct socket_context *sock = conn->connection->socket;
        TALLOC_CTX *mem_ctx;
+       size_t nread;
 
        if (!conn->gensec || !conn->session_info ||
           !(gensec_have_feature(conn->gensec, GENSEC_WANT_SIGN) &&
@@ -192,12 +205,19 @@ static BOOL ldapsrv_read_buf(struct ldapsrv_connection *conn)
                return False;
        }
 
-       status = socket_recv(sock, mem_ctx, &tmp_blob, 1024, 0);
-       if (!NT_STATUS_IS_OK(status)) {
+       tmp_blob = data_blob_talloc(mem_ctx, NULL, 1024);
+       if (tmp_blob.data == NULL) {
+               talloc_free(mem_ctx);
+               return False;
+       }
+
+       status = socket_recv(sock, tmp_blob.data, tmp_blob.length, &nread, 0);
+       if (NT_STATUS_IS_ERR(status)) {
                DEBUG(10,("socket_recv: %s\n",nt_errstr(status)));
                talloc_free(mem_ctx);
                return False;
        }
+       tmp_blob.length = nread;
 
        ret = ldapsrv_append_to_buf(&conn->sasl_in_buffer, tmp_blob.data, tmp_blob.length);
        if (!ret) {
@@ -276,7 +296,7 @@ static BOOL write_from_buf(struct socket_context *sock, struct rw_buffer *buf)
        tmp_blob.data = buf->data;
        tmp_blob.length = buf->length;
 
-       status = socket_send(sock, sock, &tmp_blob, &sendlen, 0);
+       status = socket_send(sock, &tmp_blob, &sendlen, 0);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10,("socket_send() %s\n",nt_errstr(status)));
                return False;
@@ -360,7 +380,7 @@ nodata:
        tmp_blob.data = conn->sasl_out_buffer.data;
        tmp_blob.length = conn->sasl_out_buffer.length;
 
-       status = socket_send(sock, mem_ctx, &tmp_blob, &sendlen, 0);
+       status = socket_send(sock, &tmp_blob, &sendlen, 0);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10,("socket_send() %s\n",nt_errstr(status)));
                talloc_free(mem_ctx);
@@ -420,14 +440,14 @@ NTSTATUS ldapsrv_flush_responses(struct ldapsrv_connection *conn)
 /*
   called when a LDAP socket becomes readable
 */
-static void ldapsrv_recv(struct server_connection *conn, time_t t,
+static void ldapsrv_recv(struct server_connection *conn, struct timeval t,
                         uint16_t flags)
 {
        struct ldapsrv_connection *ldap_conn = conn->private_data;
        uint8_t *buf;
        int buf_length, msg_length;
        DATA_BLOB blob;
-       ASN1_DATA data;
+       struct asn1_data data;
        struct ldapsrv_call *call;
        NTSTATUS status;
 
@@ -516,7 +536,7 @@ static void ldapsrv_recv(struct server_connection *conn, time_t t,
 /*
   called when a LDAP socket becomes writable
 */
-static void ldapsrv_send(struct server_connection *conn, time_t t,
+static void ldapsrv_send(struct server_connection *conn, struct timeval t,
                         uint16_t flags)
 {
        struct ldapsrv_connection *ldap_conn = conn->private_data;
@@ -538,7 +558,7 @@ static void ldapsrv_send(struct server_connection *conn, time_t t,
 /*
   called when connection is idle
 */
-static void ldapsrv_idle(struct server_connection *conn, time_t t)
+static void ldapsrv_idle(struct server_connection *conn, struct timeval t)
 {
        DEBUG(10,("ldapsrv_idle: not implemented!\n"));
        return;