]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Move reply_pipe_read_and_X to smb1_pipes.c
authorDavid Mulder <dmulder@suse.com>
Tue, 15 Mar 2022 21:00:05 +0000 (15:00 -0600)
committerJeremy Allison <jra@samba.org>
Thu, 7 Apr 2022 17:37:29 +0000 (17:37 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/pipes.c
source3/smbd/proto.h
source3/smbd/smb1_pipes.c
source3/smbd/smb1_pipes.h

index 0469f7f9844f9e71a37e163c715addb030800602..23cc1a3bc087328e6791ae93d25ce5727b0d3e94 100644 (file)
@@ -239,133 +239,3 @@ static void pipe_write_done(struct tevent_req *subreq)
        }
        TALLOC_FREE(req);
 }
-
-/****************************************************************************
- Reply to a read and X.
- This code is basically stolen from reply_read_and_X with some
- wrinkles to handle pipes.
-****************************************************************************/
-
-struct pipe_read_andx_state {
-       uint8_t *outbuf;
-       int smb_mincnt;
-       int smb_maxcnt;
-};
-
-static void pipe_read_andx_done(struct tevent_req *subreq);
-
-void reply_pipe_read_and_X(struct smb_request *req)
-{
-       files_struct *fsp = file_fsp(req, SVAL(req->vwv+0, 0));
-       uint8_t *data;
-       struct pipe_read_andx_state *state;
-       struct tevent_req *subreq;
-
-       /* we don't use the offset given to use for pipe reads. This
-           is deliberate, instead we always return the next lump of
-           data on the pipe */
-#if 0
-       uint32_t smb_offs = IVAL(req->vwv+3, 0);
-#endif
-
-       if (!fsp_is_np(fsp)) {
-               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
-               return;
-       }
-
-       if (fsp->vuid != req->vuid) {
-               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
-               return;
-       }
-
-       state = talloc(req, struct pipe_read_andx_state);
-       if (state == NULL) {
-               reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
-       }
-       req->async_priv = state;
-
-       state->smb_maxcnt = SVAL(req->vwv+5, 0);
-       state->smb_mincnt = SVAL(req->vwv+6, 0);
-
-       reply_outbuf(req, 12, state->smb_maxcnt + 1 /* padding byte */);
-       SSVAL(req->outbuf, smb_vwv0, 0xff); /* andx chain ends */
-       SSVAL(req->outbuf, smb_vwv1, 0);    /* no andx offset */
-       SCVAL(smb_buf(req->outbuf), 0, 0); /* padding byte */
-
-       data = (uint8_t *)smb_buf(req->outbuf) + 1 /* padding byte */;
-
-       /*
-        * We have to tell the upper layers that we're async.
-        */
-       state->outbuf = req->outbuf;
-       req->outbuf = NULL;
-
-       subreq = np_read_send(state, req->sconn->ev_ctx,
-                             fsp->fake_file_handle, data,
-                             state->smb_maxcnt);
-       if (subreq == NULL) {
-               reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
-       }
-       tevent_req_set_callback(subreq, pipe_read_andx_done,
-                               talloc_move(req->conn, &req));
-}
-
-static void pipe_read_andx_done(struct tevent_req *subreq)
-{
-       struct smb_request *req = tevent_req_callback_data(
-               subreq, struct smb_request);
-       struct pipe_read_andx_state *state = talloc_get_type_abort(
-               req->async_priv, struct pipe_read_andx_state);
-       NTSTATUS status;
-       ssize_t nread;
-       bool is_data_outstanding;
-
-       status = np_read_recv(subreq, &nread, &is_data_outstanding);
-       TALLOC_FREE(subreq);
-       if (!NT_STATUS_IS_OK(status)) {
-               NTSTATUS old = status;
-               status = nt_status_np_pipe(old);
-               reply_nterror(req, status);
-               goto done;
-       }
-
-       req->outbuf = state->outbuf;
-       state->outbuf = NULL;
-
-       srv_set_message((char *)req->outbuf, 12, nread + 1 /* padding byte */,
-                       false);
-
-#if 0
-       /*
-        * we should return STATUS_BUFFER_OVERFLOW if there's
-        * out standing data.
-        *
-        * But we can't enable it yet, as it has bad interactions
-        * with fixup_chain_error_packet() in chain_reply().
-        */
-       if (is_data_outstanding) {
-               error_packet_set((char *)req->outbuf, ERRDOS, ERRmoredata,
-                                STATUS_BUFFER_OVERFLOW, __LINE__, __FILE__);
-       }
-#endif
-
-       SSVAL(req->outbuf,smb_vwv5,nread);
-       SSVAL(req->outbuf,smb_vwv6,
-             (smb_wct - 4)     /* offset from smb header to wct */
-             + 1               /* the wct field */
-             + 12 * sizeof(uint16_t) /* vwv */
-             + 2               /* the buflen field */
-             + 1);             /* padding byte */
-
-       DEBUG(3,("readX-IPC min=%d max=%d nread=%d\n",
-                state->smb_mincnt, state->smb_maxcnt, (int)nread));
-
- done:
-       /*
-        * We must free here as the ownership of req was
-        * moved to the connection struct in reply_pipe_read_and_X().
-        */
-       smb_request_done(req);
-}
index d21aa09985a6a5152f4457e471369cf0d3cb2972..3822ed64d738593754323506e59fd03f07306586 100644 (file)
@@ -805,7 +805,6 @@ int register_homes_share(const char *username);
 NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
                      struct files_struct **pfsp);
 void reply_pipe_write(struct smb_request *req);
