s3: VFS: Change SMB_VFS_CHDIR to use const struct smb_filename * instead of const...
[sfrench/samba-autobuild/.git] / source3 / modules / vfs_cap.c
index 8d621ccec5e800ae9b9db29c87910f9bec5cee0a..44a81bbcefb6d4a9a08197ee469cbb3637d5fbe5 100644 (file)
 static char *capencode(TALLOC_CTX *ctx, const char *from);
 static char *capdecode(TALLOC_CTX *ctx, const char *from);
 
-static uint64_t cap_disk_free(vfs_handle_struct *handle, const char *path,
-                             uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
+static uint64_t cap_disk_free(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uint64_t *bsize,
+                       uint64_t *dfree,
+                       uint64_t *dsize)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       char *capname = capencode(talloc_tos(), smb_fname->base_name);
+       struct smb_filename *cap_smb_fname = NULL;
 
-       if (!cappath) {
+       if (!capname) {
+               errno = ENOMEM;
+               return (uint64_t)-1;
+       }
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       capname,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(capname);
                errno = ENOMEM;
                return (uint64_t)-1;
        }
-       return SMB_VFS_NEXT_DISK_FREE(handle, cappath, bsize, dfree, dsize);
+       return SMB_VFS_NEXT_DISK_FREE(handle, cap_smb_fname,
+                       bsize, dfree, dsize);
 }
 
-static int cap_get_quota(vfs_handle_struct *handle, const char *path,
-                        enum SMB_QUOTA_TYPE qtype, unid_t id,
-                        SMB_DISK_QUOTA *dq)
+static int cap_get_quota(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       enum SMB_QUOTA_TYPE qtype,
+                       unid_t id,
+                       SMB_DISK_QUOTA *dq)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
+       struct smb_filename *cap_smb_fname = NULL;
 
        if (!cappath) {
                errno = ENOMEM;
                return -1;
        }
