]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli:smb: Implement smb2cli_read_set_notify_async()
authorStefan Metzmacher <metze@samba.org>
Mon, 5 Aug 2024 07:16:58 +0000 (09:16 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 29 Jan 2025 11:20:33 +0000 (11:20 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14430

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
libcli/smb/smb2cli_read.c
libcli/smb/smbXcli_base.h

index c7f48741b8751d6df3a413fcb39e36df30957682..95071ed27a25bfea337500dbebca5e5330918bd6 100644 (file)
@@ -30,6 +30,9 @@ struct smb2cli_read_state {
        uint8_t *data;
        uint32_t data_length;
        bool out_valid;
+       struct tevent_req *subreq;
+       bool notify_async;
+       bool report_pending;
 };
 
 static void smb2cli_read_done(struct tevent_req *subreq);
@@ -79,9 +82,20 @@ struct tevent_req *smb2cli_read_send(TALLOC_CTX *mem_ctx,
                return tevent_req_post(req, ev);
        }
        tevent_req_set_callback(subreq, smb2cli_read_done, req);
+       state->subreq = subreq;
        return req;
 }
 
+void smb2cli_read_set_notify_async(struct tevent_req *req)
+{
+       struct smb2cli_read_state *state =
+               tevent_req_data(req,
+               struct smb2cli_read_state);
+
+       smb2cli_req_set_notify_async(state->subreq);
+       state->notify_async = true;
+}
+
 static void smb2cli_read_done(struct tevent_req *subreq)
 {
        struct tevent_req *req = tevent_req_callback_data(
@@ -108,8 +122,19 @@ static void smb2cli_read_done(struct tevent_req *subreq)
        }
        };
 
+       SMB_ASSERT(state->subreq == subreq);
+
        status = smb2cli_req_recv(subreq, state, &iov,
                                  expected, ARRAY_SIZE(expected));
+       if (NT_STATUS_EQUAL(status, NT_STATUS_PENDING) && state->notify_async) {
+               state->notify_async = false;
+               state->report_pending = true;
+               tevent_req_notify_callback(req);
+               return;
+       }
+       state->notify_async = false;
+       state->report_pending = false;
+       state->subreq = NULL;
        TALLOC_FREE(subreq);
        if (NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) {
                /* no error */
@@ -157,6 +182,12 @@ NTSTATUS smb2cli_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                struct smb2cli_read_state);
        NTSTATUS status = NT_STATUS_OK;
 
+       if (state->report_pending) {
+               *data_length = 0;
+               *data = NULL;
+               return NT_STATUS_PENDING;
+       }
+
        if (tevent_req_is_nterror(req, &status) && !state->out_valid) {
                *data_length = 0;
                *data = NULL;
index 69fa131a31d66abeaf4cd19160f6fbcc02f67de4..42f227c4fef3a3e0a430f48a90843b3073b15f6e 100644 (file)
@@ -737,6 +737,7 @@ struct tevent_req *smb2cli_read_send(TALLOC_CTX *mem_ctx,
                                     uint64_t fid_volatile,
                                     uint64_t minimum_count,
                                     uint64_t remaining_bytes);
+void smb2cli_read_set_notify_async(struct tevent_req *req);
 NTSTATUS smb2cli_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                           uint8_t **data, uint32_t *data_length);
 NTSTATUS smb2cli_read(struct smbXcli_conn *conn,