s3: VFS: Modify mkdir to take a const struct smb_filename * instead of const char *
[samba.git] / source3 / modules / vfs_media_harmony.c
index 0bc14d9..594db83 100644 (file)
@@ -93,7 +93,6 @@
 #define MH_INFO_DEBUG 10
 #define MH_ERR_DEBUG 0
 
-static const char* MH_MODULE_NAME = "media_harmony";
 static const char* MDB_FILENAME = "msmMMOB.mdb";
 static const size_t MDB_FILENAME_LEN = 11;
 static const char* PMR_FILENAME = "msmFMID.pmr";
@@ -132,11 +131,11 @@ typedef struct mh_dirinfo_struct
 static int alloc_append_client_suffix(vfs_handle_struct *handle,
                char **path)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with *path '%s'\n", *path));
-
        int status = 0;
        char *raddr = NULL;
 
+       DEBUG(MH_INFO_DEBUG, ("Entering with *path '%s'\n", *path));
+
        raddr = tsocket_address_inet_addr_string(
                        handle->conn->sconn->remote_address, talloc_tos());
        if (raddr == NULL)
@@ -172,10 +171,10 @@ err:
  */
 static bool is_apple_double(const char* fname)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n", fname));
-
        bool ret = False;
 
+       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n", fname));
+
        if (strncmp(APPLE_DOUBLE_PREFIX, fname, APPLE_DOUBLE_PREFIX_LEN)
                        == 0)
        {
@@ -189,11 +188,11 @@ static bool is_apple_double(const char* fname)
 static bool starts_with_media_dir(const char* media_dirname,
                size_t media_dirname_len, const char* path)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with media_dirname '%s' "
-                               "path '%s'\n", media_dirname, path));
-
        bool ret = False;
-       char* path_start;
+       const char *path_start;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with media_dirname '%s' "
+                             "path '%s'\n", media_dirname, path));
 
        /* Sometimes Samba gives us "./OMFI MediaFiles". */
        if (strncmp(path, "./", 2) == 0)
@@ -230,10 +229,10 @@ static bool starts_with_media_dir(const char* media_dirname,
  */
 static bool is_in_media_files(const char* path)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
-
        bool ret = False;
 
+       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
+
        if (
                starts_with_media_dir(AVID_MEDIAFILES_DIRNAME,
                                AVID_MEDIAFILES_DIRNAME_LEN, path)
@@ -264,11 +263,12 @@ static bool is_in_media_files(const char* path)
 static int depth_from_media_dir(const char* media_dirname,
                size_t media_dirname_len, const char* path)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with media_dirname '%s' "
-                               "path '%s'\n", media_dirname, path));
        int transition_count = 0;
-       char* path_start;
-       char* pathPtr;
+       const char *path_start;
+       const char *pathPtr;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with media_dirname '%s' "
+                             "path '%s'\n", media_dirname, path));
 
        /* Sometimes Samba gives us "./OMFI MediaFiles". */
        if (strncmp(path, "./", 2) == 0)
@@ -336,15 +336,15 @@ static bool is_avid_database(
                const char *avid_db_filename,
                const size_t avid_db_filename_len)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s', "
-                               "avid_db_filename '%s', "
-                               "path_len '%i', "
-                               "avid_db_filename_len '%i'\n",
-                               path, avid_db_filename,
-                               path_len, avid_db_filename_len));
-
        bool ret = False;
 
