build: Remove SMB_STRUCT_DIR define
[gd/samba-autobuild/.git] / source3 / smbd / vfs.c
index 2ce61eed30ccbabcf9a2b004c371088fc22d376c..33f270170432b9a204a0ee1c1aaa945dc3294b29 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
 #include "smbd/globals.h"
+#include "memcache.h"
+#include "transfer_file.h"
+#include "ntioctl.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
@@ -111,7 +116,8 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
        const struct vfs_init_function_entry *entry;
 
        if (!conn||!vfs_object||!vfs_object[0]) {
-               DEBUG(0,("vfs_init_custon() called with NULL pointer or emtpy vfs_object!\n"));
+               DEBUG(0, ("vfs_init_custom() called with NULL pointer or "
+                         "empty vfs_object!\n"));
                return False;
        }
 
@@ -161,7 +167,7 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
                DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
                          vfs_object));
 
-               status = smb_probe_module("vfs", module_path);
+               status = smb_load_module("vfs", module_path);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("error probing vfs module '%s': %s\n",
                                  module_path, nt_errstr(status)));
@@ -177,7 +183,7 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
 
        DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
 
-       handle = TALLOC_ZERO_P(conn, vfs_handle_struct);
+       handle = talloc_zero(conn, vfs_handle_struct);
        if (!handle) {
                DEBUG(0,("TALLOC_ZERO() failed!\n"));
                goto fail;
@@ -392,7 +398,7 @@ ssize_t vfs_write_data(struct smb_request *req,
                /* VFS_RECVFILE must drain the socket
                 * before returning. */
                req->unread_bytes = 0;
-               return SMB_VFS_RECVFILE(smbd_server_fd(),
+               return SMB_VFS_RECVFILE(req->sconn->sock,
                                        fsp,
                                        (SMB_OFF_T)-1,
                                        N);
@@ -425,7 +431,7 @@ ssize_t vfs_pwrite_data(struct smb_request *req,
                /* VFS_RECVFILE must drain the socket
                 * before returning. */
                req->unread_bytes = 0;
-               return SMB_VFS_RECVFILE(smbd_server_fd(),
+               return SMB_VFS_RECVFILE(req->sconn->sock,
                                        fsp,
                                        offset,
                                        N);
@@ -453,10 +459,10 @@ ssize_t vfs_pwrite_data(struct smb_request *req,
 int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
 {
        int ret;
-       SMB_STRUCT_STAT st;
        connection_struct *conn = fsp->conn;
        uint64_t space_avail;
        uint64_t bsize,dfree,dsize;
+       NTSTATUS status;
 
        /*
         * Actually try and commit the space on disk....
@@ -472,19 +478,20 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
                return -1;
        }
 
-       ret = SMB_VFS_FSTAT(fsp, &st);
-       if (ret == -1)
-               return ret;
+       status = vfs_stat_fsp(fsp);
+       if (!NT_STATUS_IS_OK(status)) {
+               return -1;
+       }
 
-       if (len == (uint64_t)st.st_ex_size)
+       if (len == (uint64_t)fsp->fsp_name->st.st_ex_size)
                return 0;
 
-       if (len < (uint64_t)st.st_ex_size) {
+       if (len < (uint64_t)fsp->fsp_name->st.st_ex_size) {
                /* Shrink - use ftruncate. */
 
                DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current "
                          "size %.0f\n", fsp_str_dbg(fsp),
-                         (double)st.st_ex_size));
+                         (double)fsp->fsp_name->st.st_ex_size));
 
                contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
 
@@ -498,15 +505,26 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
                return ret;
        }
 
+       if (!lp_strict_allocate(SNUM(fsp->conn)))
+               return 0;
+
        /* Grow - we need to test if we have enough space. */
 
        contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
+
+       /* See if we have a syscall that will allocate beyond end-of-file
+          without changing EOF. */
+       ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_KEEP_SIZE, 0, len);
+
        contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
 
-       if (!lp_strict_allocate(SNUM(fsp->conn)))
+       if (ret == 0) {
+               /* We changed the allocation size on disk, but not
+                  EOF - exactly as required. We're done ! */
                return 0;
+       }
 
-       len -= st.st_ex_size;
+       len -= fsp->fsp_name->st.st_ex_size;
        len /= 1024; /* Len is now number of 1k blocks needed. */
        space_avail = get_dfree_info(conn, fsp->fsp_name->base_name, false,
                                     &bsize, &dfree, &dsize);
@@ -516,7 +534,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
 
        DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, "
                  "needed blocks = %.0f, space avail = %.0f\n",
-                 fsp_str_dbg(fsp), (double)st.st_ex_size, (double)len,
+                 fsp_str_dbg(fsp), (double)fsp->fsp_name->st.st_ex_size, (double)len,
                  (double)space_avail));
 
        if (len > space_avail) {
@@ -555,6 +573,45 @@ int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len)
        return ret;
 }
 
+/****************************************************************************
+ A slow version of fallocate. Fallback code if SMB_VFS_FALLOCATE
+ fails. Needs to be outside of the default version of SMB_VFS_FALLOCATE
+ as this is also called from the default SMB_VFS_FTRUNCATE code.
+ Always extends the file size.
+ Returns 0 on success, errno on failure.
+****************************************************************************/
+
+#define SPARSE_BUF_WRITE_SIZE (32*1024)
+
+int vfs_slow_fallocate(files_struct *fsp, SMB_OFF_T offset, SMB_OFF_T len)
+{
+       ssize_t pwrite_ret;
+       size_t total = 0;
+
+       if (!sparse_buf) {
+               sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
+               if (!sparse_buf) {
+                       errno = ENOMEM;
+                       return ENOMEM;
+               }
+       }
+
+       while (total < len) {
+               size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (len - total));
+
+               pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
+               if (pwrite_ret == -1) {
+                       DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file "
+                                 "%s failed with error %s\n",
+                                 fsp_str_dbg(fsp), strerror(errno)));
+                       return errno;
+               }
+               total += pwrite_ret;
+       }
+
+       return 0;
+}
+
 /****************************************************************************
  A vfs fill sparse call.
  Writes zeros from the end of file to len, if len is greater than EOF.
@@ -562,71 +619,73 @@ int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len)
  Returns 0 on success, -1 on failure.
 ****************************************************************************/
 
-#define SPARSE_BUF_WRITE_SIZE (32*1024)
-
 int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len)
 {
        int ret;
-       SMB_STRUCT_STAT st;
+       NTSTATUS status;
        SMB_OFF_T offset;
-       size_t total;
        size_t num_to_write;
-       ssize_t pwrite_ret;
 
-       ret = SMB_VFS_FSTAT(fsp, &st);
-       if (ret == -1) {
-               return ret;
+       status = vfs_stat_fsp(fsp);
+       if (!NT_STATUS_IS_OK(status)) {
+               return -1;
+       }
+
+       if (len <= fsp->fsp_name->st.st_ex_size) {
+               return 0;
        }
 
-       if (len <= st.st_ex_size) {
+#ifdef S_ISFIFO
+       if (S_ISFIFO(fsp->fsp_name->st.st_ex_mode)) {
                return 0;
        }
+#endif
 
        DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to "
                  "len %.0f (%.0f bytes)\n", fsp_str_dbg(fsp),
-                 (double)st.st_ex_size, (double)len,
-                 (double)(len - st.st_ex_size)));
+                 (double)fsp->fsp_name->st.st_ex_size, (double)len,
+                 (double)(len - fsp->fsp_name->st.st_ex_size)));
 
        contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
 
        flush_write_cache(fsp, SIZECHANGE_FLUSH);
 
-       if (!sparse_buf) {
-               sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
-               if (!sparse_buf) {
-                       errno = ENOMEM;
+       offset = fsp->fsp_name->st.st_ex_size;
+       num_to_write = len - fsp->fsp_name->st.st_ex_size;
+
+       /* Only do this on non-stream file handles. */
+       if (fsp->base_fsp == NULL) {
+               /* for allocation try fallocate first. This can fail on some
+                * platforms e.g. when the filesystem doesn't support it and no
+                * emulation is being done by the libc (like on AIX with JFS1). In that
+                * case we do our own emulation. fallocate implementations can
+                * return ENOTSUP or EINVAL in cases like that. */
+               ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_EXTEND_SIZE,
+                               offset, num_to_write);
+               if (ret == ENOSPC) {
+                       errno = ENOSPC;
                        ret = -1;
                        goto out;
                }
-       }
-
-       offset = st.st_ex_size;
-       num_to_write = len - st.st_ex_size;
-       total = 0;
-
-       while (total < num_to_write) {
-               size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (num_to_write - total));
-
-               pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
-               if (pwrite_ret == -1) {
-                       DEBUG(10,("vfs_fill_sparse: SMB_VFS_PWRITE for file "
-                                 "%s failed with error %s\n",
-                                 fsp_str_dbg(fsp), strerror(errno)));
-                       ret = -1;
+               if (ret == 0) {
                        goto out;
                }
-               if (pwrite_ret == 0) {
-                       ret = 0;
-                       goto out;
-               }
-
-               total += pwrite_ret;
+               DEBUG(10,("vfs_fill_sparse: SMB_VFS_FALLOCATE failed with "
+                       "error %d. Falling back to slow manual allocation\n", ret));
        }
 
-       set_filelen_write_cache(fsp, len);
+       ret = vfs_slow_fallocate(fsp, offset, num_to_write);
+       if (ret != 0) {
+               errno = ret;
+               ret = -1;
+       }
 
-       ret = 0;
  out:
+
+       if (ret == 0) {
+               set_filelen_write_cache(fsp, len);
+       }
+
        contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_FILL_SPARSE);
        return ret;
 }
