[SCM] Samba Shared Repository - branch master updated

Noel Power npower at samba.org
Tue Jun 22 14:35:01 UTC 2021


The branch, master has been updated
       via  fb665462b17 s3: VFS: Update status of SMB_VFS_RENAMEAT.
       via  5059d37f1f5 s3: smbd: Make SMB_VFS_RENAMEAT() a relative call.
       via  ab01a36d4a3 s3: VFS: streams_xattr: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  e5274ecdb60 s3: VFS: streams_depot: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  395cee80e91 s3: VFS: unityed_media: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  a2f3c4f5ed2 s3: VFS: time_audit: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  c04d6e8464f s3: VFS: syncops: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  11ec689c1d8 s3: VFS: virusfilter: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  2c5ead7fd61 s3: VFS: media_harmony: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  69f38589044 s3: VFS: glusterfs: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  f02f55e84d5 s3: VFS: full_audit.c: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  770357f666f s3: VFS: extd_audit: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  5235ffea593 s3: VFS: ceph: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  a9832db6ac0 s3: VFS: cap: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  7785da8dde5 s3: VFS: audit: Use real dirfsp for SMB_VFS_RENAMEAT()
       via  5c18f074be9 s3: VFS: crossrename. Use real dirfsp for SMB_VFS_RENAMEAT()
       via  bb8e66cd2dc s3: smbd: Make copy_internals() public. vfs_crossrename() will be changed to use this.
       via  abc210943d8 s3: VFS: syncops. Do early return in syncops_renameat().
       via  d76abb32239 s3: VFS: syncops. Do early return in syncops_linkat()
       via  5da0d75dd47 s3: VFS: syncops: Do early returns in SYNCOPS_NEXT_SMB_FNAME() macro.
       via  fbeefe3b7e6 s3: VFS: syncops: Remove direct system calls and use OpenDir()/smb_vfs_fsync_sync()/TALLOC_FREE() to sync a directory.
       via  6d1972b79ea s3: VFS: syncops: Add 'connection_struct *conn' to syncops_sync_directory().
       via  1687df4d07a s3: VFS: Add 'connection_struct *conn' parameter to syncops_two_names().
       via  8848ebf504f s3: VFS: syncops. Add 'connection_struct *conn' to syncops_smb_fname().
       via  ec0c271071e s3: lib: In adouble_path(), if the parent directory name is ".", don't prepend "./" to the outgoing filename.
       via  c04df97ee52 s3: VFS: Cleanup. Remove SMB_VFS_FSYNC() macro.
      from  002ef728bb0 torture: Fix build on freebsd, missing deps on cmdline

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit fb665462b1739f3bda8b9f02f34144e856d70eed
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jun 18 11:43:30 2021 -0700

    s3: VFS: Update status of SMB_VFS_RENAMEAT.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>
    
    Autobuild-User(master): Noel Power <npower at samba.org>
    Autobuild-Date(master): Tue Jun 22 14:34:06 UTC 2021 on sn-devel-184

commit 5059d37f1f58e648c7fbf11fa1bb6f0bd3ae65d7
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jun 18 11:41:22 2021 -0700

    s3: smbd: Make SMB_VFS_RENAMEAT() a relative call.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit ab01a36d4a34a5b2112392b45d679e958aab5faf
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 21:36:33 2021 -0700

    s3: VFS: streams_xattr: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit e5274ecdb60cff9ec947a9a196891ef089bbeadd
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 21:05:00 2021 -0700

    s3: VFS: streams_depot: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 395cee80e916e39f65022b7a06557339e7bc7c7c
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 20:58:37 2021 -0700

    s3: VFS: unityed_media: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit a2f3c4f5ed2d16e34e034a92b5fabb769ad46c04
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 20:52:19 2021 -0700

    s3: VFS: time_audit: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit c04d6e8464f6db634e74de720433794e9ae19e8d
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 12:28:30 2021 -0700

    s3: VFS: syncops: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 11ec689c1d8ade1fbe42117d51c6893bdedcbd7a
