]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Add create_conn_struct_chdir()
authorVolker Lendecke <vl@samba.org>
Mon, 16 Feb 2026 11:36:25 +0000 (12:36 +0100)
committerVolker Lendecke <vl@samba.org>
Sun, 1 Mar 2026 20:19:35 +0000 (20:19 +0000)
This is supposed to replace create_conn_struct_tos() in the next patches. Stay
tuned...

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/smbd/msdfs.c
source3/smbd/proto.h

index 610ba5e29b9490c7904fc9ed561bcd9da9114d83..55dd1760db59150e0b5c5fc04f945645068abd75 100644 (file)
@@ -419,6 +419,72 @@ NTSTATUS create_conn_struct_tos_cwd(struct messaging_context *msg,
        return NT_STATUS_OK;
 }
 
+struct conn_wrap {
+       struct connection_struct *conn;
+};
+
+static int conn_wrap_destructor(struct conn_wrap *w)
+{
+       SMB_VFS_DISCONNECT(w->conn);
+       TALLOC_FREE(w->conn);
+
+       /*
+        * Make whatever directory we chdir()ed to umountable
+        */
+       SMB_ASSERT(chdir("/") == 0);
+
+       /*
+        * Prevent vfs_ChDir() from skipping the real chdir()
+        */
+       LastDir = NULL;
+
+       return 0;
+}
+
+NTSTATUS create_conn_struct_chdir(TALLOC_CTX *mem_ctx,
+                                 struct messaging_context *msg,
+                                 int snum,
+                                 const char *path,
+                                 const struct auth_session_info *session_info,
+                                 struct conn_wrap **_wrap)
+{
+       struct conn_wrap *w = NULL;
+       NTSTATUS status;
+       int ret;
+
+       w = talloc(mem_ctx, struct conn_wrap);
+       if (w == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       become_root();
+       status = create_conn_struct_as_root(
+               w, msg, &w->conn, snum, path, session_info);
+       unbecome_root();
+
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(w);
+               return status;
+       }
+       talloc_set_destructor(w, conn_wrap_destructor);
+
+       ret = vfs_ChDir_shareroot(w->conn);
+       if (ret != 0) {
+               status = map_nt_error_from_unix(errno);
+               TALLOC_FREE(w);
+               return status;
+       }
+
+       *_wrap = w;
+
+       return NT_STATUS_OK;
+}
+
+struct connection_struct *conn_wrap_connection(const struct conn_wrap *w)
+{
+       return w->conn;
+}
+
 /********************************************************
  Fake up a connection struct for the VFS layer.
  This takes an TALLOC_CTX and tevent_context from the
index 2ee29bf976e703908539a8152c046c4694ea7468..e5712c290bbe9cc691c629c692190b9a15edb6b2 100644 (file)
@@ -526,6 +526,15 @@ NTSTATUS create_conn_struct_tos_cwd(struct messaging_context *msg,
                                    const struct auth_session_info *session_info,
                                    struct conn_struct_tos **_c);
 
+struct conn_wrap;
+NTSTATUS create_conn_struct_chdir(TALLOC_CTX *mem_ctx,
+                                 struct messaging_context *msg,
+                                 int snum,
+                                 const char *path,
+                                 const struct auth_session_info *session_info,
+                                 struct conn_wrap **_wrap);
+struct connection_struct *conn_wrap_connection(const struct conn_wrap *w);
+
 /* The following definitions come from smbd/notify.c  */
 
 bool change_notify_fsp_has_changes(struct files_struct *fsp);