s3: VFS: Add SMB_VFS_UNLINKAT().
authorJeremy Allison <jra@samba.org>
Wed, 11 Sep 2019 21:37:31 +0000 (14:37 -0700)
committerRalph Boehme <slow@samba.org>
Thu, 26 Sep 2019 17:20:44 +0000 (17:20 +0000)
Currently identical to SMB_VFS_UNLINK().

Next, add to all VFS modules that implement
unlink and eventually remove unlink.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/smbprofile.h
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_default.c
source3/modules/vfs_not_implemented.c
source3/smbd/vfs.c

index c03a42fee040b34b9849097effcad2c45738e1b8..2695b82ab45a6d762eb2f5b3b40dab754503b6e7 100644 (file)
@@ -351,6 +351,15 @@ static int skel_unlink(vfs_handle_struct *handle,
        return -1;
 }
 
+static int skel_unlinkat(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       int flags)
+{
+       errno = ENOSYS;
+       return -1;
+}
+
 static int skel_chmod(vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode)
@@ -1077,6 +1086,7 @@ static struct vfs_fn_pointers skel_opaque_fns = {
        .lstat_fn = skel_lstat,
        .get_alloc_size_fn = skel_get_alloc_size,
        .unlink_fn = skel_unlink,
+       .unlinkat_fn = skel_unlinkat,
        .chmod_fn = skel_chmod,
        .fchmod_fn = skel_fchmod,
        .chown_fn = skel_chown,
index 656c933338a901e994030bfcbd31321215feb41d..f760730400b69c8fa3c3df72a38794f7b39a5b06 100644 (file)
@@ -468,6 +468,17 @@ static int skel_unlink(vfs_handle_struct *handle,
        return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
 }
 
+static int skel_unlinkat(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       int flags)
+{
+       return SMB_VFS_NEXT_UNLINKAT(handle,
+                       dirfsp,
+                       smb_fname,
+                       flags);
+}
+
 static int skel_chmod(vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode)
@@ -1362,6 +1373,7 @@ static struct vfs_fn_pointers skel_transparent_fns = {
        .lstat_fn = skel_lstat,
        .get_alloc_size_fn = skel_get_alloc_size,
        .unlink_fn = skel_unlink,
+       .unlinkat_fn = skel_unlinkat,
        .chmod_fn = skel_chmod,
        .fchmod_fn = skel_fchmod,
        .chown_fn = skel_chown,
index 489a613e3df948c89f9b3e1a7e5d20bea0db1bae..cc54669c77216400c2172ca8d9bdb87b0430ed78 100644 (file)
@@ -68,6 +68,7 @@ struct tevent_context;
        SMBPROFILE_STATS_BASIC(syscall_lstat) \
        SMBPROFILE_STATS_BASIC(syscall_get_alloc_size) \
        SMBPROFILE_STATS_BASIC(syscall_unlink) \
+       SMBPROFILE_STATS_BASIC(syscall_unlinkat) \
        SMBPROFILE_STATS_BASIC(syscall_chmod) \
        SMBPROFILE_STATS_BASIC(syscall_fchmod) \
        SMBPROFILE_STATS_BASIC(syscall_chown) \
index 47147821ffd365408924c65d55c444eb8a1a5663..883989c82ad988ba0610338826ca4c6ab3bb7baf 100644 (file)
 /* Version 42 - Move change_to_user() -> change_to_user_and_service() */
 /* Version 42 - Move change_to_user_by_fsp() -> change_to_user_and_service_by_fsp() */
 /* Version 42 - Move [un]become_user*() -> [un]become_user_without_service*() */
+/* Version 42 - Add SMB_VFS_UNLINKAT. */
 
 #define SMB_VFS_INTERFACE_VERSION 42
 
@@ -778,6 +779,10 @@ struct vfs_fn_pointers {
        uint64_t (*get_alloc_size_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_STAT *sbuf);
        int (*unlink_fn)(struct vfs_handle_struct *handle,
                         const struct smb_filename *smb_fname);
+       int (*unlinkat_fn)(struct vfs_handle_struct *handle,
+                       struct files_struct *srcdir_fsp,
+                       const struct smb_filename *smb_fname,
+                       int flags);
        int (*chmod_fn)(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode);
@@ -1305,6 +1310,10 @@ uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
                                     const SMB_STRUCT_STAT *sbuf);
 int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname);
+int smb_vfs_call_unlinkat(struct vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       int flags);
 int smb_vfs_call_chmod(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode);
@@ -1742,6 +1751,10 @@ uint64_t vfs_not_implemented_get_alloc_size(struct vfs_handle_struct *handle,
                                            const SMB_STRUCT_STAT *sbuf);
 int vfs_not_implemented_unlink(vfs_handle_struct *handle,
                               const struct smb_filename *smb_fname);
+int vfs_not_implemented_unlinkat(vfs_handle_struct *handle,
+                               struct files_struct *dirfsp,
+                               const struct smb_filename *smb_fname,
+                               int flags);
 int vfs_not_implemented_chmod(vfs_handle_struct *handle,
                              const struct smb_filename *smb_fname,
                              mode_t mode);
index 6d95d840e256094190b52eea4dac5d033ab3e3f4..055555a4b07ef6d009d24382e583ffb0c40b2294 100644 (file)
 #define SMB_VFS_NEXT_UNLINK(handle, path) \
        smb_vfs_call_unlink((handle)->next, (path))
 
+#define SMB_VFS_UNLINKAT(conn, dirfsp, path, flags) \
+       smb_vfs_call_unlinkat((conn)->vfs_handles, (dirfsp), (path), (flags))
+#define SMB_VFS_NEXT_UNLINKAT(handle, dirfsp, path, flags) \
+       smb_vfs_call_unlinkat((handle)->next, (dirfsp), (path), (flags))
+
 #define SMB_VFS_CHMOD(conn, smb_fname, mode) \
        smb_vfs_call_chmod((conn)->vfs_handles, (smb_fname), (mode))
 #define SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode) \
index f48a590e5e704be4eed9ccfe57cb6d8bbafae053..de6d7892d5e22e8ce6785f777bfc96980b4d6426 100644 (file)
@@ -2222,6 +2222,30 @@ static int vfswrap_unlink(vfs_handle_struct *handle,
        return result;
 }
 
+static int vfswrap_unlinkat(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       int flags)
+{
+       int result = -1;
+
+       START_PROFILE(syscall_unlinkat);
+
+       SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
+
+       if (smb_fname->stream_name) {
+               errno = ENOENT;
+               goto out;
+       }
+       result = unlinkat(dirfsp->fh->fd,
+                       smb_fname->base_name,
+                       flags);
+
+ out:
+       END_PROFILE(syscall_unlinkat);
+       return result;
+}
+
 static int vfswrap_chmod(vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode)
@@ -3488,6 +3512,7 @@ static struct vfs_fn_pointers vfs_default_fns = {
        .lstat_fn = vfswrap_lstat,
        .get_alloc_size_fn = vfswrap_get_alloc_size,
        .unlink_fn = vfswrap_unlink,
+       .unlinkat_fn = vfswrap_unlinkat,
        .chmod_fn = vfswrap_chmod,
        .fchmod_fn = vfswrap_fchmod,
        .chown_fn = vfswrap_chown,
index e0f36b9a6324e69d9b2467b747723f53b08ef0a9..0c7a8e686f0a8e90bdb1cae7b9a443b54ee76268 100644 (file)
@@ -349,6 +349,15 @@ int vfs_not_implemented_unlink(vfs_handle_struct *handle,
        return -1;
 }
 
+int vfs_not_implemented_unlinkat(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       int flags)
+{
+       errno = ENOSYS;
+       return -1;
+}
+
 int vfs_not_implemented_chmod(vfs_handle_struct *handle,
                              const struct smb_filename *smb_fname,
                              mode_t mode)
@@ -1081,6 +1090,7 @@ static struct vfs_fn_pointers vfs_not_implemented_fns = {
        .lstat_fn = vfs_not_implemented_lstat,
        .get_alloc_size_fn = vfs_not_implemented_get_alloc_size,
        .unlink_fn = vfs_not_implemented_unlink,
+       .unlinkat_fn = vfs_not_implemented_unlinkat,
        .chmod_fn = vfs_not_implemented_chmod,
        .fchmod_fn = vfs_not_implemented_fchmod,
        .chown_fn = vfs_not_implemented_chown,
index 20f3d34965f70c90e5f5d2e9bfa6b6daaa95a885..4a0c375e48e9d05b5cb3f604c6ec4f8745ad2ccd 100644 (file)
@@ -1981,6 +1981,18 @@ int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
        return handle->fns->unlink_fn(handle, smb_fname);
 }
 
+int smb_vfs_call_unlinkat(struct vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       int flags)
+{
+       VFS_FIND(unlinkat);
+       return handle->fns->unlinkat_fn(handle,
+                       dirfsp,
+                       smb_fname,
+                       flags);
+}
+
 int smb_vfs_call_chmod(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode)