=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rsync/receiver.c,v retrieving revision 1.22 retrieving revision 1.23 diff -c -r1.22 -r1.23 *** src/usr.bin/rsync/receiver.c 2019/03/30 07:28:55 1.22 --- src/usr.bin/rsync/receiver.c 2019/05/08 20:00:25 1.23 *************** *** 1,4 **** ! /* $Id: receiver.c,v 1.22 2019/03/30 07:28:55 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons --- 1,4 ---- ! /* $Id: receiver.c,v 1.23 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons *************** *** 57,66 **** ts[1].tv_sec = f->st.mtime; ts[1].tv_nsec = 0; if (futimens(fd, ts) == -1) { ! ERR(sess, "%s: futimens", path); return 0; } ! LOG4(sess, "%s: updated date", f->path); } /* --- 57,66 ---- ts[1].tv_sec = f->st.mtime; ts[1].tv_nsec = 0; if (futimens(fd, ts) == -1) { ! ERR("%s: futimens", path); return 0; } ! LOG4("%s: updated date", f->path); } /* *************** *** 78,91 **** if (uid != (uid_t)-1 || gid != (gid_t)-1) { if (fchown(fd, uid, gid) == -1) { if (errno != EPERM) { ! ERR(sess, "%s: fchown", path); return 0; } if (getuid() == 0) ! WARNX(sess, "%s: identity unknown or not available " "to user.group: %u.%u", f->path, uid, gid); } else ! LOG4(sess, "%s: updated uid and/or gid", f->path); mode &= ~(S_ISTXT | S_ISUID | S_ISGID); } --- 78,91 ---- if (uid != (uid_t)-1 || gid != (gid_t)-1) { if (fchown(fd, uid, gid) == -1) { if (errno != EPERM) { ! ERR("%s: fchown", path); return 0; } if (getuid() == 0) ! WARNX("%s: identity unknown or not available " "to user.group: %u.%u", f->path, uid, gid); } else ! LOG4("%s: updated uid and/or gid", f->path); mode &= ~(S_ISTXT | S_ISUID | S_ISGID); } *************** *** 93,102 **** if (newfile || sess->opts->preserve_perms) { if (fchmod(fd, mode) == -1) { ! ERR(sess, "%s: fchmod", path); return 0; } ! LOG4(sess, "%s: updated permissions", f->path); } return 1; --- 93,102 ---- if (newfile || sess->opts->preserve_perms) { if (fchmod(fd, mode) == -1) { ! ERR("%s: fchmod", path); return 0; } ! LOG4("%s: updated permissions", f->path); } return 1; *************** *** 118,127 **** ts[1].tv_sec = f->st.mtime; ts[1].tv_nsec = 0; if (utimensat(rootfd, path, ts, AT_SYMLINK_NOFOLLOW) == -1) { ! ERR(sess, "%s: utimensat", path); return 0; } ! LOG4(sess, "%s: updated date", f->path); } /* --- 118,127 ---- ts[1].tv_sec = f->st.mtime; ts[1].tv_nsec = 0; if (utimensat(rootfd, path, ts, AT_SYMLINK_NOFOLLOW) == -1) { ! ERR("%s: utimensat", path); return 0; } ! LOG4("%s: updated date", f->path); } /* *************** *** 139,152 **** if (uid != (uid_t)-1 || gid != (gid_t)-1) { if (fchownat(rootfd, path, uid, gid, AT_SYMLINK_NOFOLLOW) == -1) { if (errno != EPERM) { ! ERR(sess, "%s: fchownat", path); return 0; } if (getuid() == 0) ! WARNX(sess, "%s: identity unknown or not available " "to user.group: %u.%u", f->path, uid, gid); } else ! LOG4(sess, "%s: updated uid and/or gid", f->path); mode &= ~(S_ISTXT | S_ISUID | S_ISGID); } --- 139,152 ---- if (uid != (uid_t)-1 || gid != (gid_t)-1) { if (fchownat(rootfd, path, uid, gid, AT_SYMLINK_NOFOLLOW) == -1) { if (errno != EPERM) { ! ERR("%s: fchownat", path); return 0; } if (getuid() == 0) ! WARNX("%s: identity unknown or not available " "to user.group: %u.%u", f->path, uid, gid); } else ! LOG4("%s: updated uid and/or gid", f->path); mode &= ~(S_ISTXT | S_ISUID | S_ISGID); } *************** *** 154,163 **** if (newfile || sess->opts->preserve_perms) { if (fchmodat(rootfd, path, mode, AT_SYMLINK_NOFOLLOW) == -1) { ! ERR(sess, "%s: fchmodat", path); return 0; } ! LOG4(sess, "%s: updated permissions", f->path); } return 1; --- 154,163 ---- if (newfile || sess->opts->preserve_perms) { if (fchmodat(rootfd, path, mode, AT_SYMLINK_NOFOLLOW) == -1) { ! ERR("%s: fchmodat", path); return 0; } ! LOG4("%s: updated permissions", f->path); } return 1; *************** *** 181,187 **** mode_t oumask; if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) { ! ERR(sess, "pledge"); goto out; } --- 181,187 ---- mode_t oumask; if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) { ! ERR("pledge"); goto out; } *************** *** 189,204 **** if (!sess->opts->server && !io_write_int(sess, fdout, 0)) { ! ERRX1(sess, "io_write_int"); goto out; } if (sess->opts->server && sess->opts->del) { if (!io_read_size(sess, fdin, &excl)) { ! ERRX1(sess, "io_read_size"); goto out; } else if (excl != 0) { ! ERRX(sess, "exclusion list is non-empty"); goto out; } } --- 189,204 ---- if (!sess->opts->server && !io_write_int(sess, fdout, 0)) { ! ERRX1("io_write_int"); goto out; } if (sess->opts->server && sess->opts->del) { if (!io_read_size(sess, fdin, &excl)) { ! ERRX1("io_read_size"); goto out; } else if (excl != 0) { ! ERRX("exclusion list is non-empty"); goto out; } } *************** *** 209,236 **** */ if (!flist_recv(sess, fdin, &fl, &flsz)) { ! ERRX1(sess, "flist_recv"); goto out; } /* The IO error is sent after the file list. */ if (!io_read_int(sess, fdin, &ioerror)) { ! ERRX1(sess, "io_read_int"); goto out; } else if (ioerror != 0) { ! ERRX1(sess, "io_error is non-zero"); goto out; } if (flsz == 0 && !sess->opts->server) { ! WARNX(sess, "receiver has empty file list: exiting"); rc = 1; goto out; } else if (!sess->opts->server) ! LOG1(sess, "Transfer starting: %zu files", flsz); ! LOG2(sess, "%s: receiver destination", root); /* * Create the path for our destination directory, if we're not --- 209,236 ---- */ if (!flist_recv(sess, fdin, &fl, &flsz)) { ! ERRX1("flist_recv"); goto out; } /* The IO error is sent after the file list. */ if (!io_read_int(sess, fdin, &ioerror)) { ! ERRX1("io_read_int"); goto out; } else if (ioerror != 0) { ! ERRX1("io_error is non-zero"); goto out; } if (flsz == 0 && !sess->opts->server) { ! WARNX("receiver has empty file list: exiting"); rc = 1; goto out; } else if (!sess->opts->server) ! LOG1("Transfer starting: %zu files", flsz); ! LOG2("%s: receiver destination", root); /* * Create the path for our destination directory, if we're not *************** *** 241,250 **** if (!sess->opts->dry_run) { if ((tofree = strdup(root)) == NULL) { ! ERR(sess, "strdup"); goto out; } else if (mkpath(sess, tofree) < 0) { ! ERRX1(sess, "%s: mkpath", root); free(tofree); goto out; } --- 241,250 ---- if (!sess->opts->dry_run) { if ((tofree = strdup(root)) == NULL) { ! ERR("strdup"); goto out; } else if (mkpath(sess, tofree) < 0) { ! ERRX1("%s: mkpath", root); free(tofree); goto out; } *************** *** 261,267 **** if (!sess->opts->dry_run) { dfd = open(root, O_RDONLY | O_DIRECTORY, 0); if (dfd == -1) { ! ERR(sess, "%s: open", root); goto out; } } --- 261,267 ---- if (!sess->opts->dry_run) { dfd = open(root, O_RDONLY | O_DIRECTORY, 0); if (dfd == -1) { ! ERR("%s: open", root); goto out; } } *************** *** 274,280 **** if (sess->opts->del && sess->opts->recursive && !flist_gen_dels(sess, root, &dfl, &dflsz, fl, flsz)) { ! ERRX1(sess, "flist_gen_local"); goto out; } --- 274,280 ---- if (sess->opts->del && sess->opts->recursive && !flist_gen_dels(sess, root, &dfl, &dflsz, fl, flsz)) { ! ERRX1("flist_gen_local"); goto out; } *************** *** 286,302 **** */ if (unveil(root, "rwc") == -1) { ! ERR(sess, "%s: unveil", root); goto out; } else if (unveil(NULL, NULL) == -1) { ! ERR(sess, "%s: unveil", root); goto out; } /* If we have a local set, go for the deletion. */ if (!flist_del(sess, dfd, dfl, dflsz)) { ! ERRX1(sess, "flist_del"); goto out; } --- 286,302 ---- */ if (unveil(root, "rwc") == -1) { ! ERR("%s: unveil", root); goto out; } else if (unveil(NULL, NULL) == -1) { ! ERR("%s: unveil", root); goto out; } /* If we have a local set, go for the deletion. */ if (!flist_del(sess, dfd, dfl, dflsz)) { ! ERRX1("flist_del"); goto out; } *************** *** 315,347 **** ul = upload_alloc(sess, root, dfd, fdout, CSUM_LENGTH_PHASE1, fl, flsz, oumask); if (ul == NULL) { ! ERRX1(sess, "upload_alloc"); goto out; } dl = download_alloc(sess, fdin, fl, flsz, dfd); if (dl == NULL) { ! ERRX1(sess, "download_alloc"); goto out; } ! LOG2(sess, "%s: ready for phase 1 data", root); for (;;) { if ((c = poll(pfd, PFD__MAX, POLL_TIMEOUT)) == -1) { ! ERR(sess, "poll"); goto out; } else if (c == 0) { ! ERRX(sess, "poll: timeout"); goto out; } for (i = 0; i < PFD__MAX; i++) if (pfd[i].revents & (POLLERR|POLLNVAL)) { ! ERRX(sess, "poll: bad fd"); goto out; } else if (pfd[i].revents & POLLHUP) { ! ERRX(sess, "poll: hangup"); goto out; } --- 315,347 ---- ul = upload_alloc(sess, root, dfd, fdout, CSUM_LENGTH_PHASE1, fl, flsz, oumask); if (ul == NULL) { ! ERRX1("upload_alloc"); goto out; } dl = download_alloc(sess, fdin, fl, flsz, dfd); if (dl == NULL) { ! ERRX1("download_alloc"); goto out; } ! LOG2("%s: ready for phase 1 data", root); for (;;) { if ((c = poll(pfd, PFD__MAX, POLL_TIMEOUT)) == -1) { ! ERR("poll"); goto out; } else if (c == 0) { ! ERRX("poll: timeout"); goto out; } for (i = 0; i < PFD__MAX; i++) if (pfd[i].revents & (POLLERR|POLLNVAL)) { ! ERRX("poll: bad fd"); goto out; } else if (pfd[i].revents & POLLHUP) { ! ERRX("poll: hangup"); goto out; } *************** *** 357,363 **** if (sess->mplex_reads && (POLLIN & pfd[PFD_SENDER_IN].revents)) { if (!io_read_flush(sess, fdin)) { ! ERRX1(sess, "io_read_flush"); goto out; } else if (sess->mplex_read_remain == 0) pfd[PFD_SENDER_IN].revents &= ~POLLIN; --- 357,363 ---- if (sess->mplex_reads && (POLLIN & pfd[PFD_SENDER_IN].revents)) { if (!io_read_flush(sess, fdin)) { ! ERRX1("io_read_flush"); goto out; } else if (sess->mplex_read_remain == 0) pfd[PFD_SENDER_IN].revents &= ~POLLIN; *************** *** 376,382 **** &pfd[PFD_UPLOADER_IN].fd, sess, &pfd[PFD_SENDER_OUT].fd); if (c < 0) { ! ERRX1(sess, "rsync_uploader"); goto out; } } --- 376,382 ---- &pfd[PFD_UPLOADER_IN].fd, sess, &pfd[PFD_SENDER_OUT].fd); if (c < 0) { ! ERRX1("rsync_uploader"); goto out; } } *************** *** 395,408 **** c = rsync_downloader(dl, sess, &pfd[PFD_DOWNLOADER_IN].fd); if (c < 0) { ! ERRX1(sess, "rsync_downloader"); goto out; } else if (c == 0) { assert(phase == 0); phase++; ! LOG2(sess, ! "%s: receiver ready for phase 2 data", ! root); break; } --- 395,406 ---- c = rsync_downloader(dl, sess, &pfd[PFD_DOWNLOADER_IN].fd); if (c < 0) { ! ERRX1("rsync_downloader"); goto out; } else if (c == 0) { assert(phase == 0); phase++; ! LOG2("%s: receiver ready for phase 2 data", root); break; } *************** *** 420,432 **** if (phase == 1) { if (!io_write_int(sess, fdout, -1)) { ! ERRX1(sess, "io_write_int"); goto out; } else if (!io_read_int(sess, fdin, &ioerror)) { ! ERRX1(sess, "io_read_int"); goto out; } else if (ioerror != -1) { ! ERRX(sess, "expected phase ack"); goto out; } } --- 418,430 ---- if (phase == 1) { if (!io_write_int(sess, fdout, -1)) { ! ERRX1("io_write_int"); goto out; } else if (!io_read_int(sess, fdin, &ioerror)) { ! ERRX1("io_read_int"); goto out; } else if (ioerror != -1) { ! ERRX("expected phase ack"); goto out; } } *************** *** 437,457 **** */ if (!rsync_uploader_tail(ul, sess)) { ! ERRX1(sess, "rsync_uploader_tail"); goto out; } /* Process server statistics and say good-bye. */ if (!sess_stats_recv(sess, fdin)) { ! ERRX1(sess, "sess_stats_recv"); goto out; } else if (!io_write_int(sess, fdout, -1)) { ! ERRX1(sess, "io_write_int"); goto out; } ! LOG2(sess, "receiver finished updating"); rc = 1; out: if (dfd != -1) --- 435,455 ---- */ if (!rsync_uploader_tail(ul, sess)) { ! ERRX1("rsync_uploader_tail"); goto out; } /* Process server statistics and say good-bye. */ if (!sess_stats_recv(sess, fdin)) { ! ERRX1("sess_stats_recv"); goto out; } else if (!io_write_int(sess, fdout, -1)) { ! ERRX1("io_write_int"); goto out; } ! LOG2("receiver finished updating"); rc = 1; out: if (dfd != -1)