-void reply_pipe_read_and_X(struct smb_request *req);
 
 /* The following definitions come from smbd/posix_acls.c  */
 
index 2f83295a49cf56e45f8bbdb1788ceb3927dff9de..25862c1842b6c2c16fe3c2ca892bfcdbe268e1f2 100644 (file)
@@ -234,3 +234,133 @@ static void pipe_write_andx_done(struct tevent_req *subreq)
         */
        smb_request_done(req);
 }
+
+/****************************************************************************
+ Reply to a read and X.
+ This code is basically stolen from reply_read_and_X with some
+ wrinkles to handle pipes.
+****************************************************************************/
+
+struct pipe_read_andx_state {
+       uint8_t *outbuf;
+       int smb_mincnt;
+       int smb_maxcnt;
+};
+
+static void pipe_read_andx_done(struct tevent_req *subreq);
+
+void reply_pipe_read_and_X(struct smb_request *req)
+{
+       files_struct *fsp = file_fsp(req, SVAL(req->vwv+0, 0));
+       uint8_t *data;
+       struct pipe_read_andx_state *state;
+       struct tevent_req *subreq;
+
+       /* we don't use the offset given to use for pipe reads. This
+           is deliberate, instead we always return the next lump of
+           data on the pipe */
+#if 0
+       uint32_t smb_offs = IVAL(req->vwv+3, 0);
+#endif
+
+       if (!fsp_is_np(fsp)) {
+               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
+               return;
+       }
+
+       if (fsp->vuid != req->vuid) {
+               reply_nterror(req, NT_STATUS_INVALID_HANDLE);
+               return;
+       }
+
+       state = talloc(req, struct pipe_read_andx_state);
+       if (state == NULL) {
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
+               return;
+       }
+       req->async_priv = state;
+
+       state->smb_maxcnt = SVAL(req->vwv+5, 0);
+       state->smb_mincnt = SVAL(req->vwv+6, 0);
+
+       reply_outbuf(req, 12, state->smb_maxcnt + 1 /* padding byte */);
+       SSVAL(req->outbuf, smb_vwv0, 0xff); /* andx chain ends */
+       SSVAL(req->outbuf, smb_vwv1, 0);    /* no andx offset */
+       SCVAL(smb_buf(req->outbuf), 0, 0); /* padding byte */
+
+       data = (uint8_t *)smb_buf(req->outbuf) + 1 /* padding byte */;
+
+       /*
+        * We have to tell the upper layers that we're async.
+        */
+       state->outbuf = req->outbuf;
+       req->outbuf = NULL;
+
+       subreq = np_read_send(state, req->sconn->ev_ctx,
+                             fsp->fake_file_handle, data,
+                             state->smb_maxcnt);
+       if (subreq == NULL) {
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
+               return;
+       }
+       tevent_req_set_callback(subreq, pipe_read_andx_done,
+                               talloc_move(req->conn, &req));
+}
+
+static void pipe_read_andx_done(struct tevent_req *subreq)
+{
+       struct smb_request *req = tevent_req_callback_data(
+               subreq, struct smb_request);
+       struct pipe_read_andx_state *state = talloc_get_type_abort(
+               req->async_priv, struct pipe_read_andx_state);
+       NTSTATUS status;
+       ssize_t nread;
+       bool is_data_outstanding;
+
+       status = np_read_recv(subreq, &nread, &is_data_outstanding);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               NTSTATUS old = status;
+               status = nt_status_np_pipe(old);
+               reply_nterror(req, status);
+               goto done;
+       }
+
+       req->outbuf = state->outbuf;
+       state->outbuf = NULL;
+
+       srv_set_message((char *)req->outbuf, 12, nread + 1 /* padding byte */,
+                       false);
+
+#if 0
+       /*
+        * we should return STATUS_BUFFER_OVERFLOW if there's
+        * out standing data.
+        *
+        * But we can't enable it yet, as it has bad interactions
+        * with fixup_chain_error_packet() in chain_reply().
+        */
+       if (is_data_outstanding) {
+               error_packet_set((char *)req->outbuf, ERRDOS, ERRmoredata,
+                                STATUS_BUFFER_OVERFLOW, __LINE__, __FILE__);
+       }
+#endif
+
+       SSVAL(req->outbuf,smb_vwv5,nread);
+       SSVAL(req->outbuf,smb_vwv6,
+             (smb_wct - 4)     /* offset from smb header to wct */
+             + 1               /* the wct field */
+             + 12 * sizeof(uint16_t) /* vwv */
+             + 2               /* the buflen field */
+             + 1);             /* padding byte */
+
+       DEBUG(3,("readX-IPC min=%d max=%d nread=%d\n",
+                state->smb_mincnt, state->smb_maxcnt, (int)nread));
+
+ done:
+       /*
+        * We must free here as the ownership of req was
+        * moved to the connection struct in reply_pipe_read_and_X().
+        */
+       smb_request_done(req);
+}
index d86a7d3de1fdc0d7695a64b9048ebb7b56452515..c480138109c564156442ef07d77935a21a6b9d70 100644 (file)
@@ -22,3 +22,4 @@
 
 void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req);
 void reply_pipe_write_and_X(struct smb_request *req);
+void reply_pipe_read_and_X(struct smb_request *req);