From: Stefan Metzmacher Date: Thu, 22 Mar 2018 09:54:41 +0000 (+0100) Subject: smbd: add an effective connection_struct->user_ev_ctx that holds the event context... X-Git-Tag: tevent-0.9.37~272 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f2df8be16be9dccd3d10ec060f1efbe5007a28c6;p=thirdparty%2Fsamba.git smbd: add an effective connection_struct->user_ev_ctx that holds the event context used for the current user This will be filled with an impersonation wrapper in the next commits. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 54ab1604b79..249cf069779 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -398,6 +398,7 @@ typedef struct files_struct { struct vuid_cache_entry { struct auth_session_info *session_info; + struct tevent_context *user_ev_ctx; uint64_t vuid; /* SMB2 compat */ bool read_only; uint32_t share_access; @@ -445,6 +446,7 @@ typedef struct connection_struct { * on the vuid using this tid, this might change per SMB request. */ struct auth_session_info *session_info; + struct tevent_context *user_ev_ctx; /* * If the "force group" parameter is set, this is the primary gid that diff --git a/source3/modules/vfs_aio_pthread.c b/source3/modules/vfs_aio_pthread.c index 88794bb7acc..a9e2b09827b 100644 --- a/source3/modules/vfs_aio_pthread.c +++ b/source3/modules/vfs_aio_pthread.c @@ -276,7 +276,7 @@ static int open_async(const files_struct *fsp, } subreq = pthreadpool_tevent_job_send(opd, - fsp->conn->sconn->ev_ctx, + fsp->conn->user_ev_ctx, fsp->conn->sconn->pool, aio_open_worker, opd); if (subreq == NULL) { diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index ede11ad34ed..082b70f5a98 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -1701,7 +1701,7 @@ static struct tevent_req *vfswrap_offload_write_send( return tevent_req_post(req, ev); } - state->src_ev = state->src_fsp->conn->sconn->ev_ctx; + state->src_ev = src_fsp->conn->user_ev_ctx; state->src_fsp = src_fsp; state->buf = talloc_array(state, uint8_t, num); diff --git a/source3/modules/vfs_readonly.c b/source3/modules/vfs_readonly.c index cde8ef973ca..570eb7c4d15 100644 --- a/source3/modules/vfs_readonly.c +++ b/source3/modules/vfs_readonly.c @@ -84,6 +84,7 @@ static int readonly_connect(vfs_handle_struct *handle, for (i=0; i< VUID_CACHE_SIZE; i++) { struct vuid_cache_entry *ent = &conn->vuid_cache->array[i]; ent->vuid = UID_FIELD_INVALID; + ent->user_ev_ctx = NULL; TALLOC_FREE(ent->session_info); ent->read_only = false; ent->share_access = 0; diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c index 8f472c0d245..3b9aaac7834 100644 --- a/source3/smbd/conn.c +++ b/source3/smbd/conn.c @@ -94,6 +94,12 @@ static void conn_clear_vuid_cache(connection_struct *conn, uint64_t vuid) if (ent->vuid == vuid) { ent->vuid = UID_FIELD_INVALID; + + if (conn->user_ev_ctx == ent->user_ev_ctx) { + conn->user_ev_ctx = NULL; + } + ent->user_ev_ctx = NULL; + /* * We need to keep conn->session_info around * if it's equal to ent->session_info as a SMBulogoff @@ -117,6 +123,7 @@ static void conn_clear_vuid_cache(connection_struct *conn, uint64_t vuid) } else { TALLOC_FREE(ent->session_info); } + ent->read_only = False; ent->share_access = 0; } diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 39aef4f1116..3fba71bb084 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -314,6 +314,8 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx, vfs_user = get_current_username(); } + conn->user_ev_ctx = sconn->raw_ev_ctx; + set_conn_connectpath(conn, connpath); /* diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index 35d198b1899..e021031a8b7 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -77,6 +77,7 @@ static void free_conn_session_info_if_unused(connection_struct *conn) } } /* Not used, safe to free. */ + conn->user_ev_ctx = NULL; TALLOC_FREE(conn->session_info); } @@ -202,6 +203,7 @@ static bool check_user_ok(connection_struct *conn, } free_conn_session_info_if_unused(conn); conn->session_info = ent->session_info; + conn->user_ev_ctx = ent->user_ev_ctx; conn->read_only = ent->read_only; conn->share_access = ent->share_access; conn->vuid = ent->vuid; @@ -250,6 +252,8 @@ static bool check_user_ok(connection_struct *conn, ent->session_info->unix_token->uid = sec_initial_uid(); } + ent->user_ev_ctx = conn->sconn->raw_ev_ctx; + /* * It's actually OK to call check_user_ok() with * vuid == UID_FIELD_INVALID as called from change_to_user_by_session(). @@ -262,6 +266,7 @@ static bool check_user_ok(connection_struct *conn, free_conn_session_info_if_unused(conn); conn->session_info = ent->session_info; conn->vuid = ent->vuid; + conn->user_ev_ctx = ent->user_ev_ctx; if (vuid == UID_FIELD_INVALID) { /* * Not strictly needed, just make it really @@ -270,6 +275,7 @@ static bool check_user_ok(connection_struct *conn, ent->read_only = false; ent->share_access = 0; ent->session_info = NULL; + ent->user_ev_ctx = NULL; } conn->read_only = readonly_share;