s3-rpc_server: Fix sending of packets over named pipe proxy.
authorAndreas Schneider <asn@samba.org>
Wed, 3 Aug 2011 21:44:21 +0000 (23:44 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 9 Aug 2011 09:55:18 +0000 (11:55 +0200)
We need for named pipes we need to send each fragment on its own to be a
message.

Signed-off-by: Simo Sorce <idra@samba.org>
Autobuild-User: Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date: Tue Aug  9 11:55:18 CEST 2011 on sn-devel-104

source3/rpc_server/rpc_server.c

index c66d74771a77db0df509ed33b6dcd025e869c9cf..9134b958abb0f209e53be91a63ee95e621468b9a 100644 (file)
@@ -446,6 +446,7 @@ static void named_pipe_packet_process(struct tevent_req *subreq)
        ssize_t data_used;
        char *data;
        uint32_t to_send;
+       size_t i;
        bool ok;
 
        status = dcerpc_read_ncacn_packet_recv(subreq, npc, &pkt, &recv_buffer);
@@ -479,13 +480,6 @@ static void named_pipe_packet_process(struct tevent_req *subreq)
        to_send = out->frag.length - out->current_pdu_sent;
        if (to_send > 0) {
 
-               DEBUG(10, ("Current_pdu_len = %u, "
-                          "current_pdu_sent = %u "
-                          "Returning %u bytes\n",
-                          (unsigned int)out->frag.length,
-                          (unsigned int)out->current_pdu_sent,
-                          (unsigned int)to_send));
-
                npc->iov = talloc_zero(npc, struct iovec);
                if (!npc->iov) {
                        status = NT_STATUS_NO_MEMORY;
@@ -522,11 +516,6 @@ static void named_pipe_packet_process(struct tevent_req *subreq)
                npc->iov[npc->count].iov_base = out->frag.data;
                npc->iov[npc->count].iov_len = out->frag.length;
 
-               DEBUG(10, ("PDU number: %d, PDU Length: %u\n",
-                          (unsigned int)npc->count,
-                          (unsigned int)npc->iov[npc->count].iov_len));
-               dump_data(11, (const uint8_t *)npc->iov[npc->count].iov_base,
-                               npc->iov[npc->count].iov_len);
                npc->count++;
        }
 
@@ -544,19 +533,31 @@ static void named_pipe_packet_process(struct tevent_req *subreq)
                return;
        }
 
-       DEBUG(10, ("Sending a total of %u bytes\n",
+       DEBUG(10, ("Sending %u fragments in a total of %u bytes\n",
+                  (unsigned int)npc->count,
                   (unsigned int)npc->p->out_data.data_sent_length));
 
-       subreq = tstream_writev_queue_send(npc, npc->ev,
-                                          npc->tstream,
-                                          npc->write_queue,
-                                          npc->iov, npc->count);
-       if (!subreq) {
-               DEBUG(2, ("Failed to send packet\n"));
-               status = NT_STATUS_NO_MEMORY;
-               goto fail;
+       for (i = 0; i < npc->count; i++) {
+               DEBUG(10, ("Sending PDU number: %d, PDU Length: %u\n",
+                         (unsigned int)i,
+                         (unsigned int)npc->iov[i].iov_len));
+               dump_data(11, (const uint8_t *)npc->iov[i].iov_base,
+                               npc->iov[i].iov_len);
+
+               subreq = tstream_writev_queue_send(npc,
+                                                  npc->ev,
+                                                  npc->tstream,
+                                                  npc->write_queue,
+                                                  (npc->iov + i),
+                                                  1);
+               if (!subreq) {
+                       DEBUG(2, ("Failed to send packet\n"));
+                       status = NT_STATUS_NO_MEMORY;
+                       goto fail;
+               }
+               tevent_req_set_callback(subreq, named_pipe_packet_done, npc);
        }
-       tevent_req_set_callback(subreq, named_pipe_packet_done, npc);
+
        return;
 
 fail:
@@ -582,6 +583,10 @@ static void named_pipe_packet_done(struct tevent_req *subreq)
                goto fail;
        }
 
+       if (tevent_queue_length(npc->write_queue) > 0) {
+               return;
+       }
+
        /* clear out any data that may have been left around */
        npc->count = 0;
        TALLOC_FREE(npc->iov);