summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-06-02 17:34:46 +0200
committerStefan Metzmacher <metze@samba.org>2009-06-05 13:02:05 +0200
commit360c3c4a80e1fcf84abd4e620c95f003779b1f1f (patch)
tree86e8a9077921335b041fc8404edc50e12234d094
parent7a0895b8e8e78e3b0fda8eef9169405f1573030a (diff)
downloadsamba-360c3c4a80e1fcf84abd4e620c95f003779b1f1f.tar.gz
samba-360c3c4a80e1fcf84abd4e620c95f003779b1f1f.tar.bz2
samba-360c3c4a80e1fcf84abd4e620c95f003779b1f1f.zip
s3:smbd: split smbd_smb2_write() into tevent_req based *_send()/_recv() functions
metze
-rw-r--r--source3/smbd/smb2_write.c176
1 files changed, 129 insertions, 47 deletions
diff --git a/source3/smbd/smb2_write.c b/source3/smbd/smb2_write.c
index 99a9c40ef4..78b63dcaa6 100644
--- a/source3/smbd/smb2_write.c
+++ b/source3/smbd/smb2_write.c
@@ -22,22 +22,23 @@
#include "smbd/globals.h"
#include "../source4/libcli/smb2/smb2_constants.h"
-static NTSTATUS smbd_smb2_write(struct smbd_smb2_request *req,
- uint32_t in_smbpid,
- uint64_t in_file_id_volatile,
- DATA_BLOB in_data,
- uint64_t in_offset,
- uint32_t in_flags,
- uint32_t *out_count);
-
+static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct smbd_smb2_request *smb2req,
+ uint32_t in_smbpid,
+ uint64_t in_file_id_volatile,
+ DATA_BLOB in_data,
+ uint64_t in_offset,
+ uint32_t in_flags);
+static NTSTATUS smbd_smb2_write_recv(struct tevent_req *req,
+ uint32_t *out_count);
+
+static void smbd_smb2_request_write_done(struct tevent_req *subreq);
NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req)
{
const uint8_t *inhdr;
const uint8_t *inbody;
int i = req->current_idx;
- uint8_t *outhdr;
- DATA_BLOB outbody;
- DATA_BLOB outdyn;
size_t expected_body_size = 0x31;
size_t body_size;
uint32_t in_smbpid;
@@ -48,8 +49,7 @@ NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req)
uint64_t in_file_id_persistent;
uint64_t in_file_id_volatile;
uint32_t in_flags;
- uint32_t out_count;
- NTSTATUS status;
+ struct tevent_req *subreq;
inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
if (req->in.vector[i+1].iov_len != (expected_body_size & 0xFFFFFFFE)) {
@@ -94,22 +94,54 @@ NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req)
return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
}
- status = smbd_smb2_write(req,
- in_smbpid,
- in_file_id_volatile,
- in_data_buffer,
- in_offset,
- in_flags,
- &out_count);
+ subreq = smbd_smb2_write_send(req,
+ req->conn->smb2.event_ctx,
+ req,
+ in_smbpid,
+ in_file_id_volatile,
+ in_data_buffer,
+ in_offset,
+ in_flags);
+ if (subreq == NULL) {
+ return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
+ }
+ tevent_req_set_callback(subreq, smbd_smb2_request_write_done, req);
+ return NT_STATUS_OK;
+}
+
+static void smbd_smb2_request_write_done(struct tevent_req *subreq)
+{
+ struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
+ struct smbd_smb2_request);
+ int i = req->current_idx;
+ uint8_t *outhdr;
+ DATA_BLOB outbody;
+ DATA_BLOB outdyn;
+ uint32_t out_count;
+ NTSTATUS status;
+ NTSTATUS error; /* transport error */
+
+ status = smbd_smb2_write_recv(subreq, &out_count);
+ TALLOC_FREE(subreq);
if (!NT_STATUS_IS_OK(status)) {
- return smbd_smb2_request_error(req, status);
+ error = smbd_smb2_request_error(req, status);
+ if (!NT_STATUS_IS_OK(error)) {
+ smbd_server_connection_terminate(req->conn,
+ nt_errstr(error));
+ return;
+ }
}
outhdr = (uint8_t *)req->out.vector[i].iov_base;
outbody = data_blob_talloc(req->out.vector, NULL, 0x10);
if (outbody.data == NULL) {
- return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
+ error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
+ if (!NT_STATUS_IS_OK(error)) {
+ smbd_server_connection_terminate(req->conn,
+ nt_errstr(error));
+ return;
+ }
}
SSVAL(outbody.data, 0x00, 0x10 + 1); /* struct size */
@@ -121,51 +153,77 @@ NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req)
outdyn = data_blob_const(NULL, 0);
- return smbd_smb2_request_done(req, outbody, &outdyn);
+ error = smbd_smb2_request_done(req, outbody, &outdyn);
+ if (!NT_STATUS_IS_OK(error)) {
+ smbd_server_connection_terminate(req->conn, nt_errstr(error));
+ return;
+ }
}
-static NTSTATUS smbd_smb2_write(struct smbd_smb2_request *req,
- uint32_t in_smbpid,
- uint64_t in_file_id_volatile,
- DATA_BLOB in_data,
- uint64_t in_offset,
- uint32_t in_flags,
- uint32_t *out_count)
+struct smbd_smb2_write_state {
+ struct smbd_smb2_request *smb2req;
+ uint32_t in_length;
+ uint32_t out_count;
+};
+
+static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct smbd_smb2_request *smb2req,
+ uint32_t in_smbpid,
+ uint64_t in_file_id_volatile,
+ DATA_BLOB in_data,
+ uint64_t in_offset,
+ uint32_t in_flags)
{
NTSTATUS status;
+ struct tevent_req *req;
+ struct smbd_smb2_write_state *state;
struct smb_request *smbreq;
- connection_struct *conn = req->tcon->compat_conn;
+ connection_struct *conn = smb2req->tcon->compat_conn;
files_struct *fsp;
ssize_t nwritten;
bool write_through = false;
struct lock_struct lock;
+ req = tevent_req_create(mem_ctx, &state,
+ struct smbd_smb2_write_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->smb2req = smb2req;
+ state->in_length = in_data.length;
+ state->out_count = 0;
+
DEBUG(10,("smbd_smb2_write: file_id[0x%016llX]\n",
(unsigned long long)in_file_id_volatile));
- smbreq = smbd_smb2_fake_smb_request(req);
- if (smbreq == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- /* If it's an IPC, pass off the pipe handler. */
- if (IS_IPC(conn)) {
- return NT_STATUS_NOT_IMPLEMENTED;
+ smbreq = smbd_smb2_fake_smb_request(smb2req);
+ if (tevent_req_nomem(smbreq, req)) {
+ return tevent_req_post(req, ev);
}
fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
if (fsp == NULL) {
- return NT_STATUS_FILE_CLOSED;
+ tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
+ return tevent_req_post(req, ev);
}
if (conn != fsp->conn) {
- return NT_STATUS_FILE_CLOSED;
+ tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
+ return tevent_req_post(req, ev);
}
- if (req->session->vuid != fsp->vuid) {
- return NT_STATUS_FILE_CLOSED;
+ if (smb2req->session->vuid != fsp->vuid) {
+ tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
+ return tevent_req_post(req, ev);
}
if (!CHECK_WRITE(fsp)) {
- return NT_STATUS_ACCESS_DENIED;
+ tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
+ return tevent_req_post(req, ev);
+ }
+
+ if (IS_IPC(smbreq->conn)) {
+ tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
+ return tevent_req_post(req, ev);
}
init_strict_lock_struct(fsp,
@@ -176,7 +234,8 @@ static NTSTATUS smbd_smb2_write(struct smbd_smb2_request *req,
&lock);
if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
- return NT_STATUS_FILE_LOCK_CONFLICT;
+ tevent_req_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
+ return tevent_req_post(req, ev);
}
nwritten = write_file(smbreq, fsp,
@@ -188,7 +247,8 @@ static NTSTATUS smbd_smb2_write(struct smbd_smb2_request *req,
DEBUG(5,("smbd_smb2_write: write_file[%s] disk full\n",
fsp->fsp_name));
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
- return NT_STATUS_DISK_FULL;
+ tevent_req_nterror(req, NT_STATUS_DISK_FULL);
+ return tevent_req_post(req, ev);
}
DEBUG(3,("smbd_smb2_write: fnum=[%d/%s] length=%d offset=%d wrote=%d\n",
@@ -204,10 +264,32 @@ static NTSTATUS smbd_smb2_write(struct smbd_smb2_request *req,
DEBUG(5,("smbd_smb2_write: sync_file for %s returned %s\n",
fsp->fsp_name, nt_errstr(status)));
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
- return status;
+ tevent_req_nterror(req, status);
+ return tevent_req_post(req, ev);
}
SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+ state->out_count = nwritten;
+
+ tevent_req_done(req);
+ return tevent_req_post(req, ev);
+}
+
+static NTSTATUS smbd_smb2_write_recv(struct tevent_req *req,
+ uint32_t *out_count)
+{
+ NTSTATUS status;
+ struct smbd_smb2_write_state *state = tevent_req_data(req,
+ struct smbd_smb2_write_state);
+
+ if (tevent_req_is_nterror(req, &status)) {
+ tevent_req_received(req);
+ return status;
+ }
+
+ *out_count = state->out_count;
+
+ tevent_req_received(req);
return NT_STATUS_OK;
}