smbd: add create_conn_struct_cwd()
authorRalph Boehme <slow@samba.org>
Fri, 28 May 2021 07:25:22 +0000 (09:25 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 12 Jul 2021 12:55:43 +0000 (12:55 +0000)
Compared to create_conn_struct_tos_cwd() this takes a TALLOC_CTX and
tevent_context as additional arguments and the resulting connection_struct is
stable across the lifetime of mem_ctx and ev.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14740

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 9a2d6bcfd5797dd4db764921548c8dca6dd0eb21)

source3/smbd/msdfs.c
source3/smbd/proto.h

index f07cf75775b3f8eb895c6cf782bc778063d41da9..3a1dd11d9eb48279fa9d1340ea5fcd963aa5513d 100644 (file)
@@ -495,6 +495,44 @@ NTSTATUS create_conn_struct_tos_cwd(struct messaging_context *msg,
        return NT_STATUS_OK;
 }
 
+/********************************************************
+ Fake up a connection struct for the VFS layer.
+ This takes an TALLOC_CTX and tevent_context from the
+ caller and the resulting connection_struct is stable
+ across the lifetime of mem_ctx and ev.
+
+ Note: this performs a vfs connect and changes cwd.
+
+ See also the comment for create_conn_struct_tos() above!
+*********************************************************/
+
+NTSTATUS create_conn_struct_cwd(TALLOC_CTX *mem_ctx,
+                               struct tevent_context *ev,
+                               struct messaging_context *msg,
+                               const struct auth_session_info *session_info,
+                               int snum,
+                               const char *path,
+                               struct connection_struct **c)
+{
+       NTSTATUS status;
+
+       become_root();
+       status = create_conn_struct_as_root(mem_ctx,
+                                           ev,
+                                           msg,
+                                           c,
+                                           snum,
+                                           path,
+                                           session_info);
+       unbecome_root();
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(c);
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}
+
 static void shuffle_strlist(char **list, int count)
 {
        int i;
index a65c786c24df1fad094607b6dbc4b26a25b417c0..90543a59feb188ecb86ec149068b8274465a6320 100644 (file)
@@ -579,6 +579,14 @@ NTSTATUS dfs_redirect(TALLOC_CTX *ctx,
                        char **pp_name_out);
 struct connection_struct;
 struct smb_filename;
+
+NTSTATUS create_conn_struct_cwd(TALLOC_CTX *mem_ctx,
+                               struct tevent_context *ev,
+                               struct messaging_context *msg,
+                               const struct auth_session_info *session_info,
+                               int snum,
+                               const char *path,
+                               struct connection_struct **c);
 struct conn_struct_tos {
        struct connection_struct *conn;
        struct smb_filename *oldcwd_fname;