-       return SMB_VFS_NEXT_GET_QUOTA(handle, cappath, qtype, id, dq);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               errno = ENOMEM;
+               return -1;
+       }
+       return SMB_VFS_NEXT_GET_QUOTA(handle, cap_smb_fname, qtype, id, dq);
 }
 
 static DIR *cap_opendir(vfs_handle_struct *handle,
@@ -408,16 +436,40 @@ static int cap_lchown(vfs_handle_struct *handle,
        return ret;
 }
 
-static int cap_chdir(vfs_handle_struct *handle, const char *path)
+static int cap_chdir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       struct smb_filename *cap_smb_fname = NULL;
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
+       int ret;
+       int saved_errno = 0;
 
        if (!cappath) {
                errno = ENOMEM;
                return -1;
        }
-       DEBUG(3,("cap: cap_chdir for %s\n", path));
-       return SMB_VFS_NEXT_CHDIR(handle, cappath);
+       DEBUG(3,("cap: cap_chdir for %s\n", smb_fname->base_name));
+
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_CHDIR(handle, cap_smb_fname);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(cap_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
 static int cap_ntimes(vfs_handle_struct *handle,
@@ -451,52 +503,168 @@ static int cap_ntimes(vfs_handle_struct *handle,
 }
 
 
-static int cap_symlink(vfs_handle_struct *handle, const char *oldpath,
-                      const char *newpath)
+static int cap_symlink(vfs_handle_struct *handle,
+                       const char *link_contents,
+                       const struct smb_filename *new_smb_fname)
 {
-       char *capold = capencode(talloc_tos(), oldpath);
-       char *capnew = capencode(talloc_tos(), newpath);
+       char *capold = capencode(talloc_tos(), link_contents);
+       char *capnew = capencode(talloc_tos(), new_smb_fname->base_name);
+       struct smb_filename *new_cap_smb_fname = NULL;
+       int saved_errno = 0;
+       int ret;
 
        if (!capold || !capnew) {
                errno = ENOMEM;
                return -1;
        }
-       return SMB_VFS_NEXT_SYMLINK(handle, capold, capnew);
+       new_cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       capnew,
+                                       NULL,
+                                       NULL,
+                                       new_smb_fname->flags);
+       if (new_cap_smb_fname == NULL) {
+               TALLOC_FREE(capold);
+               TALLOC_FREE(capnew);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_SYMLINK(handle,
+                       capold,
+                       new_cap_smb_fname);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(capold);
+       TALLOC_FREE(capnew);
+       TALLOC_FREE(new_cap_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
-static int cap_readlink(vfs_handle_struct *handle, const char *path,
-                       char *buf, size_t bufsiz)
+static int cap_readlink(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       char *buf,
+                       size_t bufsiz)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
+       struct smb_filename *cap_smb_fname = NULL;
+       int saved_errno = 0;
+       int ret;
 
        if (!cappath) {
                errno = ENOMEM;
                return -1;
        }
-       return SMB_VFS_NEXT_READLINK(handle, cappath, buf, bufsiz);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_READLINK(handle, cap_smb_fname, buf, bufsiz);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(cap_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
-static int cap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
+static int cap_link(vfs_handle_struct *handle,
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
-       char *capold = capencode(talloc_tos(), oldpath);
-       char *capnew = capencode(talloc_tos(), newpath);
+       char *capold = capencode(talloc_tos(), old_smb_fname->base_name);
+       char *capnew = capencode(talloc_tos(), new_smb_fname->base_name);
+       struct smb_filename *old_cap_smb_fname = NULL;
+       struct smb_filename *new_cap_smb_fname = NULL;
+       int saved_errno = 0;
+       int ret;
 
        if (!capold || !capnew) {
                errno = ENOMEM;
                return -1;
        }
-       return SMB_VFS_NEXT_LINK(handle, capold, capnew);
+       old_cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       capold,
+                                       NULL,
+                                       NULL,
+                                       old_smb_fname->flags);
+       if (old_cap_smb_fname == NULL) {
+               TALLOC_FREE(capold);
+               TALLOC_FREE(capnew);
+               errno = ENOMEM;
+               return -1;
+       }
+       new_cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       capnew,
+                                       NULL,
+                                       NULL,
+                                       new_smb_fname->flags);
+       if (new_cap_smb_fname == NULL) {
+               TALLOC_FREE(capold);
+               TALLOC_FREE(capnew);
+               TALLOC_FREE(old_cap_smb_fname);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_LINK(handle, old_cap_smb_fname, new_cap_smb_fname);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(capold);
+       TALLOC_FREE(capnew);
+       TALLOC_FREE(old_cap_smb_fname);
+       TALLOC_FREE(new_cap_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
-static int cap_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev)
+static int cap_mknod(vfs_handle_struct *handle,
+               const struct smb_filename *smb_fname,
+               mode_t mode,
+               SMB_DEV_T dev)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       struct smb_filename *cap_smb_fname = NULL;
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
+       int ret;
+       int saved_errno = 0;
 
        if (!cappath) {
                errno = ENOMEM;
                return -1;
        }
-       return SMB_VFS_NEXT_MKNOD(handle, cappath, mode, dev);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_MKNOD(handle, cap_smb_fname, mode, dev);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(cap_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
 static char *cap_realpath(vfs_handle_struct *handle, const char *path)
@@ -652,16 +820,45 @@ static int cap_sys_acl_delete_def_file(vfs_handle_struct *handle,
        return ret;
 }
 
-static ssize_t cap_getxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t size)
+static ssize_t cap_getxattr(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *name,
+                       void *value,
+                       size_t size)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       struct smb_filename *cap_smb_fname = NULL;
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
        char *capname = capencode(talloc_tos(), name);
+       ssize_t ret;
+       int saved_errno = 0;
 
        if (!cappath || !capname) {
                errno = ENOMEM;
                return -1;
        }
-        return SMB_VFS_NEXT_GETXATTR(handle, cappath, capname, value, size);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               TALLOC_FREE(capname);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_GETXATTR(handle, cap_smb_fname,
+                       capname, value, size);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(capname);
+       TALLOC_FREE(cap_smb_fname);
+       if (saved_errno) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
 static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path, void *value, size_t size)
@@ -675,27 +872,78 @@ static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp
         return SMB_VFS_NEXT_FGETXATTR(handle, fsp, cappath, value, size);
 }
 
-static ssize_t cap_listxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size)
+static ssize_t cap_listxattr(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               char *list,
+                               size_t size)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       struct smb_filename *cap_smb_fname = NULL;
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
+       ssize_t ret;
+       int saved_errno = 0;
 
        if (!cappath) {
                errno = ENOMEM;
                return -1;
        }
-        return SMB_VFS_NEXT_LISTXATTR(handle, cappath, list, size);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_LISTXATTR(handle, cap_smb_fname, list, size);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(cap_smb_fname);
+       if (saved_errno) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
-static int cap_removexattr(vfs_handle_struct *handle, const char *path, const char *name)
+static int cap_removexattr(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               const char *name)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       struct smb_filename *cap_smb_fname = NULL;
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
        char *capname = capencode(talloc_tos(), name);
+       int ret;
+       int saved_errno = 0;
 
        if (!cappath || !capname) {
                errno = ENOMEM;
                return -1;
        }
-        return SMB_VFS_NEXT_REMOVEXATTR(handle, cappath, capname);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               TALLOC_FREE(capname);
+               errno = ENOMEM;
+               return -1;
+       }
+        ret = SMB_VFS_NEXT_REMOVEXATTR(handle, cap_smb_fname, capname);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(capname);
+       TALLOC_FREE(cap_smb_fname);
+       if (saved_errno) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
 static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path)
@@ -709,16 +957,46 @@ static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp,
         return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, cappath);
 }
 
-static int cap_setxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
+static int cap_setxattr(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *name,
+                       const void *value,
+                       size_t size,
+                       int flags)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       struct smb_filename *cap_smb_fname = NULL;
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
        char *capname = capencode(talloc_tos(), name);
+       int ret;
+       int saved_errno = 0;
 
        if (!cappath || !capname) {
                errno = ENOMEM;
                return -1;
        }
-        return SMB_VFS_NEXT_SETXATTR(handle, cappath, capname, value, size, flags);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               TALLOC_FREE(capname);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_SETXATTR(handle, cap_smb_fname,
+                               capname, value, size, flags);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(capname);
+       TALLOC_FREE(cap_smb_fname);
+       if (saved_errno) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
 static int cap_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path, const void *value, size_t size, int flags)