summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2020-03-22 12:21:10 +0100
committerJeremy Allison <jra@samba.org>2020-03-24 19:48:41 +0000
commit38cce1bccbf482fae60d9f09fc33e299d7d4816d (patch)
tree45a21f27a2d302dd2e8984877990ea27626d169c /source3
parent974ea2ce349627732bfc683598d148da20a5b118 (diff)
downloadsamba-38cce1bccbf482fae60d9f09fc33e299d7d4816d.tar.gz
vfs_shadow_copy2: use create_internal_dirfsp_at() and SMB_VFS_FDOPENDIR()
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/modules/vfs_shadow_copy2.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c
index c9b8d80e7f4..4a049d71cd3 100644
--- a/source3/modules/vfs_shadow_copy2.c
+++ b/source3/modules/vfs_shadow_copy2.c
@@ -2027,16 +2027,19 @@ static int shadow_copy2_get_shadow_copy_data(
struct shadow_copy_data *shadow_copy2_data,
bool labels)
{
- DIR *p;
+ DIR *p = NULL;
const char *snapdir;
struct smb_filename *snapdir_smb_fname = NULL;
+ struct files_struct *dirfsp = NULL;
struct dirent *d;
TALLOC_CTX *tmp_ctx = talloc_stackframe();
struct shadow_copy2_private *priv = NULL;
struct shadow_copy2_snapentry *tmpentry = NULL;
bool get_snaplist = false;
bool access_granted = false;
+ int open_flags = O_RDONLY;
int ret = -1;
+ NTSTATUS status;
snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
if (snapdir == NULL) {
@@ -2063,8 +2066,34 @@ static int shadow_copy2_get_shadow_copy_data(
goto done;
}
- p = SMB_VFS_NEXT_OPENDIR(handle, snapdir_smb_fname, NULL, 0);
+ status = create_internal_dirfsp_at(handle->conn,
+ handle->conn->cwd_fsp,
+ snapdir_smb_fname,
+ &dirfsp);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_WARNING("create_internal_dir_fsp() failed for '%s'"
+ " - %s\n", snapdir, nt_errstr(status));
+ errno = ENOSYS;
+ goto done;
+ }
+
+#ifdef O_DIRECTORY
+ open_flags |= O_DIRECTORY;
+#endif
+ dirfsp->fh->fd = SMB_VFS_NEXT_OPEN(handle,
+ snapdir_smb_fname,
+ dirfsp,
+ open_flags,
+ 0);
+ if (dirfsp->fh->fd == -1) {
+ DBG_WARNING("SMB_VFS_NEXT_OPEN failed for '%s'"
+ " - %s\n", snapdir, strerror(errno));
+ errno = ENOSYS;
+ goto done;
+ }
+
+ p = SMB_VFS_NEXT_FDOPENDIR(handle, dirfsp, NULL, 0);
if (!p) {
DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
" - %s\n", snapdir, strerror(errno)));
@@ -2148,7 +2177,6 @@ static int shadow_copy2_get_shadow_copy_data(
shadow_copy2_data->num_volumes+1);
if (tlabels == NULL) {
DEBUG(0,("shadow_copy2: out of memory\n"));
- SMB_VFS_NEXT_CLOSEDIR(handle, p);
goto done;
}
@@ -2159,12 +2187,18 @@ static int shadow_copy2_get_shadow_copy_data(
shadow_copy2_data->labels = tlabels;
}
- SMB_VFS_NEXT_CLOSEDIR(handle,p);
-
shadow_copy2_sort_data(handle, shadow_copy2_data);
ret = 0;
done:
+ if (p != NULL) {
+ SMB_VFS_NEXT_CLOSEDIR(handle, p);
+ p = NULL;
+ }
+ if (dirfsp != NULL) {
+ fd_close(dirfsp);
+ file_free(NULL, dirfsp);
+ }
TALLOC_FREE(tmp_ctx);
return ret;
}