Author: Noel Power <noel.power at suse.com>
Date:   Thu Jun 17 11:29:17 2021 -0700

    s3: VFS: virusfilter: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2c5ead7fd615843c3957751d8d1acedbdc1ec9e1
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 10:47:42 2021 -0700

    s3: VFS: media_harmony: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 69f3858904456f0e8490eab9df87385373973e64
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 10:37:12 2021 -0700

    s3: VFS: glusterfs: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit f02f55e84d577a6712433a39aeca504b7411a4a4
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 09:44:38 2021 -0700

    s3: VFS: full_audit.c: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 770357f666fe1f6a18742cbad45ce0058fa85063
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 16 21:05:31 2021 -0700

    s3: VFS: extd_audit: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 5235ffea593469d746213ed1ed42f7930f7b1f57
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 16 19:58:56 2021 -0700

    s3: VFS: ceph: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit a9832db6ac07916b91a10e4f3db52426a5ef1bd8
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 16 17:52:07 2021 -0700

    s3: VFS: cap: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 7785da8dde5c103cf548810fe6781e341f38de68
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 16 19:54:46 2021 -0700

    s3: VFS: audit: Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 5c18f074be92beea8357a93d64e7118376255ac0
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 16 21:01:33 2021 -0700

    s3: VFS: crossrename. Use real dirfsp for SMB_VFS_RENAMEAT()
    
    Finally fix the promise from the docs that this module is stackable. Re-use copy_internals().
    
    This is a horrible module that must be removed !
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit bb8e66cd2dc2af6b666370cb7b4ff9cc33a3afcd
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 09:54:58 2021 -0700

    s3: smbd: Make copy_internals() public. vfs_crossrename() will be changed to use this.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit abc210943d8d29bff10eaa78bb60de6a05f297ba
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 12:16:58 2021 -0700

    s3: VFS: syncops. Do early return in syncops_renameat().
    
    Makes the code path clearer.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit d76abb322390609766b6463e64ff83289f8361c0
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 12:31:19 2021 -0700

    s3: VFS: syncops. Do early return in syncops_linkat()
    
    We should always do the operation first, then try the sync.
    Failure to sync is not reported as an error, so failure
    to create the full_fnames shouldn't fail the operation either.
    
    Makes the code path clearer.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 5da0d75dd47e2e4e44663fc75b0b7df27b261ee8
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 12:23:46 2021 -0700

    s3: VFS: syncops: Do early returns in SYNCOPS_NEXT_SMB_FNAME() macro.
    
    Makes the macro much clearer.
    
    We should always do the operation first, then try the sync.
    Failure to sync is not reported as an error, so failure
    to create the full_fname shouldn't fail the operation either.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit fbeefe3b7e66df7212a407f601163d9b5e81480e
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 12:10:16 2021 -0700

    s3: VFS: syncops: Remove direct system calls and use OpenDir()/smb_vfs_fsync_sync()/TALLOC_FREE() to sync a directory.
    
    syncops is now *really* stackable.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 6d1972b79ea30944859e7bef57bf5b53516967d2
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 12:01:48 2021 -0700

    s3: VFS: syncops: Add 'connection_struct *conn' to syncops_sync_directory().
    
    Remove 'const' from 'char *dname' parameter. This is always a talloc
    allocated pointer.
    
    Not yet used. This will allow us to make syncops really stackable later.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 1687df4d07a9037e3cf4b23daad8626eef0267da
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 11:58:54 2021 -0700

    s3: VFS: Add 'connection_struct *conn' parameter to syncops_two_names().
    
    Not yet used. This will allow us to make syncops really stackable later.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit 8848ebf504f08dfe9a81af233b0909f92a411075
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 11:55:50 2021 -0700

    s3: VFS: syncops. Add 'connection_struct *conn' to syncops_smb_fname().
    
    Not yet used. This will allow us to make syncops really stackable later.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