@@ -662,7 +721,7 @@ SMB_OFF_T vfs_transfer_file(files_struct *in, files_struct *out, SMB_OFF_T n)
 const char *vfs_readdirname(connection_struct *conn, void *p,
                            SMB_STRUCT_STAT *sbuf, char **talloced)
 {
-       SMB_STRUCT_DIRENT *ptr= NULL;
+       struct dirent *ptr= NULL;
        const char *dname;
        char *translated;
        NTSTATUS status;
@@ -736,7 +795,7 @@ int vfs_ChDir(connection_struct *conn, const char *path)
 
 char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
 {
-        char s[PATH_MAX+1];
+        char *current_dir = NULL;
        char *result = NULL;
        DATA_BLOB cache_value;
        struct file_id key;
@@ -744,8 +803,6 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
        struct smb_filename *smb_fname_full = NULL;
        NTSTATUS status;
 
-       *s = 0;
-
        if (!lp_getwd_cache()) {
                goto nocache;
        }
@@ -807,7 +864,8 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
         * systems, or the not quite so bad getwd.
         */
 
-       if (!SMB_VFS_GETWD(conn,s)) {
+       current_dir = SMB_VFS_GETWD(conn);
+       if (current_dir == NULL) {
                DEBUG(0, ("vfs_GetWd: SMB_VFS_GETWD call failed: %s\n",
                          strerror(errno)));
                goto out;
@@ -818,10 +876,11 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
 
                memcache_add(smbd_memcache(), GETWD_CACHE,
                             data_blob_const(&key, sizeof(key)),
-                            data_blob_const(s, strlen(s)+1));
+                            data_blob_const(current_dir,
+                                               strlen(current_dir)+1));
        }
 
-       result = talloc_strdup(ctx, s);
+       result = talloc_strdup(ctx, current_dir);
        if (result == NULL) {
                errno = ENOMEM;
        }
@@ -829,9 +888,179 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
  out:
        TALLOC_FREE(smb_fname_dot);
        TALLOC_FREE(smb_fname_full);
+       SAFE_FREE(current_dir);
        return result;
 }
 
+/*******************************************************************
+ Reduce a file name, removing .. elements and checking that
+ it is below dir in the heirachy. This uses realpath.
+ This function must run as root, and will return names
+ and valid stat structs that can be checked on open.
+********************************************************************/
+
+NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
+                       const char *fname,
+                       struct smb_request *smbreq)
+{
+       NTSTATUS status;
+       TALLOC_CTX *ctx = talloc_tos();
+       const char *conn_rootdir;
+       size_t rootdir_len;
+       char *dir_name = NULL;
+       const char *last_component = NULL;
+       char *resolved_name = NULL;
+       char *saved_dir = NULL;
+       struct smb_filename *smb_fname_cwd = NULL;
+       struct privilege_paths *priv_paths = NULL;
+       int ret;
+
+       DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
+                       fname,
+                       conn->connectpath));
+
+
+       priv_paths = talloc_zero(smbreq, struct privilege_paths);
+       if (!priv_paths) {
+               status = NT_STATUS_NO_MEMORY;
+               goto err;
+       }
+
+       if (!parent_dirname(ctx, fname, &dir_name, &last_component)) {
+               status = NT_STATUS_NO_MEMORY;
+               goto err;
+       }
+
+       priv_paths->parent_name.base_name = talloc_strdup(priv_paths, dir_name);
+       priv_paths->file_name.base_name = talloc_strdup(priv_paths, last_component);
+
+       if (priv_paths->parent_name.base_name == NULL ||
+                       priv_paths->file_name.base_name == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto err;
+       }
+
+       if (SMB_VFS_STAT(conn, &priv_paths->parent_name) != 0) {
+               status = map_nt_error_from_unix(errno);
+               goto err;
+       }
+       /* Remember where we were. */
+       saved_dir = vfs_GetWd(ctx, conn);
+       if (!saved_dir) {
+               status = map_nt_error_from_unix(errno);
+               goto err;
+       }
+
+       /* Go to the parent directory to lock in memory. */
+       if (vfs_ChDir(conn, priv_paths->parent_name.base_name) == -1) {
+               status = map_nt_error_from_unix(errno);
+               goto err;
+       }
+
+       /* Get the absolute path of the parent directory. */
+       resolved_name = SMB_VFS_REALPATH(conn,".");
+       if (!resolved_name) {
+               status = map_nt_error_from_unix(errno);
+               goto err;
+       }
+
+       if (*resolved_name != '/') {
+               DEBUG(0,("check_reduced_name_with_privilege: realpath "
+                       "doesn't return absolute paths !\n"));
+               status = NT_STATUS_OBJECT_NAME_INVALID;
+               goto err;
+       }
+
+       DEBUG(10,("check_reduced_name_with_privilege: realpath [%s] -> [%s]\n",
+               priv_paths->parent_name.base_name,
+               resolved_name));
+
+       /* Now check the stat value is the same. */
+       status = create_synthetic_smb_fname(talloc_tos(), ".",
+                                       NULL, NULL,
+                                       &smb_fname_cwd);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto err;
+       }
+
+       if (SMB_VFS_LSTAT(conn, smb_fname_cwd) != 0) {
+               status = map_nt_error_from_unix(errno);
+               goto err;
+       }
+
+       /* Ensure we're pointing at the same place. */
+       if (!check_same_stat(&smb_fname_cwd->st, &priv_paths->parent_name.st)) {
+               DEBUG(0,("check_reduced_name_with_privilege: "
+                       "device/inode/uid/gid on directory %s changed. "
+                       "Denying access !\n",
+                       priv_paths->parent_name.base_name));
+               status = NT_STATUS_ACCESS_DENIED;
+               goto err;
+       }
+
+       /* Ensure we're below the connect path. */
+
+       conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
+       if (conn_rootdir == NULL) {
+               DEBUG(2, ("check_reduced_name_with_privilege: Could not get "
+                       "conn_rootdir\n"));
+               status = NT_STATUS_ACCESS_DENIED;
+               goto err;
+       }
+
+       rootdir_len = strlen(conn_rootdir);
+       if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+               DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
+                       "attempt: %s is a symlink outside the "
+                       "share path\n",
+                       dir_name));
+               DEBUGADD(2, ("conn_rootdir =%s\n", conn_rootdir));
+               DEBUGADD(2, ("resolved_name=%s\n", resolved_name));
+               status = NT_STATUS_ACCESS_DENIED;
+               goto err;
+       }
+
+       /* Now ensure that the last component either doesn't
+          exist, or is *NOT* a symlink. */
+
+       ret = SMB_VFS_LSTAT(conn, &priv_paths->file_name);
+       if (ret == -1) {
+               /* Errno must be ENOENT for this be ok. */
+               if (errno != ENOENT) {
+                       status = map_nt_error_from_unix(errno);
+                       DEBUG(2, ("check_reduced_name_with_privilege: "
+                               "LSTAT on %s failed with %s\n",
+                               priv_paths->file_name.base_name,
+                               nt_errstr(status)));
+                       goto err;
+               }
+       }
+
+       if (VALID_STAT(priv_paths->file_name.st) &&
+                       S_ISLNK(priv_paths->file_name.st.st_ex_mode)) {
+               DEBUG(2, ("check_reduced_name_with_privilege: "
+                       "Last component %s is a symlink. Denying"
+                       "access.\n",
+                       priv_paths->file_name.base_name));
+               status = NT_STATUS_ACCESS_DENIED;
+               goto err;
+       }
+
+       smbreq->priv_paths = priv_paths;
+       status = NT_STATUS_OK;
+
+  err:
+
+       if (saved_dir) {
+               vfs_ChDir(conn, saved_dir);
+       }
+       SAFE_FREE(resolved_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(priv_paths);
+       }
+       return status;
+}
+
 /*******************************************************************
  Reduce a file name, removing .. elements and checking that
  it is below dir in the heirachy. This uses realpath.
@@ -839,22 +1068,13 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
 
 NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
 {
-#ifdef REALPATH_TAKES_NULL
-       bool free_resolved_name = True;
-#else
-        char resolved_name_buf[PATH_MAX+1];
-       bool free_resolved_name = False;
-#endif
        char *resolved_name = NULL;
-       char *p = NULL;
+       bool allow_symlinks = true;
+       bool allow_widelinks = false;
 
        DEBUG(3,("check_reduced_name [%s] [%s]\n", fname, conn->connectpath));
 
-#ifdef REALPATH_TAKES_NULL
-       resolved_name = SMB_VFS_REALPATH(conn,fname,NULL);
-#else
-       resolved_name = SMB_VFS_REALPATH(conn,fname,resolved_name_buf);
-#endif
+       resolved_name = SMB_VFS_REALPATH(conn,fname);
 
        if (!resolved_name) {
                switch (errno) {
@@ -866,32 +1086,20 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                        case ENOENT:
                        {
                                TALLOC_CTX *ctx = talloc_tos();
-                               char *tmp_fname = NULL;
-                               char *last_component = NULL;
-                               /* Last component didn't exist. Remove it and try and canonicalise the directory. */
-
-                               tmp_fname = talloc_strdup(ctx, fname);
-                               if (!tmp_fname) {
+                               char *dir_name = NULL;
+                               const char *last_component = NULL;
+                               char *new_name = NULL;
+
+                               /* Last component didn't exist.
+                                  Remove it and try and canonicalise
+                                  the directory name. */
+                               if (!parent_dirname(ctx, fname,
+                                               &dir_name,
+                                               &last_component)) {
                                        return NT_STATUS_NO_MEMORY;
                                }
-                               p = strrchr_m(tmp_fname, '/');
-                               if (p) {
-                                       *p++ = '\0';
-                                       last_component = p;
-                               } else {
-                                       last_component = tmp_fname;
-                                       tmp_fname = talloc_strdup(ctx,
-                                                       ".");
-                                       if (!tmp_fname) {
-                                               return NT_STATUS_NO_MEMORY;
-                                       }
-                               }
 
-#ifdef REALPATH_TAKES_NULL
-                               resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,NULL);
-#else
-                               resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,resolved_name_buf);
-#endif
+                               resolved_name = SMB_VFS_REALPATH(conn,dir_name);
                                if (!resolved_name) {
                                        NTSTATUS status = map_nt_error_from_unix(errno);
 
@@ -899,36 +1107,29 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                                                status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
                                        }
 
