summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaddy@openbsd.org <naddy@openbsd.org>2018-10-05 14:26:09 +0000
committerDamien Miller <djm@mindrot.org>2018-10-07 14:58:24 +1100
commit2581333d564d8697837729b3d07d45738eaf5a54 (patch)
treed0fba4a6a1df98cbd17e428a07321f5339d5471a
parente0d6501e86734c48c8c503f81e1c0926e98c5c4c (diff)
upstream: Support using service names for port numbers.
* 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
-rw-r--r--misc.c12
-rw-r--r--readconf.c21
2 files changed, 23 insertions, 10 deletions
diff --git a/misc.c b/misc.c
index c4ca12560..bdc06fdb3 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.132 2018/10/03 06:38:35 djm Exp $ */ 1/* $OpenBSD: misc.c,v 1.133 2018/10/05 14:26:09 naddy Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -50,6 +50,7 @@
50#include <netinet/in_systm.h> 50#include <netinet/in_systm.h>
51#include <netinet/ip.h> 51#include <netinet/ip.h>
52#include <netinet/tcp.h> 52#include <netinet/tcp.h>
53#include <arpa/inet.h>
53 54
54#include <ctype.h> 55#include <ctype.h>
55#include <errno.h> 56#include <errno.h>
@@ -332,13 +333,16 @@ pwcopy(struct passwd *pw)
332int 333int
333a2port(const char *s) 334a2port(const char *s)
334{ 335{
336 struct servent *se;
335 long long port; 337 long long port;
336 const char *errstr; 338 const char *errstr;
337 339
338 port = strtonum(s, 0, 65535, &errstr); 340 port = strtonum(s, 0, 65535, &errstr);
339 if (errstr != NULL) 341 if (errstr == NULL)
340 return -1; 342 return (int)port;
341 return (int)port; 343 if ((se = getservbyname(s, "tcp")) != NULL)
344 return ntohs(se->s_port);
345 return -1;
342} 346}
343 347
344int 348int
diff --git a/readconf.c b/readconf.c
index d39cfa3c5..433811521 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readconf.c,v 1.299 2018/10/03 06:38:35 djm Exp $ */ 1/* $OpenBSD: readconf.c,v 1.300 2018/10/05 14:26:09 naddy Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1158,7 +1158,20 @@ parse_command:
1158 return 0; 1158 return 0;
1159 1159
1160 case oPort: 1160 case oPort:
1161 intptr = &options->port; 1161 arg = strdelim(&s);
1162 if (!arg || *arg == '\0')
1163 fatal("%.200s line %d: Missing argument.",
1164 filename, linenum);
1165 value = a2port(arg);
1166 if (value <= 0)
1167 fatal("%.200s line %d: Bad port '%s'.",
1168 filename, linenum, arg);
1169 if (*activep && options->port == -1)
1170 options->port = value;
1171 break;
1172
1173 case oConnectionAttempts:
1174 intptr = &options->connection_attempts;
1162parse_int: 1175parse_int:
1163 arg = strdelim(&s); 1176 arg = strdelim(&s);
1164 if ((errstr = atoi_err(arg, &value)) != NULL) 1177 if ((errstr = atoi_err(arg, &value)) != NULL)
@@ -1168,10 +1181,6 @@ parse_int:
1168 *intptr = value; 1181 *intptr = value;
1169 break; 1182 break;
1170 1183
1171 case oConnectionAttempts:
1172 intptr = &options->connection_attempts;
1173 goto parse_int;
1174
1175 case oCiphers: 1184 case oCiphers:
1176 arg = strdelim(&s); 1185 arg = strdelim(&s);
1177 if (!arg || *arg == '\0') 1186 if (!arg || *arg == '\0')