From: Stefan Metzmacher Date: Thu, 22 Mar 2018 09:54:41 +0000 (+0100) Subject: smbd: add an effective {smb,smbd_smb2}_request->ev_ctx that holds the event context... X-Git-Tag: tevent-0.9.37~271 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=894e5001c747ce765dad5517778dda55d7d1f4d9;p=thirdparty%2Fsamba.git smbd: add an effective {smb,smbd_smb2}_request->ev_ctx that holds the event context used for the request processing In future this will an impersonation wrapper tevent_context based on the user session. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 249cf069779..4e5b7870903 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -514,6 +514,8 @@ struct smb_request { size_t unread_bytes; bool encrypted; + /* the tevent_context (wrapper) the request operates on */ + struct tevent_context *ev_ctx; connection_struct *conn; struct smbd_server_connection *sconn; struct smbXsrv_connection *xconn; diff --git a/source3/smbd/aio.c b/source3/smbd/aio.c index b984036e9f8..c066ea1a978 100644 --- a/source3/smbd/aio.c +++ b/source3/smbd/aio.c @@ -206,7 +206,7 @@ NTSTATUS schedule_aio_read_and_X(connection_struct *conn, aio_ex->nbyte = smb_maxcnt; aio_ex->offset = startpos; - req = SMB_VFS_PREAD_SEND(aio_ex, fsp->conn->sconn->ev_ctx, + req = SMB_VFS_PREAD_SEND(aio_ex, smbreq->ev_ctx, fsp, smb_buf(aio_ex->outbuf.data) + 1 /* pad */, smb_maxcnt, startpos); @@ -459,7 +459,7 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn, aio_ex->nbyte = numtowrite; aio_ex->offset = startpos; - req = pwrite_fsync_send(aio_ex, fsp->conn->sconn->ev_ctx, fsp, + req = pwrite_fsync_send(aio_ex, smbreq->ev_ctx, fsp, data, numtowrite, startpos, aio_ex->write_through); if (req == NULL) { @@ -701,7 +701,7 @@ NTSTATUS schedule_smb2_aio_read(connection_struct *conn, aio_ex->nbyte = smb_maxcnt; aio_ex->offset = startpos; - req = SMB_VFS_PREAD_SEND(aio_ex, fsp->conn->sconn->ev_ctx, fsp, + req = SMB_VFS_PREAD_SEND(aio_ex, smbreq->ev_ctx, fsp, preadbuf->data, smb_maxcnt, startpos); if (req == NULL) { DEBUG(0, ("smb2: SMB_VFS_PREAD_SEND failed. " @@ -850,7 +850,7 @@ NTSTATUS schedule_aio_smb2_write(connection_struct *conn, aio_ex->nbyte = in_data.length; aio_ex->offset = in_offset; - req = pwrite_fsync_send(aio_ex, fsp->conn->sconn->ev_ctx, fsp, + req = pwrite_fsync_send(aio_ex, smbreq->ev_ctx, fsp, in_data.data, in_data.length, in_offset, write_through); if (req == NULL) { diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index 1ac1b47b9d3..7d7058727bf 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -701,6 +701,9 @@ struct smbd_smb2_request { struct smbXsrv_tcon *tcon; uint32_t last_tid; + /* the tevent_context (wrapper) the request operates on */ + struct tevent_context *ev_ctx; + int current_idx; bool do_signing; /* Was the request encrypted? */ diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c index f1c8ea0c2ed..85236e0102f 100644 --- a/source3/smbd/ipc.c +++ b/source3/smbd/ipc.c @@ -281,7 +281,7 @@ static void api_dcerpc_cmd(connection_struct *conn, struct smb_request *req, state->num_data = length; state->max_read = max_read; - subreq = np_write_send(state, req->sconn->ev_ctx, state->handle, + subreq = np_write_send(state, req->ev_ctx, state->handle, state->data, length); if (subreq == NULL) { TALLOC_FREE(state); @@ -330,7 +330,7 @@ static void api_dcerpc_cmd_write_done(struct tevent_req *subreq) goto send; } - subreq = np_read_send(state, req->sconn->ev_ctx, + subreq = np_read_send(state, req->ev_ctx, state->handle, state->data, state->max_read); if (subreq == NULL) { reply_nterror(req, NT_STATUS_NO_MEMORY); diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 4b28e7ff9a2..db5eb4e459b 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -2408,7 +2408,7 @@ static void defer_open(struct share_mode_lock *lck, DBG_DEBUG("defering mid %" PRIu64 "\n", req->mid); watch_req = dbwrap_watched_watch_send(watch_state, - req->sconn->ev_ctx, + req->ev_ctx, lck->data->record, (struct server_id){0}); if (watch_req == NULL) { @@ -2416,7 +2416,7 @@ static void defer_open(struct share_mode_lock *lck, } tevent_req_set_callback(watch_req, defer_open_done, watch_state); - ok = tevent_req_set_endtime(watch_req, req->sconn->ev_ctx, abs_timeout); + ok = tevent_req_set_endtime(watch_req, req->ev_ctx, abs_timeout); if (!ok) { exit_server("tevent_req_set_endtime failed"); } @@ -2508,7 +2508,7 @@ static void setup_kernel_oplock_poll_open(struct timeval request_time, * As this timer event is owned by req, it will * disappear if req it talloc_freed. */ - open_rec->te = tevent_add_timer(req->sconn->ev_ctx, + open_rec->te = tevent_add_timer(req->ev_ctx, req, timeval_current_ofs(1, 0), kernel_oplock_poll_open_timer, @@ -2695,7 +2695,7 @@ static void schedule_async_open(struct timeval request_time, exit_server("push_deferred_open_message_smb failed"); } - open_rec->te = tevent_add_timer(req->sconn->ev_ctx, + open_rec->te = tevent_add_timer(req->ev_ctx, req, timeval_current_ofs(20, 0), schedule_async_open_timer, diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c index 4be57bc2a5f..c945f0f6177 100644 --- a/source3/smbd/pipes.c +++ b/source3/smbd/pipes.c @@ -67,7 +67,7 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name, conn->sconn->remote_address, conn->sconn->local_address, conn->session_info, - conn->sconn->ev_ctx, + smb_req->ev_ctx, conn->sconn->msg_ctx, &fsp->fake_file_handle); if (!NT_STATUS_IS_OK(status)) { @@ -206,7 +206,7 @@ void reply_pipe_write(struct smb_request *req) 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, + subreq = np_write_send(state, req->ev_ctx, fsp->fake_file_handle, data, state->numtowrite); if (subreq == NULL) { TALLOC_FREE(state); @@ -322,7 +322,7 @@ void reply_pipe_write_and_X(struct smb_request *req) state->numtowrite -= 2; } - subreq = np_write_send(state, req->sconn->ev_ctx, + subreq = np_write_send(state, req->ev_ctx, fsp->fake_file_handle, data, state->numtowrite); if (subreq == NULL) { TALLOC_FREE(state); @@ -435,7 +435,7 @@ void reply_pipe_read_and_X(struct smb_request *req) state->outbuf = req->outbuf; req->outbuf = NULL; - subreq = np_read_send(state, req->sconn->ev_ctx, + subreq = np_read_send(state, req->ev_ctx, fsp->fake_file_handle, data, state->smb_maxcnt); if (subreq == NULL) { diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d2553049cd2..e730676ef36 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1506,6 +1506,8 @@ static connection_struct *switch_message(uint8_t type, struct smb_request *req) errno = 0; + req->ev_ctx = NULL; + if (!xconn->smb1.negprot.done) { switch (type) { /* @@ -1640,6 +1642,8 @@ static connection_struct *switch_message(uint8_t type, struct smb_request *req) reply_nterror(req, NT_STATUS_ACCESS_DENIED); return conn; } + + req->ev_ctx = conn->user_ev_ctx; } else if (flags & AS_GUEST) { /* * Does this protocol need to be run as guest? (Only archane @@ -1649,9 +1653,13 @@ static connection_struct *switch_message(uint8_t type, struct smb_request *req) reply_nterror(req, NT_STATUS_ACCESS_DENIED); return conn; } + + req->ev_ctx = req->sconn->guest_ev_ctx; } else { /* This call needs to be run as root */ change_to_root_user(); + + req->ev_ctx = req->sconn->root_ev_ctx; } /* load service specific parameters */ diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 1b99664cbd8..5afe57d11cb 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -5392,7 +5392,7 @@ void reply_close(struct smb_request *req) */ fsp->deferred_close = tevent_wait_send( - fsp, fsp->conn->sconn->ev_ctx); + fsp, req->ev_ctx); if (fsp->deferred_close == NULL) { status = NT_STATUS_NO_MEMORY; goto done; diff --git a/source3/smbd/smb2_break.c b/source3/smbd/smb2_break.c index 86529ed2e1f..21fbef42dce 100644 --- a/source3/smbd/smb2_break.c +++ b/source3/smbd/smb2_break.c @@ -86,7 +86,7 @@ NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER); } - subreq = smbd_smb2_oplock_break_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_oplock_break_send(req, req->ev_ctx, req, in_fsp, in_oplock_level); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); @@ -265,7 +265,7 @@ static NTSTATUS smbd_smb2_request_process_lease_break( in_lease_key.data[1] = BVAL(inbody, 16); in_lease_state = IVAL(inbody, 24); - subreq = smbd_smb2_lease_break_send(req, req->sconn->ev_ctx, req, + subreq = smbd_smb2_lease_break_send(req, req->ev_ctx, req, in_lease_key, in_lease_state); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); diff --git a/source3/smbd/smb2_close.c b/source3/smbd/smb2_close.c index 992b52929ec..33863d32f5f 100644 --- a/source3/smbd/smb2_close.c +++ b/source3/smbd/smb2_close.c @@ -70,7 +70,7 @@ NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_close_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_close_send(req, req->ev_ctx, req, in_fsp, in_flags); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c index 3f38af5dde2..8fbea238698 100644 --- a/source3/smbd/smb2_create.c +++ b/source3/smbd/smb2_create.c @@ -228,7 +228,7 @@ NTSTATUS smbd_smb2_request_process_create(struct smbd_smb2_request *smb2req) } tsubreq = smbd_smb2_create_send(smb2req, - smb2req->sconn->ev_ctx, + smb2req->ev_ctx, smb2req, in_oplock_level, in_impersonation_level, @@ -1763,7 +1763,7 @@ bool schedule_deferred_open_message_smb2( (unsigned long long)mid )); tevent_schedule_immediate(state->im, - smb2req->sconn->ev_ctx, + smb2req->ev_ctx, smbd_smb2_create_request_dispatch_immediate, smb2req); @@ -1795,7 +1795,7 @@ static bool smbd_smb2_create_cancel(struct tevent_req *req) remove_deferred_open_message_smb2_internal(smb2req, mid); - tevent_req_defer_callback(req, smb2req->sconn->ev_ctx); + tevent_req_defer_callback(req, smb2req->ev_ctx); tevent_req_nterror(req, NT_STATUS_CANCELLED); return true; } diff --git a/source3/smbd/smb2_flush.c b/source3/smbd/smb2_flush.c index 470a8df4944..4f815a6f5b0 100644 --- a/source3/smbd/smb2_flush.c +++ b/source3/smbd/smb2_flush.c @@ -58,7 +58,7 @@ NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_flush_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_flush_send(req, req->ev_ctx, req, in_fsp); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); diff --git a/source3/smbd/smb2_getinfo.c b/source3/smbd/smb2_getinfo.c index 694e9f83b75..da82bf52378 100644 --- a/source3/smbd/smb2_getinfo.c +++ b/source3/smbd/smb2_getinfo.c @@ -120,7 +120,7 @@ NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_getinfo_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_getinfo_send(req, req->ev_ctx, req, in_fsp, in_info_type, in_file_info_class, diff --git a/source3/smbd/smb2_glue.c b/source3/smbd/smb2_glue.c index 6a73ec050e2..cccc763c342 100644 --- a/source3/smbd/smb2_glue.c +++ b/source3/smbd/smb2_glue.c @@ -46,6 +46,7 @@ struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req) smbreq->conn = req->tcon->compat; smbreq->sconn = req->sconn; smbreq->xconn = req->xconn; + smbreq->ev_ctx = req->ev_ctx; smbreq->smbpid = (uint16_t)IVAL(inhdr, SMB2_HDR_PID); smbreq->flags2 = FLAGS2_UNICODE_STRINGS | FLAGS2_32_BIT_ERROR_CODES | diff --git a/source3/smbd/smb2_ioctl.c b/source3/smbd/smb2_ioctl.c index be70e3a0912..451733c1a65 100644 --- a/source3/smbd/smb2_ioctl.c +++ b/source3/smbd/smb2_ioctl.c @@ -217,7 +217,7 @@ NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req) break; } - subreq = smbd_smb2_ioctl_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_ioctl_send(req, req->ev_ctx, req, in_fsp, in_ctl_code, in_input_buffer, diff --git a/source3/smbd/smb2_ioctl_named_pipe.c b/source3/smbd/smb2_ioctl_named_pipe.c index f9e3dec049c..f8012ae1920 100644 --- a/source3/smbd/smb2_ioctl_named_pipe.c +++ b/source3/smbd/smb2_ioctl_named_pipe.c @@ -143,7 +143,7 @@ static void smbd_smb2_ioctl_pipe_write_done(struct tevent_req *subreq) (unsigned int)state->out_output.length )); subreq = np_read_send(state->smbreq->conn, - state->smb2req->sconn->ev_ctx, + state->smb2req->ev_ctx, state->fsp->fake_file_handle, state->out_output.data, state->out_output.length); diff --git a/source3/smbd/smb2_lock.c b/source3/smbd/smb2_lock.c index 3cc591089a4..da5a54df623 100644 --- a/source3/smbd/smb2_lock.c +++ b/source3/smbd/smb2_lock.c @@ -134,7 +134,7 @@ NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_lock_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_lock_send(req, req->ev_ctx, req, in_fsp, in_lock_count, in_locks); @@ -368,7 +368,7 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx, } if (async) { - tevent_req_defer_callback(req, smb2req->sconn->ev_ctx); + tevent_req_defer_callback(req, smb2req->ev_ctx); SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(smb2req->profile); return req; } diff --git a/source3/smbd/smb2_notify.c b/source3/smbd/smb2_notify.c index 24241562556..e49e76d9641 100644 --- a/source3/smbd/smb2_notify.c +++ b/source3/smbd/smb2_notify.c @@ -94,7 +94,7 @@ NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_notify_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_notify_send(req, req->ev_ctx, req, in_fsp, in_flags, in_output_buffer_length, @@ -355,7 +355,7 @@ static void smbd_smb2_notify_reply(struct smb_request *smbreq, } } - tevent_req_defer_callback(req, state->smb2req->sconn->ev_ctx); + tevent_req_defer_callback(req, state->smb2req->ev_ctx); if (!NT_STATUS_IS_OK(state->status)) { tevent_req_nterror(req, state->status); diff --git a/source3/smbd/smb2_query_directory.c b/source3/smbd/smb2_query_directory.c index 700f43e3126..50a5bca5d7b 100644 --- a/source3/smbd/smb2_query_directory.c +++ b/source3/smbd/smb2_query_directory.c @@ -124,7 +124,7 @@ NTSTATUS smbd_smb2_request_process_query_directory(struct smbd_smb2_request *req return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_query_directory_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_query_directory_send(req, req->ev_ctx, req, in_fsp, in_file_info_class, in_flags, diff --git a/source3/smbd/smb2_read.c b/source3/smbd/smb2_read.c index a7d2496bc6f..065a5cd5fc6 100644 --- a/source3/smbd/smb2_read.c +++ b/source3/smbd/smb2_read.c @@ -97,7 +97,7 @@ NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_read_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_read_send(req, req->ev_ctx, req, in_fsp, in_flags, in_length, diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c index 46b747cabff..0c1ac323891 100644 --- a/source3/smbd/smb2_server.c +++ b/source3/smbd/smb2_server.c @@ -2614,8 +2614,10 @@ NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req) SMB_ASSERT(call->fileid_ofs == 0); /* This call needs to be run as root */ change_to_root_user(); + req->ev_ctx = req->sconn->root_ev_ctx; } else { SMB_ASSERT(call->need_tcon); + req->ev_ctx = req->tcon->compat->user_ev_ctx; } #define _INBYTES(_r) \ diff --git a/source3/smbd/smb2_sesssetup.c b/source3/smbd/smb2_sesssetup.c index 5e1e8b4ec57..fe5835b83f3 100644 --- a/source3/smbd/smb2_sesssetup.c +++ b/source3/smbd/smb2_sesssetup.c @@ -95,7 +95,7 @@ NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *smb2req) in_security_buffer.length = in_security_length; subreq = smbd_smb2_session_setup_wrap_send(smb2req, - smb2req->sconn->ev_ctx, + smb2req->ev_ctx, smb2req, in_session_id, in_flags, @@ -1218,7 +1218,7 @@ NTSTATUS smbd_smb2_request_process_logoff(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, status); } - subreq = smbd_smb2_logoff_send(req, req->sconn->ev_ctx, req); + subreq = smbd_smb2_logoff_send(req, req->ev_ctx, req); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); } diff --git a/source3/smbd/smb2_setinfo.c b/source3/smbd/smb2_setinfo.c index 4958bb8f16e..5a6a28a323e 100644 --- a/source3/smbd/smb2_setinfo.c +++ b/source3/smbd/smb2_setinfo.c @@ -107,7 +107,7 @@ NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_setinfo_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_setinfo_send(req, req->ev_ctx, req, in_fsp, in_info_type, in_file_info_class, diff --git a/source3/smbd/smb2_tcon.c b/source3/smbd/smb2_tcon.c index ebd31602efc..3a4a15d3059 100644 --- a/source3/smbd/smb2_tcon.c +++ b/source3/smbd/smb2_tcon.c @@ -94,7 +94,7 @@ NTSTATUS smbd_smb2_request_process_tcon(struct smbd_smb2_request *req) } subreq = smbd_smb2_tree_connect_send(req, - req->sconn->ev_ctx, + req->ev_ctx, req, in_path_string); if (subreq == NULL) { @@ -491,7 +491,7 @@ NTSTATUS smbd_smb2_request_process_tdis(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, status); } - subreq = smbd_smb2_tdis_send(req, req->sconn->ev_ctx, req); + subreq = smbd_smb2_tdis_send(req, req->ev_ctx, req); if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); } diff --git a/source3/smbd/smb2_write.c b/source3/smbd/smb2_write.c index ee95bd317ae..d5ab12ecc21 100644 --- a/source3/smbd/smb2_write.c +++ b/source3/smbd/smb2_write.c @@ -109,7 +109,7 @@ NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED); } - subreq = smbd_smb2_write_send(req, req->sconn->ev_ctx, + subreq = smbd_smb2_write_send(req, req->ev_ctx, req, in_fsp, in_data_buffer, in_offset,