From: David Mulder Date: Thu, 31 Mar 2022 17:37:25 +0000 (-0600) Subject: smbd: Move reply_pipe_write to smb1_pipes.c X-Git-Tag: tevent-0.12.0~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=536330d2eb5219482e905d365f3ca56e3dfa2fe3;p=thirdparty%2Fsamba.git smbd: Move reply_pipe_write to smb1_pipes.c Signed-off-by: David Mulder Signed-off-by: Jeremy Allison --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index de03cb77795..ef409183e7f 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -793,7 +793,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); /* The following definitions come from smbd/posix_acls.c */ diff --git a/source3/smbd/smb1_pipes.c b/source3/smbd/smb1_pipes.c index 25862c1842b..bc5837fb632 100644 --- a/source3/smbd/smb1_pipes.c +++ b/source3/smbd/smb1_pipes.c @@ -364,3 +364,93 @@ static void pipe_read_andx_done(struct tevent_req *subreq) */ smb_request_done(req); } + +/**************************************************************************** + Reply to a write on a pipe. +****************************************************************************/ + +struct pipe_write_state { + size_t numtowrite; +}; + +static void pipe_write_done(struct tevent_req *subreq); + +void reply_pipe_write(struct smb_request *req) +{ + files_struct *fsp = file_fsp(req, SVAL(req->vwv+0, 0)); + const uint8_t *data; + struct pipe_write_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_state); + if (state == NULL) { + reply_nterror(req, NT_STATUS_NO_MEMORY); + return; + } + req->async_priv = state; + + state->numtowrite = SVAL(req->vwv+1, 0); + + data = req->buf + 3; + + DEBUG(6, ("reply_pipe_write: %s, name: %s len: %d\n", fsp_fnum_dbg(fsp), + fsp_str_dbg(fsp), (int)state->numtowrite)); + + 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_done, + talloc_move(req->conn, &req)); +} + +static void pipe_write_done(struct tevent_req *subreq) +{ + struct smb_request *req = tevent_req_callback_data( + subreq, struct smb_request); + struct pipe_write_state *state = talloc_get_type_abort( + req->async_priv, struct pipe_write_state); + NTSTATUS status; + ssize_t nwritten = -1; + + status = np_write_recv(subreq, &nwritten); + TALLOC_FREE(subreq); + if (nwritten < 0) { + reply_nterror(req, status); + goto send; + } + + /* Looks bogus to me now. Needs to be removed ? JRA. */ + if ((nwritten == 0 && state->numtowrite != 0)) { + reply_nterror(req, NT_STATUS_ACCESS_DENIED); + goto send; + } + + reply_outbuf(req, 1, 0); + + SSVAL(req->outbuf,smb_vwv0,nwritten); + + DEBUG(3,("write-IPC nwritten=%d\n", (int)nwritten)); + + send: + if (!srv_send_smb(req->xconn, (char *)req->outbuf, + true, req->seqnum+1, + IS_CONN_ENCRYPTED(req->conn)||req->encrypted, + &req->pcd)) { + exit_server_cleanly("construct_reply: srv_send_smb failed."); + } + TALLOC_FREE(req); +} diff --git a/source3/smbd/smb1_pipes.h b/source3/smbd/smb1_pipes.h index c480138109c..20e8a99157c 100644 --- a/source3/smbd/smb1_pipes.h +++ b/source3/smbd/smb1_pipes.h @@ -23,3 +23,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); +void reply_pipe_write(struct smb_request *req); diff --git a/source3/smbd/smb2_pipes.c b/source3/smbd/smb2_pipes.c index 23cc1a3bc08..b637ddf216a 100644 --- a/source3/smbd/smb2_pipes.c +++ b/source3/smbd/smb2_pipes.c @@ -149,93 +149,3 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name, return NT_STATUS_OK; } - -/**************************************************************************** - Reply to a write on a pipe. -****************************************************************************/ - -struct pipe_write_state { - size_t numtowrite; -}; - -static void pipe_write_done(struct tevent_req *subreq); - -void reply_pipe_write(struct smb_request *req) -{ - files_struct *fsp = file_fsp(req, SVAL(req->vwv+0, 0)); - const uint8_t *data; - struct pipe_write_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_state); - if (state == NULL) { - reply_nterror(req, NT_STATUS_NO_MEMORY); - return; - } - req->async_priv = state; - - state->numtowrite = SVAL(req->vwv+1, 0); - - data = req->buf + 3; - - DEBUG(6, ("reply_pipe_write: %s, name: %s len: %d\n", fsp_fnum_dbg(fsp), - fsp_str_dbg(fsp), (int)state->numtowrite)); - - 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_done, - talloc_move(req->conn, &req)); -} - -static void pipe_write_done(struct tevent_req *subreq) -{ - struct smb_request *req = tevent_req_callback_data( - subreq, struct smb_request); - struct pipe_write_state *state = talloc_get_type_abort( - req->async_priv, struct pipe_write_state); - NTSTATUS status; - ssize_t nwritten = -1; - - status = np_write_recv(subreq, &nwritten); - TALLOC_FREE(subreq); - if (nwritten < 0) { - reply_nterror(req, status); - goto send; - } - - /* Looks bogus to me now. Needs to be removed ? JRA. */ - if ((nwritten == 0 && state->numtowrite != 0)) { - reply_nterror(req, NT_STATUS_ACCESS_DENIED); - goto send; - } - - reply_outbuf(req, 1, 0); - - SSVAL(req->outbuf,smb_vwv0,nwritten); - - DEBUG(3,("write-IPC nwritten=%d\n", (int)nwritten)); - - send: - if (!srv_send_smb(req->xconn, (char *)req->outbuf, - true, req->seqnum+1, - IS_CONN_ENCRYPTED(req->conn)||req->encrypted, - &req->pcd)) { - exit_server_cleanly("construct_reply: srv_send_smb failed."); - } - TALLOC_FREE(req); -}