]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Move reply_pipe_write_and_X to smb1_pipes.c
authorDavid Mulder <dmulder@suse.com>
Tue, 15 Mar 2022 20:55:38 +0000 (14:55 -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 2c4ee8995fe80a714e98f07412d5f3387b755a98..0469f7f9844f9e71a37e163c715addb030800602 100644 (file)
@@ -240,125 +240,6 @@ static void pipe_write_done(struct tevent_req *subreq)
        TALLOC_FREE(req);
 }
 
-/****************************************************************************
- Reply to a write and X.
-
- This code is basically stolen from reply_write_and_X with some
- wrinkles to handle pipes.
-****************************************************************************/
-
-struct pipe_write_andx_state {
-       bool pipe_start_message_raw;
-       size_t numtowrite;
-};
-
-static void pipe_write_andx_done(struct tevent_req *subreq);
-
-void reply_pipe_write_and_X(struct smb_request *req)
-{
-       files_struct *fsp = file_fsp(req, SVAL(req->vwv+2, 0));
-       int smb_doff = SVAL(req->vwv+11, 0);
-       const uint8_t *data;
-       struct pipe_write_andx_state *state;
-       struct tevent_req *subreq;
-
-       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_write_andx_state);
-       if (state == NULL) {
-               reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
-       }
-       req->async_priv = state;
-
-       state->numtowrite = SVAL(req->vwv+10, 0);
-       state->pipe_start_message_raw =
-               ((SVAL(req->vwv+7, 0) & (PIPE_START_MESSAGE|PIPE_RAW_MODE))
-                == (PIPE_START_MESSAGE|PIPE_RAW_MODE));
-
-       DEBUG(6, ("reply_pipe_write_and_X: %s, name: %s len: %d\n",
-                 fsp_fnum_dbg(fsp), fsp_str_dbg(fsp), (int)state->numtowrite));
-
-       data = (const uint8_t *)smb_base(req->inbuf) + smb_doff;
-
-       if (state->pipe_start_message_raw) {
-               /*
-                * For the start of a message in named pipe byte mode,
-                * the first two bytes are a length-of-pdu field. Ignore
-                * them (we don't trust the client). JRA.
-                */
-               if (state->numtowrite < 2) {
-                       DEBUG(0,("reply_pipe_write_and_X: start of message "
-                                "set and not enough data sent.(%u)\n",
-                                (unsigned int)state->numtowrite ));
-                       reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                       return;
-               }
-
-               data += 2;
-               state->numtowrite -= 2;
-       }
-
-       subreq = np_write_send(state, req->sconn->ev_ctx,
-                              fsp->fake_file_handle, data, state->numtowrite);
-       if (subreq == NULL) {
-               TALLOC_FREE(state);
-               reply_nterror(req, NT_STATUS_NO_MEMORY);
-               return;
-       }
-       tevent_req_set_callback(subreq, pipe_write_andx_done,
-                               talloc_move(req->conn, &req));
-}
-
-static void pipe_write_andx_done(struct tevent_req *subreq)
-{
-       struct smb_request *req = tevent_req_callback_data(
-               subreq, struct smb_request);
-       struct pipe_write_andx_state *state = talloc_get_type_abort(
-               req->async_priv, struct pipe_write_andx_state);
-       NTSTATUS status;
-       ssize_t nwritten = -1;
-
-       status = np_write_recv(subreq, &nwritten);
-       TALLOC_FREE(subreq);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               reply_nterror(req, status);
-               goto done;
-       }
-
-       /* Looks bogus to me now. Is this error message correct ? JRA. */
-       if (nwritten != state->numtowrite) {
-               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
-               goto done;
-       }
-
-       reply_outbuf(req, 6, 0);
-
-       SSVAL(req->outbuf, smb_vwv0, 0xff); /* andx chain ends */
-       SSVAL(req->outbuf, smb_vwv1, 0);    /* no andx offset */
-
-       nwritten = (state->pipe_start_message_raw ? nwritten + 2 : nwritten);
-       SSVAL(req->outbuf,smb_vwv2,nwritten);
-
-       DEBUG(3,("writeX-IPC nwritten=%d\n", (int)nwritten));
-
- done:
-       /*
-        * We must free here as the ownership of req was
-        * moved to the connection struct in reply_pipe_write_and_X().
-        */
-       smb_request_done(req);
-}
-
 /****************************************************************************
  Reply to a read and X.
  This code is basically stolen from reply_read_and_X with some
index 3c3e9a247fde97857a743ed30de8996421e50c47..d21aa09985a6a5152f4457e471369cf0d3cb2972 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_write_and_X(struct smb_request *req);
 void reply_pipe_read_and_X(struct smb_request *req);
 
 /* The following definitions come from smbd/posix_acls.c  */
