summaryrefslogtreecommitdiff
path: root/servconf.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2019-06-05 06:41:44 +0100
committerColin Watson <cjwatson@debian.org>2019-06-09 22:09:07 +0100
commit865a97e05b6aab1619e1c8eeb33ccb8f9a9e48d3 (patch)
tree7bb2128eb663180bacfabca88f26d26bf0733824 /servconf.c
parentba627ba172d6649919baedff5ba2789610da382a (diff)
parent7d50f9e5be88179325983a1f58c9d51bb58f025a (diff)
New upstream release (8.0p1)
Diffstat (limited to 'servconf.c')
-rw-r--r--servconf.c95
1 files changed, 67 insertions, 28 deletions
diff --git a/servconf.c b/servconf.c
index bf2669147..365e6ff1e 100644
--- a/servconf.c
+++ b/servconf.c
@@ -1,5 +1,5 @@
1 1
2/* $OpenBSD: servconf.c,v 1.342 2018/09/20 23:40:16 djm Exp $ */ 2/* $OpenBSD: servconf.c,v 1.350 2019/03/25 22:33:44 djm Exp $ */
3/* 3/*
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved 5 * All rights reserved
@@ -64,6 +64,7 @@
64#include "auth.h" 64#include "auth.h"
65#include "myproposal.h" 65#include "myproposal.h"
66#include "digest.h" 66#include "digest.h"
67#include "ssh-gss.h"
67 68
68static void add_listen_addr(ServerOptions *, const char *, 69static void add_listen_addr(ServerOptions *, const char *,
69 const char *, int); 70 const char *, int);
@@ -128,6 +129,7 @@ initialize_server_options(ServerOptions *options)
128 options->gss_cleanup_creds = -1; 129 options->gss_cleanup_creds = -1;
129 options->gss_strict_acceptor = -1; 130 options->gss_strict_acceptor = -1;
130 options->gss_store_rekey = -1; 131 options->gss_store_rekey = -1;
132 options->gss_kex_algorithms = NULL;
131 options->password_authentication = -1; 133 options->password_authentication = -1;
132 options->kbd_interactive_authentication = -1; 134 options->kbd_interactive_authentication = -1;
133 options->challenge_response_authentication = -1; 135 options->challenge_response_authentication = -1;
@@ -224,26 +226,40 @@ assemble_algorithms(ServerOptions *o)
224} 226}
225 227
226static void 228static void
227array_append(const char *file, const int line, const char *directive, 229array_append2(const char *file, const int line, const char *directive,
228 char ***array, u_int *lp, const char *s) 230 char ***array, int **iarray, u_int *lp, const char *s, int i)
229{ 231{
230 232
231 if (*lp >= INT_MAX) 233 if (*lp >= INT_MAX)
232 fatal("%s line %d: Too many %s entries", file, line, directive); 234 fatal("%s line %d: Too many %s entries", file, line, directive);
233 235
236 if (iarray != NULL) {
237 *iarray = xrecallocarray(*iarray, *lp, *lp + 1,
238 sizeof(**iarray));
239 (*iarray)[*lp] = i;
240 }
241
234 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array)); 242 *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
235 (*array)[*lp] = xstrdup(s); 243 (*array)[*lp] = xstrdup(s);
236 (*lp)++; 244 (*lp)++;
237} 245}
238 246
247static void
248array_append(const char *file, const int line, const char *directive,
249 char ***array, u_int *lp, const char *s)
250{
251 array_append2(file, line, directive, array, NULL, lp, s, 0);
252}
253
239void 254void
240servconf_add_hostkey(const char *file, const int line, 255servconf_add_hostkey(const char *file, const int line,
241 ServerOptions *options, const char *path) 256 ServerOptions *options, const char *path, int userprovided)
242{ 257{
243 char *apath = derelativise_path(path); 258 char *apath = derelativise_path(path);
244 259
245 array_append(file, line, "HostKey", 260 array_append2(file, line, "HostKey",
246 &options->host_key_files, &options->num_host_key_files, apath); 261 &options->host_key_files, &options->host_key_file_userprovided,
262 &options->num_host_key_files, apath, userprovided);
247 free(apath); 263 free(apath);
248} 264}
249 265
@@ -271,16 +287,16 @@ fill_default_server_options(ServerOptions *options)
271 if (options->num_host_key_files == 0) { 287 if (options->num_host_key_files == 0) {
272 /* fill default hostkeys for protocols */ 288 /* fill default hostkeys for protocols */
273 servconf_add_hostkey("[default]", 0, options, 289 servconf_add_hostkey("[default]", 0, options,
274 _PATH_HOST_RSA_KEY_FILE); 290 _PATH_HOST_RSA_KEY_FILE, 0);
275#ifdef OPENSSL_HAS_ECC 291#ifdef OPENSSL_HAS_ECC
276 servconf_add_hostkey("[default]", 0, options, 292 servconf_add_hostkey("[default]", 0, options,
277 _PATH_HOST_ECDSA_KEY_FILE); 293 _PATH_HOST_ECDSA_KEY_FILE, 0);
278#endif 294#endif
279 servconf_add_hostkey("[default]", 0, options, 295 servconf_add_hostkey("[default]", 0, options,
280 _PATH_HOST_ED25519_KEY_FILE); 296 _PATH_HOST_ED25519_KEY_FILE, 0);
281#ifdef WITH_XMSS 297#ifdef WITH_XMSS
282 servconf_add_hostkey("[default]", 0, options, 298 servconf_add_hostkey("[default]", 0, options,
283 _PATH_HOST_XMSS_KEY_FILE); 299 _PATH_HOST_XMSS_KEY_FILE, 0);
284#endif /* WITH_XMSS */ 300#endif /* WITH_XMSS */
285 } 301 }
286 /* No certificates by default */ 302 /* No certificates by default */
@@ -348,6 +364,10 @@ fill_default_server_options(ServerOptions *options)
348 options->gss_strict_acceptor = 1; 364 options->gss_strict_acceptor = 1;
349 if (options->gss_store_rekey == -1) 365 if (options->gss_store_rekey == -1)
350 options->gss_store_rekey = 0; 366 options->gss_store_rekey = 0;
367#ifdef GSSAPI
368 if (options->gss_kex_algorithms == NULL)
369 options->gss_kex_algorithms = strdup(GSS_KEX_DEFAULT_KEX);
370#endif
351 if (options->password_authentication == -1) 371 if (options->password_authentication == -1)
352 options->password_authentication = 1; 372 options->password_authentication = 1;
353 if (options->kbd_interactive_authentication == -1) 373 if (options->kbd_interactive_authentication == -1)
@@ -465,7 +485,6 @@ fill_default_server_options(ServerOptions *options)
465 options->compression = 0; 485 options->compression = 0;
466 } 486 }
467#endif 487#endif
468
469} 488}
470 489
471/* Keyword tokens. */ 490/* Keyword tokens. */
@@ -494,7 +513,7 @@ typedef enum {
494 sHostKeyAlgorithms, 513 sHostKeyAlgorithms,
495 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile, 514 sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
496 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor, 515 sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
497 sGssKeyEx, sGssStoreRekey, 516 sGssKeyEx, sGssKexAlgorithms, sGssStoreRekey,
498 sAcceptEnv, sSetEnv, sPermitTunnel, 517 sAcceptEnv, sSetEnv, sPermitTunnel,
499 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory, 518 sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
500 sUsePrivilegeSeparation, sAllowAgentForwarding, 519 sUsePrivilegeSeparation, sAllowAgentForwarding,
@@ -574,6 +593,7 @@ static struct {
574 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL }, 593 { "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
575 { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL }, 594 { "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
576 { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL }, 595 { "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
596 { "gssapikexalgorithms", sGssKexAlgorithms, SSHCFG_GLOBAL },
577#else 597#else
578 { "gssapiauthentication", sUnsupported, SSHCFG_ALL }, 598 { "gssapiauthentication", sUnsupported, SSHCFG_ALL },
579 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL }, 599 { "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
@@ -581,6 +601,7 @@ static struct {
581 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL }, 601 { "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
582 { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL }, 602 { "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
583 { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL }, 603 { "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
604 { "gssapikexalgorithms", sUnsupported, SSHCFG_GLOBAL },
584#endif 605#endif
585 { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL }, 606 { "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
586 { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL }, 607 { "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
@@ -723,7 +744,7 @@ derelativise_path(const char *path)
723 if (strcasecmp(path, "none") == 0) 744 if (strcasecmp(path, "none") == 0)
724 return xstrdup("none"); 745 return xstrdup("none");
725 expanded = tilde_expand_filename(path, getuid()); 746 expanded = tilde_expand_filename(path, getuid());
726 if (*expanded == '/') 747 if (path_absolute(expanded))
727 return expanded; 748 return expanded;
728 if (getcwd(cwd, sizeof(cwd)) == NULL) 749 if (getcwd(cwd, sizeof(cwd)) == NULL)
729 fatal("%s: getcwd: %s", __func__, strerror(errno)); 750 fatal("%s: getcwd: %s", __func__, strerror(errno));
@@ -885,7 +906,7 @@ process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
885{ 906{
886 u_int i; 907 u_int i;
887 int port; 908 int port;
888 char *host, *arg, *oarg; 909 char *host, *arg, *oarg, ch;
889 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE; 910 int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE;
890 const char *what = lookup_opcode_name(opcode); 911 const char *what = lookup_opcode_name(opcode);
891 912
@@ -903,8 +924,9 @@ process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode,
903 /* Otherwise treat it as a list of permitted host:port */ 924 /* Otherwise treat it as a list of permitted host:port */
904 for (i = 0; i < num_opens; i++) { 925 for (i = 0; i < num_opens; i++) {
905 oarg = arg = xstrdup(opens[i]); 926 oarg = arg = xstrdup(opens[i]);
906 host = hpdelim(&arg); 927 ch = '\0';
907 if (host == NULL) 928 host = hpdelim2(&arg, &ch);
929 if (host == NULL || ch == '/')
908 fatal("%s: missing host in %s", __func__, what); 930 fatal("%s: missing host in %s", __func__, what);
909 host = cleanhostname(host); 931 host = cleanhostname(host);
910 if (arg == NULL || ((port = permitopen_port(arg)) < 0)) 932 if (arg == NULL || ((port = permitopen_port(arg)) < 0))
@@ -930,12 +952,11 @@ process_permitopen(struct ssh *ssh, ServerOptions *options)
930} 952}
931 953
932struct connection_info * 954struct connection_info *
933get_connection_info(int populate, int use_dns) 955get_connection_info(struct ssh *ssh, int populate, int use_dns)
934{ 956{
935 struct ssh *ssh = active_state; /* XXX */
936 static struct connection_info ci; 957 static struct connection_info ci;
937 958
938 if (!populate) 959 if (ssh == NULL || !populate)
939 return &ci; 960 return &ci;
940 ci.host = auth_get_canonical_hostname(ssh, use_dns); 961 ci.host = auth_get_canonical_hostname(ssh, use_dns);
941 ci.address = ssh_remote_ipaddr(ssh); 962 ci.address = ssh_remote_ipaddr(ssh);
@@ -1056,7 +1077,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci)
1056 } 1077 }
1057 if (ci->user == NULL) 1078 if (ci->user == NULL)
1058 match_test_missing_fatal("User", "user"); 1079 match_test_missing_fatal("User", "user");
1059 if (match_pattern_list(ci->user, arg, 0) != 1) 1080 if (match_usergroup_pattern_list(ci->user, arg) != 1)
1060 result = 0; 1081 result = 0;
1061 else 1082 else
1062 debug("user %.100s matched 'User %.100s' at " 1083 debug("user %.100s matched 'User %.100s' at "
@@ -1222,7 +1243,7 @@ process_server_config_line(ServerOptions *options, char *line,
1222 const char *filename, int linenum, int *activep, 1243 const char *filename, int linenum, int *activep,
1223 struct connection_info *connectinfo) 1244 struct connection_info *connectinfo)
1224{ 1245{
1225 char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p; 1246 char ch, *cp, ***chararrayptr, **charptr, *arg, *arg2, *p;
1226 int cmdline = 0, *intptr, value, value2, n, port; 1247 int cmdline = 0, *intptr, value, value2, n, port;
1227 SyslogFacility *log_facility_ptr; 1248 SyslogFacility *log_facility_ptr;
1228 LogLevel *log_level_ptr; 1249 LogLevel *log_level_ptr;
@@ -1322,8 +1343,10 @@ process_server_config_line(ServerOptions *options, char *line,
1322 port = 0; 1343 port = 0;
1323 p = arg; 1344 p = arg;
1324 } else { 1345 } else {
1325 p = hpdelim(&arg); 1346 arg2 = NULL;
1326 if (p == NULL) 1347 ch = '\0';
1348 p = hpdelim2(&arg, &ch);
1349 if (p == NULL || ch == '/')
1327 fatal("%s line %d: bad address:port usage", 1350 fatal("%s line %d: bad address:port usage",
1328 filename, linenum); 1351 filename, linenum);
1329 p = cleanhostname(p); 1352 p = cleanhostname(p);
@@ -1376,8 +1399,10 @@ process_server_config_line(ServerOptions *options, char *line,
1376 if (!arg || *arg == '\0') 1399 if (!arg || *arg == '\0')
1377 fatal("%s line %d: missing file name.", 1400 fatal("%s line %d: missing file name.",
1378 filename, linenum); 1401 filename, linenum);
1379 if (*activep) 1402 if (*activep) {
1380 servconf_add_hostkey(filename, linenum, options, arg); 1403 servconf_add_hostkey(filename, linenum,
1404 options, arg, 1);
1405 }
1381 break; 1406 break;
1382 1407
1383 case sHostKeyAgent: 1408 case sHostKeyAgent:
@@ -1505,6 +1530,18 @@ process_server_config_line(ServerOptions *options, char *line,
1505 intptr = &options->gss_store_rekey; 1530 intptr = &options->gss_store_rekey;
1506 goto parse_flag; 1531 goto parse_flag;
1507 1532
1533 case sGssKexAlgorithms:
1534 arg = strdelim(&cp);
1535 if (!arg || *arg == '\0')
1536 fatal("%.200s line %d: Missing argument.",
1537 filename, linenum);
1538 if (!kex_gss_names_valid(arg))
1539 fatal("%.200s line %d: Bad GSSAPI KexAlgorithms '%s'.",
1540 filename, linenum, arg ? arg : "<NONE>");
1541 if (*activep && options->gss_kex_algorithms == NULL)
1542 options->gss_kex_algorithms = xstrdup(arg);
1543 break;
1544
1508 case sPasswordAuthentication: 1545 case sPasswordAuthentication:
1509 intptr = &options->password_authentication; 1546 intptr = &options->password_authentication;
1510 goto parse_flag; 1547 goto parse_flag;
@@ -1957,8 +1994,9 @@ process_server_config_line(ServerOptions *options, char *line,
1957 xasprintf(&arg2, "*:%s", arg); 1994 xasprintf(&arg2, "*:%s", arg);
1958 } else { 1995 } else {
1959 arg2 = xstrdup(arg); 1996 arg2 = xstrdup(arg);
1960 p = hpdelim(&arg); 1997 ch = '\0';
1961 if (p == NULL) { 1998 p = hpdelim2(&arg, &ch);
1999 if (p == NULL || ch == '/') {
1962 fatal("%s line %d: missing host in %s", 2000 fatal("%s line %d: missing host in %s",
1963 filename, linenum, 2001 filename, linenum,
1964 lookup_opcode_name(opcode)); 2002 lookup_opcode_name(opcode));
@@ -2593,10 +2631,11 @@ dump_config(ServerOptions *o)
2593#endif 2631#endif
2594#ifdef GSSAPI 2632#ifdef GSSAPI
2595 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication); 2633 dump_cfg_fmtint(sGssAuthentication, o->gss_authentication);
2596 dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
2597 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds); 2634 dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
2635 dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
2598 dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor); 2636 dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
2599 dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey); 2637 dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
2638 dump_cfg_string(sGssKexAlgorithms, o->gss_kex_algorithms);
2600#endif 2639#endif
2601 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication); 2640 dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
2602 dump_cfg_fmtint(sKbdInteractiveAuthentication, 2641 dump_cfg_fmtint(sKbdInteractiveAuthentication,