+       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s', "
+                             "avid_db_filename '%s', "
+                             "path_len '%i', "
+                             "avid_db_filename_len '%i'\n",
+                             path, avid_db_filename,
+                             (int)path_len, (int)avid_db_filename_len));
+
        if (
                path_len > avid_db_filename_len
                        &&
@@ -354,7 +354,7 @@ static bool is_avid_database(
                (
                        path[path_len - avid_db_filename_len - 1] == '/'
                        ||
-                       path_len > avid_db_filename_len
+                       (path_len > avid_db_filename_len
                                + APPLE_DOUBLE_PREFIX_LEN
                                &&
                        path[path_len - avid_db_filename_len
@@ -362,7 +362,7 @@ static bool is_avid_database(
                                &&
                        is_apple_double(&path[path_len
                                - avid_db_filename_len
-                               - APPLE_DOUBLE_PREFIX_LEN])
+                               - APPLE_DOUBLE_PREFIX_LEN]))
                )
        )
        {
@@ -387,14 +387,16 @@ static int alloc_get_client_path(vfs_handle_struct *handle,
                const char *path,
                char **newPath)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
-
        /* replace /CREATING_DIRNAME/ or /._CREATING_DIRNAME/
         * directory in path - potentially in middle of path
         * - with suffixed name.
         */
        int status = 0;
        char* pathPtr;
+       size_t intermPathLen;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
+
        *newPath = talloc_strdup(ctx, path);
        if (*newPath == NULL)
        {
@@ -414,15 +416,15 @@ static int alloc_get_client_path(vfs_handle_struct *handle,
                )
                        &&
                (
-                       pathPtr - path > 0
+                       (pathPtr - path > 0
                                &&
-                       *(pathPtr - 1) == '/'
+                        *(pathPtr - 1) == '/')
                        ||
-                       pathPtr - path > APPLE_DOUBLE_PREFIX_LEN
+                       (pathPtr - path > APPLE_DOUBLE_PREFIX_LEN
                                &&
                        *(pathPtr - APPLE_DOUBLE_PREFIX_LEN - 1) == '/'
                                &&
-                       is_apple_double(pathPtr - APPLE_DOUBLE_PREFIX_LEN)
+                        is_apple_double(pathPtr - APPLE_DOUBLE_PREFIX_LEN))
                )
        )
        {
@@ -430,7 +432,7 @@ static int alloc_get_client_path(vfs_handle_struct *handle,
                (*newPath)[pathPtr - path + CREATING_DIRNAME_LEN] = '\0';
                DEBUG(MH_INFO_DEBUG, ("newPath #2 %s\n", *newPath));
 
-               if (status = alloc_append_client_suffix(handle, newPath))
+               if ((status = alloc_append_client_suffix(handle, newPath)))
                {
                        goto out;
                }
@@ -452,7 +454,7 @@ static int alloc_get_client_path(vfs_handle_struct *handle,
        /* replace /MDB_FILENAME or /PMR_FILENAME or /._MDB_FILENAME
         * or /._PMR_FILENAME at newPath end with suffixed name.
         */
-       size_t intermPathLen = strlen(*newPath);
+       intermPathLen = strlen(*newPath);
        if (
                is_avid_database(*newPath, intermPathLen,
                        MDB_FILENAME, MDB_FILENAME_LEN)
@@ -462,7 +464,7 @@ static int alloc_get_client_path(vfs_handle_struct *handle,
        )
        {
                DEBUG(MH_INFO_DEBUG, ("newPath #5 %s\n", *newPath));
-               if (status = alloc_append_client_suffix(handle, newPath))
+               if ((status = alloc_append_client_suffix(handle, newPath)))
                {
                        goto out;
                }
@@ -483,24 +485,22 @@ static int alloc_get_client_smb_fname(struct vfs_handle_struct *handle,
                const struct smb_filename *smb_fname,
                struct smb_filename **clientFname)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
-                               smb_fname->base_name));
-
        int status = 0;
-       NTSTATUS copystatus;
 
-       copystatus = copy_smb_filename(ctx, smb_fname, clientFname);
-       if (!NT_STATUS_IS_OK(copystatus))
-       {
+       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
+                             smb_fname->base_name));
+
+       *clientFname = cp_smb_filename(ctx, smb_fname);
+       if ((*clientFname) == NULL) {
                DEBUG(MH_ERR_DEBUG, ("alloc_get_client_smb_fname "
                                        "NTERR\n"));
-               errno = map_errno_from_nt_status(copystatus);
+               errno = ENOMEM;
                status = -1;
                goto err;
        }
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                smb_fname->base_name,
-                               &(*clientFname)->base_name))
+                               &(*clientFname)->base_name)))
        {
                goto err;
        }
@@ -520,11 +520,11 @@ static int alloc_set_client_dirinfo_path(struct vfs_handle_struct *handle,
                char **path,
                const char *avid_db_filename)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with avid_db_filename '%s'\n",
-                               avid_db_filename));
-
        int status = 0;
 
