1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

smbd: Move reply_pipe_write to smb1_pipes.c

Signed-off-by: David Mulder <dmulder@suse.com>
Signed-off-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
David Mulder 2022-03-31 11:37:25 -06:00 committed by Jeremy Allison
parent 085b16e0c2
commit 536330d2eb
4 changed files with 91 additions and 91 deletions

View File

@ -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 */

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}