]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: Support using service names for port numbers.
authornaddy@openbsd.org <naddy@openbsd.org>
Fri, 5 Oct 2018 14:26:09 +0000 (14:26 +0000)
committerDamien Miller <djm@mindrot.org>
Sun, 7 Oct 2018 03:58:24 +0000 (14:58 +1100)
* Try to resolve a port specification with getservbyname(3) if a
 numeric conversion fails.
* Make the "Port" option in ssh_config handle its argument as a
 port rather than a plain integer.

ok dtucker@ deraadt@

OpenBSD-Commit-ID: e7f03633133205ab3dfbc67f9df7475fabae660d

misc.c
readconf.c

diff --git a/misc.c b/misc.c
index c4ca12560c153df7eabb5cd0d2e43d39825f1a9a..bdc06fdb3332fb113b8770572e1c14050214559b 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.132 2018/10/03 06:38:35 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.133 2018/10/05 14:26:09 naddy Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  * Copyright (c) 2005,2006 Damien Miller.  All rights reserved.
@@ -50,6 +50,7 @@
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
+#include <arpa/inet.h>
 
 #include <ctype.h>
 #include <errno.h>
@@ -332,13 +333,16 @@ pwcopy(struct passwd *pw)
 int
 a2port(const char *s)
 {
+       struct servent *se;
        long long port;
        const char *errstr;
 
        port = strtonum(s, 0, 65535, &errstr);
-       if (errstr != NULL)
-               return -1;
-       return (int)port;
+       if (errstr == NULL)
+               return (int)port;
+       if ((se = getservbyname(s, "tcp")) != NULL)
+               return ntohs(se->s_port);
+       return -1;
 }
 
 int
index d39cfa3c5bc9bd7f3648372a5acca2ef704ea9a9..433811521bb10af1de237ab44697071868992e92 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: readconf.c,v 1.299 2018/10/03 06:38:35 djm Exp $ */
+/* $OpenBSD: readconf.c,v 1.300 2018/10/05 14:26:09 naddy Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1158,7 +1158,20 @@ parse_command:
                return 0;
 
        case oPort:
-               intptr = &options->port;
+               arg = strdelim(&s);
+               if (!arg || *arg == '\0')
+                       fatal("%.200s line %d: Missing argument.",
+                           filename, linenum);
+               value = a2port(arg);
+               if (value <= 0)
+                       fatal("%.200s line %d: Bad port '%s'.",
+                           filename, linenum, arg);
+               if (*activep && options->port == -1)
+                       options->port = value;
+               break;
+
+       case oConnectionAttempts:
+               intptr = &options->connection_attempts;
 parse_int:
                arg = strdelim(&s);
                if ((errstr = atoi_err(arg, &value)) != NULL)
@@ -1168,10 +1181,6 @@ parse_int:
                        *intptr = value;
                break;
 
-       case oConnectionAttempts:
-               intptr = &options->connection_attempts;
-               goto parse_int;
-
        case oCiphers:
                arg = strdelim(&s);
                if (!arg || *arg == '\0')