mdssvc: maintain a connection struct in the mds_ctx
authorRalph Boehme <slow@samba.org>
Mon, 10 May 2021 10:10:08 +0000 (12:10 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 12 Jul 2021 10:13:08 +0000 (10:13 +0000)
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 8b681cfb5d9b1ece03f7e7b9d3a08ae6c461d679)

source3/rpc_server/mdssvc/mdssvc.c
source3/rpc_server/mdssvc/mdssvc.h

index cdb0eaafd80b9bb3b080dbb904f5942c64346bd2..c0a59ebd3ab5b92e6b0b75720fe64def57805e2a 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "smbd/proto.h"
 #include "librpc/gen_ndr/auth.h"
 #include "dbwrap/dbwrap.h"
 #include "lib/util/dlinklist.h"
@@ -1530,10 +1531,15 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx,
                             const char *sharename,
                             const char *path)
 {
+       const struct loadparm_substitution *lp_sub =
+               loadparm_s3_global_substitution();
+       struct smb_filename conn_basedir;
        struct mds_ctx *mds_ctx;
        int backend;
+       int ret;
        bool ok;
        smb_iconv_t iconv_hnd = (smb_iconv_t)-1;
+       NTSTATUS status;
 
        mds_ctx = talloc_zero(mem_ctx, struct mds_ctx);
        if (mds_ctx == NULL) {
@@ -1615,6 +1621,30 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx,
                goto error;
        }
 
+       status = create_conn_struct_cwd(mds_ctx,
+                                       ev,
+                                       msg_ctx,
+                                       session_info,
+                                       snum,
+                                       lp_path(talloc_tos(), lp_sub, snum),
+                                       &mds_ctx->conn);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_ERR("failed to create conn for vfs: %s\n",
+                       nt_errstr(status));
+               goto error;
+       }
+
+       conn_basedir = (struct smb_filename) {
+               .base_name = mds_ctx->conn->connectpath,
+       };
+
+       ret = vfs_ChDir(mds_ctx->conn, &conn_basedir);
+       if (ret != 0) {
+               DBG_ERR("vfs_ChDir [%s] failed: %s\n",
+                       conn_basedir.base_name, strerror(errno));
+               goto error;
+       }
+
        ok = mds_ctx->backend->connect(mds_ctx);
        if (!ok) {
                DBG_ERR("backend connect failed\n");
index d37f68467118757d5b75e458eef9d876e73a7724..392482767dd837368475db2e80f00ee48cc216d0 100644 (file)
@@ -126,6 +126,7 @@ struct mds_ctx {
        int snum;
        const char *sharename;
        const char *spath;
+       struct connection_struct *conn;
        struct sl_query *query_list;     /* list of active queries */
        struct db_context *ino_path_map; /* dbwrap rbt for storing inode->path mappings */
 };