Fix bug 7583 - Smbclient fails to kerberos connect to a Alfresco JLAN CIFS Server
[samba.git] / source3 / libsmb / async_smb.c
index 9f92ae70121eee76e16b99c9b7b86f772d10df4f..4518518a4328c5cc6062ef02b08fbee26e6093fc 100644 (file)
@@ -201,6 +201,7 @@ struct cli_smb_state {
        uint8_t *inbuf;
        uint32_t seqnum;
        int chain_num;
+       int chain_length;
        struct tevent_req **chained_requests;
 };
 
@@ -423,9 +424,11 @@ struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx,
        }
        state->iov_count = iov_count + 3;
 
-       endtime = timeval_current_ofs(0, cli->timeout * 1000);
-       if (!tevent_req_set_endtime(result, ev, endtime)) {
-               tevent_req_nomem(NULL, result);
+       if (cli->timeout) {
+               endtime = timeval_current_ofs(0, cli->timeout * 1000);
+               if (!tevent_req_set_endtime(result, ev, endtime)) {
+                       tevent_req_nomem(NULL, result);
+               }
        }
        return result;
 }
@@ -710,6 +713,8 @@ static void cli_smb_received(struct tevent_req *subreq)
                state->inbuf = talloc_move(state, &inbuf);
                talloc_set_destructor(req, NULL);
                cli_smb_req_destructor(req);
+               state->chain_num = 0;
+               state->chain_length = 1;
                tevent_req_done(req);
        } else {
                struct tevent_req **chain = talloc_move(
@@ -721,6 +726,7 @@ static void cli_smb_received(struct tevent_req *subreq)
                                                cli_smb_state);
                        state->inbuf = inbuf;
                        state->chain_num = i;
+                       state->chain_length = num_chained;
                        tevent_req_done(chain[i]);
                }
                TALLOC_FREE(inbuf);
@@ -870,7 +876,11 @@ no_err:
                *pbytes = (uint8_t *)state->inbuf + bytes_offset + 2;
        }
        if ((mem_ctx != NULL) && (pinbuf != NULL)) {
-               *pinbuf = talloc_move(mem_ctx, &state->inbuf);
+               if (state->chain_num == state->chain_length-1) {
+                       *pinbuf = talloc_move(mem_ctx, &state->inbuf);
+               } else {
+                       *pinbuf = state->inbuf;
+               }
        }
 
        return status;
@@ -1057,12 +1067,13 @@ static void cli_smb_oplock_break_waiter_done(struct tevent_req *subreq)
        uint16_t *vwv;
        uint32_t num_bytes;
        uint8_t *bytes;
+       uint8_t *inbuf;
        NTSTATUS status;
 
-       status = cli_smb_recv(subreq, NULL, NULL, 8, &wct, &vwv,
+       status = cli_smb_recv(subreq, state, &inbuf, 8, &wct, &vwv,
                              &num_bytes, &bytes);
+       TALLOC_FREE(subreq);
        if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(subreq);
                tevent_req_nterror(req, status);
                return;
        }