s3:utils: let smbstatus report anonymous signing/encryption explicitly
[samba.git] / source3 / modules / vfs_posix_eadb.c
index e60c39a5e6a62ff6f6162965978963d4394d94cc..b3e21b09b8c3647e7c01dce27bce3b4d6f6ca1b9 100644 (file)
@@ -76,20 +76,6 @@ static ssize_t posix_eadb_getattr(struct tdb_wrap *db_ctx,
        return result;
 }
 
-static ssize_t posix_eadb_getxattr(struct vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname,
-                               const char *name,
-                               void *value,
-                               size_t size)
-{
-       struct tdb_wrap *db;
-
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
-
-       return posix_eadb_getattr(db, smb_fname->base_name,
-                       -1, name, value, size);
-}
-
 static ssize_t posix_eadb_fgetxattr(struct vfs_handle_struct *handle,
                                   struct files_struct *fsp,
                                   const char *name, void *value, size_t size)
@@ -98,7 +84,7 @@ static ssize_t posix_eadb_fgetxattr(struct vfs_handle_struct *handle,
 
        SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
 
-       return posix_eadb_getattr(db, fsp->fsp_name->base_name, fsp->fh->fd, name, value, size);
+       return posix_eadb_getattr(db, fsp->fsp_name->base_name, fsp_get_io_fd(fsp), name, value, size);
 }
 
 /*
@@ -126,21 +112,6 @@ static int posix_eadb_setattr(struct tdb_wrap *db_ctx,
        return 0;
 }
 
-static int posix_eadb_setxattr(struct vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname,
-                               const char *name,
-                               const void *value,
-                               size_t size,
-                               int flags)
-{
-       struct tdb_wrap *db;
-
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
-
-       return posix_eadb_setattr(db, smb_fname->base_name,
-                       -1, name, value, size, flags);
-}
-
 static int posix_eadb_fsetxattr(struct vfs_handle_struct *handle,
                               struct files_struct *fsp,
                               const char *name, const void *value,
@@ -150,7 +121,7 @@ static int posix_eadb_fsetxattr(struct vfs_handle_struct *handle,
 
        SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
 
-       return posix_eadb_setattr(db, fsp->fsp_name->base_name, fsp->fh->fd, name, value, size, flags);
+       return posix_eadb_setattr(db, fsp->fsp_name->base_name, fsp_get_io_fd(fsp), name, value, size, flags);
 }
 
 /*
@@ -185,18 +156,6 @@ static ssize_t posix_eadb_listattr(struct tdb_wrap *db_ctx,
        return blob.length;
 }
 
-static ssize_t posix_eadb_listxattr(struct vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname,
-                               char *list,
-                               size_t size)
-{
-       struct tdb_wrap *db;
-
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
-
-       return posix_eadb_listattr(db, smb_fname->base_name, -1, list, size);
-}
-
 static ssize_t posix_eadb_flistxattr(struct vfs_handle_struct *handle,
                                    struct files_struct *fsp, char *list,
                                    size_t size)
@@ -205,7 +164,7 @@ static ssize_t posix_eadb_flistxattr(struct vfs_handle_struct *handle,
 
        SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
 
-       return posix_eadb_listattr(db, fsp->fsp_name->base_name, fsp->fh->fd, list, size);
+       return posix_eadb_listattr(db, fsp->fsp_name->base_name, fsp_get_io_fd(fsp), list, size);
 }
 
 /*
@@ -227,17 +186,6 @@ static int posix_eadb_removeattr(struct tdb_wrap *db_ctx,
        return 0;
 }
 
-static int posix_eadb_removexattr(struct vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname,
-                               const char *name)
-{
-       struct tdb_wrap *db;
-
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
-
-       return posix_eadb_removeattr(db, smb_fname->base_name, -1, name);
-}
-
 static int posix_eadb_fremovexattr(struct vfs_handle_struct *handle,
                                  struct files_struct *fsp, const char *name)
 {
@@ -245,7 +193,7 @@ static int posix_eadb_fremovexattr(struct vfs_handle_struct *handle,
 
        SMB_VFS_HANDLE_GET_DATA(handle, db, struct tdb_wrap, return -1);
 
-       return posix_eadb_removeattr(db, fsp->fsp_name->base_name, fsp->fh->fd, name);
+       return posix_eadb_removeattr(db, fsp->fsp_name->base_name, fsp_get_io_fd(fsp), name);
 }
 
 /*
@@ -290,9 +238,12 @@ static bool posix_eadb_init(int snum, struct tdb_wrap **p_db)
 /*
  * On unlink we need to delete the tdb record
  */
