smbd: add an effective connection_struct->user_ev_ctx that holds the event context...
authorStefan Metzmacher <metze@samba.org>
Thu, 22 Mar 2018 09:54:41 +0000 (10:54 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 18 Jun 2018 06:59:21 +0000 (08:59 +0200)
This will be filled with an impersonation wrapper in the next commits.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/vfs.h
source3/modules/vfs_aio_pthread.c
source3/modules/vfs_default.c
source3/modules/vfs_readonly.c
source3/smbd/conn.c
source3/smbd/msdfs.c
source3/smbd/uid.c

index 54ab1604b799fc0bb00d6f540ecf0b7adb4aa84f..249cf0697792cc085388d4dc28d24c3e83728ecf 100644 (file)
@@ -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
index 88794bb7acc7e2787a4e406f337ac475426a07c0..a9e2b09827bda8e73f51003e23b8f306e3c730e0 100644 (file)
@@ -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) {
index ede11ad34ed958d942ce07478797cb24d21ba3fc..082b70f5a98eeccbd3d69aca0f23bb3fa8c8175a 100644 (file)
@@ -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);
index cde8ef973ca158075b227dd5ae07984fc8b52e69..570eb7c4d15a24b42f9cffe33a61025819f885fb 100644 (file)
@@ -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;
index 8f472c0d2458f742edccf441a90840f2900a442a..3b9aaac7834bedd53ddc3545dd71f4aa243b51ea 100644 (file)
@@ -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;
                }
index 39aef4f1116836688d6c9afd571671386b89ea0f..3fba71bb084e07ade5497de3162a1f677707ba4d 100644 (file)
@@ -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);
 
        /*
index 35d198b1899a7f7f0ac0ffc898f08700579f8215..e021031a8b7576533968c42bbd81c3c5eb6ba3d6 100644 (file)
@@ -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;