-                                       DEBUG(3,("check_reduce_named: "
+                                       DEBUG(3,("check_reduce_name: "
                                                 "couldn't get realpath for "
                                                 "%s (%s)\n",
                                                fname,
                                                nt_errstr(status)));
                                        return status;
                                }
-                               tmp_fname = talloc_asprintf(ctx,
+                               new_name = talloc_asprintf(ctx,
                                                "%s/%s",
                                                resolved_name,
                                                last_component);
-                               if (!tmp_fname) {
+                               if (!new_name) {
                                        return NT_STATUS_NO_MEMORY;
                                }
-#ifdef REALPATH_TAKES_NULL
                                SAFE_FREE(resolved_name);
-                               resolved_name = SMB_STRDUP(tmp_fname);
+                               resolved_name = SMB_STRDUP(new_name);
                                if (!resolved_name) {
-                                       DEBUG(0, ("check_reduced_name: malloc "
-                                                 "fail for %s\n", tmp_fname));
                                        return NT_STATUS_NO_MEMORY;
                                }
-#else
-                               safe_strcpy(resolved_name_buf, tmp_fname, PATH_MAX);
-                               resolved_name = resolved_name_buf;
-#endif
                                break;
                        }
                        default:
-                               DEBUG(1,("check_reduced_name: couldn't get "
+                               DEBUG(3,("check_reduced_name: couldn't get "
                                         "realpath for %s\n", fname));
                                return map_nt_error_from_unix(errno);
                }
@@ -940,75 +1141,73 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
        if (*resolved_name != '/') {
                DEBUG(0,("check_reduced_name: realpath doesn't return "
                         "absolute paths !\n"));
-               if (free_resolved_name) {
-                       SAFE_FREE(resolved_name);
-               }
+               SAFE_FREE(resolved_name);
                return NT_STATUS_OBJECT_NAME_INVALID;
        }
 
-       /* Check for widelinks allowed. */
-       if (!lp_widelinks(SNUM(conn))) {
-                   const char *conn_rootdir;
+       allow_widelinks = lp_widelinks(SNUM(conn));
+       allow_symlinks = lp_symlinks(SNUM(conn));
 
-                   conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
-                   if (conn_rootdir == NULL) {
-                           DEBUG(2, ("check_reduced_name: Could not get "
-                                     "conn_rootdir\n"));
-                           if (free_resolved_name) {
-                                   SAFE_FREE(resolved_name);
-                           }
-                           return NT_STATUS_ACCESS_DENIED;
-                   }
+       /* Common widelinks and symlinks checks. */
+       if (!allow_widelinks || !allow_symlinks) {
+               const char *conn_rootdir;
+               size_t rootdir_len;
 
-                   if (strncmp(conn_rootdir, resolved_name,
-                               strlen(conn_rootdir)) != 0) {
-                           DEBUG(2, ("check_reduced_name: Bad access "
-                                     "attempt: %s is a symlink outside the "
-                                     "share path", fname));
-                           if (free_resolved_name) {
-                                   SAFE_FREE(resolved_name);
-                           }
-                           return NT_STATUS_ACCESS_DENIED;
-                   }
-       }
+               conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
+               if (conn_rootdir == NULL) {
+                       DEBUG(2, ("check_reduced_name: Could not get "
+                               "conn_rootdir\n"));
+                       SAFE_FREE(resolved_name);
+                       return NT_STATUS_ACCESS_DENIED;
+               }
+
+               rootdir_len = strlen(conn_rootdir);
+               if (strncmp(conn_rootdir, resolved_name,
+                               rootdir_len) != 0) {
+                       DEBUG(2, ("check_reduced_name: Bad access "
+                               "attempt: %s is a symlink outside the "
+                               "share path\n", fname));
+                       DEBUGADD(2, ("conn_rootdir =%s\n", conn_rootdir));
+                       DEBUGADD(2, ("resolved_name=%s\n", resolved_name));
+                       SAFE_FREE(resolved_name);
+                       return NT_STATUS_ACCESS_DENIED;
+               }
 
-        /* Check if we are allowing users to follow symlinks */
-        /* Patch from David Clerc <David.Clerc@cui.unige.ch>
-                University of Geneva */
+               /* Extra checks if all symlinks are disallowed. */
+               if (!allow_symlinks) {
+                       /* fname can't have changed in resolved_path. */
+                       const char *p = &resolved_name[rootdir_len];
 
-#ifdef S_ISLNK
-        if (!lp_symlinks(SNUM(conn))) {
-               struct smb_filename *smb_fname = NULL;
-               NTSTATUS status;
+                       /* *p can be '\0' if fname was "." */
+                       if (*p == '\0' && ISDOT(fname)) {
+                               goto out;
+                       }
 
-               status = create_synthetic_smb_fname(talloc_tos(), fname, NULL,
-                                                   NULL, &smb_fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       if (free_resolved_name) {
+                       if (*p != '/') {
+                               DEBUG(2, ("check_reduced_name: logic error (%c) "
+                                       "in resolved_name: %s\n",
+                                       *p,
+                                       fname));
                                SAFE_FREE(resolved_name);
+                               return NT_STATUS_ACCESS_DENIED;
                        }
-                        return status;
-               }
 
-               if ( (SMB_VFS_LSTAT(conn, smb_fname) != -1) &&
-                                (S_ISLNK(smb_fname->st.st_ex_mode)) ) {
-                       if (free_resolved_name) {
+                       p++;
+                       if (strcmp(fname, p)!=0) {
+                               DEBUG(2, ("check_reduced_name: Bad access "
+                                       "attempt: %s is a symlink\n",
+                                       fname));
                                SAFE_FREE(resolved_name);
+                               return NT_STATUS_ACCESS_DENIED;
                        }
-                        DEBUG(3,("check_reduced_name: denied: file path name "
-                                "%s is a symlink\n",resolved_name));
-                       TALLOC_FREE(smb_fname);
-                       return NT_STATUS_ACCESS_DENIED;
-                }
-               TALLOC_FREE(smb_fname);
-        }
-#endif
+               }
+       }
+
+  out:
 
        DEBUG(3,("check_reduced_name: %s reduced to %s\n", fname,
                 resolved_name));
-       if (free_resolved_name) {
-               SAFE_FREE(resolved_name);
-       }
+       SAFE_FREE(resolved_name);
        return NT_STATUS_OK;
 }
 
@@ -1079,7 +1278,7 @@ NTSTATUS vfs_stat_fsp(files_struct *fsp)
 {
        int ret;
 
-       if(fsp->is_directory || fsp->fh->fd == -1) {
+       if(fsp->fh->fd == -1) {
                if (fsp->posix_open) {
                        ret = SMB_VFS_LSTAT(fsp->conn, fsp->fsp_name);
                } else {
@@ -1096,6 +1295,21 @@ NTSTATUS vfs_stat_fsp(files_struct *fsp)
        return NT_STATUS_OK;
 }
 
+/**
+ * Initialize num_streams and streams, then call VFS op streaminfo
+ */
+NTSTATUS vfs_streaminfo(connection_struct *conn,
+                       struct files_struct *fsp,
+                       const char *fname,
+                       TALLOC_CTX *mem_ctx,
+                       unsigned int *num_streams,
+                       struct stream_struct **streams)
+{
+       *num_streams = 0;
+       *streams = NULL;
+       return SMB_VFS_STREAMINFO(conn, fsp, fname, mem_ctx, num_streams, streams);
+}
+
 /*
   generate a file_id from a stat structure
  */
@@ -1107,14 +1321,14 @@ struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_S
 int smb_vfs_call_connect(struct vfs_handle_struct *handle,
                         const char *service, const char *user)
 {
-       VFS_FIND(connect_fn);
+       VFS_FIND(connect);
        return handle->fns->connect_fn(handle, service, user);
 }
 
 void smb_vfs_call_disconnect(struct vfs_handle_struct *handle)
 {
        VFS_FIND(disconnect);
-       handle->fns->disconnect(handle);
+       handle->fns->disconnect_fn(handle);
 }
 
 uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
@@ -1123,8 +1337,8 @@ uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
                                uint64_t *dsize)
 {
        VFS_FIND(disk_free);
-       return handle->fns->disk_free(handle, path, small_query, bsize, dfree,
-                                     dsize);
+       return handle->fns->disk_free_fn(handle, path, small_query, bsize, 
+                                        dfree, dsize);
 }
 
 int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
@@ -1132,7 +1346,7 @@ int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
                           SMB_DISK_QUOTA *qt)
 {
        VFS_FIND(get_quota);
-       return handle->fns->get_quota(handle, qtype, id, qt);
+       return handle->fns->get_quota_fn(handle, qtype, id, qt);
 }
 
 int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
@@ -1140,94 +1354,111 @@ int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
                           SMB_DISK_QUOTA *qt)
 {
        VFS_FIND(set_quota);
-       return handle->fns->set_quota(handle, qtype, id, qt);
+       return handle->fns->set_quota_fn(handle, qtype, id, qt);
 }
 
 int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct *handle,
                                      struct files_struct *fsp,
-                                     SHADOW_COPY_DATA *shadow_copy_data,
+                                     struct shadow_copy_data *shadow_copy_data,
                                      bool labels)
 {
        VFS_FIND(get_shadow_copy_data);
-       return handle->fns->get_shadow_copy_data(handle, fsp, shadow_copy_data,
-                                                labels);
+       return handle->fns->get_shadow_copy_data_fn(handle, fsp, 
+                                                   shadow_copy_data,
+                                                   labels);
 }
 int smb_vfs_call_statvfs(struct vfs_handle_struct *handle, const char *path,
                         struct vfs_statvfs_struct *statbuf)
 {
        VFS_FIND(statvfs);
-       return handle->fns->statvfs(handle, path, statbuf);
+       return handle->fns->statvfs_fn(handle, path, statbuf);
 }
 
 uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
                        enum timestamp_set_resolution *p_ts_res)
 {
        VFS_FIND(fs_capabilities);
-       return handle->fns->fs_capabilities(handle, p_ts_res);
+       return handle->fns->fs_capabilities_fn(handle, p_ts_res);
 }
 
-SMB_STRUCT_DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
+NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
+                                       struct dfs_GetDFSReferral *r)
+{
+       VFS_FIND(get_dfs_referrals);
+       return handle->fns->get_dfs_referrals_fn(handle, r);
+}
+
+DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
                                     const char *fname, const char *mask,
                                     uint32 attributes)
 {
        VFS_FIND(opendir);
-       return handle->fns->opendir(handle, fname, mask, attributes);
+       return handle->fns->opendir_fn(handle, fname, mask, attributes);
 }
 