-static int posix_eadb_unlink(vfs_handle_struct *handle,
-                           const struct smb_filename *smb_fname)
+static int posix_eadb_unlink_internal(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
+                       const struct smb_filename *smb_fname,
+                       int flags)
 {
+       struct smb_filename *full_fname = NULL;
        struct smb_filename *smb_fname_tmp = NULL;
        int ret = -1;
 
@@ -306,14 +257,26 @@ static int posix_eadb_unlink(vfs_handle_struct *handle,
                return -1;
        }
 
+       /*
+        * TODO: use SMB_VFS_STATX() once we have that.
+        */
+
+       full_fname = full_path_from_dirfsp_atname(talloc_tos(),
+                                                 dirfsp,
+                                                 smb_fname);
+       if (full_fname == NULL) {
+               goto out;
+       }
+
        if (smb_fname->flags & SMB_FILENAME_POSIX_PATH) {
-               ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_tmp);
+               ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
        } else {
-               ret = SMB_VFS_NEXT_STAT(handle, smb_fname_tmp);
+               ret = SMB_VFS_NEXT_STAT(handle, full_fname);
        }
        if (ret == -1) {
                goto out;
        }
+       smb_fname_tmp->st = full_fname->st;
 
        if (smb_fname_tmp->st.st_ex_nlink == 1) {
                NTSTATUS status;
@@ -325,7 +288,9 @@ static int posix_eadb_unlink(vfs_handle_struct *handle,
                        goto out;
                }
 
-               status = unlink_posix_eadb_raw(ea_tdb, smb_fname->base_name, -1);
+               status = unlink_posix_eadb_raw(ea_tdb,
+                                              full_fname->base_name,
+                                              -1);
                if (!NT_STATUS_IS_OK(status)) {
                        tdb_transaction_cancel(ea_tdb->tdb);
                        ret = -1;
@@ -333,7 +298,10 @@ static int posix_eadb_unlink(vfs_handle_struct *handle,
                }
        }
 
-       ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
+       ret = SMB_VFS_NEXT_UNLINKAT(handle,
+                       dirfsp,
+                       smb_fname_tmp,
+                       flags);
 
        if (ret == -1) {
                tdb_transaction_cancel(ea_tdb->tdb);
@@ -347,32 +315,46 @@ static int posix_eadb_unlink(vfs_handle_struct *handle,
 
 out:
        TALLOC_FREE(smb_fname_tmp);
+       TALLOC_FREE(full_fname);
        return ret;
 }
 
 /*
  * On rmdir we need to delete the tdb record
  */
-static int posix_eadb_rmdir(vfs_handle_struct *handle,
+static int posix_eadb_rmdir_internal(vfs_handle_struct *handle,
+                       struct files_struct *dirfsp,
                        const struct smb_filename *smb_fname)
 {
        NTSTATUS status;
        struct tdb_wrap *ea_tdb;
        int ret;
-       const char *path = smb_fname->base_name;
+       struct smb_filename *full_fname = NULL;
 
        SMB_VFS_HANDLE_GET_DATA(handle, ea_tdb, struct tdb_wrap, return -1);
 
+       full_fname = full_path_from_dirfsp_atname(talloc_tos(),
+                                                 dirfsp,
+                                                 smb_fname);
+       if (full_fname == NULL) {
+               return -1;
+       }
+
        if (tdb_transaction_start(ea_tdb->tdb) != 0) {
+               TALLOC_FREE(full_fname);
                return -1;
        }
 
-       status = unlink_posix_eadb_raw(ea_tdb, path, -1);
+       status = unlink_posix_eadb_raw(ea_tdb, full_fname->base_name, -1);
+       TALLOC_FREE(full_fname);
        if (!NT_STATUS_IS_OK(status)) {
                tdb_transaction_cancel(ea_tdb->tdb);
        }
 
-       ret = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
+       ret = SMB_VFS_NEXT_UNLINKAT(handle,
+                               dirfsp,
+                               smb_fname,
+                               AT_REMOVEDIR);
 
        if (ret == -1) {
                tdb_transaction_cancel(ea_tdb->tdb);
@@ -392,11 +374,15 @@ static int posix_eadb_unlinkat(vfs_handle_struct *handle,
 {
        int ret;
 
-       SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
        if (flags & AT_REMOVEDIR) {
-               ret = posix_eadb_rmdir(handle, smb_fname);
+               ret = posix_eadb_rmdir_internal(handle,
+                                       dirfsp,
+                                       smb_fname);
        } else {
-               ret = posix_eadb_unlink(handle, smb_fname);
+               ret = posix_eadb_unlink_internal(handle,
+                                       dirfsp,
+                                       smb_fname,
+                                       flags);
        }
        return ret;
 }
@@ -446,19 +432,13 @@ static int posix_eadb_connect(vfs_handle_struct *handle, const char *service,
 }
 
 static struct vfs_fn_pointers vfs_posix_eadb_fns = {
-       .getxattr_fn = posix_eadb_getxattr,
        .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
        .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
        .fgetxattr_fn = posix_eadb_fgetxattr,
-       .setxattr_fn = posix_eadb_setxattr,
        .fsetxattr_fn = posix_eadb_fsetxattr,
-       .listxattr_fn = posix_eadb_listxattr,
        .flistxattr_fn = posix_eadb_flistxattr,
-       .removexattr_fn = posix_eadb_removexattr,
        .fremovexattr_fn = posix_eadb_fremovexattr,
-       .unlink_fn = posix_eadb_unlink,
        .unlinkat_fn = posix_eadb_unlinkat,
-       .rmdir_fn = posix_eadb_rmdir,
        .connect_fn = posix_eadb_connect,
 };