commit ec0c271071ec053a29337eac13325a2793ba950a
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jun 16 21:10:55 2021 -0700

    s3: lib: In adouble_path(), if the parent directory name is ".", don't prepend "./" to the outgoing filename.
    
    We expect smb_fname->base_name values to not contain "./name".
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit c04df97ee52d8fae4b4438a6634d7ed10320a9f3
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jun 17 10:57:27 2021 -0700

    s3: VFS: Cleanup. Remove SMB_VFS_FSYNC() macro.
    
    This hasn't been used since bc71cd035c816de4ca98002860496bf8f5d50fe3.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Noel Power <npower at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/include/vfs_macros.h        |   5 -
 source3/lib/adouble.c               |   7 +-
 source3/modules/The_New_VFS.org     |   2 +-
 source3/modules/The_New_VFS.txt     |   2 +-
 source3/modules/vfs_audit.c         |  32 +++++-
 source3/modules/vfs_cap.c           |  42 ++++++--
 source3/modules/vfs_ceph.c          |  28 +++++-
 source3/modules/vfs_crossrename.c   | 195 ++++++++++++++++--------------------
 source3/modules/vfs_extd_audit.c    |  42 ++++++--
 source3/modules/vfs_full_audit.c    |  32 +++++-
 source3/modules/vfs_glusterfs.c     |  27 ++++-
 source3/modules/vfs_media_harmony.c |  43 +++++---
 source3/modules/vfs_streams_depot.c |  33 +++++-
 source3/modules/vfs_streams_xattr.c |  89 +++++++++++-----
 source3/modules/vfs_syncops.c       | 141 ++++++++++++++++++--------
 source3/modules/vfs_time_audit.c    |  13 ++-
 source3/modules/vfs_unityed_media.c |  42 ++++++--
 source3/modules/vfs_virusfilter.c   |  33 +++++-
 source3/smbd/nttrans.c              |  12 +--
 source3/smbd/proto.h                |   6 ++
 source3/smbd/reply.c                |  98 +++++++++++++++++-
 21 files changed, 673 insertions(+), 251 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h
index c5c7a993ac8..2d2aa206c2e 100644
--- a/source3/include/vfs_macros.h
+++ b/source3/include/vfs_macros.h
@@ -207,11 +207,6 @@
 #define SMB_VFS_NEXT_RENAMEAT(handle, oldfsp, old, newfsp, new) \
 	smb_vfs_call_renameat((handle)->next, (oldfsp), (old), (newfsp), (new))
 
-#define SMB_VFS_FSYNC(fsp) \
-	smb_vfs_call_fsync((fsp)->conn->vfs_handles, (fsp))
-#define SMB_VFS_NEXT_FSYNC(handle, fsp) \
-	smb_vfs_call_fsync((handle)->next, (fsp))
-
 #define SMB_VFS_FSYNC_SEND(mem_ctx, ev, fsp) \
 	smb_vfs_call_fsync_send((fsp)->conn->vfs_handles, (mem_ctx), (ev), \
 				(fsp))
diff --git a/source3/lib/adouble.c b/source3/lib/adouble.c
index bfbdb3f9709..3dcabeb5739 100644
--- a/source3/lib/adouble.c
+++ b/source3/lib/adouble.c
@@ -2717,8 +2717,13 @@ int adouble_path(TALLOC_CTX *ctx,
 		return -1;
 	}
 