-SMB_STRUCT_DIRENT *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
-                                             SMB_STRUCT_DIR *dirp,
+DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
+                                       struct files_struct *fsp,
+                                       const char *mask,
+                                       uint32 attributes)
+{
+       VFS_FIND(fdopendir);
+       return handle->fns->fdopendir_fn(handle, fsp, mask, attributes);
+}
+
+struct dirent *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
+                                             DIR *dirp,
                                              SMB_STRUCT_STAT *sbuf)
 {
        VFS_FIND(readdir);
-       return handle->fns->readdir(handle, dirp, sbuf);
+       return handle->fns->readdir_fn(handle, dirp, sbuf);
 }
 
 void smb_vfs_call_seekdir(struct vfs_handle_struct *handle,
-                         SMB_STRUCT_DIR *dirp, long offset)
+                         DIR *dirp, long offset)
 {
        VFS_FIND(seekdir);
-       handle->fns->seekdir(handle, dirp, offset);
+       handle->fns->seekdir_fn(handle, dirp, offset);
 }
 
 long smb_vfs_call_telldir(struct vfs_handle_struct *handle,
-                         SMB_STRUCT_DIR *dirp)
+                         DIR *dirp)
 {
        VFS_FIND(telldir);
-       return handle->fns->telldir(handle, dirp);
+       return handle->fns->telldir_fn(handle, dirp);
 }
 
 void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
-                            SMB_STRUCT_DIR *dirp)
+                            DIR *dirp)
 {
        VFS_FIND(rewind_dir);
-       handle->fns->rewind_dir(handle, dirp);
+       handle->fns->rewind_dir_fn(handle, dirp);
 }
 
 int smb_vfs_call_mkdir(struct vfs_handle_struct *handle, const char *path,
                       mode_t mode)
 {
        VFS_FIND(mkdir);
-       return handle->fns->mkdir(handle, path, mode);
+       return handle->fns->mkdir_fn(handle, path, mode);
 }
 
 int smb_vfs_call_rmdir(struct vfs_handle_struct *handle, const char *path)
 {
        VFS_FIND(rmdir);
-       return handle->fns->rmdir(handle, path);
+       return handle->fns->rmdir_fn(handle, path);
 }
 
 int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
-                         SMB_STRUCT_DIR *dir)
+                         DIR *dir)
 {
        VFS_FIND(closedir);
-       return handle->fns->closedir(handle, dir);
+       return handle->fns->closedir_fn(handle, dir);
 }
 
 void smb_vfs_call_init_search_op(struct vfs_handle_struct *handle,
-                                SMB_STRUCT_DIR *dirp)
+                                DIR *dirp)
 {
        VFS_FIND(init_search_op);
-       handle->fns->init_search_op(handle, dirp);
+       handle->fns->init_search_op_fn(handle, dirp);
 }
 
 int smb_vfs_call_open(struct vfs_handle_struct *handle,
@@ -1235,7 +1466,7 @@ int smb_vfs_call_open(struct vfs_handle_struct *handle,
                      int flags, mode_t mode)
 {
        VFS_FIND(open);
-       return handle->fns->open(handle, smb_fname, fsp, flags, mode);
+       return handle->fns->open_fn(handle, smb_fname, fsp, flags, mode);
 }
 
 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
@@ -1249,31 +1480,33 @@ NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
                                  uint32_t file_attributes,
                                  uint32_t oplock_request,
                                  uint64_t allocation_size,
+                                 uint32_t private_flags,
                                  struct security_descriptor *sd,
                                  struct ea_list *ea_list,
                                  files_struct **result,
                                  int *pinfo)
 {
        VFS_FIND(create_file);
-       return handle->fns->create_file(
+       return handle->fns->create_file_fn(
                handle, req, root_dir_fid, smb_fname, access_mask,
                share_access, create_disposition, create_options,
-               file_attributes, oplock_request, allocation_size, sd, ea_list,
+               file_attributes, oplock_request, allocation_size,
+               private_flags, sd, ea_list,
                result, pinfo);
 }
 
-int smb_vfs_call_close_fn(struct vfs_handle_struct *handle,
-                         struct files_struct *fsp)
+int smb_vfs_call_close(struct vfs_handle_struct *handle,
+                      struct files_struct *fsp)
 {
-       VFS_FIND(close_fn);
+       VFS_FIND(close);
        return handle->fns->close_fn(handle, fsp);
 }
 
-ssize_t smb_vfs_call_vfs_read(struct vfs_handle_struct *handle,
-                             struct files_struct *fsp, void *data, size_t n)
+ssize_t smb_vfs_call_read(struct vfs_handle_struct *handle,
+                         struct files_struct *fsp, void *data, size_t n)
 {
-       VFS_FIND(vfs_read);
-       return handle->fns->vfs_read(handle, fsp, data, n);
+       VFS_FIND(read);
+       return handle->fns->read_fn(handle, fsp, data, n);
 }
 
 ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
@@ -1281,7 +1514,7 @@ ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
                           SMB_OFF_T offset)
 {
        VFS_FIND(pread);
-       return handle->fns->pread(handle, fsp, data, n, offset);
+       return handle->fns->pread_fn(handle, fsp, data, n, offset);
 }
 
 ssize_t smb_vfs_call_write(struct vfs_handle_struct *handle,
@@ -1289,7 +1522,7 @@ ssize_t smb_vfs_call_write(struct vfs_handle_struct *handle,
                           size_t n)
 {
        VFS_FIND(write);
-       return handle->fns->write(handle, fsp, data, n);
+       return handle->fns->write_fn(handle, fsp, data, n);
 }
 
 ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
@@ -1297,7 +1530,7 @@ ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
                            size_t n, SMB_OFF_T offset)
 {
        VFS_FIND(pwrite);
-       return handle->fns->pwrite(handle, fsp, data, n, offset);
+       return handle->fns->pwrite_fn(handle, fsp, data, n, offset);
 }
 
 SMB_OFF_T smb_vfs_call_lseek(struct vfs_handle_struct *handle,
@@ -1305,7 +1538,7 @@ SMB_OFF_T smb_vfs_call_lseek(struct vfs_handle_struct *handle,
                             int whence)
 {
        VFS_FIND(lseek);
-       return handle->fns->lseek(handle, fsp, offset, whence);
+       return handle->fns->lseek_fn(handle, fsp, offset, whence);
 }
 
 ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd,
@@ -1313,8 +1546,8 @@ ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd,
                              SMB_OFF_T offset, size_t count)
 {
        VFS_FIND(sendfile);
-       return handle->fns->sendfile(handle, tofd, fromfsp, header, offset,
-                                    count);
+       return handle->fns->sendfile_fn(handle, tofd, fromfsp, header, offset,
+                                       count);
 }
 
 ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd,
