s3: VFS: vfs_xattr_tdb. Implement mkdirat().
authorJeremy Allison <jra@samba.org>
Thu, 5 Sep 2019 18:09:40 +0000 (11:09 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 11 Sep 2019 18:24:29 +0000 (18:24 +0000)
Currently identical to mkdir().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_xattr_tdb.c

index 037c40456323fdeefb50e76613413c2115b9762a..3841627b9049211e3f40795764b07eaaabdf1b3f 100644 (file)
@@ -586,6 +586,59 @@ static int xattr_tdb_mkdir(vfs_handle_struct *handle,
        return 0;
 }
 
+static int xattr_tdb_mkdirat(vfs_handle_struct *handle,
+               struct files_struct *dirfsp,
+               const struct smb_filename *smb_fname,
+               mode_t mode)
+{
+       struct db_context *db = NULL;
+       TALLOC_CTX *frame = NULL;
+       struct file_id fileid;
+       int ret;
+       struct smb_filename *smb_fname_tmp = NULL;
+
+       ret = SMB_VFS_NEXT_MKDIRAT(handle,
+                               dirfsp,
+                               smb_fname,
+                               mode);
+       if (ret < 0) {
+               return ret;
+       }
+
+       frame = talloc_stackframe();
+       smb_fname_tmp = cp_smb_filename(frame, smb_fname);
+       if (smb_fname_tmp == NULL) {
+               TALLOC_FREE(frame);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       /* Always use LSTAT here - we just creaded the directory. */
+       ret = SMB_VFS_LSTAT(handle->conn, smb_fname_tmp);
+       if (ret == -1) {
+               /* Rename race. Let upper level take care of it. */
+               TALLOC_FREE(frame);
+               return -1;
+       }
+       if (!S_ISDIR(smb_fname_tmp->st.st_ex_mode)) {
+               /* Rename race. Let upper level take care of it. */
+               TALLOC_FREE(frame);
+               return -1;
+       }
+
+       fileid = SMB_VFS_FILE_ID_CREATE(handle->conn, &smb_fname_tmp->st);
+
+       SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context,
+                               if (!xattr_tdb_init(-1, frame, &db))
+                               {
+                                       TALLOC_FREE(frame); return -1;
+                               });
+
+       xattr_tdb_remove_all_attrs(db, &fileid);
+       TALLOC_FREE(frame);
+       return 0;
+}
+
 /*
  * On unlink we need to delete the tdb record
  */
@@ -742,6 +795,7 @@ static struct vfs_fn_pointers vfs_xattr_tdb_fns = {
        .fremovexattr_fn = xattr_tdb_fremovexattr,
        .open_fn = xattr_tdb_open,
        .mkdir_fn = xattr_tdb_mkdir,
+       .mkdirat_fn = xattr_tdb_mkdirat,
        .unlink_fn = xattr_tdb_unlink,
        .rmdir_fn = xattr_tdb_rmdir,
        .connect_fn = xattr_tdb_connect,