diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-02-17 18:11:51 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-02-17 18:11:51 +0000 |
commit | 756b929678e43f31b527fe46b414e152622848d4 (patch) | |
tree | 900fe891ebe545ec71c1b31d760e062d853ce7c1 | |
parent | 330f7183b064904c9a53f06db7c77b82b3d67dc5 (diff) |
Add support for --port=PORT and ":port" in the rsync:// URL.
real rsync only supports numbers, but this supports service names also
ok florian benno
-rw-r--r-- | usr.bin/rsync/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/rsync/main.c | 22 | ||||
-rw-r--r-- | usr.bin/rsync/rsync.1 | 4 | ||||
-rw-r--r-- | usr.bin/rsync/socket.c | 8 |
4 files changed, 27 insertions, 10 deletions
diff --git a/usr.bin/rsync/extern.h b/usr.bin/rsync/extern.h index de907484505..8137faba946 100644 --- a/usr.bin/rsync/extern.h +++ b/usr.bin/rsync/extern.h @@ -1,4 +1,4 @@ -/* $Id: extern.h,v 1.17 2019/02/16 23:16:54 deraadt Exp $ */ +/* $Id: extern.h,v 1.18 2019/02/17 18:11:50 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -118,6 +118,7 @@ struct opts { int specials; /* --specials */ char *rsync_path; /* --rsync-path */ char *ssh_prog; /* --rsh or -e */ + char *port; /* --port */ }; /* diff --git a/usr.bin/rsync/main.c b/usr.bin/rsync/main.c index 061e0e94634..e38216467e0 100644 --- a/usr.bin/rsync/main.c +++ b/usr.bin/rsync/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.25 2019/02/17 17:19:05 deraadt Exp $ */ +/* $Id: main.c,v 1.26 2019/02/17 18:11:50 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -89,10 +89,10 @@ fargs_is_daemon(const char *v) * Always returns the parsed and sanitised options. */ static struct fargs * -fargs_parse(size_t argc, char *argv[]) +fargs_parse(size_t argc, char *argv[], struct opts *opts) { struct fargs *f = NULL; - char *cp; + char *cp, *ccp; size_t i, j, len = 0; /* Allocations. */ @@ -149,6 +149,11 @@ fargs_parse(size_t argc, char *argv[]) f->module = cp; if ((cp = strchr(f->module, '/')) != NULL) *cp = '\0'; + if ((cp = strchr(f->host, ':'))) { + /* host:port --> extract port */ + *cp++ = '\0'; + opts->port = cp; + } } else { /* host:[/path] */ cp = strchr(f->host, ':'); @@ -243,6 +248,8 @@ fargs_parse(size_t argc, char *argv[]) strncasecmp(cp, "rsync://", 8) == 0) { /* rsync://path */ cp += 8; + if ((ccp = strchr(cp, ':'))) /* skip :port */ + *ccp = '\0'; if (strncmp(cp, f->host, len) || (cp[len] != '/' && cp[len] != '\0')) errx(1, "different remote " @@ -287,6 +294,7 @@ main(int argc, char *argv[]) int fds[2], rc = 0, c, st; struct fargs *fargs; struct option lopts[] = { + { "port", required_argument, NULL, 3 }, { "rsh", required_argument, NULL, 'e' }, { "rsync-path", required_argument, NULL, 1 }, { "sender", no_argument, &opts.sender, 1 }, @@ -379,6 +387,9 @@ main(int argc, char *argv[]) fprintf(stderr, "openrsync: protocol version %u\n", RSYNC_PROTOCOL); exit(0); + case 3: + opts.port = optarg; + break; case 'h': default: goto usage; @@ -393,6 +404,9 @@ main(int argc, char *argv[]) if (argc < 2) goto usage; + if (opts.port == NULL) + opts.port = "rsync"; + /* * This is what happens when we're started with the "hidden" * --server option, which is invoked for the rsync on the remote @@ -415,7 +429,7 @@ main(int argc, char *argv[]) * invoke rsync with the --server option. */ - fargs = fargs_parse(argc, argv); + fargs = fargs_parse(argc, argv, &opts); assert(fargs != NULL); /* diff --git a/usr.bin/rsync/rsync.1 b/usr.bin/rsync/rsync.1 index 78ea3a3f359..3df2a2ebe66 100644 --- a/usr.bin/rsync/rsync.1 +++ b/usr.bin/rsync/rsync.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rsync.1,v 1.8 2019/02/17 15:57:01 deraadt Exp $ +.\" $OpenBSD: rsync.1,v 1.9 2019/02/17 18:11:50 deraadt Exp $ .\" .\" Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -111,6 +111,8 @@ Increase verbosity. Specify once for files being transferred, twice for specific status, thrice for per-file transfer information, and four times for per-file breakdowns. +.It Fl -port Ns = Ns portnumber +Specify alternative port number. .It Fl -delete Delete files in .Ar directory diff --git a/usr.bin/rsync/socket.c b/usr.bin/rsync/socket.c index c0e2e3c0407..c8bf1224d94 100644 --- a/usr.bin/rsync/socket.c +++ b/usr.bin/rsync/socket.c @@ -1,4 +1,4 @@ -/* $Id: socket.c,v 1.14 2019/02/17 16:34:04 deraadt Exp $ */ +/* $Id: socket.c,v 1.15 2019/02/17 18:11:50 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -116,7 +116,7 @@ inet_resolve(struct sess *sess, const char *host, size_t *sz) hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - error = getaddrinfo(host, "rsync", &hints, &res0); + error = getaddrinfo(host, sess->opts->port, &hints, &res0); LOG2(sess, "resolving: %s", host); @@ -125,8 +125,8 @@ inet_resolve(struct sess *sess, const char *host, size_t *sz) host, gai_strerror(error)); return NULL; } else if (error == EAI_SERVICE) { - ERRX(sess, "Could not resolve service rsync: %s", - gai_strerror(error)); + ERRX(sess, "Could not resolve service '%s': %s", + sess->opts->port, gai_strerror(error)); return NULL; } else if (error) { ERRX(sess, "getaddrinfo: %s: %s", host, gai_strerror(error)); |