version 1.18, 2019/02/18 22:47:34 |
version 1.19, 2019/03/06 18:37:22 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <err.h> |
|
|
#include "extern.h" |
#include "extern.h" |
|
|
|
|
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 = 0, c; |
int sd = -1, rc = 0; |
char **args, buf[BUFSIZ]; |
char **args, buf[BUFSIZ]; |
uint8_t byte; |
uint8_t byte; |
|
|
|
if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw unveil", |
|
NULL) == -1) |
|
err(1, "pledge"); |
|
|
memset(&sess, 0, sizeof(struct sess)); |
memset(&sess, 0, sizeof(struct sess)); |
sess.lver = RSYNC_PROTOCOL; |
sess.lver = RSYNC_PROTOCOL; |
sess.opts = opts; |
sess.opts = opts; |
|
|
|
|
if ((args = fargs_cmdline(&sess, f)) == NULL) { |
if ((args = fargs_cmdline(&sess, f)) == NULL) { |
ERRX1(&sess, "fargs_cmdline"); |
ERRX1(&sess, "fargs_cmdline"); |
return 0; |
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); |
free(args); |
return 0; |
exit(1); |
} |
} |
|
|
/* Drop the DNS pledge. */ |
/* Drop the DNS pledge. */ |
|
|
if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw inet unveil", NULL) == -1) { |
if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw inet unveil", |
|
NULL) == -1) { |
ERR(&sess, "pledge"); |
ERR(&sess, "pledge"); |
goto out; |
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); |
rc = inet_connect(&sess, &sd, &src[i], f->host); |
if (c < 0) { |
if (rc < 0) { |
ERRX1(&sess, "inet_connect"); |
ERRX1(&sess, "inet_connect"); |
goto out; |
goto out; |
} else if (c > 0) |
} else if (rc > 0) |
break; |
break; |
} |
} |
|
|
/* Drop the inet pledge. */ |
/* Drop the inet pledge. */ |
if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) { |
if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", |
|
NULL) == -1) { |
ERR(&sess, "pledge"); |
ERR(&sess, "pledge"); |
goto out; |
goto out; |
} |
} |
|
|
if (buf[i - 1] == '\r') |
if (buf[i - 1] == '\r') |
buf[i - 1] = '\0'; |
buf[i - 1] = '\0'; |
|
|
if ((c = protocol_line(&sess, f->host, buf)) < 0) { |
if ((rc = protocol_line(&sess, f->host, buf)) < 0) { |
ERRX1(&sess, "protocol_line"); |
ERRX1(&sess, "protocol_line"); |
goto out; |
goto out; |
} else if (c > 0) |
} else if (rc > 0) |
break; |
break; |
} |
} |
|
|