summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2013-10-23 16:30:51 +1100
committerDamien Miller <djm@mindrot.org>2013-10-23 16:30:51 +1100
commit084bcd24e9fe874020e4df4e073e7408e1b17fb7 (patch)
tree3c3c78c1ae09d345be74e9758d846adc1201efeb
parent8e5a67f46916def40b2758bb7755350dd2eee843 (diff)
- djm@cvs.openbsd.org 2013/10/23 03:03:07
[readconf.c] Hostname may have %h sequences that should be expanded prior to Match evaluation; spotted by Iain Morgan
-rw-r--r--ChangeLog4
-rw-r--r--readconf.c20
2 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index eceb85b4e..b0bdf5c6c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,10 @@
15 - jmc@cvs.openbsd.org 2013/10/20 18:00:13 15 - jmc@cvs.openbsd.org 2013/10/20 18:00:13
16 [ssh_config.5] 16 [ssh_config.5]
17 tweak the "exec" description, as worded by djm; 17 tweak the "exec" description, as worded by djm;
18 - djm@cvs.openbsd.org 2013/10/23 03:03:07
19 [readconf.c]
20 Hostname may have %h sequences that should be expanded prior to Match
21 evaluation; spotted by Iain Morgan
18 22
1920131018 2320131018
20 - (djm) OpenBSD CVS Sync 24 - (djm) OpenBSD CVS Sync
diff --git a/readconf.c b/readconf.c
index bd13d4176..dad249007 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readconf.c,v 1.210 2013/10/20 06:19:27 djm Exp $ */ 1/* $OpenBSD: readconf.c,v 1.211 2013/10/23 03:03:07 djm 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
@@ -457,8 +457,8 @@ static int
457match_cfg_line(Options *options, char **condition, struct passwd *pw, 457match_cfg_line(Options *options, char **condition, struct passwd *pw,
458 const char *host_arg, const char *filename, int linenum) 458 const char *host_arg, const char *filename, int linenum)
459{ 459{
460 char *arg, *attrib, *cmd, *cp = *condition; 460 char *arg, *attrib, *cmd, *cp = *condition, *host;
461 const char *ruser, *host; 461 const char *ruser;
462 int r, port, result = 1; 462 int r, port, result = 1;
463 size_t len; 463 size_t len;
464 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV]; 464 char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV];
@@ -469,13 +469,18 @@ match_cfg_line(Options *options, char **condition, struct passwd *pw,
469 */ 469 */
470 port = options->port <= 0 ? default_ssh_port() : options->port; 470 port = options->port <= 0 ? default_ssh_port() : options->port;
471 ruser = options->user == NULL ? pw->pw_name : options->user; 471 ruser = options->user == NULL ? pw->pw_name : options->user;
472 host = options->hostname == NULL ? host_arg : options->hostname; 472 if (options->hostname != NULL) {
473 host = percent_expand(options->hostname,
474 "h", host_arg, (char *)NULL);
475 } else
476 host = xstrdup(host_arg);
473 477
474 debug3("checking match for '%s' host %s", cp, host); 478 debug3("checking match for '%s' host %s", cp, host);
475 while ((attrib = strdelim(&cp)) && *attrib != '\0') { 479 while ((attrib = strdelim(&cp)) && *attrib != '\0') {
476 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') { 480 if ((arg = strdelim(&cp)) == NULL || *arg == '\0') {
477 error("Missing Match criteria for %s", attrib); 481 error("Missing Match criteria for %s", attrib);
478 return -1; 482 result = -1;
483 goto out;
479 } 484 }
480 len = strlen(arg); 485 len = strlen(arg);
481 if (strcasecmp(attrib, "host") == 0) { 486 if (strcasecmp(attrib, "host") == 0) {
@@ -534,11 +539,14 @@ match_cfg_line(Options *options, char **condition, struct passwd *pw,
534 free(cmd); 539 free(cmd);
535 } else { 540 } else {
536 error("Unsupported Match attribute %s", attrib); 541 error("Unsupported Match attribute %s", attrib);
537 return -1; 542 result = -1;
543 goto out;
538 } 544 }
539 } 545 }
540 debug3("match %sfound", result ? "" : "not "); 546 debug3("match %sfound", result ? "" : "not ");
541 *condition = cp; 547 *condition = cp;
548 out:
549 free(host);
542 return result; 550 return result;
543} 551}
544 552