-	smb_fname->base_name = talloc_asprintf(smb_fname,
+	if (ISDOT(parent)) {
+		smb_fname->base_name = talloc_asprintf(smb_fname,
+					"._%s", base);
+	} else {
+		smb_fname->base_name = talloc_asprintf(smb_fname,
 					"%s/._%s", parent, base);
+	}
 	if (smb_fname->base_name == NULL) {
 		TALLOC_FREE(smb_fname);
 		return -1;
diff --git a/source3/modules/The_New_VFS.org b/source3/modules/The_New_VFS.org
index 799db6be0bf..12eed5ba9a0 100644
--- a/source3/modules/The_New_VFS.org
+++ b/source3/modules/The_New_VFS.org
@@ -277,7 +277,7 @@ whenever VFS access is done in a piecemeal fashion.
 | SMB_VFS_REALPATH()                | [[P2px][P2px]]     | -      |
 | SMB_VFS_RECVFILE()                | [[fsp][fsp]]      | -      |
 | SMB_VFS_REMOVEXATTR()             | [[Path][Path]]     | -      |
-| SMB_VFS_RENAMEAT()                | [[Path][Path]]     | Todo   |
+| SMB_VFS_RENAMEAT()                | [[Path][Path]]     | ----   |
 | SMB_VFS_REWINDDIR()               | [[fsp][fsp]]      | -      |
 | SMB_VFS_SEEKDIR()                 | [[fsp][fsp]]      | -      |
 | SMB_VFS_SENDFILE()                | [[fsp][fsp]]      | -      |
diff --git a/source3/modules/The_New_VFS.txt b/source3/modules/The_New_VFS.txt
index f407c44ac6d..b3da1a3c97e 100644
--- a/source3/modules/The_New_VFS.txt
+++ b/source3/modules/The_New_VFS.txt
@@ -345,7 +345,7 @@ Table of Contents
    SMB_VFS_REALPATH()                 [P2px]      -
    SMB_VFS_RECVFILE()                 [fsp]       -
    SMB_VFS_REMOVEXATTR()              [Path]      -
-   SMB_VFS_RENAMEAT()                 [Path]      Todo
+   SMB_VFS_RENAMEAT()                 [Path]      -
    SMB_VFS_REWINDDIR()                [fsp]       -
    SMB_VFS_SEEKDIR()                  [fsp]       -
    SMB_VFS_SENDFILE()                 [fsp]       -
diff --git a/source3/modules/vfs_audit.c b/source3/modules/vfs_audit.c
index 2b0171b9c09..91fbd8c19ba 100644
--- a/source3/modules/vfs_audit.c
+++ b/source3/modules/vfs_audit.c
@@ -248,20 +248,48 @@ static int audit_renameat(vfs_handle_struct *handle,
 			files_struct *dstfsp,
 			const struct smb_filename *smb_fname_dst)
 {
+	struct smb_filename *full_fname_src = NULL;
+	struct smb_filename *full_fname_dst = NULL;
 	int result;
+	int saved_errno = 0;
 
+	full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
+						  srcfsp,
+						  smb_fname_src);
+	if (full_fname_src == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
+	full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
+						  dstfsp,
+						  smb_fname_dst);
+	if (full_fname_dst == NULL) {
+		TALLOC_FREE(full_fname_src);
+		errno = ENOMEM;
+		return -1;
+	}
 	result = SMB_VFS_NEXT_RENAMEAT(handle,
 			srcfsp,
 			smb_fname_src,
 			dstfsp,
 			smb_fname_dst);
+	if (result == -1) {
+		saved_errno = errno;
+	}
 
 	syslog(audit_syslog_priority(handle), "renameat %s -> %s %s%s\n",
-	       smb_fname_src->base_name,
-	       smb_fname_dst->base_name,
+	       full_fname_src->base_name,
+	       full_fname_dst->base_name,
 	       (result < 0) ? "failed: " : "",
 	       (result < 0) ? strerror(errno) : "");
 
+	TALLOC_FREE(full_fname_src);
+	TALLOC_FREE(full_fname_dst);
+
+	if (saved_errno != 0) {
+		errno = saved_errno;
+	}
+
 	return result;
 }
 
diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c
index 27805858530..3bb3d5d9d5e 100644
--- a/source3/modules/vfs_cap.c
+++ b/source3/modules/vfs_cap.c
@@ -203,22 +203,41 @@ static int cap_renameat(vfs_handle_struct *handle,
 	char *capnew = NULL;
 	struct smb_filename *smb_fname_src_tmp = NULL;
 	struct smb_filename *smb_fname_dst_tmp = NULL;
+	struct smb_filename *full_fname_src = NULL;
+	struct smb_filename *full_fname_dst = NULL;
 	int ret = -1;
+	int saved_errno = 0;
+
+	full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
+						  srcfsp,
+						  smb_fname_src);
+	if (full_fname_src == NULL) {
+		errno = ENOMEM;
+		goto out;
+	}
+
+	full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
+						  dstfsp,
+						  smb_fname_dst);
+	if (full_fname_dst == NULL) {
+		errno = ENOMEM;
+		goto out;
+	}
 