@@ -1322,7 +1555,7 @@ ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd,
                              size_t count)
 {
        VFS_FIND(recvfile);
-       return handle->fns->recvfile(handle, fromfd, tofsp, offset, count);
+       return handle->fns->recvfile_fn(handle, fromfd, tofsp, offset, count);
 }
 
 int smb_vfs_call_rename(struct vfs_handle_struct *handle,
@@ -1330,35 +1563,35 @@ int smb_vfs_call_rename(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname_dst)
 {
        VFS_FIND(rename);
-       return handle->fns->rename(handle, smb_fname_src, smb_fname_dst);
+       return handle->fns->rename_fn(handle, smb_fname_src, smb_fname_dst);
 }
 
 int smb_vfs_call_fsync(struct vfs_handle_struct *handle,
                       struct files_struct *fsp)
 {
        VFS_FIND(fsync);
-       return handle->fns->fsync(handle, fsp);
+       return handle->fns->fsync_fn(handle, fsp);
 }
 
 int smb_vfs_call_stat(struct vfs_handle_struct *handle,
                      struct smb_filename *smb_fname)
 {
        VFS_FIND(stat);
-       return handle->fns->stat(handle, smb_fname);
+       return handle->fns->stat_fn(handle, smb_fname);
 }
 
 int smb_vfs_call_fstat(struct vfs_handle_struct *handle,
                       struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
 {
        VFS_FIND(fstat);
-       return handle->fns->fstat(handle, fsp, sbuf);
+       return handle->fns->fstat_fn(handle, fsp, sbuf);
 }
 
 int smb_vfs_call_lstat(struct vfs_handle_struct *handle,
                       struct smb_filename *smb_filename)
 {
        VFS_FIND(lstat);
-       return handle->fns->lstat(handle, smb_filename);
+       return handle->fns->lstat_fn(handle, smb_filename);
 }
 
 uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
@@ -1366,61 +1599,161 @@ uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
                                     const SMB_STRUCT_STAT *sbuf)
 {
        VFS_FIND(get_alloc_size);
-       return handle->fns->get_alloc_size(handle, fsp, sbuf);
+       return handle->fns->get_alloc_size_fn(handle, fsp, sbuf);
 }
 
 int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname)
 {
        VFS_FIND(unlink);
-       return handle->fns->unlink(handle, smb_fname);
+       return handle->fns->unlink_fn(handle, smb_fname);
 }
 
 int smb_vfs_call_chmod(struct vfs_handle_struct *handle, const char *path,
                       mode_t mode)
 {
        VFS_FIND(chmod);
-       return handle->fns->chmod(handle, path, mode);
+       return handle->fns->chmod_fn(handle, path, mode);
 }
 
 int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
                        struct files_struct *fsp, mode_t mode)
 {
        VFS_FIND(fchmod);
-       return handle->fns->fchmod(handle, fsp, mode);
+       return handle->fns->fchmod_fn(handle, fsp, mode);
 }
 
 int smb_vfs_call_chown(struct vfs_handle_struct *handle, const char *path,
                       uid_t uid, gid_t gid)
 {
        VFS_FIND(chown);
-       return handle->fns->chown(handle, path, uid, gid);
+       return handle->fns->chown_fn(handle, path, uid, gid);
 }
 
 int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
                        struct files_struct *fsp, uid_t uid, gid_t gid)
 {
        VFS_FIND(fchown);
-       return handle->fns->fchown(handle, fsp, uid, gid);
+       return handle->fns->fchown_fn(handle, fsp, uid, gid);
 }
 
 int smb_vfs_call_lchown(struct vfs_handle_struct *handle, const char *path,
                        uid_t uid, gid_t gid)
 {
        VFS_FIND(lchown);
-       return handle->fns->lchown(handle, path, uid, gid);
+       return handle->fns->lchown_fn(handle, path, uid, gid);
+}
+
+NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
+{
+       int ret;
+       bool as_root = false;
+       const char *path;
+       char *saved_dir = NULL;
+       char *parent_dir = NULL;
+       NTSTATUS status;
+
+       if (fsp->fh->fd != -1) {
+               /* Try fchown. */
+               ret = SMB_VFS_FCHOWN(fsp, uid, gid);
+               if (ret == 0) {
+                       return NT_STATUS_OK;
+               }
+               if (ret == -1 && errno != ENOSYS) {
+                       return map_nt_error_from_unix(errno);
+               }
+       }
+
+       as_root = (geteuid() == 0);
+
+       if (as_root) {
+               /*
+                * We are being asked to chown as root. Make
+                * sure we chdir() into the path to pin it,
+                * and always act using lchown to ensure we
+                * don't deref any symbolic links.
+                */
+               const char *final_component = NULL;
+               struct smb_filename local_fname;
+
+               saved_dir = vfs_GetWd(talloc_tos(),fsp->conn);
+               if (!saved_dir) {
+                       status = map_nt_error_from_unix(errno);
+                       DEBUG(0,("vfs_chown_fsp: failed to get "
+                               "current working directory. Error was %s\n",
+                               strerror(errno)));
+                       return status;
+               }
+
+               if (!parent_dirname(talloc_tos(),
+                               fsp->fsp_name->base_name,
+                               &parent_dir,
+                               &final_component)) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               /* cd into the parent dir to pin it. */
+               ret = vfs_ChDir(fsp->conn, parent_dir);
+               if (ret == -1) {
+                       return map_nt_error_from_unix(errno);
+               }
+
+               ZERO_STRUCT(local_fname);
+               local_fname.base_name = discard_const_p(char, final_component);
+
+               /* Must use lstat here. */
+               ret = SMB_VFS_LSTAT(fsp->conn, &local_fname);
+               if (ret == -1) {
+                       status = map_nt_error_from_unix(errno);
+                       goto out;
+               }
+
+               /* Ensure it matches the fsp stat. */
+               if (!check_same_stat(&local_fname.st, &fsp->fsp_name->st)) {
+                        status = NT_STATUS_ACCESS_DENIED;
+                       goto out;
+                }
+                path = final_component;
+        } else {
+                path = fsp->fsp_name->base_name;
+        }
+
+       if (fsp->posix_open || as_root) {
+               ret = SMB_VFS_LCHOWN(fsp->conn,
+                       path,
+                       uid, gid);
+       } else {
+               ret = SMB_VFS_CHOWN(fsp->conn,
+                       path,
+                       uid, gid);
+       }
+
+       if (ret == 0) {
+               status = NT_STATUS_OK;
+       } else {
+               status = map_nt_error_from_unix(errno);
+       }
+
+  out:
+
+       if (as_root) {
+               vfs_ChDir(fsp->conn,saved_dir);
+               TALLOC_FREE(saved_dir);
+               TALLOC_FREE(parent_dir);
+       }
+       return status;
 }
 
 int smb_vfs_call_chdir(struct vfs_handle_struct *handle, const char *path)
 {
        VFS_FIND(chdir);
-       return handle->fns->chdir(handle, path);
+       return handle->fns->chdir_fn(handle, path);
 }
 
