summaryrefslogtreecommitdiff
path: root/readconf.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2016-02-29 12:15:15 +0000
committerColin Watson <cjwatson@debian.org>2016-02-29 12:15:15 +0000
commitc52a95cc4754e6630c96fe65ae0c65eb41d2c590 (patch)
tree793395934013923b7b2426382c0676edcd4be3d4 /readconf.c
parenteeff4de96f5d7365750dc56912c2c62b5c28db6b (diff)
parent72b061d4ba0f909501c595d709ea76e06b01e5c9 (diff)
Import openssh_7.2p1.orig.tar.gz
Diffstat (limited to 'readconf.c')
-rw-r--r--readconf.c110
1 files changed, 82 insertions, 28 deletions
diff --git a/readconf.c b/readconf.c
index cd014821a..69d4553af 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readconf.c,v 1.239 2015/07/30 00:01:34 djm Exp $ */ 1/* $OpenBSD: readconf.c,v 1.250 2016/02/08 23:40:12 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
@@ -135,6 +135,7 @@ typedef enum {
135 oPasswordAuthentication, oRSAAuthentication, 135 oPasswordAuthentication, oRSAAuthentication,
136 oChallengeResponseAuthentication, oXAuthLocation, 136 oChallengeResponseAuthentication, oXAuthLocation,
137 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward, 137 oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
138 oCertificateFile, oAddKeysToAgent,
138 oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand, 139 oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
139 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts, 140 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
140 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression, 141 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
@@ -151,7 +152,7 @@ typedef enum {
151 oSendEnv, oControlPath, oControlMaster, oControlPersist, 152 oSendEnv, oControlPath, oControlMaster, oControlPersist,
152 oHashKnownHosts, 153 oHashKnownHosts,
153 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand, 154 oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
154 oVisualHostKey, oUseRoaming, 155 oVisualHostKey,
155 oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass, 156 oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
156 oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots, 157 oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
157 oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs, 158 oCanonicalizeFallbackLocal, oCanonicalizePermittedCNAMEs,
@@ -202,6 +203,8 @@ static struct {
202 { "identityfile", oIdentityFile }, 203 { "identityfile", oIdentityFile },
203 { "identityfile2", oIdentityFile }, /* obsolete */ 204 { "identityfile2", oIdentityFile }, /* obsolete */
204 { "identitiesonly", oIdentitiesOnly }, 205 { "identitiesonly", oIdentitiesOnly },
206 { "certificatefile", oCertificateFile },
207 { "addkeystoagent", oAddKeysToAgent },
205 { "hostname", oHostName }, 208 { "hostname", oHostName },
206 { "hostkeyalias", oHostKeyAlias }, 209 { "hostkeyalias", oHostKeyAlias },
207 { "proxycommand", oProxyCommand }, 210 { "proxycommand", oProxyCommand },
@@ -260,7 +263,7 @@ static struct {
260 { "localcommand", oLocalCommand }, 263 { "localcommand", oLocalCommand },
261 { "permitlocalcommand", oPermitLocalCommand }, 264 { "permitlocalcommand", oPermitLocalCommand },
262 { "visualhostkey", oVisualHostKey }, 265 { "visualhostkey", oVisualHostKey },
263 { "useroaming", oUseRoaming }, 266 { "useroaming", oDeprecated },
264 { "kexalgorithms", oKexAlgorithms }, 267 { "kexalgorithms", oKexAlgorithms },
265 { "ipqos", oIPQoS }, 268 { "ipqos", oIPQoS },
266 { "requesttty", oRequestTTY }, 269 { "requesttty", oRequestTTY },
@@ -366,6 +369,30 @@ clear_forwardings(Options *options)
366} 369}
367 370
368void 371void
372add_certificate_file(Options *options, const char *path, int userprovided)
373{
374 int i;
375
376 if (options->num_certificate_files >= SSH_MAX_CERTIFICATE_FILES)
377 fatal("Too many certificate files specified (max %d)",
378 SSH_MAX_CERTIFICATE_FILES);
379
380 /* Avoid registering duplicates */
381 for (i = 0; i < options->num_certificate_files; i++) {
382 if (options->certificate_file_userprovided[i] == userprovided &&
383 strcmp(options->certificate_files[i], path) == 0) {
384 debug2("%s: ignoring duplicate key %s", __func__, path);
385 return;
386 }
387 }
388
389 options->certificate_file_userprovided[options->num_certificate_files] =
390 userprovided;
391 options->certificate_files[options->num_certificate_files++] =
392 xstrdup(path);
393}
394
395void
369add_identity_file(Options *options, const char *dir, const char *filename, 396add_identity_file(Options *options, const char *dir, const char *filename,
370 int userprovided) 397 int userprovided)
371{ 398{
@@ -416,7 +443,7 @@ default_ssh_port(void)
416static int 443static int
417execute_in_shell(const char *cmd) 444execute_in_shell(const char *cmd)
418{ 445{
419 char *shell, *command_string; 446 char *shell;
420 pid_t pid; 447 pid_t pid;
421 int devnull, status; 448 int devnull, status;
422 extern uid_t original_real_uid; 449 extern uid_t original_real_uid;
@@ -424,12 +451,6 @@ execute_in_shell(const char *cmd)
424 if ((shell = getenv("SHELL")) == NULL) 451 if ((shell = getenv("SHELL")) == NULL)
425 shell = _PATH_BSHELL; 452 shell = _PATH_BSHELL;
426 453
427 /*
428 * Use "exec" to avoid "sh -c" processes on some platforms
429 * (e.g. Solaris)
430 */
431 xasprintf(&command_string, "exec %s", cmd);
432
433 /* Need this to redirect subprocess stdin/out */ 454 /* Need this to redirect subprocess stdin/out */
434 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) 455 if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1)
435 fatal("open(/dev/null): %s", strerror(errno)); 456 fatal("open(/dev/null): %s", strerror(errno));
@@ -454,7 +475,7 @@ execute_in_shell(const char *cmd)
454 475
455 argv[0] = shell; 476 argv[0] = shell;
456 argv[1] = "-c"; 477 argv[1] = "-c";
457 argv[2] = command_string; 478 argv[2] = xstrdup(cmd);
458 argv[3] = NULL; 479 argv[3] = NULL;
459 480
460 execv(argv[0], argv); 481 execv(argv[0], argv);
@@ -469,7 +490,6 @@ execute_in_shell(const char *cmd)
469 fatal("%s: fork: %.100s", __func__, strerror(errno)); 490 fatal("%s: fork: %.100s", __func__, strerror(errno));
470 491
471 close(devnull); 492 close(devnull);
472 free(command_string);
473 493
474 while (waitpid(pid, &status, 0) == -1) { 494 while (waitpid(pid, &status, 0) == -1) {
475 if (errno != EINTR && errno != EAGAIN) 495 if (errno != EINTR && errno != EAGAIN)
@@ -502,12 +522,15 @@ match_cfg_line(Options *options, char **condition, struct passwd *pw,
502 */ 522 */
503 port = options->port <= 0 ? default_ssh_port() : options->port; 523 port = options->port <= 0 ? default_ssh_port() : options->port;
504 ruser = options->user == NULL ? pw->pw_name : options->user; 524 ruser = options->user == NULL ? pw->pw_name : options->user;
505 if (options->hostname != NULL) { 525 if (post_canon) {
526 host = xstrdup(options->hostname);
527 } else if (options->hostname != NULL) {
506 /* NB. Please keep in sync with ssh.c:main() */ 528 /* NB. Please keep in sync with ssh.c:main() */
507 host = percent_expand(options->hostname, 529 host = percent_expand(options->hostname,
508 "h", host_arg, (char *)NULL); 530 "h", host_arg, (char *)NULL);
509 } else 531 } else {
510 host = xstrdup(host_arg); 532 host = xstrdup(host_arg);
533 }
511 534
512 debug2("checking match for '%s' host %s originally %s", 535 debug2("checking match for '%s' host %s originally %s",
513 cp, host, original_host); 536 cp, host, original_host);
@@ -693,6 +716,15 @@ static const struct multistate multistate_yesnoask[] = {
693 { "ask", 2 }, 716 { "ask", 2 },
694 { NULL, -1 } 717 { NULL, -1 }
695}; 718};
719static const struct multistate multistate_yesnoaskconfirm[] = {
720 { "true", 1 },
721 { "false", 0 },
722 { "yes", 1 },
723 { "no", 0 },
724 { "ask", 2 },
725 { "confirm", 3 },
726 { NULL, -1 }
727};
696static const struct multistate multistate_addressfamily[] = { 728static const struct multistate multistate_addressfamily[] = {
697 { "inet", AF_INET }, 729 { "inet", AF_INET },
698 { "inet6", AF_INET6 }, 730 { "inet6", AF_INET6 },
@@ -947,16 +979,12 @@ parse_time:
947 if (scan_scaled(arg, &val64) == -1) 979 if (scan_scaled(arg, &val64) == -1)
948 fatal("%.200s line %d: Bad number '%s': %s", 980 fatal("%.200s line %d: Bad number '%s': %s",
949 filename, linenum, arg, strerror(errno)); 981 filename, linenum, arg, strerror(errno));
950 /* check for too-large or too-small limits */
951 if (val64 > UINT_MAX)
952 fatal("%.200s line %d: RekeyLimit too large",
953 filename, linenum);
954 if (val64 != 0 && val64 < 16) 982 if (val64 != 0 && val64 < 16)
955 fatal("%.200s line %d: RekeyLimit too small", 983 fatal("%.200s line %d: RekeyLimit too small",
956 filename, linenum); 984 filename, linenum);
957 } 985 }
958 if (*activep && options->rekey_limit == -1) 986 if (*activep && options->rekey_limit == -1)
959 options->rekey_limit = (u_int32_t)val64; 987 options->rekey_limit = val64;
960 if (s != NULL) { /* optional rekey interval present */ 988 if (s != NULL) { /* optional rekey interval present */
961 if (strcmp(s, "none") == 0) { 989 if (strcmp(s, "none") == 0) {
962 (void)strdelim(&s); /* discard */ 990 (void)strdelim(&s); /* discard */
@@ -981,6 +1009,24 @@ parse_time:
981 } 1009 }
982 break; 1010 break;
983 1011
1012 case oCertificateFile:
1013 arg = strdelim(&s);
1014 if (!arg || *arg == '\0')
1015 fatal("%.200s line %d: Missing argument.",
1016 filename, linenum);
1017 if (*activep) {
1018 intptr = &options->num_certificate_files;
1019 if (*intptr >= SSH_MAX_CERTIFICATE_FILES) {
1020 fatal("%.200s line %d: Too many certificate "
1021 "files specified (max %d).",
1022 filename, linenum,
1023 SSH_MAX_CERTIFICATE_FILES);
1024 }
1025 add_certificate_file(options, arg,
1026 flags & SSHCONF_USERCONF);
1027 }
1028 break;
1029
984 case oXAuthLocation: 1030 case oXAuthLocation:
985 charptr=&options->xauth_location; 1031 charptr=&options->xauth_location;
986 goto parse_string; 1032 goto parse_string;
@@ -1378,10 +1424,6 @@ parse_keytypes:
1378 } 1424 }
1379 break; 1425 break;
1380 1426
1381 case oUseRoaming:
1382 intptr = &options->use_roaming;
1383 goto parse_flag;
1384
1385 case oRequestTTY: 1427 case oRequestTTY:
1386 intptr = &options->request_tty; 1428 intptr = &options->request_tty;
1387 multistate_ptr = multistate_requesttty; 1429 multistate_ptr = multistate_requesttty;
@@ -1496,6 +1538,11 @@ parse_keytypes:
1496 charptr = &options->pubkey_key_types; 1538 charptr = &options->pubkey_key_types;
1497 goto parse_keytypes; 1539 goto parse_keytypes;
1498 1540
1541 case oAddKeysToAgent:
1542 intptr = &options->add_keys_to_agent;
1543 multistate_ptr = multistate_yesnoaskconfirm;
1544 goto parse_multistate;
1545
1499 case oDeprecated: 1546 case oDeprecated:
1500 debug("%s line %d: Deprecated option \"%s\"", 1547 debug("%s line %d: Deprecated option \"%s\"",
1501 filename, linenum, keyword); 1548 filename, linenum, keyword);
@@ -1625,6 +1672,7 @@ initialize_options(Options * options)
1625 options->hostkeyalgorithms = NULL; 1672 options->hostkeyalgorithms = NULL;
1626 options->protocol = SSH_PROTO_UNKNOWN; 1673 options->protocol = SSH_PROTO_UNKNOWN;
1627 options->num_identity_files = 0; 1674 options->num_identity_files = 0;
1675 options->num_certificate_files = 0;
1628 options->hostname = NULL; 1676 options->hostname = NULL;
1629 options->host_key_alias = NULL; 1677 options->host_key_alias = NULL;
1630 options->proxy_command = NULL; 1678 options->proxy_command = NULL;
@@ -1660,7 +1708,7 @@ initialize_options(Options * options)
1660 options->tun_remote = -1; 1708 options->tun_remote = -1;
1661 options->local_command = NULL; 1709 options->local_command = NULL;
1662 options->permit_local_command = -1; 1710 options->permit_local_command = -1;
1663 options->use_roaming = 0; 1711 options->add_keys_to_agent = -1;
1664 options->visual_host_key = -1; 1712 options->visual_host_key = -1;
1665 options->ip_qos_interactive = -1; 1713 options->ip_qos_interactive = -1;
1666 options->ip_qos_bulk = -1; 1714 options->ip_qos_bulk = -1;
@@ -1765,6 +1813,8 @@ fill_default_options(Options * options)
1765 /* options->hostkeyalgorithms, default set in myproposals.h */ 1813 /* options->hostkeyalgorithms, default set in myproposals.h */
1766 if (options->protocol == SSH_PROTO_UNKNOWN) 1814 if (options->protocol == SSH_PROTO_UNKNOWN)
1767 options->protocol = SSH_PROTO_2; 1815 options->protocol = SSH_PROTO_2;
1816 if (options->add_keys_to_agent == -1)
1817 options->add_keys_to_agent = 0;
1768 if (options->num_identity_files == 0) { 1818 if (options->num_identity_files == 0) {
1769 if (options->protocol & SSH_PROTO_1) { 1819 if (options->protocol & SSH_PROTO_1) {
1770 add_identity_file(options, "~/", 1820 add_identity_file(options, "~/",
@@ -1833,7 +1883,6 @@ fill_default_options(Options * options)
1833 options->tun_remote = SSH_TUNID_ANY; 1883 options->tun_remote = SSH_TUNID_ANY;
1834 if (options->permit_local_command == -1) 1884 if (options->permit_local_command == -1)
1835 options->permit_local_command = 0; 1885 options->permit_local_command = 0;
1836 options->use_roaming = 0;
1837 if (options->visual_host_key == -1) 1886 if (options->visual_host_key == -1)
1838 options->visual_host_key = 0; 1887 options->visual_host_key = 0;
1839 if (options->ip_qos_interactive == -1) 1888 if (options->ip_qos_interactive == -1)
@@ -2242,6 +2291,10 @@ dump_client_config(Options *o, const char *host)
2242 int i; 2291 int i;
2243 char vbuf[5]; 2292 char vbuf[5];
2244 2293
2294 /* This is normally prepared in ssh_kex2 */
2295 if (kex_assemble_names(KEX_DEFAULT_PK_ALG, &o->hostkeyalgorithms) != 0)
2296 fatal("%s: kex_assemble_names failed", __func__);
2297
2245 /* Most interesting options first: user, host, port */ 2298 /* Most interesting options first: user, host, port */
2246 dump_cfg_string(oUser, o->user); 2299 dump_cfg_string(oUser, o->user);
2247 dump_cfg_string(oHostName, host); 2300 dump_cfg_string(oHostName, host);
@@ -2302,7 +2355,7 @@ dump_client_config(Options *o, const char *host)
2302 dump_cfg_string(oBindAddress, o->bind_address); 2355 dump_cfg_string(oBindAddress, o->bind_address);
2303 dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT); 2356 dump_cfg_string(oCiphers, o->ciphers ? o->ciphers : KEX_CLIENT_ENCRYPT);
2304 dump_cfg_string(oControlPath, o->control_path); 2357 dump_cfg_string(oControlPath, o->control_path);
2305 dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms ? o->hostkeyalgorithms : KEX_DEFAULT_PK_ALG); 2358 dump_cfg_string(oHostKeyAlgorithms, o->hostkeyalgorithms);
2306 dump_cfg_string(oHostKeyAlias, o->host_key_alias); 2359 dump_cfg_string(oHostKeyAlias, o->host_key_alias);
2307 dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types); 2360 dump_cfg_string(oHostbasedKeyTypes, o->hostbased_key_types);
2308 dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices); 2361 dump_cfg_string(oKbdInteractiveDevices, o->kbd_interactive_devices);
@@ -2313,6 +2366,7 @@ dump_client_config(Options *o, const char *host)
2313 dump_cfg_string(oPKCS11Provider, o->pkcs11_provider); 2366 dump_cfg_string(oPKCS11Provider, o->pkcs11_provider);
2314 dump_cfg_string(oPreferredAuthentications, o->preferred_authentications); 2367 dump_cfg_string(oPreferredAuthentications, o->preferred_authentications);
2315 dump_cfg_string(oProxyCommand, o->proxy_command); 2368 dump_cfg_string(oProxyCommand, o->proxy_command);
2369 dump_cfg_string(oPubkeyAcceptedKeyTypes, o->pubkey_key_types);
2316 dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys); 2370 dump_cfg_string(oRevokedHostKeys, o->revoked_host_keys);
2317 dump_cfg_string(oXAuthLocation, o->xauth_location); 2371 dump_cfg_string(oXAuthLocation, o->xauth_location);
2318 2372
@@ -2381,8 +2435,8 @@ dump_client_config(Options *o, const char *host)
2381 printf("%s\n", iptos2str(o->ip_qos_bulk)); 2435 printf("%s\n", iptos2str(o->ip_qos_bulk));
2382 2436
2383 /* oRekeyLimit */ 2437 /* oRekeyLimit */
2384 printf("rekeylimit %lld %d\n", 2438 printf("rekeylimit %llu %d\n",
2385 (long long)o->rekey_limit, o->rekey_interval); 2439 (unsigned long long)o->rekey_limit, o->rekey_interval);
2386 2440
2387 /* oStreamLocalBindMask */ 2441 /* oStreamLocalBindMask */
2388 printf("streamlocalbindmask 0%o\n", 2442 printf("streamlocalbindmask 0%o\n",