index 18e93a2c26dd1328a9523ab195197da5ccb304c0..2f83295a49cf56e45f8bbdb1788ceb3927dff9de 100644 (file)
@@ -115,3 +115,122 @@ void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req)
        SSVAL(req->outbuf, smb_vwv8, 0);        /* rmode */
        SSVAL(req->outbuf, smb_vwv11, 0x0001);
 }
+
+/****************************************************************************
+ Reply to a write and X.
+
+ This code is basically stolen from reply_write_and_X with some
+ wrinkles to handle pipes.
+****************************************************************************/
+
+struct pipe_write_andx_state {
+       bool pipe_start_message_raw;
+       size_t numtowrite;
+};
+
+static void pipe_write_andx_done(struct tevent_req *subreq);
+
+void reply_pipe_write_and_X(struct smb_request *req)
+{
+       files_struct *fsp = file_fsp(req, SVAL(req->vwv+2, 0));
+       int smb_doff = SVAL(req->vwv+11, 0);
+       const uint8_t *data;
+       struct pipe_write_andx_state *state;
+       struct tevent_req *subreq;
+
+       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_write_andx_state);
+       if (state == NULL) {
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
+               return;
+       }
+       req->async_priv = state;
+
+       state->numtowrite = SVAL(req->vwv+10, 0);
+       state->pipe_start_message_raw =
+               ((SVAL(req->vwv+7, 0) & (PIPE_START_MESSAGE|PIPE_RAW_MODE))
+                == (PIPE_START_MESSAGE|PIPE_RAW_MODE));
+
+       DEBUG(6, ("reply_pipe_write_and_X: %s, name: %s len: %d\n",
+                 fsp_fnum_dbg(fsp), fsp_str_dbg(fsp), (int)state->numtowrite));
+
+       data = (const uint8_t *)smb_base(req->inbuf) + smb_doff;
+
+       if (state->pipe_start_message_raw) {
+               /*
+                * For the start of a message in named pipe byte mode,
+                * the first two bytes are a length-of-pdu field. Ignore
+                * them (we don't trust the client). JRA.
+                */
+               if (state->numtowrite < 2) {
+                       DEBUG(0,("reply_pipe_write_and_X: start of message "
+                                "set and not enough data sent.(%u)\n",
+                                (unsigned int)state->numtowrite ));
+                       reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+                       return;
+               }
+
+               data += 2;
+               state->numtowrite -= 2;
+       }
+
+       subreq = np_write_send(state, req->sconn->ev_ctx,
+                              fsp->fake_file_handle, data, state->numtowrite);
+       if (subreq == NULL) {
+               TALLOC_FREE(state);
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
+               return;
+       }
+       tevent_req_set_callback(subreq, pipe_write_andx_done,
+                               talloc_move(req->conn, &req));
+}
+
+static void pipe_write_andx_done(struct tevent_req *subreq)
+{
+       struct smb_request *req = tevent_req_callback_data(
+               subreq, struct smb_request);
+       struct pipe_write_andx_state *state = talloc_get_type_abort(
+               req->async_priv, struct pipe_write_andx_state);
+       NTSTATUS status;
+       ssize_t nwritten = -1;
+
+       status = np_write_recv(subreq, &nwritten);
+       TALLOC_FREE(subreq);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               reply_nterror(req, status);
+               goto done;
+       }
+
+       /* Looks bogus to me now. Is this error message correct ? JRA. */
+       if (nwritten != state->numtowrite) {
+               reply_nterror(req, NT_STATUS_ACCESS_DENIED);
+               goto done;
+       }
+
+       reply_outbuf(req, 6, 0);
+
+       SSVAL(req->outbuf, smb_vwv0, 0xff); /* andx chain ends */
+       SSVAL(req->outbuf, smb_vwv1, 0);    /* no andx offset */
+
+       nwritten = (state->pipe_start_message_raw ? nwritten + 2 : nwritten);
+       SSVAL(req->outbuf,smb_vwv2,nwritten);
+
+       DEBUG(3,("writeX-IPC nwritten=%d\n", (int)nwritten));
+
+ done:
+       /*
+        * We must free here as the ownership of req was
+        * moved to the connection struct in reply_pipe_write_and_X().
+        */
+       smb_request_done(req);
+}
index b8eb35e4a43fd7eac6fb6b16c5f1d0e9ead2e216..d86a7d3de1fdc0d7695a64b9048ebb7b56452515 100644 (file)
@@ -21,3 +21,4 @@
 */
 
 void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req);
+void reply_pipe_write_and_X(struct smb_request *req);