[BACK]Return to client.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rsync

Annotation of src/usr.bin/rsync/client.c, Revision 1.7

1.7     ! deraadt     1: /*     $Id: client.c,v 1.6 2019/02/16 10:44:01 florian Exp $ */
1.1       benno       2: /*
                      3:  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #include <sys/stat.h>
                     18:
                     19: #include <assert.h>
                     20: #include <inttypes.h>
                     21: #include <stdlib.h>
                     22: #include <string.h>
                     23: #include <unistd.h>
                     24:
                     25: #include "extern.h"
                     26:
                     27: /*
                     28:  * The rsync client runs on the operator's local machine.
                     29:  * It can either be in sender or receiver mode.
                     30:  * In the former, it synchronises local files from a remote sink.
                     31:  * In the latter, the remote sink synchronses to the local files.
                     32:  *
1.6       florian    33:  * Pledges: stdio, rpath, wpath, cpath, unveil, fattr, chown.
1.1       benno      34:  *
1.6       florian    35:  * Pledges (dry-run): -cpath, -wpath, -fattr, chown.
1.1       benno      36:  * Pledges (!preserve_times): -fattr.
                     37:  */
                     38: int
                     39: rsync_client(const struct opts *opts, int fd, const struct fargs *f)
                     40: {
                     41:        struct sess      sess;
                     42:        int              rc = 0;
                     43:
                     44:        /* Standard rsync preamble, sender side. */
                     45:
                     46:        memset(&sess, 0, sizeof(struct sess));
                     47:        sess.opts = opts;
                     48:        sess.lver = RSYNC_PROTOCOL;
                     49:
1.3       deraadt    50:        if (!io_write_int(&sess, fd, sess.lver)) {
1.1       benno      51:                ERRX1(&sess, "io_write_int");
                     52:                goto out;
1.3       deraadt    53:        } else if (!io_read_int(&sess, fd, &sess.rver)) {
1.1       benno      54:                ERRX1(&sess, "io_read_int");
                     55:                goto out;
1.3       deraadt    56:        } else if (!io_read_int(&sess, fd, &sess.seed)) {
1.1       benno      57:                ERRX1(&sess, "io_read_int");
                     58:                goto out;
                     59:        }
                     60:
                     61:        if (sess.rver < sess.lver) {
1.7     ! deraadt    62:                ERRX(&sess,
        !            63:                    "remote protocol %d is older than own %d: unsupported\n",
        !            64:                    sess.rver, sess.lver);
        !            65:                rc = 2; /* Protocol incompatibility*/
1.1       benno      66:                goto out;
                     67:        }
                     68:
                     69:        LOG2(&sess, "client detected client version %" PRId32
                     70:                ", server version %" PRId32 ", seed %" PRId32,
                     71:                sess.lver, sess.rver, sess.seed);
                     72:
                     73:        sess.mplex_reads = 1;
                     74:
                     75:        /*
                     76:         * Now we need to get our list of files.
                     77:         * Senders (and locals) send; receivers receive.
                     78:         */
                     79:
                     80:        if (FARGS_RECEIVER != f->mode) {
                     81:                LOG2(&sess, "client starting sender: %s",
1.4       deraadt    82:                    f->host == NULL ? "(local)" : f->host);
1.5       deraadt    83:                if (!rsync_sender(&sess, fd, fd, f->sourcesz,
                     84:                    f->sources)) {
1.1       benno      85:                        ERRX1(&sess, "rsync_sender");
                     86:                        goto out;
                     87:                }
                     88:        } else {
                     89:                LOG2(&sess, "client starting receiver: %s",
1.4       deraadt    90:                    f->host == NULL ? "(local)" : f->host);
1.3       deraadt    91:                if (!rsync_receiver(&sess, fd, fd, f->sink)) {
1.1       benno      92:                        ERRX1(&sess, "rsync_receiver");
                     93:                        goto out;
                     94:                }
                     95:        }
                     96:
                     97: #if 0
                     98:        /* Probably the EOF. */
                     99:        if (io_read_check(&sess, fd))
                    100:                WARNX(&sess, "data remains in read pipe");
                    101: #endif
                    102:
                    103:        rc = 1;
                    104: out:
                    105:        return rc;
                    106: }