s3: VFS: Change SMB_VFS_SYMLINK to use const struct smb_filename * instead of const...
[sfrench/samba-autobuild/.git] / source3 / modules / vfs_cap.c
index c124592af934cadb662239fa0cc215c1bf2d8b65..c07a05954c0f233ea0ae519c4863b6a6314296f4 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,
@@ -451,52 +479,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)