diff options
author | Colin Watson <cjwatson@debian.org> | 2019-06-05 06:41:44 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2019-06-05 06:41:44 +0100 |
commit | 102062f825fb26a74295a1c089c00c4c4c76b68a (patch) | |
tree | 3db66bc8c8483cce66516dff36f6ef56065143d9 /servconf.c | |
parent | 3d246f10429fc9a37b98eabef94fe8dc7c61002b (diff) | |
parent | fd0fa130ecf06d7d092932adcd5d77f1549bfc8d (diff) |
Import openssh_8.0p1.orig.tar.gz
Diffstat (limited to 'servconf.c')
-rw-r--r-- | servconf.c | 70 |
1 files changed, 44 insertions, 26 deletions
diff --git a/servconf.c b/servconf.c index 932d363bb..ffac5d2c7 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 |
@@ -221,26 +221,40 @@ assemble_algorithms(ServerOptions *o) | |||
221 | } | 221 | } |
222 | 222 | ||
223 | static void | 223 | static void |
224 | array_append(const char *file, const int line, const char *directive, | 224 | array_append2(const char *file, const int line, const char *directive, |
225 | char ***array, u_int *lp, const char *s) | 225 | char ***array, int **iarray, u_int *lp, const char *s, int i) |
226 | { | 226 | { |
227 | 227 | ||
228 | if (*lp >= INT_MAX) | 228 | if (*lp >= INT_MAX) |
229 | fatal("%s line %d: Too many %s entries", file, line, directive); | 229 | fatal("%s line %d: Too many %s entries", file, line, directive); |
230 | 230 | ||
231 | if (iarray != NULL) { | ||
232 | *iarray = xrecallocarray(*iarray, *lp, *lp + 1, | ||
233 | sizeof(**iarray)); | ||
234 | (*iarray)[*lp] = i; | ||
235 | } | ||
236 | |||
231 | *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array)); | 237 | *array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array)); |
232 | (*array)[*lp] = xstrdup(s); | 238 | (*array)[*lp] = xstrdup(s); |
233 | (*lp)++; | 239 | (*lp)++; |
234 | } | 240 | } |
235 | 241 | ||
242 | static void | ||
243 | array_append(const char *file, const int line, const char *directive, | ||
244 | char ***array, u_int *lp, const char *s) | ||
245 | { | ||
246 | array_append2(file, line, directive, array, NULL, lp, s, 0); | ||
247 | } | ||
248 | |||
236 | void | 249 | void |
237 | servconf_add_hostkey(const char *file, const int line, | 250 | servconf_add_hostkey(const char *file, const int line, |
238 | ServerOptions *options, const char *path) | 251 | ServerOptions *options, const char *path, int userprovided) |
239 | { | 252 | { |
240 | char *apath = derelativise_path(path); | 253 | char *apath = derelativise_path(path); |
241 | 254 | ||
242 | array_append(file, line, "HostKey", | 255 | array_append2(file, line, "HostKey", |
243 | &options->host_key_files, &options->num_host_key_files, apath); | 256 | &options->host_key_files, &options->host_key_file_userprovided, |
257 | &options->num_host_key_files, apath, userprovided); | ||
244 | free(apath); | 258 | free(apath); |
245 | } | 259 | } |
246 | 260 | ||
@@ -268,16 +282,16 @@ fill_default_server_options(ServerOptions *options) | |||
268 | if (options->num_host_key_files == 0) { | 282 | if (options->num_host_key_files == 0) { |
269 | /* fill default hostkeys for protocols */ | 283 | /* fill default hostkeys for protocols */ |
270 | servconf_add_hostkey("[default]", 0, options, | 284 | servconf_add_hostkey("[default]", 0, options, |
271 | _PATH_HOST_RSA_KEY_FILE); | 285 | _PATH_HOST_RSA_KEY_FILE, 0); |
272 | #ifdef OPENSSL_HAS_ECC | 286 | #ifdef OPENSSL_HAS_ECC |
273 | servconf_add_hostkey("[default]", 0, options, | 287 | servconf_add_hostkey("[default]", 0, options, |
274 | _PATH_HOST_ECDSA_KEY_FILE); | 288 | _PATH_HOST_ECDSA_KEY_FILE, 0); |
275 | #endif | 289 | #endif |
276 | servconf_add_hostkey("[default]", 0, options, | 290 | servconf_add_hostkey("[default]", 0, options, |
277 | _PATH_HOST_ED25519_KEY_FILE); | 291 | _PATH_HOST_ED25519_KEY_FILE, 0); |
278 | #ifdef WITH_XMSS | 292 | #ifdef WITH_XMSS |
279 | servconf_add_hostkey("[default]", 0, options, | 293 | servconf_add_hostkey("[default]", 0, options, |
280 | _PATH_HOST_XMSS_KEY_FILE); | 294 | _PATH_HOST_XMSS_KEY_FILE, 0); |
281 | #endif /* WITH_XMSS */ | 295 | #endif /* WITH_XMSS */ |
282 | } | 296 | } |
283 | /* No certificates by default */ | 297 | /* No certificates by default */ |
@@ -456,7 +470,6 @@ fill_default_server_options(ServerOptions *options) | |||
456 | options->compression = 0; | 470 | options->compression = 0; |
457 | } | 471 | } |
458 | #endif | 472 | #endif |
459 | |||
460 | } | 473 | } |
461 | 474 | ||
462 | /* Keyword tokens. */ | 475 | /* Keyword tokens. */ |
@@ -702,7 +715,7 @@ derelativise_path(const char *path) | |||
702 | if (strcasecmp(path, "none") == 0) | 715 | if (strcasecmp(path, "none") == 0) |
703 | return xstrdup("none"); | 716 | return xstrdup("none"); |
704 | expanded = tilde_expand_filename(path, getuid()); | 717 | expanded = tilde_expand_filename(path, getuid()); |
705 | if (*expanded == '/') | 718 | if (path_absolute(expanded)) |
706 | return expanded; | 719 | return expanded; |
707 | if (getcwd(cwd, sizeof(cwd)) == NULL) | 720 | if (getcwd(cwd, sizeof(cwd)) == NULL) |
708 | fatal("%s: getcwd: %s", __func__, strerror(errno)); | 721 | fatal("%s: getcwd: %s", __func__, strerror(errno)); |
@@ -864,7 +877,7 @@ process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode, | |||
864 | { | 877 | { |
865 | u_int i; | 878 | u_int i; |
866 | int port; | 879 | int port; |
867 | char *host, *arg, *oarg; | 880 | char *host, *arg, *oarg, ch; |
868 | int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE; | 881 | int where = opcode == sPermitOpen ? FORWARD_LOCAL : FORWARD_REMOTE; |
869 | const char *what = lookup_opcode_name(opcode); | 882 | const char *what = lookup_opcode_name(opcode); |
870 | 883 | ||
@@ -882,8 +895,9 @@ process_permitopen_list(struct ssh *ssh, ServerOpCodes opcode, | |||
882 | /* Otherwise treat it as a list of permitted host:port */ | 895 | /* Otherwise treat it as a list of permitted host:port */ |
883 | for (i = 0; i < num_opens; i++) { | 896 | for (i = 0; i < num_opens; i++) { |
884 | oarg = arg = xstrdup(opens[i]); | 897 | oarg = arg = xstrdup(opens[i]); |
885 | host = hpdelim(&arg); | 898 | ch = '\0'; |
886 | if (host == NULL) | 899 | host = hpdelim2(&arg, &ch); |
900 | if (host == NULL || ch == '/') | ||
887 | fatal("%s: missing host in %s", __func__, what); | 901 | fatal("%s: missing host in %s", __func__, what); |
888 | host = cleanhostname(host); | 902 | host = cleanhostname(host); |
889 | if (arg == NULL || ((port = permitopen_port(arg)) < 0)) | 903 | if (arg == NULL || ((port = permitopen_port(arg)) < 0)) |
@@ -909,12 +923,11 @@ process_permitopen(struct ssh *ssh, ServerOptions *options) | |||
909 | } | 923 | } |
910 | 924 | ||
911 | struct connection_info * | 925 | struct connection_info * |
912 | get_connection_info(int populate, int use_dns) | 926 | get_connection_info(struct ssh *ssh, int populate, int use_dns) |
913 | { | 927 | { |
914 | struct ssh *ssh = active_state; /* XXX */ | ||
915 | static struct connection_info ci; | 928 | static struct connection_info ci; |
916 | 929 | ||
917 | if (!populate) | 930 | if (ssh == NULL || !populate) |
918 | return &ci; | 931 | return &ci; |
919 | ci.host = auth_get_canonical_hostname(ssh, use_dns); | 932 | ci.host = auth_get_canonical_hostname(ssh, use_dns); |
920 | ci.address = ssh_remote_ipaddr(ssh); | 933 | ci.address = ssh_remote_ipaddr(ssh); |
@@ -1035,7 +1048,7 @@ match_cfg_line(char **condition, int line, struct connection_info *ci) | |||
1035 | } | 1048 | } |
1036 | if (ci->user == NULL) | 1049 | if (ci->user == NULL) |
1037 | match_test_missing_fatal("User", "user"); | 1050 | match_test_missing_fatal("User", "user"); |
1038 | if (match_pattern_list(ci->user, arg, 0) != 1) | 1051 | if (match_usergroup_pattern_list(ci->user, arg) != 1) |
1039 | result = 0; | 1052 | result = 0; |
1040 | else | 1053 | else |
1041 | debug("user %.100s matched 'User %.100s' at " | 1054 | debug("user %.100s matched 'User %.100s' at " |
@@ -1201,7 +1214,7 @@ process_server_config_line(ServerOptions *options, char *line, | |||
1201 | const char *filename, int linenum, int *activep, | 1214 | const char *filename, int linenum, int *activep, |
1202 | struct connection_info *connectinfo) | 1215 | struct connection_info *connectinfo) |
1203 | { | 1216 | { |
1204 | char *cp, ***chararrayptr, **charptr, *arg, *arg2, *p; | 1217 | char ch, *cp, ***chararrayptr, **charptr, *arg, *arg2, *p; |
1205 | int cmdline = 0, *intptr, value, value2, n, port; | 1218 | int cmdline = 0, *intptr, value, value2, n, port; |
1206 | SyslogFacility *log_facility_ptr; | 1219 | SyslogFacility *log_facility_ptr; |
1207 | LogLevel *log_level_ptr; | 1220 | LogLevel *log_level_ptr; |
@@ -1301,8 +1314,10 @@ process_server_config_line(ServerOptions *options, char *line, | |||
1301 | port = 0; | 1314 | port = 0; |
1302 | p = arg; | 1315 | p = arg; |
1303 | } else { | 1316 | } else { |
1304 | p = hpdelim(&arg); | 1317 | arg2 = NULL; |
1305 | if (p == NULL) | 1318 | ch = '\0'; |
1319 | p = hpdelim2(&arg, &ch); | ||
1320 | if (p == NULL || ch == '/') | ||
1306 | fatal("%s line %d: bad address:port usage", | 1321 | fatal("%s line %d: bad address:port usage", |
1307 | filename, linenum); | 1322 | filename, linenum); |
1308 | p = cleanhostname(p); | 1323 | p = cleanhostname(p); |
@@ -1355,8 +1370,10 @@ process_server_config_line(ServerOptions *options, char *line, | |||
1355 | if (!arg || *arg == '\0') | 1370 | if (!arg || *arg == '\0') |
1356 | fatal("%s line %d: missing file name.", | 1371 | fatal("%s line %d: missing file name.", |
1357 | filename, linenum); | 1372 | filename, linenum); |
1358 | if (*activep) | 1373 | if (*activep) { |
1359 | servconf_add_hostkey(filename, linenum, options, arg); | 1374 | servconf_add_hostkey(filename, linenum, |
1375 | options, arg, 1); | ||
1376 | } | ||
1360 | break; | 1377 | break; |
1361 | 1378 | ||
1362 | case sHostKeyAgent: | 1379 | case sHostKeyAgent: |
@@ -1928,8 +1945,9 @@ process_server_config_line(ServerOptions *options, char *line, | |||
1928 | xasprintf(&arg2, "*:%s", arg); | 1945 | xasprintf(&arg2, "*:%s", arg); |
1929 | } else { | 1946 | } else { |
1930 | arg2 = xstrdup(arg); | 1947 | arg2 = xstrdup(arg); |
1931 | p = hpdelim(&arg); | 1948 | ch = '\0'; |
1932 | if (p == NULL) { | 1949 | p = hpdelim2(&arg, &ch); |
1950 | if (p == NULL || ch == '/') { | ||
1933 | fatal("%s line %d: missing host in %s", | 1951 | fatal("%s line %d: missing host in %s", |
1934 | filename, linenum, | 1952 | filename, linenum, |
1935 | lookup_opcode_name(opcode)); | 1953 | lookup_opcode_name(opcode)); |