-char *smb_vfs_call_getwd(struct vfs_handle_struct *handle, char *buf)
+char *smb_vfs_call_getwd(struct vfs_handle_struct *handle)
 {
        VFS_FIND(getwd);
-       return handle->fns->getwd(handle, buf);
+       return handle->fns->getwd_fn(handle);
 }
 
 int smb_vfs_call_ntimes(struct vfs_handle_struct *handle,
@@ -1428,14 +1761,24 @@ int smb_vfs_call_ntimes(struct vfs_handle_struct *handle,
                        struct smb_file_time *ft)
 {
        VFS_FIND(ntimes);
-       return handle->fns->ntimes(handle, smb_fname, ft);
+       return handle->fns->ntimes_fn(handle, smb_fname, ft);
 }
 
 int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle,
                           struct files_struct *fsp, SMB_OFF_T offset)
 {
        VFS_FIND(ftruncate);
-       return handle->fns->ftruncate(handle, fsp, offset);
+       return handle->fns->ftruncate_fn(handle, fsp, offset);
+}
+
+int smb_vfs_call_fallocate(struct vfs_handle_struct *handle,
+                               struct files_struct *fsp,
+                               enum vfs_fallocate_mode mode,
+                               SMB_OFF_T offset,
+                               SMB_OFF_T len)
+{
+       VFS_FIND(fallocate);
+       return handle->fns->fallocate_fn(handle, fsp, mode, offset, len);
 }
 
 int smb_vfs_call_kernel_flock(struct vfs_handle_struct *handle,
@@ -1443,7 +1786,7 @@ int smb_vfs_call_kernel_flock(struct vfs_handle_struct *handle,
                              uint32_t access_mask)
 {
        VFS_FIND(kernel_flock);
-       return handle->fns->kernel_flock(handle, fsp, share_mode,
+       return handle->fns->kernel_flock_fn(handle, fsp, share_mode,
                                         access_mask);
 }
 
@@ -1451,69 +1794,71 @@ int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle,
                                struct files_struct *fsp, int leasetype)
 {
        VFS_FIND(linux_setlease);
-       return handle->fns->linux_setlease(handle, fsp, leasetype);
+       return handle->fns->linux_setlease_fn(handle, fsp, leasetype);
 }
 
 int smb_vfs_call_symlink(struct vfs_handle_struct *handle, const char *oldpath,
                         const char *newpath)
 {
        VFS_FIND(symlink);
-       return handle->fns->symlink(handle, oldpath, newpath);
+       return handle->fns->symlink_fn(handle, oldpath, newpath);
 }
 
-int smb_vfs_call_vfs_readlink(struct vfs_handle_struct *handle,
+int smb_vfs_call_readlink(struct vfs_handle_struct *handle,
                              const char *path, char *buf, size_t bufsiz)
 {
-       VFS_FIND(vfs_readlink);
-       return handle->fns->vfs_readlink(handle, path, buf, bufsiz);
+       VFS_FIND(readlink);
+       return handle->fns->readlink_fn(handle, path, buf, bufsiz);
 }
 
 int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
                      const char *newpath)
 {
        VFS_FIND(link);
-       return handle->fns->link(handle, oldpath, newpath);
+       return handle->fns->link_fn(handle, oldpath, newpath);
 }
 
 int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
                       mode_t mode, SMB_DEV_T dev)
 {
        VFS_FIND(mknod);
-       return handle->fns->mknod(handle, path, mode, dev);
+       return handle->fns->mknod_fn(handle, path, mode, dev);
 }
 
-char *smb_vfs_call_realpath(struct vfs_handle_struct *handle,
-                           const char *path, char *resolved_path)
+char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path)
 {
        VFS_FIND(realpath);
-       return handle->fns->realpath(handle, path, resolved_path);
+       return handle->fns->realpath_fn(handle, path);
 }
 
 NTSTATUS smb_vfs_call_notify_watch(struct vfs_handle_struct *handle,
                                   struct sys_notify_context *ctx,
-                                  struct notify_entry *e,
+                                  const char *path,
+                                  uint32_t *filter,
+                                  uint32_t *subdir_filter,
                                   void (*callback)(struct sys_notify_context *ctx,
                                                    void *private_data,
                                                    struct notify_event *ev),
                                   void *private_data, void *handle_p)
 {
        VFS_FIND(notify_watch);
-       return handle->fns->notify_watch(handle, ctx, e, callback,
-                                        private_data, handle_p);
+       return handle->fns->notify_watch_fn(handle, ctx, path,
+                                           filter, subdir_filter, callback,
+                                           private_data, handle_p);
 }
 
 int smb_vfs_call_chflags(struct vfs_handle_struct *handle, const char *path,
                         unsigned int flags)
 {
        VFS_FIND(chflags);
-       return handle->fns->chflags(handle, path, flags);
+       return handle->fns->chflags_fn(handle, path, flags);
 }
 
 struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
                                           const SMB_STRUCT_STAT *sbuf)
 {
        VFS_FIND(file_id_create);
-       return handle->fns->file_id_create(handle, sbuf);
+       return handle->fns->file_id_create_fn(handle, sbuf);
 }
 
 NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle,