+       DEBUG(MH_INFO_DEBUG, ("Entering with avid_db_filename '%s'\n",
+                             avid_db_filename));
+
        if ((*path = talloc_strdup(ctx, avid_db_filename)) == NULL)
        {
                DEBUG(MH_ERR_DEBUG, ("alloc_set_client_dirinfo_path "
@@ -533,7 +533,7 @@ static int alloc_set_client_dirinfo_path(struct vfs_handle_struct *handle,
                status = -1;
                goto err;
        }
-       if (status = alloc_append_client_suffix(handle, path))
+       if ((status = alloc_append_client_suffix(handle, path)))
        {
                goto err;
        }
@@ -554,12 +554,15 @@ static int set_fake_mtime(vfs_handle_struct *handle,
                struct smb_filename **clientFname,
                int (*statFn)(const char *, SMB_STRUCT_STAT *, bool))
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with (*clientFname)->base_name "
-                       "'%s', (*clientFname)->st.st_ex_mtime %s",
-                       (*clientFname)->base_name,
-                       ctime(&((*clientFname)->st.st_ex_mtime.tv_sec))));
-
        int status = 0;
+       char *statPath;
+       SMB_STRUCT_STAT fakeStat;
+       int copy_len;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with (*clientFname)->base_name "
+                             "'%s', (*clientFname)->st.st_ex_mtime %s",
+                             (*clientFname)->base_name,
+                             ctime(&((*clientFname)->st.st_ex_mtime.tv_sec))));
 
        if (
                depth_from_media_dir(AVID_MXF_DIRNAME,
@@ -576,9 +579,7 @@ static int set_fake_mtime(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *statPath;
-       SMB_STRUCT_STAT fakeStat;
-       int copy_len = strlen((*clientFname)->base_name);
+       copy_len = strlen((*clientFname)->base_name);
 
        /* Hack to deal with occasional "Avid MediaFiles/MXF/1/." paths.
         * We know we're under a media dir, so paths are at least 2 chars
@@ -590,21 +591,21 @@ static int set_fake_mtime(vfs_handle_struct *handle,
                copy_len -= 2;
        }
 
-       if ((statPath = talloc_strndup(ctx,
-                       (*clientFname)->base_name, copy_len)) == NULL)
+       if (((statPath = talloc_strndup(ctx,
+                       (*clientFname)->base_name, copy_len)) == NULL))
        {
                errno = ENOMEM;
                status = -1;
                goto err;
        }
-       if (status = alloc_append_client_suffix(handle, &statPath))
+       if ((status = alloc_append_client_suffix(handle, &statPath)))
        {
                goto err;
        }
 
        DEBUG(MH_INFO_DEBUG, ("Fake stat'ing '%s'\n", statPath));
        if (statFn(statPath, &fakeStat,
-                       lp_fake_dir_create_times(SNUM(handle->conn))))
+                       lp_fake_directory_create_times(SNUM(handle->conn))))
        {
                /* This can fail for legitimate reasons - i.e. the
                 * fakeStat directory doesn't exist, which is okay
@@ -634,9 +635,11 @@ static int mh_statvfs(struct vfs_handle_struct *handle,
                const char *path,
                struct vfs_statvfs_struct *statbuf)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
-
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
 
        if (!is_in_media_files(path))
        {
@@ -644,12 +647,12 @@ static int mh_statvfs(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -666,9 +669,11 @@ static int alloc_set_client_dirinfo(vfs_handle_struct *handle,
                const char *fname,
                struct mh_dirinfo_struct **dirInfo)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n", fname));
-
        int status = 0;
+       char *clientPath;
+       TALLOC_CTX *ctx;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n", fname));
 
        *dirInfo = talloc(NULL, struct mh_dirinfo_struct);
        if (*dirInfo == NULL)
@@ -718,8 +723,8 @@ static int alloc_set_client_dirinfo(vfs_handle_struct *handle,
                goto err;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
        if (alloc_get_client_path(handle, ctx,
                                fname,
@@ -757,12 +762,12 @@ err:
 static DIR *mh_opendir(vfs_handle_struct *handle,
                const char *fname,
                const char *mask,
-               uint32 attr)
+               uint32_t attr)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n", fname));
-
        struct mh_dirinfo_struct *dirInfo;
 
+       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n", fname));
+
        if (alloc_set_client_dirinfo(handle, fname, &dirInfo))
        {
                goto err;
@@ -781,7 +786,6 @@ static DIR *mh_opendir(vfs_handle_struct *handle,
                goto err;
        }
 
-out:
        /* Success is freed in closedir. */
        DEBUG(MH_INFO_DEBUG, ("Leaving with dirInfo->dirpath '%s', "
                                "dirInfo->clientPath '%s'\n",
@@ -798,14 +802,14 @@ err:
 static DIR *mh_fdopendir(vfs_handle_struct *handle,
                files_struct *fsp,
                const char *mask,
-               uint32 attr)
+               uint32_t attr)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with fsp->fsp_name->base_name '%s'\n",
-                       fsp->fsp_name->base_name));
-
-       struct mh_dirinfo_struct *dirInfo;
+       struct mh_dirinfo_struct *dirInfo = NULL;
        DIR *dirstream;
 
+       DEBUG(MH_INFO_DEBUG, ("Entering with fsp->fsp_name->base_name '%s'\n",
+                             fsp->fsp_name->base_name));
+
        dirstream = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
        if (!dirstream)
        {
@@ -861,24 +865,24 @@ static struct dirent *mh_readdir(vfs_handle_struct *handle,
                DIR *dirp,
                SMB_STRUCT_STAT *sbuf)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering mh_readdir\n"));
-
        mh_dirinfo_struct* dirInfo = (mh_dirinfo_struct*)dirp;
+       struct dirent *d = NULL;
+       int skip;
 
-       DEBUG(MH_INFO_DEBUG, ("dirInfo->dirpath '%s', "
-                               "dirInfo->clientPath '%s', "
-                               "dirInfo->isInMediaFiles '%s', "
-                               "dirInfo->clientMDBFilename '%s', "
-                               "dirInfo->clientPMRFilename '%s', "
-                               "dirInfo->clientCreatingDirname '%s'\n",
-                               dirInfo->dirpath,
-                               dirInfo->clientPath,
-                               dirInfo->isInMediaFiles ? "True" : "False",
-                               dirInfo->clientMDBFilename,
-                               dirInfo->clientPMRFilename,
-                               dirInfo->clientCreatingDirname));
+       DEBUG(MH_INFO_DEBUG, ("Entering mh_readdir\n"));
 
-       struct dirent *d = NULL;
+       DEBUG(MH_INFO_DEBUG, ("dirInfo->dirpath '%s', "
+                             "dirInfo->clientPath '%s', "
+                             "dirInfo->isInMediaFiles '%s', "
+                             "dirInfo->clientMDBFilename '%s', "
+                             "dirInfo->clientPMRFilename '%s', "
+                             "dirInfo->clientCreatingDirname '%s'\n",
+                             dirInfo->dirpath,
+                             dirInfo->clientPath,
+                             dirInfo->isInMediaFiles ? "True" : "False",
+                             dirInfo->clientMDBFilename,
+                             dirInfo->clientPMRFilename,
+                             dirInfo->clientCreatingDirname));
 
        if (! dirInfo->isInMediaFiles)
        {
@@ -886,9 +890,11 @@ static struct dirent *mh_readdir(vfs_handle_struct *handle,
                goto out;
        }
 
-       int skip;
        do
        {
+               const char* dname;
+               bool isAppleDouble;
+
                skip = False;
                d = SMB_VFS_NEXT_READDIR(handle, dirInfo->dirstream, sbuf);
 
@@ -897,9 +903,6 @@ static struct dirent *mh_readdir(vfs_handle_struct *handle,
                        break;
                }
 
-               const char* dname;
-               bool isAppleDouble;
-
                /* ignore apple double prefix for logic below */
                if (is_apple_double(d->d_name))
                {
@@ -999,7 +1002,6 @@ static void mh_seekdir(vfs_handle_struct *handle,
        DEBUG(MH_INFO_DEBUG, ("Entering and leaving mh_seekdir\n"));
        SMB_VFS_NEXT_SEEKDIR(handle,
                        ((mh_dirinfo_struct*)dirp)->dirstream, offset);
-       return;
 }
 
 /*
@@ -1024,7 +1026,6 @@ static void mh_rewinddir(vfs_handle_struct *handle,
        DEBUG(MH_INFO_DEBUG, ("Entering and leaving mh_rewinddir\n"));
        SMB_VFS_NEXT_REWINDDIR(handle,
                        ((mh_dirinfo_struct*)dirp)->dirstream);
-       return;
 }
 
 /*
@@ -1032,32 +1033,32 @@ static void mh_rewinddir(vfs_handle_struct *handle,
  * Failure: set errno, return -1
  */
 static int mh_mkdir(vfs_handle_struct *handle,
-               const char *path,
+               const struct smb_filename *smb_fname,
                mode_t mode)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
-
        int status;
+       struct smb_filename *clientFname = NULL;
+       const char *path = smb_fname->base_name;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
 
        if (!is_in_media_files(path))
        {
-               status = SMB_VFS_NEXT_MKDIR(handle, path, mode);
+               status = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
-
-       if (status = alloc_get_client_path(handle, ctx,
-                               path,
-                               &clientPath))
-       {
+       status = alloc_get_client_smb_fname(handle,
+                               talloc_tos(),
+                               smb_fname,
+                               &clientFname);
+       if (status != 0) {
                goto err;
        }
 
-       status = SMB_VFS_NEXT_MKDIR(handle, clientPath, mode);
+       status = SMB_VFS_NEXT_MKDIR(handle, clientFname, mode);
 err:
-       TALLOC_FREE(clientPath);
+       TALLOC_FREE(clientFname);
 out:
        DEBUG(MH_INFO_DEBUG, ("Leaving with path '%s'\n", path));
        return status;
@@ -1070,9 +1071,12 @@ out:
 static int mh_rmdir(vfs_handle_struct *handle,
                const char *path)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
-
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
+
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with path '%s'\n", path));
 
        if (!is_in_media_files(path))
        {
@@ -1080,12 +1084,12 @@ static int mh_rmdir(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1105,8 +1109,9 @@ out:
 static int mh_closedir(vfs_handle_struct *handle,
                DIR *dirp)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering mh_closedir\n"));
        DIR *realdirp = ((mh_dirinfo_struct*)dirp)->dirstream;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering mh_closedir\n"));
        // Will this talloc_free destroy realdirp?
        TALLOC_FREE(dirp);
 
@@ -1124,7 +1129,6 @@ static void mh_init_search_op(vfs_handle_struct *handle,
        DEBUG(MH_INFO_DEBUG, ("Entering and leaving mh_init_search_op\n"));
        SMB_VFS_NEXT_INIT_SEARCH_OP(handle,
                        ((mh_dirinfo_struct*)dirp)->dirstream);
-       return;
 }
 
 /*
@@ -1137,10 +1141,13 @@ static int mh_open(vfs_handle_struct *handle,
                int flags,
                mode_t mode)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
-                               smb_fname->base_name));
-
        int ret;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
+
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
+                             smb_fname->base_name));
 
        if (!is_in_media_files(smb_fname->base_name))
        {
@@ -1149,8 +1156,8 @@ static int mh_open(vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
        if(alloc_get_client_smb_fname(handle, ctx,
                                smb_fname,
@@ -1194,14 +1201,20 @@ static NTSTATUS mh_create_file(vfs_handle_struct *handle,
                uint32_t create_options,
                uint32_t file_attributes,
                uint32_t oplock_request,
+               struct smb2_lease *lease,
                uint64_t allocation_size,
                uint32_t private_flags,
                struct security_descriptor *sd,
                struct ea_list *ea_list,
                files_struct **result_fsp,
-               int *pinfo)
+               int *pinfo,
+               const struct smb2_create_blobs *in_context_blobs,
+               struct smb2_create_blobs *out_context_blobs)
 {
        NTSTATUS status;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
+
 
        DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
                                smb_fname->base_name));
@@ -1218,17 +1231,20 @@ static NTSTATUS mh_create_file(vfs_handle_struct *handle,
                        create_options,
                        file_attributes,
                        oplock_request,
+                       lease,
                        allocation_size,
                        private_flags,
                        sd,
                        ea_list,
                        result_fsp,
-                       pinfo);
+                       pinfo,
+                       in_context_blobs,
+                       out_context_blobs);
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
        if (alloc_get_client_smb_fname(handle, ctx,
                                smb_fname,
@@ -1254,12 +1270,15 @@ static NTSTATUS mh_create_file(vfs_handle_struct *handle,
                create_options,
                file_attributes,
                oplock_request,
+               lease,
                allocation_size,
                private_flags,
                sd,
                ea_list,
                result_fsp,
-               pinfo);
+               pinfo,
+               in_context_blobs,
+               out_context_blobs);
 err:
        TALLOC_FREE(clientFname);
 out:
@@ -1282,13 +1301,17 @@ static int mh_rename(vfs_handle_struct *handle,
                const struct smb_filename *smb_fname_src,
                const struct smb_filename *smb_fname_dst)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with "
-                               "smb_fname_src->base_name '%s', "
-                               "smb_fname_dst->base_name '%s'\n",
-                               smb_fname_src->base_name,
-                               smb_fname_dst->base_name));
-
        int status;
+       struct smb_filename *srcClientFname;
+       struct smb_filename *dstClientFname;
+       TALLOC_CTX *ctx;
+
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with "
+                             "smb_fname_src->base_name '%s', "
+                             "smb_fname_dst->base_name '%s'\n",
+                             smb_fname_src->base_name,
+                             smb_fname_dst->base_name));
 
        if (!is_in_media_files(smb_fname_src->base_name)
                                &&
@@ -1299,20 +1322,20 @@ static int mh_rename(vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *srcClientFname = NULL;
-       struct smb_filename *dstClientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       srcClientFname = NULL;
+       dstClientFname = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_smb_fname(handle, ctx,
+       if ((status = alloc_get_client_smb_fname(handle, ctx,
                                smb_fname_src,
-                               &srcClientFname))
+                               &srcClientFname)))
        {
                goto err;
        }
 
-       if (status = alloc_get_client_smb_fname(handle, ctx,
+       if ((status = alloc_get_client_smb_fname(handle, ctx,
                                smb_fname_dst,
-                               &dstClientFname))
+                               &dstClientFname)))
        {
                goto err;
        }
@@ -1337,10 +1360,13 @@ out:
 static int mh_stat(vfs_handle_struct *handle,
                struct smb_filename *smb_fname)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
-                               smb_fname->base_name));
-
        int status = 0;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
+
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
+                             smb_fname->base_name));
 
        if (!is_in_media_files(smb_fname->base_name))
        {
@@ -1348,22 +1374,22 @@ static int mh_stat(vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_smb_fname(handle, ctx,
+       if ((status = alloc_get_client_smb_fname(handle, ctx,
                                smb_fname,
-                               &clientFname))
+                               &clientFname)))
        {
                goto err;
        }
        DEBUG(MH_INFO_DEBUG, ("Stat'ing clientFname->base_name '%s'\n",
                                clientFname->base_name));
-       if (status = SMB_VFS_NEXT_STAT(handle, clientFname))
+       if ((status = SMB_VFS_NEXT_STAT(handle, clientFname)))
        {
                goto err;
        }
-       if (status = set_fake_mtime(handle, ctx, &clientFname, sys_stat))
+       if ((status = set_fake_mtime(handle, ctx, &clientFname, sys_stat)))
        {
                goto err;
        }
@@ -1391,10 +1417,12 @@ out:
 static int mh_lstat(vfs_handle_struct *handle,
                struct smb_filename *smb_fname)
 {
-       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
-                               smb_fname->base_name));
-
        int status = 0;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
+
+       DEBUG(MH_INFO_DEBUG, ("Entering with smb_fname->base_name '%s'\n",
+                             smb_fname->base_name));
 
        if (!is_in_media_files(smb_fname->base_name))
        {
@@ -1402,21 +1430,21 @@ static int mh_lstat(vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_smb_fname(handle, ctx,
+       if ((status = alloc_get_client_smb_fname(handle, ctx,
                                smb_fname,
-                               &clientFname))
+                               &clientFname)))
        {
                goto err;
        }
-       if (status = SMB_VFS_NEXT_LSTAT(handle, clientFname))
+       if ((status = SMB_VFS_NEXT_LSTAT(handle, clientFname)))
        {
                goto err;
        }
 
-       if (status = set_fake_mtime(handle, ctx, &clientFname, sys_lstat))
+       if ((status = set_fake_mtime(handle, ctx, &clientFname, sys_lstat)))
        {
                goto err;
        }
@@ -1439,12 +1467,12 @@ out:
 static int mh_fstat(vfs_handle_struct *handle,
                files_struct *fsp, SMB_STRUCT_STAT *sbuf)
 {
+       int status = 0;
+
        DEBUG(MH_INFO_DEBUG, ("Entering with fsp->fsp_name->base_name "
                                "'%s'\n", fsp_str_dbg(fsp)));
 
-       int status = 0;
-
-       if (status = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf))
+       if ((status = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf)))
        {
                goto out;
        }
@@ -1455,7 +1483,7 @@ static int mh_fstat(vfs_handle_struct *handle,
                goto out;
        }
 
-       if (status = mh_stat(handle, fsp->fsp_name))
+       if ((status = mh_stat(handle, fsp->fsp_name)))
        {
                goto out;
        }
@@ -1464,7 +1492,9 @@ static int mh_fstat(vfs_handle_struct *handle,
 out:
        DEBUG(MH_INFO_DEBUG, ("Leaving with fsp->fsp_name->st.st_ex_mtime "
                        "%s",
-                       ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec))));
+                       fsp->fsp_name != NULL ?
+                               ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec)) :
+                               "0"));
        return status;
 }
 
@@ -1476,6 +1506,8 @@ static int mh_unlink(vfs_handle_struct *handle,
                const struct smb_filename *smb_fname)
 {
        int status;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_unlink\n"));
        if (!is_in_media_files(smb_fname->base_name))
@@ -1484,12 +1516,12 @@ static int mh_unlink(vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_smb_fname(handle, ctx,
+       if ((status = alloc_get_client_smb_fname(handle, ctx,
                                smb_fname,
-                               &clientFname))
+                               &clientFname)))
        {
                goto err;
        }
@@ -1510,6 +1542,8 @@ static int mh_chmod(vfs_handle_struct *handle,
                mode_t mode)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_chmod\n"));
        if (!is_in_media_files(path))
@@ -1518,12 +1552,12 @@ static int mh_chmod(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1545,6 +1579,8 @@ static int mh_chown(vfs_handle_struct *handle,
                gid_t gid)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_chown\n"));
        if (!is_in_media_files(path))
@@ -1553,12 +1589,12 @@ static int mh_chown(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1580,6 +1616,8 @@ static int mh_lchown(vfs_handle_struct *handle,
                gid_t gid)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_lchown\n"));
        if (!is_in_media_files(path))
@@ -1588,12 +1626,12 @@ static int mh_lchown(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1613,6 +1651,8 @@ static int mh_chdir(vfs_handle_struct *handle,
                const char *path)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_chdir\n"));
        if (!is_in_media_files(path))
@@ -1621,12 +1661,12 @@ static int mh_chdir(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1647,6 +1687,9 @@ static int mh_ntimes(vfs_handle_struct *handle,
                struct smb_file_time *ft)
 {
        int status;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
+
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_ntimes\n"));
        if (!is_in_media_files(smb_fname->base_name))
@@ -1655,12 +1698,12 @@ static int mh_ntimes(vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_smb_fname(handle, ctx,
+       if ((status = alloc_get_client_smb_fname(handle, ctx,
                                smb_fname,
-                               &clientFname))
+                               &clientFname)))
        {
                goto err;
        }
@@ -1681,6 +1724,9 @@ static int mh_symlink(vfs_handle_struct *handle,
                const char *newpath)
 {
        int status;
+       char *oldClientPath;
+       char *newClientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_symlink\n"));
        if (!is_in_media_files(oldpath) && !is_in_media_files(newpath))
@@ -1689,20 +1735,20 @@ static int mh_symlink(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *oldClientPath = NULL;
-       char *newClientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       oldClientPath = NULL;
+       newClientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                oldpath,
-                               &oldClientPath))
+                               &oldClientPath)))
        {
                goto err;
        }
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                newpath,
-                               &newClientPath))
+                               &newClientPath)))
        {
                goto err;
        }
@@ -1728,6 +1774,8 @@ static int mh_readlink(vfs_handle_struct *handle,
                size_t bufsiz)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_readlink\n"));
        if (!is_in_media_files(path))
@@ -1736,12 +1784,12 @@ static int mh_readlink(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1762,6 +1810,9 @@ static int mh_link(vfs_handle_struct *handle,
                const char *newpath)
 {
        int status;
+       char *oldClientPath;
+       char *newClientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_link\n"));
        if (!is_in_media_files(oldpath) && !is_in_media_files(newpath))
@@ -1770,20 +1821,20 @@ static int mh_link(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *oldClientPath = NULL;
-       char *newClientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       oldClientPath = NULL;
+       newClientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                oldpath,
-                               &oldClientPath))
+                               &oldClientPath)))
        {
                goto err;
        }
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                newpath,
-                               &newClientPath))
+                               &newClientPath)))
        {
                goto err;
        }
@@ -1806,6 +1857,8 @@ static int mh_mknod(vfs_handle_struct *handle,
                SMB_DEV_T dev)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_mknod\n"));
        if (!is_in_media_files(pathname))
@@ -1814,12 +1867,12 @@ static int mh_mknod(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                pathname,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1839,6 +1892,8 @@ static char *mh_realpath(vfs_handle_struct *handle,
                const char *path)
 {
        char *buf;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_realpath\n"));
        if (!is_in_media_files(path))
@@ -1847,8 +1902,8 @@ static char *mh_realpath(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
        if (alloc_get_client_path(handle, ctx,
                                path,
@@ -1874,6 +1929,8 @@ static int mh_chflags(vfs_handle_struct *handle,
                unsigned int flags)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_chflags\n"));
        if (!is_in_media_files(path))
@@ -1882,12 +1939,12 @@ static int mh_chflags(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -1911,6 +1968,8 @@ static NTSTATUS mh_streaminfo(struct vfs_handle_struct *handle,
                struct stream_struct **streams)
 {
        NTSTATUS status;
+       char *clientPath;
+       TALLOC_CTX *mem_ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_streaminfo\n"));
        if (!is_in_media_files(fname))
@@ -1920,8 +1979,8 @@ static NTSTATUS mh_streaminfo(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *mem_ctx = talloc_tos();
+       clientPath = NULL;
+       mem_ctx = talloc_tos();
 
        if (alloc_get_client_path(handle, mem_ctx,
                                fname,
@@ -1954,35 +2013,51 @@ out:
  * In this case, "name" is a path.
  */
 static NTSTATUS mh_get_nt_acl(vfs_handle_struct *handle,
-               const char *name,
-               uint32 security_info,
-               struct security_descriptor **ppdesc)
+                             const struct smb_filename *smb_fname,
+                             uint32_t security_info,
+                             TALLOC_CTX *mem_ctx,
+                             struct security_descriptor **ppdesc)
 {
        NTSTATUS status;
+       char *clientPath;
+       struct smb_filename *client_smb_fname = NULL;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_get_nt_acl\n"));
-       if (!is_in_media_files(name))
+       if (!is_in_media_files(smb_fname->base_name))
        {
-               status = SMB_VFS_NEXT_GET_NT_ACL(handle, name,
-                               security_info, ppdesc);
+               status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname,
+                                                security_info,
+                                                mem_ctx, ppdesc);
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
        if (alloc_get_client_path(handle, ctx,
-                               name,
+                               smb_fname->base_name,
                                &clientPath))
        {
                status = map_nt_error_from_unix(errno);
                goto err;
        }
 
-       status = SMB_VFS_NEXT_GET_NT_ACL(handle, clientPath,
-                       security_info, ppdesc);
+       client_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       clientPath,
+                                       NULL,
+                                       NULL);
+       if (client_smb_fname == NULL) {
+               TALLOC_FREE(clientPath);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = SMB_VFS_NEXT_GET_NT_ACL(handle, client_smb_fname,
+                                        security_info,
+                                        mem_ctx, ppdesc);
 err:
        TALLOC_FREE(clientPath);
+       TALLOC_FREE(client_smb_fname);
 out:
        return status;
 }
@@ -1996,6 +2071,8 @@ static int mh_chmod_acl(vfs_handle_struct *handle,
                mode_t mode)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_chmod_acl\n"));
        if (!is_in_media_files(path))
@@ -2004,12 +2081,12 @@ static int mh_chmod_acl(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -2026,20 +2103,23 @@ out:
  * Failure: set errno, return NULL
  */
 static SMB_ACL_T mh_sys_acl_get_file(vfs_handle_struct *handle,
-               const char *path_p,
-               SMB_ACL_TYPE_T type)
+                                    const char *path_p,
+                                    SMB_ACL_TYPE_T type,
+                                    TALLOC_CTX *mem_ctx)
 {
        SMB_ACL_T ret;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_sys_acl_get_file\n"));
        if (!is_in_media_files(path_p))
        {
-               ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
+               ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
        if (alloc_get_client_path(handle, ctx,
                                path_p,
@@ -2049,7 +2129,7 @@ static SMB_ACL_T mh_sys_acl_get_file(vfs_handle_struct *handle,
                goto err;
        }
 
-       ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, clientPath, type);
+       ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, clientPath, type, mem_ctx);
 err:
        TALLOC_FREE(clientPath);
 out:
@@ -2067,6 +2147,8 @@ static int mh_sys_acl_set_file(vfs_handle_struct *handle,
                SMB_ACL_T theacl)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_sys_acl_set_file\n"));
        if (!is_in_media_files(name))
@@ -2076,12 +2158,12 @@ static int mh_sys_acl_set_file(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                name,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -2102,6 +2184,8 @@ static int mh_sys_acl_delete_def_file(vfs_handle_struct *handle,
                const char *path)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_sys_acl_delete_def_file\n"));
        if (!is_in_media_files(path))
@@ -2111,12 +2195,12 @@ static int mh_sys_acl_delete_def_file(vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -2140,6 +2224,8 @@ static ssize_t mh_getxattr(struct vfs_handle_struct *handle,
                size_t size)
 {
        ssize_t ret;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_getxattr\n"));
        if (!is_in_media_files(path))
@@ -2149,8 +2235,8 @@ static ssize_t mh_getxattr(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
        if (alloc_get_client_path(handle, ctx,
                                path,
@@ -2177,6 +2263,8 @@ static ssize_t mh_listxattr(struct vfs_handle_struct *handle,
                size_t size)
 {
        ssize_t ret;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_listxattr\n"));
        if (!is_in_media_files(path))
@@ -2185,8 +2273,8 @@ static ssize_t mh_listxattr(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
        if (alloc_get_client_path(handle, ctx,
                                path,
@@ -2213,6 +2301,8 @@ static int mh_removexattr(struct vfs_handle_struct *handle,
                const char *name)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_removexattr\n"));
        if (!is_in_media_files(path))
@@ -2221,12 +2311,12 @@ static int mh_removexattr(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -2251,6 +2341,8 @@ static int mh_setxattr(struct vfs_handle_struct *handle,
                int flags)
 {
        int status;
+       char *clientPath;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_setxattr\n"));
        if (!is_in_media_files(path))
@@ -2260,12 +2352,12 @@ static int mh_setxattr(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       char *clientPath = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientPath = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_path(handle, ctx,
+       if ((status = alloc_get_client_path(handle, ctx,
                                path,
-                               &clientPath))
+                               &clientPath)))
        {
                goto err;
        }
@@ -2288,6 +2380,8 @@ static bool mh_is_offline(struct vfs_handle_struct *handle,
 {
        // check if sbuf is modified further down the chain.
        bool ret;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_is_offline\n"));
        if (!is_in_media_files(fname->base_name))
@@ -2296,8 +2390,8 @@ static bool mh_is_offline(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
        if(alloc_get_client_smb_fname(handle, ctx,
                                fname,
@@ -2322,6 +2416,8 @@ static int mh_set_offline(struct vfs_handle_struct *handle,
                const struct smb_filename *fname)
 {
        int status;
+       struct smb_filename *clientFname;
+       TALLOC_CTX *ctx;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_set_offline\n"));
        if (!is_in_media_files(fname->base_name))
@@ -2330,12 +2426,12 @@ static int mh_set_offline(struct vfs_handle_struct *handle,
                goto out;
        }
 
-       struct smb_filename *clientFname = NULL;
-       TALLOC_CTX *ctx = talloc_tos();
+       clientFname = NULL;
+       ctx = talloc_tos();
 
-       if (status = alloc_get_client_smb_fname(handle, ctx,
+       if ((status = alloc_get_client_smb_fname(handle, ctx,
                                fname,
-                               &clientFname))
+                               &clientFname)))
        {
                goto err;
        }