-	capold = capencode(talloc_tos(), smb_fname_src->base_name);
-	capnew = capencode(talloc_tos(), smb_fname_dst->base_name);
+	capold = capencode(talloc_tos(), full_fname_src->base_name);
+	capnew = capencode(talloc_tos(), full_fname_dst->base_name);
 	if (!capold || !capnew) {
 		errno = ENOMEM;
 		goto out;
 	}
 
 	/* Setup temporary smb_filename structs. */
-	smb_fname_src_tmp = cp_smb_filename(talloc_tos(), smb_fname_src);
+	smb_fname_src_tmp = cp_smb_filename(talloc_tos(), full_fname_src);
 	if (smb_fname_src_tmp == NULL) {
 		errno = ENOMEM;
 		goto out;
 	}
-	smb_fname_dst_tmp = cp_smb_filename(talloc_tos(), smb_fname_dst);
+	smb_fname_dst_tmp = cp_smb_filename(talloc_tos(), full_fname_dst);
 	if (smb_fname_dst_tmp == NULL) {
 		errno = ENOMEM;
 		goto out;
@@ -228,17 +247,28 @@ static int cap_renameat(vfs_handle_struct *handle,
 	smb_fname_dst_tmp->base_name = capnew;
 
 	ret = SMB_VFS_NEXT_RENAMEAT(handle,
-				srcfsp,
+				srcfsp->conn->cwd_fsp,
 				smb_fname_src_tmp,
-				dstfsp,
+				dstfsp->conn->cwd_fsp,
 				smb_fname_dst_tmp);
 
  out:
+
+	if (ret != 0) {
+		saved_errno = errno;
+	}
+
+	TALLOC_FREE(full_fname_src);
+	TALLOC_FREE(full_fname_dst);
 	TALLOC_FREE(capold);
 	TALLOC_FREE(capnew);
 	TALLOC_FREE(smb_fname_src_tmp);
 	TALLOC_FREE(smb_fname_dst_tmp);
 
+	if (ret != 0) {
+		errno = saved_errno;
+	}
+
 	return ret;
 }
 
diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c
index 973b45d90b0..0e7f2d89c88 100644
--- a/source3/modules/vfs_ceph.c
+++ b/source3/modules/vfs_ceph.c
@@ -621,17 +621,39 @@ static int cephwrap_renameat(struct vfs_handle_struct *handle,
 			files_struct *dstfsp,
 			const struct smb_filename *smb_fname_dst)
 {
+	struct smb_filename *full_fname_src = NULL;
+	struct smb_filename *full_fname_dst = NULL;
 	int result = -1;
+
 	DBG_DEBUG("[CEPH] cephwrap_renameat\n");
 	if (smb_fname_src->stream_name || smb_fname_dst->stream_name) {
 		errno = ENOENT;
 		return result;
 	}
 
-	SMB_ASSERT(srcfsp == srcfsp->conn->cwd_fsp);
-	SMB_ASSERT(dstfsp == dstfsp->conn->cwd_fsp);
+	full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
+						  srcfsp,
+						  smb_fname_src);
+	if (full_fname_src == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
+	full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
+						  dstfsp,
+						  smb_fname_dst);
+	if (full_fname_dst == NULL) {
+		TALLOC_FREE(full_fname_src);
+		errno = ENOMEM;
+		return -1;
+	}
+
+	result = ceph_rename(handle->data,
+			     full_fname_src->base_name,
+			     full_fname_dst->base_name);
+
+	TALLOC_FREE(full_fname_src);
+	TALLOC_FREE(full_fname_dst);
 
-	result = ceph_rename(handle->data, smb_fname_src->base_name, smb_fname_dst->base_name);
 	WRAP_RETURN(result);
 }
 
