diff options
Diffstat (limited to 'source3/modules')
-rw-r--r-- | source3/modules/onefs.h | 5 | ||||
-rw-r--r-- | source3/modules/onefs_streams.c | 78 | ||||
-rw-r--r-- | source3/modules/vfs_audit.c | 13 | ||||
-rw-r--r-- | source3/modules/vfs_cap.c | 48 | ||||
-rw-r--r-- | source3/modules/vfs_catia.c | 50 | ||||
-rw-r--r-- | source3/modules/vfs_default.c | 17 | ||||
-rw-r--r-- | source3/modules/vfs_extd_audit.c | 16 | ||||
-rw-r--r-- | source3/modules/vfs_full_audit.c | 12 | ||||
-rw-r--r-- | source3/modules/vfs_netatalk.c | 28 | ||||
-rw-r--r-- | source3/modules/vfs_onefs_shadow_copy.c | 46 | ||||
-rw-r--r-- | source3/modules/vfs_recycle.c | 20 | ||||
-rw-r--r-- | source3/modules/vfs_shadow_copy2.c | 16 | ||||
-rw-r--r-- | source3/modules/vfs_streams_depot.c | 106 | ||||
-rw-r--r-- | source3/modules/vfs_streams_xattr.c | 94 | ||||
-rw-r--r-- | source3/modules/vfs_syncops.c | 8 |
15 files changed, 355 insertions, 202 deletions
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; } |