version 1.21, 2019/03/23 16:04:28 |
version 1.22, 2019/03/31 08:47:46 |
|
|
} |
} |
|
|
/* |
/* |
* Talk to a remote rsync://-enabled server sender. |
* Connect to a remote rsync://-enabled server sender. |
* Returns exit code 0 on success, 1 on failure, 2 on failure with |
* Returns exit code 0 on success, 1 on failure. |
* incompatible protocols. |
|
*/ |
*/ |
int |
int |
rsync_socket(const struct opts *opts, const struct fargs *f) |
rsync_connect(const struct opts *opts, int *sd, const struct fargs *f) |
{ |
{ |
struct sess sess; |
struct sess sess; |
struct source *src = NULL; |
struct source *src = NULL; |
size_t i, srcsz = 0; |
size_t i, srcsz = 0; |
int sd = -1, rc = 1, c; |
int c, rc = 1; |
char **args, buf[BUFSIZ]; |
|
uint8_t byte; |
|
|
|
if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw unveil", |
if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw unveil", |
NULL) == -1) |
NULL) == -1) |
err(1, "pledge"); |
err(1, "pledge"); |
|
|
memset(&sess, 0, sizeof(struct sess)); |
memset(&sess, 0, sizeof(struct sess)); |
sess.lver = RSYNC_PROTOCOL; |
|
sess.opts = opts; |
sess.opts = opts; |
|
|
assert(f->host != NULL); |
assert(f->host != NULL); |
assert(f->module != NULL); |
|
|
|
if ((args = fargs_cmdline(&sess, f)) == NULL) { |
|
ERRX1(&sess, "fargs_cmdline"); |
|
exit(1); |
|
} |
|
|
|
/* Resolve all IP addresses from the host. */ |
/* Resolve all IP addresses from the host. */ |
|
|
if ((src = inet_resolve(&sess, f->host, &srcsz)) == NULL) { |
if ((src = inet_resolve(&sess, f->host, &srcsz)) == NULL) { |
ERRX1(&sess, "inet_resolve"); |
ERRX1(&sess, "inet_resolve"); |
free(args); |
|
exit(1); |
exit(1); |
} |
} |
|
|
|
|
|
|
assert(srcsz); |
assert(srcsz); |
for (i = 0; i < srcsz; i++) { |
for (i = 0; i < srcsz; i++) { |
c = inet_connect(&sess, &sd, &src[i], f->host); |
c = inet_connect(&sess, sd, &src[i], f->host); |
if (c < 0) { |
if (c < 0) { |
ERRX1(&sess, "inet_connect"); |
ERRX1(&sess, "inet_connect"); |
goto out; |
goto out; |
|
|
goto out; |
goto out; |
} |
} |
|
|
/* Initiate with the rsyncd version and module request. */ |
|
|
|
LOG2(&sess, "connected: %s, %s", src[i].ip, f->host); |
LOG2(&sess, "connected: %s, %s", src[i].ip, f->host); |
|
|
|
free(src); |
|
return 0; |
|
out: |
|
free(src); |
|
if (*sd != -1) |
|
close(*sd); |
|
return rc; |
|
} |
|
|
|
/* |
|
* Talk to a remote rsync://-enabled server sender. |
|
* Returns exit code 0 on success, 1 on failure, 2 on failure with |
|
* incompatible protocols. |
|
*/ |
|
int |
|
rsync_socket(const struct opts *opts, int sd, const struct fargs *f) |
|
{ |
|
struct sess sess; |
|
size_t i, skip; |
|
int c, rc = 1; |
|
char **args, buf[BUFSIZ]; |
|
uint8_t byte; |
|
|
|
if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", |
|
NULL) == -1) |
|
err(1, "pledge"); |
|
|
|
memset(&sess, 0, sizeof(struct sess)); |
|
sess.lver = RSYNC_PROTOCOL; |
|
sess.opts = opts; |
|
|
|
assert(f->host != NULL); |
|
assert(f->module != NULL); |
|
|
|
if ((args = fargs_cmdline(&sess, f, &skip)) == NULL) { |
|
ERRX1(&sess, "fargs_cmdline"); |
|
exit(1); |
|
} |
|
|
|
/* Initiate with the rsyncd version and module request. */ |
|
|
(void)snprintf(buf, sizeof(buf), "@RSYNCD: %d", sess.lver); |
(void)snprintf(buf, sizeof(buf), "@RSYNCD: %d", sess.lver); |
if (!io_write_line(&sess, sd, buf)) { |
if (!io_write_line(&sess, sd, buf)) { |
ERRX1(&sess, "io_write_line"); |
ERRX1(&sess, "io_write_line"); |
|
|
* Emit a standalone newline afterward. |
* Emit a standalone newline afterward. |
*/ |
*/ |
|
|
if (f->mode == FARGS_RECEIVER || f->mode == FARGS_SENDER) |
for (i = skip ; args[i] != NULL; i++) |
i = 3; /* ssh host rsync... */ |
|
else |
|
i = 1; /* rsync... */ |
|
|
|
for ( ; args[i] != NULL; i++) |
|
if (!io_write_line(&sess, sd, args[i])) { |
if (!io_write_line(&sess, sd, args[i])) { |
ERRX1(&sess, "io_write_line"); |
ERRX1(&sess, "io_write_line"); |
goto out; |
goto out; |
|
|
|
|
rc = 0; |
rc = 0; |
out: |
out: |
free(src); |
|
free(args); |
free(args); |
if (sd != -1) |
close(sd); |
close(sd); |
|
return rc; |
return rc; |
} |
} |