summaryrefslogtreecommitdiffstats
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h3
-rw-r--r--source3/include/vfs.h7
-rw-r--r--source3/modules/onefs.h5
-rw-r--r--source3/modules/onefs_streams.c78
-rw-r--r--source3/modules/vfs_audit.c13
-rw-r--r--source3/modules/vfs_cap.c48
-rw-r--r--source3/modules/vfs_catia.c50
-rw-r--r--source3/modules/vfs_default.c17
-rw-r--r--source3/modules/vfs_extd_audit.c16
-rw-r--r--source3/modules/vfs_full_audit.c12
-rw-r--r--source3/modules/vfs_netatalk.c28
-rw-r--r--source3/modules/vfs_onefs_shadow_copy.c46
-rw-r--r--source3/modules/vfs_recycle.c20
-rw-r--r--source3/modules/vfs_shadow_copy2.c16
-rw-r--r--source3/modules/vfs_streams_depot.c106
-rw-r--r--source3/modules/vfs_streams_xattr.c94
-rw-r--r--source3/modules/vfs_syncops.c8
-rw-r--r--source3/smbd/reply.c314
-rw-r--r--source3/smbd/trans2.c48
-rw-r--r--source3/torture/cmd_vfs.c21
20 files changed, 629 insertions, 321 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index e4bcdb5016..a2fcd95e7d 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -6876,8 +6876,7 @@ NTSTATUS rmdir_internals(TALLOC_CTX *ctx,
void reply_rmdir(struct smb_request *req);
NTSTATUS rename_internals_fsp(connection_struct *conn,
files_struct *fsp,
- char *newname,
- const char *newname_last_component,
+ const struct smb_filename *smb_fname_dst_in,
uint32 attrs,
bool replace_if_exists);
NTSTATUS rename_internals(TALLOC_CTX *ctx,
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 2a0c5ec805..c3580da5d0 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -118,7 +118,8 @@
/* Leave at 25 - not yet released. Add locking calls. -- zkirsch. */
/* Leave at 25 - not yet released. Add strict locking calls. -- drichards. */
/* Changed to version 26 - Plumb struct smb_filename to SMB_VFS_CREATE_FILE,
- SMB_VFS_OPEN, SMB_VFS_STAT, SMB_VFS_LSTAT. */
+ SMB_VFS_OPEN, SMB_VFS_STAT, SMB_VFS_LSTAT,
+ SMB_VFS_RENAME. */
#define SMB_VFS_INTERFACE_VERSION 26
@@ -357,7 +358,9 @@ struct vfs_ops {
SMB_OFF_T (*lseek)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_OFF_T offset, int whence);
ssize_t (*sendfile)(struct vfs_handle_struct *handle, int tofd, files_struct *fromfsp, const DATA_BLOB *header, SMB_OFF_T offset, size_t count);
ssize_t (*recvfile)(struct vfs_handle_struct *handle, int fromfd, files_struct *tofsp, SMB_OFF_T offset, size_t count);
- int (*rename)(struct vfs_handle_struct *handle, const char *oldname, const char *newname);
+ int (*rename)(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst);
int (*fsync)(struct vfs_handle_struct *handle, struct files_struct *fsp);
int (*stat)(struct vfs_handle_struct *handle, struct smb_filename *smb_fname);
int (*fstat)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_STAT *sbuf);
diff --git a/source3/modules/onefs.h b/source3/modules/onefs.h
index 6cb8036e85..0c39a282d4 100644
--- a/source3/modules/onefs.h
+++ b/source3/modules/onefs.h
@@ -61,8 +61,9 @@ NTSTATUS onefs_create_file(vfs_handle_struct *handle,
int onefs_close(vfs_handle_struct *handle, struct files_struct *fsp);
-int onefs_rename(vfs_handle_struct *handle, const char *oldname,
- const char *newname);
+int onefs_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst);
int onefs_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname);
diff --git a/source3/modules/onefs_streams.c b/source3/modules/onefs_streams.c
index a4c6146fb0..8963037c22 100644
--- a/source3/modules/onefs_streams.c
+++ b/source3/modules/onefs_streams.c
@@ -195,68 +195,80 @@ static int get_stream_dir_fd(connection_struct *conn, const char *base,
return dir_fd;
}
-int onefs_rename(vfs_handle_struct *handle, const char *oldname,
- const char *newname)
+int onefs_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- TALLOC_CTX *frame = NULL;
- int ret = -1;
- int dir_fd = -1;
+ struct smb_filename *smb_fname_src_onefs = NULL;
+ struct smb_filename *smb_fname_dst_onefs = NULL;
+ NTSTATUS status;
int saved_errno;
- bool old_is_stream;
- bool new_is_stream;
- char *obase = NULL;
- char *osname = NULL;
- char *nbase = NULL;
- char *nsname = NULL;
+ int dir_fd = -1;
+ int ret = -1;
START_PROFILE(syscall_rename_at);
- frame = talloc_stackframe();
-
- ret = onefs_is_stream(oldname, &obase, &osname, &old_is_stream);
- if (ret) {
- END_PROFILE(syscall_rename_at);
- return ret;
+ if (!is_ntfs_stream_smb_fname(smb_fname_src) &&
+ !is_ntfs_stream_smb_fname(smb_fname_dst)) {
+ ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
+ smb_fname_dst);
+ goto done;
}
- ret = onefs_is_stream(newname, &nbase, &nsname, &new_is_stream);
- if (ret) {
- END_PROFILE(syscall_rename_at);
- return ret;
+ /* For now don't allow renames from or to the default stream. */
+ if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
+ is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
+ errno = ENOSYS;
+ goto done;
}
- if (!old_is_stream && !new_is_stream) {
- ret = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
- END_PROFILE(syscall_rename_at);
- return ret;
+ /* prep stream smb_filename structs. */
+ status = onefs_stream_prep_smb_fname(talloc_tos(), smb_fname_src,
+ &smb_fname_src_onefs);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto done;
+ }
+ status = onefs_stream_prep_smb_fname(talloc_tos(), smb_fname_dst,
+ &smb_fname_dst_onefs);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto done;
}
- dir_fd = get_stream_dir_fd(handle->conn, obase, NULL);
+ dir_fd = get_stream_dir_fd(handle->conn, smb_fname_src->base_name,
+ NULL);
if (dir_fd < -1) {
goto done;
}
- DEBUG(8,("onefs_rename called for %s : %s => %s : %s\n",
- obase, osname, nbase, nsname));
+ DEBUG(8, ("onefs_rename called for %s => %s\n",
+ smb_fname_str_dbg(smb_fname_src_onefs),
+ smb_fname_str_dbg(smb_fname_dst_onefs)));
/* Handle rename of stream to default stream specially. */
- if (nsname == NULL) {
- ret = enc_renameat(dir_fd, osname, ENC_DEFAULT, AT_FDCWD,
- nbase, ENC_DEFAULT);
+ if (smb_fname_dst_onefs->stream_name == NULL) {
+ ret = enc_renameat(dir_fd, smb_fname_src_onefs->stream_name,
+ ENC_DEFAULT, AT_FDCWD,
+ smb_fname_dst_onefs->base_name,
+ ENC_DEFAULT);
} else {
- ret = enc_renameat(dir_fd, osname, ENC_DEFAULT, dir_fd, nsname,
+ ret = enc_renameat(dir_fd, smb_fname_src_onefs->stream_name,
+ ENC_DEFAULT, dir_fd,
+ smb_fname_dst_onefs->stream_name,
ENC_DEFAULT);
}
done:
END_PROFILE(syscall_rename_at);
+ TALLOC_FREE(smb_fname_src_onefs);
+ TALLOC_FREE(smb_fname_dst_onefs);
saved_errno = errno;
if (dir_fd >= 0) {
close(dir_fd);
}
errno = saved_errno;
- TALLOC_FREE(frame);
return ret;
}
diff --git a/source3/modules/vfs_audit.c b/source3/modules/vfs_audit.c
index 2897cefb96..352e4d39e7 100644
--- a/source3/modules/vfs_audit.c
+++ b/source3/modules/vfs_audit.c
@@ -35,7 +35,9 @@ static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
static int audit_rmdir(vfs_handle_struct *handle, const char *path);
static int audit_open(vfs_handle_struct *handle, struct smb_filename *smb_fname, files_struct *fsp, int flags, mode_t mode);
static int audit_close(vfs_handle_struct *handle, files_struct *fsp);
-static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname);
+static int audit_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst);
static int audit_unlink(vfs_handle_struct *handle, const char *path);
static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode);
static int audit_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode);
@@ -218,14 +220,17 @@ static int audit_close(vfs_handle_struct *handle, files_struct *fsp)
return result;
}
-static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname)
+static int audit_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
int result;
- result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
+ result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
syslog(audit_syslog_priority(handle), "rename %s -> %s %s%s\n",
- oldname, newname,
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst),
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c
index 12a88750ee..4d16aa44ae 100644
--- a/source3/modules/vfs_cap.c
+++ b/source3/modules/vfs_cap.c
@@ -132,16 +132,50 @@ static int cap_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
return ret;
}
-static int cap_rename(vfs_handle_struct *handle, const char *oldname, const char *newname)
-{
- char *capold = capencode(talloc_tos(), oldname);
- char *capnew = capencode(talloc_tos(), newname);
-
+static int cap_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
+{
+ char *capold = NULL;
+ char *capnew = NULL;
+ struct smb_filename *smb_fname_src_tmp = NULL;
+ struct smb_filename *smb_fname_dst_tmp = NULL;
+ NTSTATUS status;
+ int ret = -1;
+
+ capold = capencode(talloc_tos(), smb_fname_src->base_name);
+ capnew = capencode(talloc_tos(), smb_fname_dst->base_name);
if (!capold || !capnew) {
errno = ENOMEM;
- return -1;
+ goto out;
+ }
+
+ /* Setup temporary smb_filename structs. */
+ status = copy_smb_filename(talloc_tos(), smb_fname_src,
+ &smb_fname_src_tmp);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
}
- return SMB_VFS_NEXT_RENAME(handle, capold, capnew);
+ status = copy_smb_filename(talloc_tos(), smb_fname_dst,
+ &smb_fname_dst_tmp);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
+ }
+
+ smb_fname_src_tmp->base_name = capold;
+ smb_fname_dst_tmp->base_name = capnew;
+
+ ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
+ smb_fname_dst_tmp);
+ out:
+ TALLOC_FREE(capold);
+ TALLOC_FREE(capnew);
+ TALLOC_FREE(smb_fname_src_tmp);
+ TALLOC_FREE(smb_fname_dst_tmp);
+
+ return ret;
}
static int cap_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c
index c8c340d0a5..b5283d25c2 100644
--- a/source3/modules/vfs_catia.c
+++ b/source3/modules/vfs_catia.c
@@ -160,20 +160,54 @@ static int catia_open(vfs_handle_struct *handle,
}
static int catia_rename(vfs_handle_struct *handle,
- const char *oldname, const char *newname)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
TALLOC_CTX *ctx = talloc_tos();
- char *oname = to_unix(ctx, oldname);
- char *nname = to_unix(ctx, newname);
-
+ char *oname = NULL;
+ char *nname = NULL;
+ struct smb_filename *smb_fname_src_tmp = NULL;
+ struct smb_filename *smb_fname_dst_tmp = NULL;
+ NTSTATUS status;
+ int ret = -1;
+
+ oname = to_unix(ctx, smb_fname_src->base_name);
+ nname = to_unix(ctx, smb_fname_dst->base_name);
if (!oname || !nname) {
errno = ENOMEM;
- return -1;
+ goto out;
+ }
+
+ /* Setup temporary smb_filename structs. */
+ status = copy_smb_filename(talloc_tos(), smb_fname_src,
+ &smb_fname_src_tmp);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
+ }
+ status = copy_smb_filename(talloc_tos(), smb_fname_dst,
+ &smb_fname_dst_tmp);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
}
- DEBUG(10, ("converted old name: %s\n", oname));
- DEBUG(10, ("converted new name: %s\n", nname));
- return SMB_VFS_NEXT_RENAME(handle, oname, nname);
+ smb_fname_src_tmp->base_name = oname;
+ smb_fname_dst_tmp->base_name = nname;
+
+ DEBUG(10, ("converted old name: %s\n",
+ smb_fname_str_dbg(smb_fname_src_tmp)));
+ DEBUG(10, ("converted new name: %s\n",
+ smb_fname_str_dbg(smb_fname_dst_tmp)));
+
+ ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
+ smb_fname_dst_tmp);
+ out:
+ TALLOC_FREE(oname);
+ TALLOC_FREE(newname);
+ TALLOC_FREE(smb_fname_src_tmp);
+ TALLOC_FREE(smb_fname_dst_tmp);
+ return ret;
}
static int catia_stat(vfs_handle_struct *handle,
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index cd792aba32..9a55456b0c 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -520,17 +520,28 @@ static int copy_reg(const char *source, const char *dest)
return -1;
}
-static int vfswrap_rename(vfs_handle_struct *handle, const char *oldname, const char *newname)
+static int vfswrap_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
int result;
START_PROFILE(syscall_rename);
- result = rename(oldname, newname);
+
+ if (smb_fname_src->stream_name || smb_fname_dst->stream_name) {
+ errno = ENOENT;
+ result = -1;
+ goto out;
+ }
+
+ result = rename(smb_fname_src->base_name, smb_fname_dst->base_name);
if ((result == -1) && (errno == EXDEV)) {
/* Rename across filesystems needed. */
- result = copy_reg(oldname, newname);
+ result = copy_reg(smb_fname_src->base_name,
+ smb_fname_dst->base_name);
}
+ out:
END_PROFILE(syscall_rename);
return result;
}
diff --git a/source3/modules/vfs_extd_audit.c b/source3/modules/vfs_extd_audit.c
index 763f1545d7..cb455b49e6 100644
--- a/source3/modules/vfs_extd_audit.c
+++ b/source3/modules/vfs_extd_audit.c
@@ -38,7 +38,9 @@ static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
static int audit_rmdir(vfs_handle_struct *handle, const char *path);
static int audit_open(vfs_handle_struct *handle, struct smb_filename *smb_fname, files_struct *fsp, int flags, mode_t mode);
static int audit_close(vfs_handle_struct *handle, files_struct *fsp);
-static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname);
+static int audit_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst);
static int audit_unlink(vfs_handle_struct *handle, const char *path);
static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode);
static int audit_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode);
@@ -259,20 +261,24 @@ static int audit_close(vfs_handle_struct *handle, files_struct *fsp)
return result;
}
-static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname)
+static int audit_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
int result;
- result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
+ result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
if (lp_syslog() > 0) {
syslog(audit_syslog_priority(handle), "rename %s -> %s %s%s\n",
- oldname, newname,
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst),
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
}
DEBUG(1, ("vfs_extd_audit: rename old: %s newname: %s %s %s\n",
- oldname, newname,
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst),
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : ""));
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index e47609d0a9..7428de1a51 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -148,7 +148,8 @@ static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
SMB_OFF_T offset,
size_t n);
static int smb_full_audit_rename(vfs_handle_struct *handle,
- const char *oldname, const char *newname);
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst);
static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp);
static int smb_full_audit_stat(vfs_handle_struct *handle,
struct smb_filename *smb_fname);
@@ -1338,13 +1339,16 @@ static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
}
static int smb_full_audit_rename(vfs_handle_struct *handle,
- const char *oldname, const char *newname)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
int result;
- result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
+ result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
- do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname);
+ do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst));
return result;
}
diff --git a/source3/modules/vfs_netatalk.c b/source3/modules/vfs_netatalk.c
index ed35922359..0e20beca41 100644
--- a/source3/modules/vfs_netatalk.c
+++ b/source3/modules/vfs_netatalk.c
@@ -222,24 +222,28 @@ exit_rmdir:
/* File operations */
-static int atalk_rename(struct vfs_handle_struct *handle, const char *oldname, const char *newname)
+static int atalk_rename(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
int ret = 0;
- char *adbl_path = 0;
- char *orig_path = 0;
+ char *oldname = NULL;
+ char *adbl_path = NULL;
+ char *orig_path = NULL;
SMB_STRUCT_STAT adbl_info;
SMB_STRUCT_STAT orig_info;
- TALLOC_CTX *ctx;
-
- ret = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
+ NTSTATUS status;
- if (!oldname) return ret;
+ ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
- if (!(ctx = talloc_init("rename_file")))
+ status = get_full_smb_filename(talloc_tos(), smb_fname_src, &oldname);
+ if (!NT_STATUS_IS_OK(status)) {
return ret;
+ }
- if (atalk_build_paths(ctx, handle->conn->origpath, oldname, &adbl_path, &orig_path,
- &adbl_info, &orig_info) != 0)
+ if (atalk_build_paths(talloc_tos(), handle->conn->origpath, oldname,
+ &adbl_path, &orig_path, &adbl_info,
+ &orig_info) != 0)
goto exit_rename;
if (S_ISDIR(orig_info.st_ex_mode) || S_ISREG(orig_info.st_ex_mode)) {
@@ -250,7 +254,9 @@ static int atalk_rename(struct vfs_handle_struct *handle, const char *oldname, c
atalk_unlink_file(adbl_path);
exit_rename:
- talloc_destroy(ctx);
+ TALLOC_FREE(adbl_path);
+ TALLOC_FREE(orig_path);
+ TALLOC_FREE(orig_path);
return ret;
}
diff --git a/source3/modules/vfs_onefs_shadow_copy.c b/source3/modules/vfs_onefs_shadow_copy.c
index 3eca664c8a..8d7e109170 100644
--- a/source3/modules/vfs_onefs_shadow_copy.c
+++ b/source3/modules/vfs_onefs_shadow_copy.c
@@ -253,26 +253,54 @@ onefs_shadow_copy_create_file(vfs_handle_struct *handle,
* XXX: macro-ize
*/
static int
-onefs_shadow_copy_rename(vfs_handle_struct *handle, const char *old_name,
- const char *new_name)
+onefs_shadow_copy_rename(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
char *old_cpath = NULL;
char *old_snap_component = NULL;
char *new_cpath = NULL;
char *new_snap_component = NULL;
- int ret;
+ struct smb_filename *smb_fname_src_tmp = NULL;
+ struct smb_filename *smb_fname_dst_tmp = NULL;
+ NTSTATUS status;
+ int ret = -1;
+
+ status = copy_smb_filename(talloc_tos(), smb_fname_src,
+ &smb_fname_src_tmp);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
+ }
+ status = copy_smb_filename(talloc_tos(), smb_fname_dst,
+ &smb_fname_dst_tmp);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
+ }
- if (shadow_copy_match_name(old_name, &old_snap_component))
- old_cpath = osc_canonicalize_path(old_name, old_snap_component);
+ if (shadow_copy_match_name(smb_fname_src_tmp->base_name,
+ &old_snap_component)) {
+ old_cpath = osc_canonicalize_path(smb_fname_src_tmp->base_name,
+ old_snap_component);
+ smb_fname_src_tmp->base_name = old_cpath;
+ }
- if (shadow_copy_match_name(new_name, &new_snap_component))
- new_cpath = osc_canonicalize_path(new_name, new_snap_component);
+ if (shadow_copy_match_name(smb_fname_dst_tmp->base_name,
+ &new_snap_component)) {
+ new_cpath = osc_canonicalize_path(smb_fname_dst_tmp->base_name,
+ new_snap_component);
+ smb_fname_dst_tmp->base_name = new_cpath;
+ }
- ret = SMB_VFS_NEXT_RENAME(handle, old_cpath ?: old_name,
- new_cpath ?: new_name);
+ ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
+ smb_fname_dst_tmp);
+ out:
SAFE_FREE(old_cpath);
SAFE_FREE(new_cpath);
+ TALLOC_FREE(smb_fname_src_tmp);
+ TALLOC_FREE(smb_fname_dst_tmp);
return ret;
}
diff --git a/source3/modules/vfs_recycle.c b/source3/modules/vfs_recycle.c
index f42fab72f7..3fbe8d7e55 100644
--- a/source3/modules/vfs_recycle.c
+++ b/source3/modules/vfs_recycle.c
@@ -423,12 +423,15 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
char *path_name = NULL;
char *temp_name = NULL;
char *final_name = NULL;
+ struct smb_filename *smb_fname_file = NULL;
+ struct smb_filename *smb_fname_final = NULL;
const char *base;
char *repository = NULL;
int i = 1;
SMB_OFF_T maxsize, minsize;
SMB_OFF_T file_size; /* space_avail; */
bool exist;
+ NTSTATUS status;
int rc = -1;
repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)),
@@ -571,8 +574,21 @@ static int recycle_unlink(vfs_handle_struct *handle, const char *file_name)
}
}
+ status = create_synthetic_smb_fname_split(talloc_tos(), file_name,
+ NULL, &smb_fname_file);
+ if (!NT_STATUS_IS_OK(status)) {
+ rc = SMB_VFS_NEXT_UNLINK(handle, file_name);
+ goto done;
+ }
+ status = create_synthetic_smb_fname_split(talloc_tos(), final_name,
+ NULL, &smb_fname_final);
+ if (!NT_STATUS_IS_OK(status)) {
+ rc = SMB_VFS_NEXT_UNLINK(handle, file_name);
+ goto done;
+ }
+
DEBUG(10, ("recycle: Moving %s to %s\n", file_name, final_name));
- rc = SMB_VFS_NEXT_RENAME(handle, file_name, final_name);
+ rc = SMB_VFS_NEXT_RENAME(handle, smb_fname_file, smb_fname_final);
if (rc != 0) {
DEBUG(3, ("recycle: Move error %d (%s), purging file %s (%s)\n", errno, strerror(errno), file_name, final_name));
rc = SMB_VFS_NEXT_UNLINK(handle, file_name);
@@ -587,6 +603,8 @@ done:
SAFE_FREE(path_name);
SAFE_FREE(temp_name);
SAFE_FREE(final_name);
+ TALLOC_FREE(smb_fname_file);
+ TALLOC_FREE(smb_fname_final);
TALLOC_FREE(repository);
return rc;
}
diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c
index 03a8fd24ea..25c5096da7 100644
--- a/source3/modules/vfs_shadow_copy2.c
+++ b/source3/modules/vfs_shadow_copy2.c
@@ -176,6 +176,16 @@ static inline bool shadow_copy2_match_name(const char *name)
} \
} while (0)
+#define SHADOW2_NEXT2_SMB_FNAME(op, args) do { \
+ if (shadow_copy2_match_name(smb_fname_src->base_name) || \
+ shadow_copy2_match_name(smb_fname_dst->base_name)) { \
+ errno = EROFS; \
+ return -1; \
+ } else { \
+ return SMB_VFS_NEXT_ ## op args; \
+ } \
+} while (0)
+
/*
find the mount point of a filesystem
@@ -343,9 +353,11 @@ static void convert_sbuf(vfs_handle_struct *handle, const char *fname, SMB_STRUC
}
static int shadow_copy2_rename(vfs_handle_struct *handle,
- const char *oldname, const char *newname)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- SHADOW2_NEXT2(RENAME, (handle, oldname, newname));
+ SHADOW2_NEXT2_SMB_FNAME(RENAME,
+ (handle, smb_fname_src, smb_fname_dst));
}
static int shadow_copy2_symlink(vfs_handle_struct *handle,
diff --git a/source3/modules/vfs_streams_depot.c b/source3/modules/vfs_streams_depot.c
index 5f850174d8..f1b9a504b9 100644
--- a/source3/modules/vfs_streams_depot.c
+++ b/source3/modules/vfs_streams_depot.c
@@ -206,6 +206,7 @@ static char *stream_dir(vfs_handle_struct *handle,
}
if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
+ struct smb_filename *smb_fname_new = NULL;
char *newname;
if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
@@ -230,15 +231,25 @@ static char *stream_dir(vfs_handle_struct *handle,
goto fail;
}
- if (SMB_VFS_NEXT_RENAME(handle, result, newname) == -1) {
+ status = create_synthetic_smb_fname(talloc_tos(), newname,
+ NULL, NULL,
+ &smb_fname_new);
+ TALLOC_FREE(newname);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto fail;
+ }
+
+ if (SMB_VFS_NEXT_RENAME(handle, smb_fname_hash,
+ smb_fname_new) == -1) {
+ TALLOC_FREE(smb_fname_new);
if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
- TALLOC_FREE(newname);
goto again;
}
goto fail;
}
- TALLOC_FREE(newname);
+ TALLOC_FREE(smb_fname_new);
}
if (!create_it) {
@@ -561,8 +572,7 @@ static int streams_depot_open(vfs_handle_struct *handle,
int ret = -1;
if (!is_ntfs_stream_smb_fname(smb_fname)) {
- ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
- return ret;
+ return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
}
/* If the default stream is requested, just open the base file. */
@@ -669,80 +679,72 @@ static int streams_depot_unlink(vfs_handle_struct *handle, const char *fname)
}
static int streams_depot_rename(vfs_handle_struct *handle,
- const char *oldname,
- const char *newname)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- TALLOC_CTX *frame = NULL;
+ struct smb_filename *smb_fname_src_stream = NULL;
+ struct smb_filename *smb_fname_dst_stream = NULL;
+ struct smb_filename *smb_fname_dst_mod = NULL;
+ bool src_is_stream, dst_is_stream;
+ NTSTATUS status;
int ret = -1;
- bool old_is_stream;
- bool new_is_stream;
- char *obase = NULL;
- char *osname = NULL;
- char *nbase = NULL;
- char *nsname = NULL;
- char *ostream_fname = NULL;
- char *nstream_fname = NULL;
- char *newname_full = NULL;
DEBUG(10, ("streams_depot_rename called for %s => %s\n",
- oldname, newname));
-
- old_is_stream = is_ntfs_stream_name(oldname);
- new_is_stream = is_ntfs_stream_name(newname);
-
- if (!old_is_stream && !new_is_stream) {
- return SMB_VFS_NEXT_RENAME(handle, oldname, newname);
- }
+ smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
- frame = talloc_stackframe();
+ src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
+ dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
- if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), oldname,
- &obase, &osname))) {
- errno = ENOMEM;
- goto done;
- }
-
- if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), newname,
- &nbase, &nsname))) {
- errno = ENOMEM;
- goto done;
+ if (!src_is_stream && !dst_is_stream) {
+ return SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
+ smb_fname_dst);
}
/* for now don't allow renames from or to the default stream */
- if (!osname || !nsname) {
+ if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
+ is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
errno = ENOSYS;
goto done;
}
- ostream_fname = stream_name(handle, oldname, false);
- if (ostream_fname == NULL) {
- return -1;
+ status = stream_smb_fname(handle, smb_fname_src, &smb_fname_src_stream,
+ false);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto done;
}
/*
* Handle passing in a stream name without the base file. This is
* exercised by the NTRENAME streams rename path.
*/
- if (StrCaseCmp(nbase, "./") == 0) {
- newname_full = talloc_asprintf(talloc_tos(), "%s:%s", obase,
- nsname);
- if (newname_full == NULL) {
- errno = ENOMEM;
+ if (StrCaseCmp(smb_fname_dst->base_name, "./") == 0) {
+ status = create_synthetic_smb_fname(talloc_tos(),
+ smb_fname_src->base_name,
+ smb_fname_dst->stream_name,
+ NULL, &smb_fname_dst_mod);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
goto done;
}
}
- nstream_fname = stream_name(handle,
- newname_full ? newname_full : newname,
- false);
- if (nstream_fname == NULL) {
- return -1;
+ status = stream_smb_fname(handle, (smb_fname_dst_mod ?
+ smb_fname_dst_mod : smb_fname_dst),
+ &smb_fname_dst_stream, false);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto done;
}
- ret = SMB_VFS_NEXT_RENAME(handle, ostream_fname, nstream_fname);
+ ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_stream,
+ smb_fname_dst_stream);
done:
- TALLOC_FREE(frame);
+ TALLOC_FREE(smb_fname_src_stream);
+ TALLOC_FREE(smb_fname_dst_stream);
+ TALLOC_FREE(smb_fname_dst_mod);
return ret;
}
diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c
index e87d60ec60..49f11a22ac 100644
--- a/source3/modules/vfs_streams_xattr.c
+++ b/source3/modules/vfs_streams_xattr.c
@@ -578,91 +578,67 @@ static int streams_xattr_unlink(vfs_handle_struct *handle, const char *fname)
}
static int streams_xattr_rename(vfs_handle_struct *handle,
- const char *oldname,
- const char *newname)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
NTSTATUS status;
- TALLOC_CTX *frame = NULL;
- char *obase;
- char *ostream;
- char *nbase;
- char *nstream;
- const char *base;
int ret = -1;
- char *oxattr_name;
- char *nxattr_name;
- bool o_is_stream;
- bool n_is_stream;
+ char *src_xattr_name = NULL;
+ char *dst_xattr_name = NULL;
+ bool src_is_stream, dst_is_stream;
ssize_t oret;
ssize_t nret;
struct ea_struct ea;
- o_is_stream = is_ntfs_stream_name(oldname);
- n_is_stream = is_ntfs_stream_name(newname);
+ src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
+ dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
- if (!o_is_stream && !n_is_stream) {
- return SMB_VFS_NEXT_RENAME(handle, oldname, newname);
+ if (!src_is_stream && !dst_is_stream) {
+ return SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
+ smb_fname_dst);
}
- frame = talloc_stackframe();
- if (!frame) {
- goto fail;
- }
-
- status = split_ntfs_stream_name(talloc_tos(), oldname, &obase, &ostream);
- if (!NT_STATUS_IS_OK(status)) {
- errno = EINVAL;
- goto fail;
- }
-
- status = split_ntfs_stream_name(talloc_tos(), newname, &nbase, &nstream);
- if (!NT_STATUS_IS_OK(status)) {
- errno = EINVAL;
- goto fail;
- }
-
- /*TODO: maybe call SMB_VFS_NEXT_RENAME() both streams are NULL (::$DATA) */
- if (ostream == NULL) {
- errno = ENOSYS;
- goto fail;
- }
-
- if (nstream == NULL) {
+ /* For now don't allow renames from or to the default stream. */
+ if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
+ is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
errno = ENOSYS;
- goto fail;
+ goto done;
}
- if (StrCaseCmp(ostream, nstream) == 0) {
+ /* Don't rename if the streams are identical. */
+ if (StrCaseCmp(smb_fname_src->stream_name,
+ smb_fname_dst->stream_name) == 0) {
goto done;
}
- base = obase;
-
- oxattr_name = talloc_asprintf(talloc_tos(), "%s%s",
- SAMBA_XATTR_DOSSTREAM_PREFIX, ostream);
- if (oxattr_name == NULL) {
- errno = ENOMEM;
+ /* Get the xattr names. */
+ status = streams_xattr_get_name(talloc_tos(),
+ smb_fname_src->stream_name,
+ &src_xattr_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
goto fail;
}
-
- nxattr_name = talloc_asprintf(talloc_tos(), "%s%s",
- SAMBA_XATTR_DOSSTREAM_PREFIX, nstream);
- if (nxattr_name == NULL) {
- errno = ENOMEM;
+ status = streams_xattr_get_name(talloc_tos(),
+ smb_fname_dst->stream_name,
+ &dst_xattr_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
goto fail;
}
/* read the old stream */
status = get_ea_value(talloc_tos(), handle->conn, NULL,
- base, oxattr_name, &ea);
+ smb_fname_src->base_name, src_xattr_name, &ea);
if (!NT_STATUS_IS_OK(status)) {
errno = ENOENT;
goto fail;
}
/* (over)write the new stream */
- nret = SMB_VFS_SETXATTR(handle->conn, base, nxattr_name,
- ea.value.data, ea.value.length, 0);
+ nret = SMB_VFS_SETXATTR(handle->conn, smb_fname_src->base_name,
+ dst_xattr_name, ea.value.data, ea.value.length,
+ 0);
if (nret < 0) {
if (errno == ENOATTR) {
errno = ENOENT;
@@ -671,7 +647,8 @@ static int streams_xattr_rename(vfs_handle_struct *handle,
}
/* remove the old stream */
- oret = SMB_VFS_REMOVEXATTR(handle->conn, base, oxattr_name);
+ oret = SMB_VFS_REMOVEXATTR(handle->conn, smb_fname_src->base_name,
+ src_xattr_name);
if (oret < 0) {
if (errno == ENOATTR) {
errno = ENOENT;
@@ -683,7 +660,8 @@ static int streams_xattr_rename(vfs_handle_struct *handle,
errno = 0;
ret = 0;
fail:
- TALLOC_FREE(frame);
+ TALLOC_FREE(src_xattr_name);
+ TALLOC_FREE(dst_xattr_name);
return ret;
}
diff --git a/source3/modules/vfs_syncops.c b/source3/modules/vfs_syncops.c
index 562195cbda..ff210e695b 100644
--- a/source3/modules/vfs_syncops.c
+++ b/source3/modules/vfs_syncops.c
@@ -122,11 +122,13 @@ static void syncops_smb_fname(struct smb_filename *smb_fname)
rename needs special handling, as we may need to fsync two directories
*/
static int syncops_rename(vfs_handle_struct *handle,
- const char *oldname, const char *newname)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- int ret = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
+ int ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
if (ret == 0) {
- syncops_two_names(oldname, newname);
+ syncops_two_names(smb_fname_src->base_name,
+ smb_fname_dst->base_name);
}
return ret;
}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index eb3bfe565a..f9dc58311c 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -5629,10 +5629,18 @@ static bool resolve_wildcards(TALLOC_CTX *ctx,
static void rename_open_files(connection_struct *conn,
struct share_mode_lock *lck,
- const char *newname)
+ const struct smb_filename *smb_fname_dst)
{
files_struct *fsp;
bool did_rename = False;
+ char *fname_dst = NULL;
+ NTSTATUS status;
+
+ status = get_full_smb_filename(talloc_tos(), smb_fname_dst,
+ &fname_dst);
+ if (!NT_STATUS_IS_OK(status)) {
+ return;
+ }
for(fsp = file_find_di_first(lck->id); fsp;
fsp = file_find_di_next(fsp)) {
@@ -5643,21 +5651,24 @@ static void rename_open_files(connection_struct *conn,
if (!strequal(fsp->conn->connectpath, conn->connectpath)) {
continue;
}
- DEBUG(10,("rename_open_files: renaming file fnum %d (file_id %s) from %s -> %s\n",
- fsp->fnum, file_id_string_tos(&fsp->file_id),
- fsp->fsp_name, newname ));
- string_set(&fsp->fsp_name, newname);
+ DEBUG(10, ("rename_open_files: renaming file fnum %d "
+ "(file_id %s) from %s -> %s\n", fsp->fnum,
+ file_id_string_tos(&fsp->file_id), fsp->fsp_name,
+ smb_fname_str_dbg(smb_fname_dst)));
+ string_set(&fsp->fsp_name, fname_dst);
did_rename = True;
}
if (!did_rename) {
- DEBUG(10,("rename_open_files: no open files on file_id %s for %s\n",
- file_id_string_tos(&lck->id), newname ));
+ DEBUG(10, ("rename_open_files: no open files on file_id %s "
+ "for %s\n", file_id_string_tos(&lck->id),
+ smb_fname_str_dbg(smb_fname_dst)));
}
/* Send messages to all smbd's (not ourself) that the name has changed. */
rename_share_filename(smbd_messaging_context(), lck, conn->connectpath,
- newname);
+ fname_dst);
+ TALLOC_FREE(fname_dst);
}
/****************************************************************************
@@ -5671,10 +5682,11 @@ static void rename_open_files(connection_struct *conn,
report from <AndyLiebman@aol.com>.
****************************************************************************/
-static bool rename_path_prefix_equal(const char *src, const char *dest)
+static bool rename_path_prefix_equal(const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- const char *psrc = src;
- const char *pdst = dest;
+ const char *psrc = smb_fname_src->base_name;
+ const char *pdst = smb_fname_dst->base_name;
size_t slen;
if (psrc[0] == '.' && psrc[1] == '/') {
@@ -5694,30 +5706,45 @@ static bool rename_path_prefix_equal(const char *src, const char *dest)
*/
static void notify_rename(connection_struct *conn, bool is_dir,
- const char *oldpath, const char *newpath)
+ const struct smb_filename *smb_fname_src,
+ const struct smb_filename *smb_fname_dst)
{
- char *olddir, *newdir;
+ char *parent_dir_src = NULL;
+ char *parent_dir_dst = NULL;
+ char *fname_src = NULL;
+ char *fname_dst = NULL;
+ NTSTATUS status;
uint32 mask;
mask = is_dir ? FILE_NOTIFY_CHANGE_DIR_NAME
: FILE_NOTIFY_CHANGE_FILE_NAME;
- if (!parent_dirname(talloc_tos(), oldpath, &olddir, NULL)
- || !parent_dirname(talloc_tos(), newpath, &newdir, NULL)) {
- TALLOC_FREE(olddir);
- return;
+ if (!parent_dirname(talloc_tos(), smb_fname_src->base_name,
+ &parent_dir_src, NULL) ||
+ !parent_dirname(talloc_tos(), smb_fname_dst->base_name,
+ &parent_dir_dst, NULL)) {
+ goto out;
}
- if (strcmp(olddir, newdir) == 0) {
- notify_fname(conn, NOTIFY_ACTION_OLD_NAME, mask, oldpath);
- notify_fname(conn, NOTIFY_ACTION_NEW_NAME, mask, newpath);
+ status = get_full_smb_filename(talloc_tos(), smb_fname_src,
+ &fname_src);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+ status = get_full_smb_filename(talloc_tos(), smb_fname_dst,
+ &fname_dst);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ if (strcmp(parent_dir_src, parent_dir_dst) == 0) {
+ notify_fname(conn, NOTIFY_ACTION_OLD_NAME, mask, fname_src);
+ notify_fname(conn, NOTIFY_ACTION_NEW_NAME, mask, fname_dst);
}
else {
- notify_fname(conn, NOTIFY_ACTION_REMOVED, mask, oldpath);
- notify_fname(conn, NOTIFY_ACTION_ADDED, mask, newpath);
+ notify_fname(conn, NOTIFY_ACTION_REMOVED, mask, fname_src);
+ notify_fname(conn, NOTIFY_ACTION_ADDED, mask, fname_dst);
}
- TALLOC_FREE(olddir);
- TALLOC_FREE(newdir);
/* this is a strange one. w2k3 gives an additional event for
CHANGE_ATTRIBUTES and CHANGE_CREATION on the new file when renaming
@@ -5726,8 +5753,13 @@ static void notify_rename(connection_struct *conn, bool is_dir,
notify_fname(conn, NOTIFY_ACTION_MODIFIED,
FILE_NOTIFY_CHANGE_ATTRIBUTES
|FILE_NOTIFY_CHANGE_CREATION,
- newpath);
+ fname_dst);
}
+ out:
+ TALLOC_FREE(parent_dir_src);
+ TALLOC_FREE(parent_dir_dst);
+ TALLOC_FREE(fname_src);
+ TALLOC_FREE(fname_dst);
}
/****************************************************************************
@@ -5736,32 +5768,52 @@ static void notify_rename(connection_struct *conn, bool is_dir,
NTSTATUS rename_internals_fsp(connection_struct *conn,
files_struct *fsp,
- char *newname,
- const char *newname_last_component,
+ const struct smb_filename *smb_fname_dst_in,
uint32 attrs,
bool replace_if_exists)
{
TALLOC_CTX *ctx = talloc_tos();
- SMB_STRUCT_STAT sbuf, sbuf1;
+ struct smb_filename *smb_fname_src = NULL;
+ struct smb_filename *smb_fname_dst = NULL;
+ SMB_STRUCT_STAT sbuf;
NTSTATUS status = NT_STATUS_OK;
struct share_mode_lock *lck = NULL;
bool dst_exists, old_is_stream, new_is_stream;
ZERO_STRUCT(sbuf);
- status = check_name(conn, newname);
+ status = check_name(conn, smb_fname_dst_in->base_name);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
- /* Ensure newname contains a '/' */
- if(strrchr_m(newname,'/') == 0) {
- newname = talloc_asprintf(ctx,
- "./%s",
- newname);
- if (!newname) {
- return NT_STATUS_NO_MEMORY;
+ /* Make a copy of the src and dst smb_fname structs */
+ status = copy_smb_filename(ctx, smb_fname_dst_in, &smb_fname_dst);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ /*
+ * This will be replaced with copy_smb_filename() when fsp->fsp_name
+ * is converted to store an smb_filename struct.
+ */
+ status = create_synthetic_smb_fname_split(ctx, fsp->fsp_name, NULL,
+ &smb_fname_src);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ /* Ensure the dst smb_fname contains a '/' */
+ if(strrchr_m(smb_fname_dst->base_name,'/') == 0) {
+ char * tmp;
+ tmp = talloc_asprintf(smb_fname_dst, "./%s",
+ smb_fname_dst->base_name);
+ if (!tmp) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
+ TALLOC_FREE(smb_fname_dst->base_name);
+ smb_fname_dst->base_name = tmp;
}
/*
@@ -5771,36 +5823,78 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
* the rename (user is trying to change the case of the
* filename).
*/
-
if((conn->case_sensitive == False) && (conn->case_preserve == True) &&
- strequal(newname, fsp->fsp_name)) {
- char *p;
- char *newname_modified_last_component = NULL;
+ strequal(smb_fname_src->base_name, smb_fname_dst->base_name) &&
+ strequal(smb_fname_src->stream_name, smb_fname_dst->stream_name)) {
+ char *last_slash;
+ char *fname_dst_lcomp_base_mod = NULL;
+ struct smb_filename *smb_fname_orig_lcomp = NULL;
+
+ /*
+ * Get the last component of the destination name. Note that
+ * we guarantee that destination name contains a '/' character
+ * above.
+ */
+ last_slash = strrchr_m(smb_fname_dst->base_name, '/');
+ fname_dst_lcomp_base_mod = talloc_strdup(ctx, last_slash + 1);
+ if (!fname_dst_lcomp_base_mod) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
+ }
/*
- * Get the last component of the modified name.
- * Note that we guarantee that newname contains a '/'
- * character above.
+ * Create an smb_filename struct using the original last
+ * component of the destination.
*/
- p = strrchr_m(newname,'/');
- newname_modified_last_component = talloc_strdup(ctx,
- p+1);
- if (!newname_modified_last_component) {
- return NT_STATUS_NO_MEMORY;
+ status = create_synthetic_smb_fname_split(ctx,
+ smb_fname_dst->original_lcomp, NULL,
+ &smb_fname_orig_lcomp);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ goto out;
}
- if(strcsequal(newname_modified_last_component,
- newname_last_component) == False) {
+ /* If the base names only differ by case, use original. */
+ if(!strcsequal(fname_dst_lcomp_base_mod,
+ smb_fname_orig_lcomp->base_name)) {
+ char *tmp;
/*
- * Replace the modified last component with
- * the original.
+ * Replace the modified last component with the
+ * original.
*/
- *p = '\0'; /* Truncate at the '/' */
- newname = talloc_asprintf(ctx,
+ *last_slash = '\0'; /* Truncate at the '/' */
+ tmp = talloc_asprintf(smb_fname_dst,
"%s/%s",
- newname,
- newname_last_component);
+ smb_fname_dst->base_name,
+ smb_fname_orig_lcomp->base_name);
+ if (tmp == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ TALLOC_FREE(smb_fname_orig_lcomp);
+ goto out;
+ }
+ TALLOC_FREE(smb_fname_dst->base_name);
+ smb_fname_dst->base_name = tmp;
+ }
+
+ /* If the stream_names only differ by case, use original. */
+ if(!strcsequal(smb_fname_dst->stream_name,
+ smb_fname_orig_lcomp->stream_name)) {
+ char *tmp = NULL;
+ /* Use the original stream. */
+ tmp = talloc_strdup(smb_fname_dst,
+ smb_fname_orig_lcomp->stream_name);
+ if (tmp == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ TALLOC_FREE(smb_fname_orig_lcomp);
+ goto out;
+ }
+ TALLOC_FREE(smb_fname_dst->stream_name);
+ smb_fname_dst->stream_name = tmp;
}
+ TALLOC_FREE(fname_dst_lcomp_base_mod);
+ TALLOC_FREE(smb_fname_orig_lcomp);
}
/*
@@ -5808,72 +5902,86 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
* don't do the rename, just return success.
*/
- if (strcsequal(fsp->fsp_name, newname)) {
- DEBUG(3,("rename_internals_fsp: identical names in rename %s - returning success\n",
- newname));
- return NT_STATUS_OK;
+ if (strcsequal(smb_fname_src->base_name, smb_fname_dst->base_name) &&
+ strcsequal(smb_fname_src->stream_name,
+ smb_fname_dst->stream_name)) {
+ DEBUG(3, ("rename_internals_fsp: identical names in rename %s "
+ "- returning success\n",
+ smb_fname_str_dbg(smb_fname_dst)));
+ status = NT_STATUS_OK;
+ goto out;
}
- old_is_stream = is_ntfs_stream_name(fsp->fsp_name);
- new_is_stream = is_ntfs_stream_name(newname);
+ old_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
+ new_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
/* Return the correct error code if both names aren't streams. */
if (!old_is_stream && new_is_stream) {
- return NT_STATUS_OBJECT_NAME_INVALID;
+ status = NT_STATUS_OBJECT_NAME_INVALID;
+ goto out;
}
if (old_is_stream && !new_is_stream) {
- return NT_STATUS_INVALID_PARAMETER;
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto out;
}
- dst_exists = vfs_stat_smb_fname(conn, newname, &sbuf1) == 0;
+ dst_exists = SMB_VFS_STAT(conn, smb_fname_dst) == 0;
if(!replace_if_exists && dst_exists) {
- DEBUG(3,("rename_internals_fsp: dest exists doing rename %s -> %s\n",
- fsp->fsp_name,newname));
- return NT_STATUS_OBJECT_NAME_COLLISION;
+ DEBUG(3, ("rename_internals_fsp: dest exists doing rename "
+ "%s -> %s\n", smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
+ status = NT_STATUS_OBJECT_NAME_COLLISION;
+ goto out;
}
if (dst_exists) {
- struct file_id fileid = vfs_file_id_from_sbuf(conn, &sbuf1);
+ struct file_id fileid = vfs_file_id_from_sbuf(conn,
+ &smb_fname_dst->st);
files_struct *dst_fsp = file_find_di_first(fileid);
/* The file can be open when renaming a stream */
if (dst_fsp && !new_is_stream) {
DEBUG(3, ("rename_internals_fsp: Target file open\n"));
- return NT_STATUS_ACCESS_DENIED;
+ status = NT_STATUS_ACCESS_DENIED;
+ goto out;
}
}
/* Ensure we have a valid stat struct for the source. */
if (fsp->fh->fd != -1) {
if (SMB_VFS_FSTAT(fsp, &sbuf) == -1) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
} else {
int ret = -1;
if (fsp->posix_open) {
- ret = vfs_lstat_smb_fname(conn,fsp->fsp_name,&sbuf);
+ ret = SMB_VFS_LSTAT(conn, smb_fname_src);
} else {
- ret = vfs_stat_smb_fname(conn,fsp->fsp_name,&sbuf);
+ ret = SMB_VFS_STAT(conn, smb_fname_src);
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
+ sbuf = smb_fname_src->st;
}
status = can_rename(conn, fsp, attrs, &sbuf);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(3,("rename_internals_fsp: Error %s rename %s -> %s\n",
- nt_errstr(status), fsp->fsp_name,newname));
+ DEBUG(3, ("rename_internals_fsp: Error %s rename %s -> %s\n",
+ nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
if (NT_STATUS_EQUAL(status,NT_STATUS_SHARING_VIOLATION))
status = NT_STATUS_ACCESS_DENIED;
- return status;
+ goto out;
}
- if (rename_path_prefix_equal(fsp->fsp_name, newname)) {
- return NT_STATUS_ACCESS_DENIED;
+ if (rename_path_prefix_equal(smb_fname_src, smb_fname_dst)) {
+ status = NT_STATUS_ACCESS_DENIED;
}
lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
@@ -5886,15 +5994,17 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
SMB_ASSERT(lck != NULL);
- if(SMB_VFS_RENAME(conn,fsp->fsp_name, newname) == 0) {
+ if(SMB_VFS_RENAME(conn, smb_fname_src, smb_fname_dst) == 0) {
uint32 create_options = fsp->fh->private_options;
- DEBUG(3,("rename_internals_fsp: succeeded doing rename on %s -> %s\n",
- fsp->fsp_name,newname));
+ DEBUG(3, ("rename_internals_fsp: succeeded doing rename on "
+ "%s -> %s\n", smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
- notify_rename(conn, fsp->is_directory, fsp->fsp_name, newname);
+ notify_rename(conn, fsp->is_directory, smb_fname_src,
+ smb_fname_dst);
- rename_open_files(conn, lck, newname);
+ rename_open_files(conn, lck, smb_fname_dst);
/*
* A rename acts as a new file create w.r.t. allowing an initial delete
@@ -5915,7 +6025,8 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
}
}
TALLOC_FREE(lck);
- return NT_STATUS_OK;
+ status = NT_STATUS_OK;
+ goto out;
}
TALLOC_FREE(lck);
@@ -5926,8 +6037,13 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
status = map_nt_error_from_unix(errno);
}
- DEBUG(3,("rename_internals_fsp: Error %s rename %s -> %s\n",
- nt_errstr(status), fsp->fsp_name,newname));
+ DEBUG(3, ("rename_internals_fsp: Error %s rename %s -> %s\n",
+ nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
+ smb_fname_str_dbg(smb_fname_dst)));
+
+ out:
+ TALLOC_FREE(smb_fname_src);
+ TALLOC_FREE(smb_fname_dst);
return status;
}
@@ -6012,10 +6128,9 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
if (!src_has_wild) {
files_struct *fsp;
- char *fname_dst = NULL;
/*
- * Only one file needs to be renamied. Append the mask back
+ * Only one file needs to be renamed. Append the mask back
* onto the directory.
*/
TALLOC_FREE(smb_fname_src->base_name);
@@ -6105,17 +6220,9 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
goto out;
}
- status = get_full_smb_filename(ctx, smb_fname_dst, &fname_dst);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- status = rename_internals_fsp(conn, fsp, fname_dst,
- smb_fname_dst->original_lcomp,
+ status = rename_internals_fsp(conn, fsp, smb_fname_dst,
attrs, replace_if_exists);
- TALLOC_FREE(fname_dst);
-
close_file(req, fsp, NORMAL_CLOSE);
DEBUG(3, ("rename_internals: Error %s rename %s -> %s\n",
@@ -6157,7 +6264,6 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
while ((dname = ReadDirName(dir_hnd, &offset, &smb_fname_src->st))) {
files_struct *fsp = NULL;
- char *fname_dst = NULL;
char *destname = NULL;
bool sysdir_entry = False;
@@ -6249,16 +6355,16 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
break;
}
- status = get_full_smb_filename(ctx, smb_fname_dst, &fname_dst);
- if (!NT_STATUS_IS_OK(status)) {
+ smb_fname_dst->original_lcomp = talloc_strdup(smb_fname_dst,
+ dname);
+ if (!smb_fname_dst->original_lcomp) {
+ status = NT_STATUS_NO_MEMORY;
goto out;
}
- status = rename_internals_fsp(conn, fsp, fname_dst, dname,
+ status = rename_internals_fsp(conn, fsp, smb_fname_dst,
attrs, replace_if_exists);
- TALLOC_FREE(fname_dst);
-
close_file(req, fsp, NORMAL_CLOSE);
if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index ffa3de5af6..d8a78e339e 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -5484,11 +5484,32 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
if (newname[0] != ':') {
return NT_STATUS_NOT_SUPPORTED;
}
+
+ /* Create an smb_fname to call rename_internals_fsp() with. */
+ status = create_synthetic_smb_fname(talloc_tos(),
+ fsp->base_fsp->fsp_name,
+ newname, NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ /*
+ * Set the original last component, since
+ * rename_internals_fsp() requires it.
+ */
+ smb_fname->original_lcomp = talloc_strdup(smb_fname, newname);
+ if (smb_fname->original_lcomp == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
+ }
+
+ /* Create a char * to call rename_internals() with. */
base_name = talloc_asprintf(ctx, "%s%s",
fsp->base_fsp->fsp_name,
newname);
if (!base_name) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
} else {
/* newname must *not* be a stream name. */
@@ -5518,26 +5539,33 @@ static NTSTATUS smb_file_rename_information(connection_struct *conn,
return NT_STATUS_NO_MEMORY;
}
- status = unix_convert(ctx, conn, newname, &smb_fname,
+ status = unix_convert(ctx, conn, base_name, &smb_fname,
UCF_SAVE_LCOMP);
/* If an error we expect this to be
* NT_STATUS_OBJECT_PATH_NOT_FOUND */
- if (!NT_STATUS_IS_OK(status)
- && !NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
- status)) {
- goto out;
+ if (!NT_STATUS_IS_OK(status)) {
+ if(!NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
+ status)) {
+ goto out;
+ }
+ /* Create an smb_fname to call rename_internals_fsp() */
+ status = create_synthetic_smb_fname(talloc_tos(),
+ base_name, NULL,
+ NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
}
+
}
if (fsp) {
DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
fsp->fnum, fsp->fsp_name, base_name ));
- status = rename_internals_fsp(conn, fsp, base_name,
- smb_fname ?
- smb_fname->original_lcomp : NULL,
- 0, overwrite);
+ status = rename_internals_fsp(conn, fsp, smb_fname, 0,
+ overwrite);
} else {
DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
fname, base_name ));
diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c
index 0a682c7fd9..9585d6d226 100644
--- a/source3/torture/cmd_vfs.c
+++ b/source3/torture/cmd_vfs.c
@@ -511,12 +511,31 @@ static NTSTATUS cmd_lseek(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
static NTSTATUS cmd_rename(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
{
int ret;
+ struct smb_filename *smb_fname_src = NULL;
+ struct smb_filename *smb_fname_dst = NULL;
+ NTSTATUS status;
+
if (argc != 3) {
printf("Usage: rename <old> <new>\n");
return NT_STATUS_OK;
}
- ret = SMB_VFS_RENAME(vfs->conn, argv[1], argv[2]);
+ status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL,
+ &smb_fname_src);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ status = create_synthetic_smb_fname_split(mem_ctx, argv[2], NULL,
+ &smb_fname_dst);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(smb_fname_src);
+ return status;
+ }
+
+ ret = SMB_VFS_RENAME(vfs->conn, smb_fname_src, smb_fname_dst);
+ TALLOC_FREE(smb_fname_src);
+ TALLOC_FREE(smb_fname_dst);
if (ret == -1) {
printf("rename: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;