Add safety check for local --remove-source-files.
[rsync.git] / receiver.c
index 90e1685be6e2835508b6872293826cf2d1948f91..0f5d92d213fe0c35b4af7937182607ac1903189d 100644 (file)
@@ -439,9 +439,8 @@ static void handle_delayed_updates(char *local_name)
                                        "rename failed for %s (from %s)",
                                        full_fname(fname), partialptr);
                        } else {
-                               if (remove_source_files
-                                || (preserve_hard_links && F_IS_HLINKED(file)))
-                                       send_msg_int(MSG_SUCCESS, ndx);
+                               if (remove_source_files || (preserve_hard_links && F_IS_HLINKED(file)))
+                                       send_msg_success(fname, ndx);
                                handle_partial_dir(partialptr, PDIR_DELETE);
                        }
                }
@@ -593,10 +592,13 @@ int recv_files(int f_in, int f_out, char *local_name)
                if (DEBUG_GTE(RECV, 1))
                        rprintf(FINFO, "recv_files(%s)\n", fname);
 
-               if (daemon_filter_list.head && (*fname != '.' || fname[1] != '\0')
-                && check_filter(&daemon_filter_list, FLOG, fname, 0) < 0) {
-                       rprintf(FERROR, "attempt to hack rsync failed.\n");
-                       exit_cleanup(RERR_PROTOCOL);
+               if (daemon_filter_list.head && (*fname != '.' || fname[1] != '\0')) {
+                       int filt_flags = S_ISDIR(file->mode) ? NAME_IS_DIR : NAME_IS_FILE;
+                       if (check_filter(&daemon_filter_list, FLOG, fname, filt_flags) < 0) {
+                               rprintf(FERROR, "ERROR: rejecting file transfer request for daemon excluded file: %s\n",
+                                       fname);
+                               exit_cleanup(RERR_PROTOCOL);
+                       }
                }
 
 #ifdef SUPPORT_XATTRS
@@ -695,7 +697,7 @@ int recv_files(int f_in, int f_out, char *local_name)
                        if (!am_server)
                                discard_receive_data(f_in, file);
                        if (inc_recurse)
-                               send_msg_int(MSG_SUCCESS, ndx);
+                               send_msg_success(fname, ndx);
                        continue;
                }
 
@@ -808,14 +810,16 @@ int recv_files(int f_in, int f_out, char *local_name)
                        continue;
                }
 
-               if (fd1 != -1 && !(S_ISREG(st.st_mode) || (write_devices && IS_DEVICE(st.st_mode)))) {
+               if (write_devices && IS_DEVICE(st.st_mode)) {
+                       if (fd1 != -1 && st.st_size == 0)
+                               st.st_size = get_device_size(fd1, fname);
+                       /* Mark the file entry as a device so that we don't try to truncate it later on. */
+                       file->mode = S_IFBLK | (file->mode & ACCESSPERMS);
+               } else if (fd1 != -1 && !(S_ISREG(st.st_mode))) {
                        close(fd1);
                        fd1 = -1;
                }
 
-               if (fd1 != -1 && IS_DEVICE(st.st_mode) && st.st_size == 0)
-                       st.st_size = get_device_size(fd1, fname);
-
                /* If we're not preserving permissions, change the file-list's
                 * mode based on the local permissions and some heuristics. */
                if (!preserve_perms) {
@@ -921,9 +925,8 @@ int recv_files(int f_in, int f_out, char *local_name)
                case 2:
                        break;
                case 1:
-                       if (remove_source_files || inc_recurse
-                        || (preserve_hard_links && F_IS_HLINKED(file)))
-                               send_msg_int(MSG_SUCCESS, ndx);
+                       if (remove_source_files || inc_recurse || (preserve_hard_links && F_IS_HLINKED(file)))
+                               send_msg_success(fname, ndx);
                        break;
                case 0: {
                        enum logcode msgtype = redoing ? FERROR_XFER : FWARNING;