s3: VFS: Add SMB_VFS_MKDIRAT().
authorJeremy Allison <jra@samba.org>
Wed, 4 Sep 2019 19:20:46 +0000 (12:20 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 11 Sep 2019 18:24:28 +0000 (18:24 +0000)
Currently identical to SMB_VFS_MKDIR().

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

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 5a18268e6f47a5c21143e3c54db7347e82e85d5d..a4bfe81966b6fc9d5e3d46e428523da8041e08a2 100644 (file)
@@ -173,6 +173,15 @@ static int skel_mkdir(vfs_handle_struct *handle,
        return -1;
 }
 
+static int skel_mkdirat(vfs_handle_struct *handle,
+               struct files_struct *dirfsp,
+               const struct smb_filename *smb_fname,
+               mode_t mode)
+{
+       errno = ENOSYS;
+       return -1;
+}
+
 static int skel_rmdir(vfs_handle_struct *handle,
                const struct smb_filename *smb_fname)
 {
@@ -1051,6 +1060,7 @@ static struct vfs_fn_pointers skel_opaque_fns = {
        .telldir_fn = skel_telldir,
        .rewind_dir_fn = skel_rewind_dir,
        .mkdir_fn = skel_mkdir,
+       .mkdirat_fn = skel_mkdirat,
        .rmdir_fn = skel_rmdir,
        .closedir_fn = skel_closedir,
 
index 654c0e6ca851d816e8e0cca028f2ba372cb9c2cf..b827d2ff77cc160e695fcd4c41dfa94427d667f4 100644 (file)
@@ -171,6 +171,17 @@ static int skel_mkdir(vfs_handle_struct *handle,
        return SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
 }
 
+static int skel_mkdirat(vfs_handle_struct *handle,
+               struct files_struct *dirfsp,
+               const struct smb_filename *smb_fname,
+               mode_t mode)
+{
+       return SMB_VFS_NEXT_MKDIRAT(handle,
+                       dirfsp,
+                       smb_fname,
+                       mode);
+}
+
 static int skel_rmdir(vfs_handle_struct *handle,
                const struct smb_filename *smb_fname)
 {
@@ -1333,6 +1344,7 @@ static struct vfs_fn_pointers skel_transparent_fns = {
        .telldir_fn = skel_telldir,
        .rewind_dir_fn = skel_rewind_dir,
        .mkdir_fn = skel_mkdir,
+       .mkdirat_fn = skel_mkdirat,
        .rmdir_fn = skel_rmdir,
        .closedir_fn = skel_closedir,
 
index fc8945b8bc8b4c661927148e8a655e463248a395..e1b933ea2dda1d86ed8bc665c3ff36b078ddfa65 100644 (file)
@@ -49,6 +49,7 @@ struct tevent_context;
        SMBPROFILE_STATS_BASIC(syscall_telldir) \
        SMBPROFILE_STATS_BASIC(syscall_rewinddir) \
        SMBPROFILE_STATS_BASIC(syscall_mkdir) \
+       SMBPROFILE_STATS_BASIC(syscall_mkdirat) \
        SMBPROFILE_STATS_BASIC(syscall_rmdir) \
        SMBPROFILE_STATS_BASIC(syscall_closedir) \
        SMBPROFILE_STATS_BASIC(syscall_open) \
index 6c741e09919cc14df9ca59d9ef7950bb856cb624..9ecc0e554970891dba5b3f440e8ea717b9172f76 100644 (file)
 /* Version 42 - Move SMB_VFS_MKNOD -> SMB_VFS_MKDNODAT. */
 /* Version 42 - Move SMB_VFS_READLINK -> SMB_VFS_READLINKAT. */
 /* Version 42 - Move SMB_VFS_SYMLINK -> SMB_VFS_SYMLINKAT. */
+/* Version 42 - Add SMB_VFS_MKDIRAT. */
 
 #define SMB_VFS_INTERFACE_VERSION 42
 
@@ -701,6 +702,10 @@ struct vfs_fn_pointers {
        int (*mkdir_fn)(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode);
+       int (*mkdirat_fn)(struct vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode);
        int (*rmdir_fn)(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname);
        int (*closedir_fn)(struct vfs_handle_struct *handle, DIR *dir);
@@ -1208,6 +1213,10 @@ void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
 int smb_vfs_call_mkdir(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode);
+int smb_vfs_call_mkdirat(struct vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode);
 int smb_vfs_call_rmdir(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname);
 int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
@@ -1655,6 +1664,10 @@ void vfs_not_implemented_rewind_dir(vfs_handle_struct *handle, DIR *dirp);
 int vfs_not_implemented_mkdir(vfs_handle_struct *handle,
                const struct smb_filename *smb_fname,
                mode_t mode);
+int vfs_not_implemented_mkdirat(vfs_handle_struct *handle,
+               struct files_struct *dirfsp,
+               const struct smb_filename *smb_fname,
+               mode_t mode);
 int vfs_not_implemented_rmdir(vfs_handle_struct *handle,
                const struct smb_filename *smb_fname);
 int vfs_not_implemented_closedir(vfs_handle_struct *handle, DIR *dir);
index c43a7e5a4b539aada81921c1fc73a63465f9abfd..a093a08ee118b7538e1994b7a8b6a2ff5b444363 100644 (file)
 #define SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode) \
        smb_vfs_call_mkdir((handle)->next,(smb_fname), (mode))
 
+#define SMB_VFS_MKDIRAT(conn, dirfsp, smb_fname, mode) \
+       smb_vfs_call_mkdirat((conn)->vfs_handles,(dirfsp), (smb_fname), (mode))
+#define SMB_VFS_NEXT_MKDIRAT(handle, dirfsp, smb_fname, mode) \
+       smb_vfs_call_mkdirat((handle)->next,(dirfsp), (smb_fname), (mode))
+
 #define SMB_VFS_RMDIR(conn, smb_fname) \
        smb_vfs_call_rmdir((conn)->vfs_handles, (smb_fname))
 #define SMB_VFS_NEXT_RMDIR(handle, smb_fname) \
index bb7eba40df930907fdd0c6bd4b5598dcc69932d1..2e353e5da75c324a7fa8b59462dce07a56e7b6ad 100644 (file)
@@ -517,6 +517,33 @@ static int vfswrap_mkdir(vfs_handle_struct *handle,
        return result;
 }
 
+static int vfswrap_mkdirat(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
+{
+       int result;
+       const char *path = smb_fname->base_name;
+       char *parent = NULL;
+
+       START_PROFILE(syscall_mkdirat);
+
+       SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
+
+       if (lp_inherit_acls(SNUM(handle->conn))
+           && parent_dirname(talloc_tos(), path, &parent, NULL)
+           && directory_has_default_acl(handle->conn, parent)) {
+               mode = (0777 & lp_directory_mask(SNUM(handle->conn)));
+       }
+
+       TALLOC_FREE(parent);
+
+       result = mkdirat(dirfsp->fh->fd, path, mode);
+
+       END_PROFILE(syscall_mkdirat);
+       return result;
+}
+
 static int vfswrap_rmdir(vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname)
 {
@@ -3460,6 +3487,7 @@ static struct vfs_fn_pointers vfs_default_fns = {
        .telldir_fn = vfswrap_telldir,
        .rewind_dir_fn = vfswrap_rewinddir,
        .mkdir_fn = vfswrap_mkdir,
+       .mkdirat_fn = vfswrap_mkdirat,
        .rmdir_fn = vfswrap_rmdir,
        .closedir_fn = vfswrap_closedir,
 
index 6009abd8d7e2765d80999d1ef164c9b883c58430..9fa143a6729543be494e20274acbc7576450c07e 100644 (file)
@@ -170,6 +170,15 @@ int vfs_not_implemented_mkdir(vfs_handle_struct *handle,
        return -1;
 }
 
+int vfs_not_implemented_mkdirat(vfs_handle_struct *handle,
+               struct files_struct *dirfsp,
+               const struct smb_filename *smb_fname,
+               mode_t mode)
+{
+       errno = ENOSYS;
+       return -1;
+}
+
 int vfs_not_implemented_rmdir(vfs_handle_struct *handle,
                const struct smb_filename *smb_fname)
 {
@@ -1055,6 +1064,7 @@ static struct vfs_fn_pointers vfs_not_implemented_fns = {
        .telldir_fn = vfs_not_implemented_telldir,
        .rewind_dir_fn = vfs_not_implemented_rewind_dir,
        .mkdir_fn = vfs_not_implemented_mkdir,
+       .mkdirat_fn = vfs_not_implemented_mkdirat,
        .rmdir_fn = vfs_not_implemented_rmdir,
        .closedir_fn = vfs_not_implemented_closedir,
 
index a131b3303d581fb072c5d85d454fae88dc76e3a0..836fcf41e6576d474e9a48ec27e2fb4f652297ef 100644 (file)
@@ -1588,6 +1588,18 @@ int smb_vfs_call_mkdir(struct vfs_handle_struct *handle,
        return handle->fns->mkdir_fn(handle, smb_fname, mode);
 }
 
+int smb_vfs_call_mkdirat(struct vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
+{
+       VFS_FIND(mkdirat);
+       return handle->fns->mkdirat_fn(handle,
+                       dirfsp,
+                       smb_fname,
+                       mode);
+}
+
 int smb_vfs_call_rmdir(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname)
 {