version 1.25, 2019/02/17 17:19:05 |
version 1.26, 2019/02/17 18:11:50 |
|
|
* Always returns the parsed and sanitised options. |
* Always returns the parsed and sanitised options. |
*/ |
*/ |
static struct fargs * |
static struct fargs * |
fargs_parse(size_t argc, char *argv[]) |
fargs_parse(size_t argc, char *argv[], struct opts *opts) |
{ |
{ |
struct fargs *f = NULL; |
struct fargs *f = NULL; |
char *cp; |
char *cp, *ccp; |
size_t i, j, len = 0; |
size_t i, j, len = 0; |
|
|
/* Allocations. */ |
/* Allocations. */ |
|
|
f->module = cp; |
f->module = cp; |
if ((cp = strchr(f->module, '/')) != NULL) |
if ((cp = strchr(f->module, '/')) != NULL) |
*cp = '\0'; |
*cp = '\0'; |
|
if ((cp = strchr(f->host, ':'))) { |
|
/* host:port --> extract port */ |
|
*cp++ = '\0'; |
|
opts->port = cp; |
|
} |
} else { |
} else { |
/* host:[/path] */ |
/* host:[/path] */ |
cp = strchr(f->host, ':'); |
cp = strchr(f->host, ':'); |
|
|
strncasecmp(cp, "rsync://", 8) == 0) { |
strncasecmp(cp, "rsync://", 8) == 0) { |
/* rsync://path */ |
/* rsync://path */ |
cp += 8; |
cp += 8; |
|
if ((ccp = strchr(cp, ':'))) /* skip :port */ |
|
*ccp = '\0'; |
if (strncmp(cp, f->host, len) || |
if (strncmp(cp, f->host, len) || |
(cp[len] != '/' && cp[len] != '\0')) |
(cp[len] != '/' && cp[len] != '\0')) |
errx(1, "different remote " |
errx(1, "different remote " |
|
|
int fds[2], rc = 0, c, st; |
int fds[2], rc = 0, c, st; |
struct fargs *fargs; |
struct fargs *fargs; |
struct option lopts[] = { |
struct option lopts[] = { |
|
{ "port", required_argument, NULL, 3 }, |
{ "rsh", required_argument, NULL, 'e' }, |
{ "rsh", required_argument, NULL, 'e' }, |
{ "rsync-path", required_argument, NULL, 1 }, |
{ "rsync-path", required_argument, NULL, 1 }, |
{ "sender", no_argument, &opts.sender, 1 }, |
{ "sender", no_argument, &opts.sender, 1 }, |
|
|
fprintf(stderr, "openrsync: protocol version %u\n", |
fprintf(stderr, "openrsync: protocol version %u\n", |
RSYNC_PROTOCOL); |
RSYNC_PROTOCOL); |
exit(0); |
exit(0); |
|
case 3: |
|
opts.port = optarg; |
|
break; |
case 'h': |
case 'h': |
default: |
default: |
goto usage; |
goto usage; |
|
|
if (argc < 2) |
if (argc < 2) |
goto usage; |
goto usage; |
|
|
|
if (opts.port == NULL) |
|
opts.port = "rsync"; |
|
|
/* |
/* |
* This is what happens when we're started with the "hidden" |
* This is what happens when we're started with the "hidden" |
* --server option, which is invoked for the rsync on the remote |
* --server option, which is invoked for the rsync on the remote |
|
|
* invoke rsync with the --server option. |
* invoke rsync with the --server option. |
*/ |
*/ |
|
|
fargs = fargs_parse(argc, argv); |
fargs = fargs_parse(argc, argv, &opts); |
assert(fargs != NULL); |
assert(fargs != NULL); |
|
|
/* |
/* |