@@ -1524,8 +1869,8 @@ NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle,
                                 struct stream_struct **streams)
 {
        VFS_FIND(streaminfo);
-       return handle->fns->streaminfo(handle, fsp, fname, mem_ctx,
-                                      num_streams, streams);
+       return handle->fns->streaminfo_fn(handle, fsp, fname, mem_ctx,
+                                         num_streams, streams);
 }
 
 int smb_vfs_call_get_real_filename(struct vfs_handle_struct *handle,
@@ -1533,15 +1878,15 @@ int smb_vfs_call_get_real_filename(struct vfs_handle_struct *handle,
                                   TALLOC_CTX *mem_ctx, char **found_name)
 {
        VFS_FIND(get_real_filename);
-       return handle->fns->get_real_filename(handle, path, name, mem_ctx,
-                                             found_name);
+       return handle->fns->get_real_filename_fn(handle, path, name, mem_ctx,
+                                                found_name);
 }
 
 const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
                                     const char *filename)
 {
        VFS_FIND(connectpath);
-       return handle->fns->connectpath(handle, filename);
+       return handle->fns->connectpath_fn(handle, filename);
 }
 
 bool smb_vfs_call_strict_lock(struct vfs_handle_struct *handle,
@@ -1549,7 +1894,7 @@ bool smb_vfs_call_strict_lock(struct vfs_handle_struct *handle,
                              struct lock_struct *plock)
 {
        VFS_FIND(strict_lock);
-       return handle->fns->strict_lock(handle, fsp, plock);
+       return handle->fns->strict_lock_fn(handle, fsp, plock);
 }
 
 void smb_vfs_call_strict_unlock(struct vfs_handle_struct *handle,
@@ -1557,7 +1902,7 @@ void smb_vfs_call_strict_unlock(struct vfs_handle_struct *handle,
                                struct lock_struct *plock)
 {
        VFS_FIND(strict_unlock);
-       handle->fns->strict_unlock(handle, fsp, plock);
+       handle->fns->strict_unlock_fn(handle, fsp, plock);
 }
 
 NTSTATUS smb_vfs_call_translate_name(struct vfs_handle_struct *handle,
@@ -1567,8 +1912,25 @@ NTSTATUS smb_vfs_call_translate_name(struct vfs_handle_struct *handle,
                                     char **mapped_name)
 {
        VFS_FIND(translate_name);
-       return handle->fns->translate_name(handle, name, direction, mem_ctx,
-                                          mapped_name);
+       return handle->fns->translate_name_fn(handle, name, direction, mem_ctx,
+                                             mapped_name);
+}
+
+NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle,
+                           struct files_struct *fsp,
+                           TALLOC_CTX *ctx,
+                           uint32_t function,
+                           uint16_t req_flags,
+                           const uint8_t *in_data,
+                           uint32_t in_len,
+                           uint8_t **out_data,
+                           uint32_t max_out_len,
+                           uint32_t *out_len)
+{
+       VFS_FIND(fsctl);
+       return handle->fns->fsctl_fn(handle, fsp, ctx, function, req_flags, 
+                                    in_data, in_len, out_data, max_out_len, 
+                                    out_len);
 }
 
 NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
@@ -1577,8 +1939,8 @@ NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
                                  struct security_descriptor **ppdesc)
 {
        VFS_FIND(fget_nt_acl);
-       return handle->fns->fget_nt_acl(handle, fsp, security_info,
-                                       ppdesc);
+       return handle->fns->fget_nt_acl_fn(handle, fsp, security_info,
+                                          ppdesc);
 }
 
 NTSTATUS smb_vfs_call_get_nt_acl(struct vfs_handle_struct *handle,
@@ -1587,7 +1949,7 @@ NTSTATUS smb_vfs_call_get_nt_acl(struct vfs_handle_struct *handle,
                                 struct security_descriptor **ppdesc)
 {
        VFS_FIND(get_nt_acl);
-       return handle->fns->get_nt_acl(handle, name, security_info, ppdesc);
+       return handle->fns->get_nt_acl_fn(handle, name, security_info, ppdesc);
 }
 
 NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
@@ -1596,21 +1958,22 @@ NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
                                  const struct security_descriptor *psd)
 {
        VFS_FIND(fset_nt_acl);
-       return handle->fns->fset_nt_acl(handle, fsp, security_info_sent, psd);
+       return handle->fns->fset_nt_acl_fn(handle, fsp, security_info_sent, 
+                                          psd);
 }
 
 int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle, const char *name,
                           mode_t mode)
 {
        VFS_FIND(chmod_acl);
-       return handle->fns->chmod_acl(handle, name, mode);
+       return handle->fns->chmod_acl_fn(handle, name, mode);
 }
 
 int smb_vfs_call_fchmod_acl(struct vfs_handle_struct *handle,
                            struct files_struct *fsp, mode_t mode)
 {
        VFS_FIND(fchmod_acl);
-       return handle->fns->fchmod_acl(handle, fsp, mode);
+       return handle->fns->fchmod_acl_fn(handle, fsp, mode);
 }
 
 int smb_vfs_call_sys_acl_get_entry(struct vfs_handle_struct *handle,
@@ -1618,8 +1981,8 @@ int smb_vfs_call_sys_acl_get_entry(struct vfs_handle_struct *handle,
                                   SMB_ACL_ENTRY_T *entry_p)
 {
        VFS_FIND(sys_acl_get_entry);
-       return handle->fns->sys_acl_get_entry(handle, theacl, entry_id,
-                                             entry_p);
+       return handle->fns->sys_acl_get_entry_fn(handle, theacl, entry_id,
+                                                entry_p);
 }
 
 int smb_vfs_call_sys_acl_get_tag_type(struct vfs_handle_struct *handle,
@@ -1627,7 +1990,8 @@ int smb_vfs_call_sys_acl_get_tag_type(struct vfs_handle_struct *handle,
                                      SMB_ACL_TAG_T *tag_type_p)
 {
        VFS_FIND(sys_acl_get_tag_type);
-       return handle->fns->sys_acl_get_tag_type(handle, entry_d, tag_type_p);
+       return handle->fns->sys_acl_get_tag_type_fn(handle, entry_d, 
+                                                   tag_type_p);
 }
 
 int smb_vfs_call_sys_acl_get_permset(struct vfs_handle_struct *handle,
@@ -1635,14 +1999,14 @@ int smb_vfs_call_sys_acl_get_permset(struct vfs_handle_struct *handle,
                                     SMB_ACL_PERMSET_T *permset_p)
 {
        VFS_FIND(sys_acl_get_permset);
-       return handle->fns->sys_acl_get_permset(handle, entry_d, permset_p);
+       return handle->fns->sys_acl_get_permset_fn(handle, entry_d, permset_p);
 }
 
 void * smb_vfs_call_sys_acl_get_qualifier(struct vfs_handle_struct *handle,
                                          SMB_ACL_ENTRY_T entry_d)
 {
        VFS_FIND(sys_acl_get_qualifier);
-       return handle->fns->sys_acl_get_qualifier(handle, entry_d);
+       return handle->fns->sys_acl_get_qualifier_fn(handle, entry_d);
 }
 
 SMB_ACL_T smb_vfs_call_sys_acl_get_file(struct vfs_handle_struct *handle,
@@ -1650,21 +2014,21 @@ SMB_ACL_T smb_vfs_call_sys_acl_get_file(struct vfs_handle_struct *handle,
                                        SMB_ACL_TYPE_T type)
 {
        VFS_FIND(sys_acl_get_file);
-       return handle->fns->sys_acl_get_file(handle, path_p, type);
+       return handle->fns->sys_acl_get_file_fn(handle, path_p, type);
 }
 
 SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
                                      struct files_struct *fsp)
 {
        VFS_FIND(sys_acl_get_fd);
-       return handle->fns->sys_acl_get_fd(handle, fsp);
+       return handle->fns->sys_acl_get_fd_fn(handle, fsp);
 }
 
 int smb_vfs_call_sys_acl_clear_perms(struct vfs_handle_struct *handle,
                                     SMB_ACL_PERMSET_T permset)
 {
        VFS_FIND(sys_acl_clear_perms);
-       return handle->fns->sys_acl_clear_perms(handle, permset);
+       return handle->fns->sys_acl_clear_perms_fn(handle, permset);
 }
 
 int smb_vfs_call_sys_acl_add_perm(struct vfs_handle_struct *handle,
@@ -1672,28 +2036,28 @@ int smb_vfs_call_sys_acl_add_perm(struct vfs_handle_struct *handle,
                                  SMB_ACL_PERM_T perm)
 {
        VFS_FIND(sys_acl_add_perm);
-       return handle->fns->sys_acl_add_perm(handle, permset, perm);
+       return handle->fns->sys_acl_add_perm_fn(handle, permset, perm);
 }
 
 char * smb_vfs_call_sys_acl_to_text(struct vfs_handle_struct *handle,
                                    SMB_ACL_T theacl, ssize_t *plen)
 {
        VFS_FIND(sys_acl_to_text);
-       return handle->fns->sys_acl_to_text(handle, theacl, plen);
+       return handle->fns->sys_acl_to_text_fn(handle, theacl, plen);
 }
 
 SMB_ACL_T smb_vfs_call_sys_acl_init(struct vfs_handle_struct *handle,
                                    int count)
 {
        VFS_FIND(sys_acl_init);
-       return handle->fns->sys_acl_init(handle, count);
+       return handle->fns->sys_acl_init_fn(handle, count);
 }
 
 int smb_vfs_call_sys_acl_create_entry(struct vfs_handle_struct *handle,
                                      SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
 {
        VFS_FIND(sys_acl_create_entry);
-       return handle->fns->sys_acl_create_entry(handle, pacl, pentry);
+       return handle->fns->sys_acl_create_entry_fn(handle, pacl, pentry);
 }
 
 int smb_vfs_call_sys_acl_set_tag_type(struct vfs_handle_struct *handle,
@@ -1701,14 +2065,14 @@ int smb_vfs_call_sys_acl_set_tag_type(struct vfs_handle_struct *handle,
                                      SMB_ACL_TAG_T tagtype)
 {
        VFS_FIND(sys_acl_set_tag_type);
-       return handle->fns->sys_acl_set_tag_type(handle, entry, tagtype);
+       return handle->fns->sys_acl_set_tag_type_fn(handle, entry, tagtype);
 }
 
 int smb_vfs_call_sys_acl_set_qualifier(struct vfs_handle_struct *handle,
                                       SMB_ACL_ENTRY_T entry, void *qual)
 {
        VFS_FIND(sys_acl_set_qualifier);
-       return handle->fns->sys_acl_set_qualifier(handle, entry, qual);
+       return handle->fns->sys_acl_set_qualifier_fn(handle, entry, qual);
 }
 
 int smb_vfs_call_sys_acl_set_permset(struct vfs_handle_struct *handle,
@@ -1716,14 +2080,14 @@ int smb_vfs_call_sys_acl_set_permset(struct vfs_handle_struct *handle,
                                     SMB_ACL_PERMSET_T permset)
 {
        VFS_FIND(sys_acl_set_permset);
-       return handle->fns->sys_acl_set_permset(handle, entry, permset);
+       return handle->fns->sys_acl_set_permset_fn(handle, entry, permset);
 }
 
 int smb_vfs_call_sys_acl_valid(struct vfs_handle_struct *handle,
                               SMB_ACL_T theacl)
 {
        VFS_FIND(sys_acl_valid);
-       return handle->fns->sys_acl_valid(handle, theacl);
+       return handle->fns->sys_acl_valid_fn(handle, theacl);
 }
 
 int smb_vfs_call_sys_acl_set_file(struct vfs_handle_struct *handle,
@@ -1731,21 +2095,21 @@ int smb_vfs_call_sys_acl_set_file(struct vfs_handle_struct *handle,
                                  SMB_ACL_T theacl)
 {
        VFS_FIND(sys_acl_set_file);
-       return handle->fns->sys_acl_set_file(handle, name, acltype, theacl);
+       return handle->fns->sys_acl_set_file_fn(handle, name, acltype, theacl);
 }
 
 int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle,
                                struct files_struct *fsp, SMB_ACL_T theacl)
 {
        VFS_FIND(sys_acl_set_fd);
-       return handle->fns->sys_acl_set_fd(handle, fsp, theacl);
+       return handle->fns->sys_acl_set_fd_fn(handle, fsp, theacl);
 }
 
 int smb_vfs_call_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
                                         const char *path)
 {
        VFS_FIND(sys_acl_delete_def_file);
-       return handle->fns->sys_acl_delete_def_file(handle, path);
+       return handle->fns->sys_acl_delete_def_file_fn(handle, path);
 }
 
 int smb_vfs_call_sys_acl_get_perm(struct vfs_handle_struct *handle,
@@ -1753,28 +2117,29 @@ int smb_vfs_call_sys_acl_get_perm(struct vfs_handle_struct *handle,
                                  SMB_ACL_PERM_T perm)
 {
        VFS_FIND(sys_acl_get_perm);
-       return handle->fns->sys_acl_get_perm(handle, permset, perm);
+       return handle->fns->sys_acl_get_perm_fn(handle, permset, perm);
 }
 
 int smb_vfs_call_sys_acl_free_text(struct vfs_handle_struct *handle,
                                   char *text)
 {
        VFS_FIND(sys_acl_free_text);
-       return handle->fns->sys_acl_free_text(handle, text);
+       return handle->fns->sys_acl_free_text_fn(handle, text);
 }
 
 int smb_vfs_call_sys_acl_free_acl(struct vfs_handle_struct *handle,
                                  SMB_ACL_T posix_acl)
 {
        VFS_FIND(sys_acl_free_acl);
-       return handle->fns->sys_acl_free_acl(handle, posix_acl);
+       return handle->fns->sys_acl_free_acl_fn(handle, posix_acl);
 }
 
 int smb_vfs_call_sys_acl_free_qualifier(struct vfs_handle_struct *handle,
                                        void *qualifier, SMB_ACL_TAG_T tagtype)
 {
        VFS_FIND(sys_acl_free_qualifier);
-       return handle->fns->sys_acl_free_qualifier(handle, qualifier, tagtype);
+       return handle->fns->sys_acl_free_qualifier_fn(handle, qualifier, 
+                                                     tagtype);
 }
 
 ssize_t smb_vfs_call_getxattr(struct vfs_handle_struct *handle,
@@ -1782,7 +2147,7 @@ ssize_t smb_vfs_call_getxattr(struct vfs_handle_struct *handle,
                              size_t size)
 {
        VFS_FIND(getxattr);
-       return handle->fns->getxattr(handle, path, name, value, size);
+       return handle->fns->getxattr_fn(handle, path, name, value, size);
 }
 
 ssize_t smb_vfs_call_lgetxattr(struct vfs_handle_struct *handle,
@@ -1790,7 +2155,7 @@ ssize_t smb_vfs_call_lgetxattr(struct vfs_handle_struct *handle,
                               size_t size)
 {
        VFS_FIND(lgetxattr);
-       return handle->fns->lgetxattr(handle, path, name, value, size);
+       return handle->fns->lgetxattr_fn(handle, path, name, value, size);
 }
 
 ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
@@ -1798,21 +2163,21 @@ ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
                               void *value, size_t size)
 {
        VFS_FIND(fgetxattr);
-       return handle->fns->fgetxattr(handle, fsp, name, value, size);
+       return handle->fns->fgetxattr_fn(handle, fsp, name, value, size);
 }
 
 ssize_t smb_vfs_call_listxattr(struct vfs_handle_struct *handle,
                               const char *path, char *list, size_t size)
 {
        VFS_FIND(listxattr);
-       return handle->fns->listxattr(handle, path, list, size);
+       return handle->fns->listxattr_fn(handle, path, list, size);
 }
 
 ssize_t smb_vfs_call_llistxattr(struct vfs_handle_struct *handle,
                                const char *path, char *list, size_t size)
 {
        VFS_FIND(llistxattr);
-       return handle->fns->llistxattr(handle, path, list, size);
+       return handle->fns->llistxattr_fn(handle, path, list, size);
 }
 
 ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
@@ -1820,28 +2185,28 @@ ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
                                size_t size)
 {
        VFS_FIND(flistxattr);
-       return handle->fns->flistxattr(handle, fsp, list, size);
+       return handle->fns->flistxattr_fn(handle, fsp, list, size);
 }
 
 int smb_vfs_call_removexattr(struct vfs_handle_struct *handle,
                             const char *path, const char *name)
 {
        VFS_FIND(removexattr);
-       return handle->fns->removexattr(handle, path, name);
+       return handle->fns->removexattr_fn(handle, path, name);
 }
 
 int smb_vfs_call_lremovexattr(struct vfs_handle_struct *handle,
                              const char *path, const char *name)
 {
        VFS_FIND(lremovexattr);
-       return handle->fns->lremovexattr(handle, path, name);
+       return handle->fns->lremovexattr_fn(handle, path, name);
 }
 
 int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle,
                              struct files_struct *fsp, const char *name)
 {
        VFS_FIND(fremovexattr);
-       return handle->fns->fremovexattr(handle, fsp, name);
+       return handle->fns->fremovexattr_fn(handle, fsp, name);
 }
 
 int smb_vfs_call_setxattr(struct vfs_handle_struct *handle, const char *path,
@@ -1849,7 +2214,7 @@ int smb_vfs_call_setxattr(struct vfs_handle_struct *handle, const char *path,
                          int flags)
 {
        VFS_FIND(setxattr);
-       return handle->fns->setxattr(handle, path, name, value, size, flags);
+       return handle->fns->setxattr_fn(handle, path, name, value, size, flags);
 }
 
 int smb_vfs_call_lsetxattr(struct vfs_handle_struct *handle, const char *path,
@@ -1857,7 +2222,8 @@ int smb_vfs_call_lsetxattr(struct vfs_handle_struct *handle, const char *path,
                           int flags)
 {
        VFS_FIND(lsetxattr);
-       return handle->fns->lsetxattr(handle, path, name, value, size, flags);
+       return handle->fns->lsetxattr_fn(handle, path, name, value, size, 
+                                        flags);
 }
 
 int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
@@ -1865,28 +2231,28 @@ int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
                           const void *value, size_t size, int flags)
 {
        VFS_FIND(fsetxattr);
-       return handle->fns->fsetxattr(handle, fsp, name, value, size, flags);
+       return handle->fns->fsetxattr_fn(handle, fsp, name, value, size, flags);
 }
 
 int smb_vfs_call_aio_read(struct vfs_handle_struct *handle,
                          struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
 {
        VFS_FIND(aio_read);
-       return handle->fns->aio_read(handle, fsp, aiocb);
+       return handle->fns->aio_read_fn(handle, fsp, aiocb);
 }
 
 int smb_vfs_call_aio_write(struct vfs_handle_struct *handle,
                           struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
 {
        VFS_FIND(aio_write);
-       return handle->fns->aio_write(handle, fsp, aiocb);
+       return handle->fns->aio_write_fn(handle, fsp, aiocb);
 }
 
-ssize_t smb_vfs_call_aio_return_fn(struct vfs_handle_struct *handle,
-                                  struct files_struct *fsp,
-                                  SMB_STRUCT_AIOCB *aiocb)
+ssize_t smb_vfs_call_aio_return(struct vfs_handle_struct *handle,
+                               struct files_struct *fsp,
+                               SMB_STRUCT_AIOCB *aiocb)
 {
-       VFS_FIND(aio_return_fn);
+       VFS_FIND(aio_return);
        return handle->fns->aio_return_fn(handle, fsp, aiocb);
 }
 
@@ -1894,14 +2260,14 @@ int smb_vfs_call_aio_cancel(struct vfs_handle_struct *handle,
                            struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
 {
        VFS_FIND(aio_cancel);
-       return handle->fns->aio_cancel(handle, fsp, aiocb);
+       return handle->fns->aio_cancel_fn(handle, fsp, aiocb);
 }
 
-int smb_vfs_call_aio_error_fn(struct vfs_handle_struct *handle,
-                             struct files_struct *fsp,
-                             SMB_STRUCT_AIOCB *aiocb)
+int smb_vfs_call_aio_error(struct vfs_handle_struct *handle,
+                          struct files_struct *fsp,
+                          SMB_STRUCT_AIOCB *aiocb)
 {
-       VFS_FIND(aio_error_fn);
+       VFS_FIND(aio_error);
        return handle->fns->aio_error_fn(handle, fsp, aiocb);
 }
 
@@ -1910,7 +2276,7 @@ int smb_vfs_call_aio_fsync(struct vfs_handle_struct *handle,
                           SMB_STRUCT_AIOCB *aiocb)
 {
        VFS_FIND(aio_fsync);
-       return handle->fns->aio_fsync(handle, fsp, op, aiocb);
+       return handle->fns->aio_fsync_fn(handle, fsp, op, aiocb);
 }
 
 int smb_vfs_call_aio_suspend(struct vfs_handle_struct *handle,
@@ -1919,26 +2285,27 @@ int smb_vfs_call_aio_suspend(struct vfs_handle_struct *handle,
                             const struct timespec *timeout)
 {
        VFS_FIND(aio_suspend);
-       return handle->fns->aio_suspend(handle, fsp, aiocb, n, timeout);
+       return handle->fns->aio_suspend_fn(handle, fsp, aiocb, n, timeout);
 }
 
 bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle,
                            struct files_struct *fsp)
 {
        VFS_FIND(aio_force);
-       return handle->fns->aio_force(handle, fsp);
+       return handle->fns->aio_force_fn(handle, fsp);
 }
 
 bool smb_vfs_call_is_offline(struct vfs_handle_struct *handle,
-                            const char *path, SMB_STRUCT_STAT *sbuf)
+                            const struct smb_filename *fname,
+                            SMB_STRUCT_STAT *sbuf)
 {
        VFS_FIND(is_offline);
-       return handle->fns->is_offline(handle, path, sbuf);
+       return handle->fns->is_offline_fn(handle, fname, sbuf);
 }
 
 int smb_vfs_call_set_offline(struct vfs_handle_struct *handle,
-                            const char *path)
+                             const struct smb_filename *fname)
 {
        VFS_FIND(set_offline);
-       return handle->fns->set_offline(handle, path);
+       return handle->fns->set_offline_fn(handle, fname);
 }