diff --git a/source3/modules/vfs_crossrename.c b/source3/modules/vfs_crossrename.c
index 4e512655c33..52b8af9d3f6 100644
--- a/source3/modules/vfs_crossrename.c
+++ b/source3/modules/vfs_crossrename.c
@@ -48,123 +48,94 @@ static int crossrename_connect(
  <warrenb at hpcvscdp.cv.hp.com>
 **********************************************************/
 
-static int copy_reg(const char *source, const char *dest)
+static NTSTATUS copy_reg(vfs_handle_struct *handle,
+			 struct files_struct *srcfsp,
+			 const struct smb_filename *source,
+			 struct files_struct *dstfsp,
+			 const struct smb_filename *dest)
 {
-	SMB_STRUCT_STAT source_stats;
-	int saved_errno;
-	int ifd = -1;
-	int ofd = -1;
-
-	if (sys_lstat(source, &source_stats, false) == -1)
-		return -1;
-
-	if (!S_ISREG (source_stats.st_ex_mode))
-		return -1;
-
-	if (source_stats.st_ex_size > module_sizelimit) {
-		DEBUG(5,
-			("%s: size of %s larger than sizelimit (%lld > %lld), rename prohititted\n",
-			MODULE, source,
-			(long long)source_stats.st_ex_size,
-			(long long)module_sizelimit));
-		return -1;
-	}
-
-	if((ifd = open (source, O_RDONLY, 0)) < 0)
-		return -1;
+	NTSTATUS status;
+	struct smb_filename *full_fname_src = NULL;
+	struct smb_filename *full_fname_dst = NULL;
+	int ret;
 
-	if (unlink (dest) && errno != ENOENT) {
-		close(ifd);
-		return -1;
+	if (!VALID_STAT(source->st)) {
+		status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
+		goto out;
+	}
+	if (!S_ISREG(source->st.st_ex_mode)) {
+		status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
+		goto out;
 	}
 
-#ifdef O_NOFOLLOW
-	if((ofd = open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 )
-#else
-	if((ofd = open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 )
-#endif
-		goto err;
-
-	if (transfer_file(ifd, ofd, source_stats.st_ex_size) == -1)
-		goto err;
+	if (source->st.st_ex_size > module_sizelimit) {
+		DBG_INFO("%s: size of %s larger than sizelimit (%lld > %lld), "
+			 "rename prohibited\n",
+			MODULE,
+			source->base_name,
+			(long long)source->st.st_ex_size,
+			(long long)module_sizelimit);
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto out;
+	}
 
-	/*
-	 * Try to preserve ownership.  For non-root it might fail, but that's ok.
-	 * But root probably wants to know, e.g. if NFS disallows it.
-	 */
+	full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
+						      srcfsp,
+						      source);
+	if (full_fname_dst == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto out;
+	}
+	full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
+						      dstfsp,
+						      dest);
+	if (full_fname_dst == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto out;
+	}
 
-#ifdef HAVE_FCHOWN
-	if ((fchown(ofd, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM))
-#else
-	if ((chown(dest, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM))
-#endif
-		goto err;
+	ret = SMB_VFS_NEXT_UNLINKAT(handle,
+				    dstfsp,
+				    dest,
+				    0);
+	if (ret == -1) {
+		status = map_nt_error_from_unix(errno);
+		goto out;
+	}
 
 	/*
-	 * fchown turns off set[ug]id bits for non-root,
-	 * so do the chmod last.
+	 * copy_internals() takes attribute values from the NTrename call.
+	 *
+	 * From MS-CIFS:
+	 *
+	 * "If the attribute is 0x0000, then only normal files are renamed.
+	 * If the system file or hidden attributes are specified, then the
+	 * rename is inclusive of both special types."
 	 */
-
-#if defined(HAVE_FCHMOD)
-	if ((fchmod (ofd, source_stats.st_ex_mode & 07777) == -1) &&
-			(errno != EPERM))
-#else
-	if ((chmod (dest, source_stats.st_ex_mode & 07777) == -1) &&
-			(errno != EPERM))
-#endif
-		goto err;
-
-	if (close (ifd) == -1)
-		goto err;
-
-	if (close (ofd) == -1)
-		return -1;
-
-	/* Try to copy the old file's modtime and access time.  */
-#if defined(HAVE_UTIMENSAT)
-	{
-		struct timespec ts[2];
-
-		ts[0] = source_stats.st_ex_atime;
-		ts[1] = source_stats.st_ex_mtime;
-		utimensat(AT_FDCWD, dest, ts, AT_SYMLINK_NOFOLLOW);
-	}
-#elif defined(HAVE_UTIMES)
-	{
-		struct timeval tv[2];
-
-		tv[0] = convert_timespec_to_timeval(source_stats.st_ex_atime);
-		tv[1] = convert_timespec_to_timeval(source_stats.st_ex_mtime);
-#ifdef HAVE_LUTIMES
-		lutimes(dest, tv);
-#else
-		utimes(dest, tv);
-#endif
+	status = copy_internals(talloc_tos(),
+				handle->conn,
+				NULL,
+				full_fname_src,
+				full_fname_dst,
+				FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto out;
 	}
-#elif defined(HAVE_UTIME)
-	{
-		struct utimbuf tv;
 
-		tv.actime = convert_timespec_to_time_t(source_stats.st_ex_atime);
-		tv.modtime = convert_timespec_to_time_t(source_stats.st_ex_mtime);
-		utime(dest, &tv);
+	ret = SMB_VFS_NEXT_UNLINKAT(handle,
+				    srcfsp,
+				    source,
+				    0);
+	if (ret == -1) {
+		status = map_nt_error_from_unix(errno);
+		goto out;
 	}
-#endif
-
-	if (unlink (source) == -1)
-		return -1;
 
-	return 0;
-
-  err:
+  out:
 
-	saved_errno = errno;
-	if (ifd != -1)
-		close(ifd);
-	if (ofd != -1)
-		close(ofd);
-	errno = saved_errno;
-	return -1;
+	TALLOC_FREE(full_fname_src);
+	TALLOC_FREE(full_fname_dst);
+	return status;
 }
 
 static int crossrename_renameat(vfs_handle_struct *handle,
@@ -182,11 +153,23 @@ static int crossrename_renameat(vfs_handle_struct *handle,
 		goto out;
 	}
 
-	result = rename(smb_fname_src->base_name, smb_fname_dst->base_name);
+	result = SMB_VFS_NEXT_RENAMEAT(handle,
+				       srcfsp,
+				       smb_fname_src,
+				       dstfsp,
+				       smb_fname_dst);
+
 	if ((result == -1) && (errno == EXDEV)) {
 		/* Rename across filesystems needed. */
-		result = copy_reg(smb_fname_src->base_name,
-				  smb_fname_dst->base_name);
+		NTSTATUS status = copy_reg(handle,
+					   srcfsp,
+					   smb_fname_src,
+					   dstfsp,
+					   smb_fname_dst);
+		if (!NT_STATUS_IS_OK(status)) {
+			errno = map_errno_from_nt_status(status);
+			result = -1;
+		}
 	}
 
  out:
diff --git a/source3/modules/vfs_extd_audit.c b/source3/modules/vfs_extd_audit.c
index 98ad9bdcacb..3ac75fb890e 100644
--- a/source3/modules/vfs_extd_audit.c
+++ b/source3/modules/vfs_extd_audit.c
@@ -280,27 +280,55 @@ static int audit_renameat(vfs_handle_struct *handle,
 			files_struct *dstfsp,
 			const struct smb_filename *smb_fname_dst)
 {
+	struct smb_filename *full_fname_src = NULL;
+	struct smb_filename *full_fname_dst = NULL;
 	int result;
+	int saved_errno = 0;
+
+	full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
+						      srcfsp,
+						      smb_fname_src);
+	if (full_fname_src == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
+
+	full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
+						      dstfsp,
+						      smb_fname_dst);
+	if (full_fname_dst == NULL) {
+		TALLOC_FREE(full_fname_src);
+		errno = ENOMEM;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list