diff options
Diffstat (limited to 'readconf.c')
-rw-r--r-- | readconf.c | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/readconf.c b/readconf.c index 097bb0515..36265e431 100644 --- a/readconf.c +++ b/readconf.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: readconf.c,v 1.194 2011/09/23 07:45:05 markus Exp $ */ | 1 | /* $OpenBSD: readconf.c,v 1.196 2013/02/22 04:45:08 dtucker 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 |
@@ -326,6 +326,26 @@ clear_forwardings(Options *options) | |||
326 | options->tun_open = SSH_TUNMODE_NO; | 326 | options->tun_open = SSH_TUNMODE_NO; |
327 | } | 327 | } |
328 | 328 | ||
329 | void | ||
330 | add_identity_file(Options *options, const char *dir, const char *filename, | ||
331 | int userprovided) | ||
332 | { | ||
333 | char *path; | ||
334 | |||
335 | if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES) | ||
336 | fatal("Too many identity files specified (max %d)", | ||
337 | SSH_MAX_IDENTITY_FILES); | ||
338 | |||
339 | if (dir == NULL) /* no dir, filename is absolute */ | ||
340 | path = xstrdup(filename); | ||
341 | else | ||
342 | (void)xasprintf(&path, "%.100s%.100s", dir, filename); | ||
343 | |||
344 | options->identity_file_userprovided[options->num_identity_files] = | ||
345 | userprovided; | ||
346 | options->identity_files[options->num_identity_files++] = path; | ||
347 | } | ||
348 | |||
329 | /* | 349 | /* |
330 | * Returns the number of the token pointed to by cp or oBadOption. | 350 | * Returns the number of the token pointed to by cp or oBadOption. |
331 | */ | 351 | */ |
@@ -353,7 +373,7 @@ parse_token(const char *cp, const char *filename, int linenum) | |||
353 | int | 373 | int |
354 | process_config_line(Options *options, const char *host, | 374 | process_config_line(Options *options, const char *host, |
355 | char *line, const char *filename, int linenum, | 375 | char *line, const char *filename, int linenum, |
356 | int *activep) | 376 | int *activep, int userconfig) |
357 | { | 377 | { |
358 | char *s, **charptr, *endofnumber, *keyword, *arg, *arg2; | 378 | char *s, **charptr, *endofnumber, *keyword, *arg, *arg2; |
359 | char **cpptr, fwdarg[256]; | 379 | char **cpptr, fwdarg[256]; |
@@ -586,9 +606,7 @@ parse_yesnoask: | |||
586 | if (*intptr >= SSH_MAX_IDENTITY_FILES) | 606 | if (*intptr >= SSH_MAX_IDENTITY_FILES) |
587 | fatal("%.200s line %d: Too many identity files specified (max %d).", | 607 | fatal("%.200s line %d: Too many identity files specified (max %d).", |
588 | filename, linenum, SSH_MAX_IDENTITY_FILES); | 608 | filename, linenum, SSH_MAX_IDENTITY_FILES); |
589 | charptr = &options->identity_files[*intptr]; | 609 | add_identity_file(options, NULL, arg, userconfig); |
590 | *charptr = xstrdup(arg); | ||
591 | *intptr = *intptr + 1; | ||
592 | } | 610 | } |
593 | break; | 611 | break; |
594 | 612 | ||
@@ -1075,7 +1093,7 @@ parse_int: | |||
1075 | 1093 | ||
1076 | int | 1094 | int |
1077 | read_config_file(const char *filename, const char *host, Options *options, | 1095 | read_config_file(const char *filename, const char *host, Options *options, |
1078 | int checkperm) | 1096 | int flags) |
1079 | { | 1097 | { |
1080 | FILE *f; | 1098 | FILE *f; |
1081 | char line[1024]; | 1099 | char line[1024]; |
@@ -1085,7 +1103,7 @@ read_config_file(const char *filename, const char *host, Options *options, | |||
1085 | if ((f = fopen(filename, "r")) == NULL) | 1103 | if ((f = fopen(filename, "r")) == NULL) |
1086 | return 0; | 1104 | return 0; |
1087 | 1105 | ||
1088 | if (checkperm) { | 1106 | if (flags & SSHCONF_CHECKPERM) { |
1089 | struct stat sb; | 1107 | struct stat sb; |
1090 | 1108 | ||
1091 | if (fstat(fileno(f), &sb) == -1) | 1109 | if (fstat(fileno(f), &sb) == -1) |
@@ -1106,7 +1124,8 @@ read_config_file(const char *filename, const char *host, Options *options, | |||
1106 | while (fgets(line, sizeof(line), f)) { | 1124 | while (fgets(line, sizeof(line), f)) { |
1107 | /* Update line number counter. */ | 1125 | /* Update line number counter. */ |
1108 | linenum++; | 1126 | linenum++; |
1109 | if (process_config_line(options, host, line, filename, linenum, &active) != 0) | 1127 | if (process_config_line(options, host, line, filename, linenum, |
1128 | &active, flags & SSHCONF_USERCONF) != 0) | ||
1110 | bad_options++; | 1129 | bad_options++; |
1111 | } | 1130 | } |
1112 | fclose(f); | 1131 | fclose(f); |
@@ -1280,30 +1299,17 @@ fill_default_options(Options * options) | |||
1280 | options->protocol = SSH_PROTO_2; | 1299 | options->protocol = SSH_PROTO_2; |
1281 | if (options->num_identity_files == 0) { | 1300 | if (options->num_identity_files == 0) { |
1282 | if (options->protocol & SSH_PROTO_1) { | 1301 | if (options->protocol & SSH_PROTO_1) { |
1283 | len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1; | 1302 | add_identity_file(options, "~/", |
1284 | options->identity_files[options->num_identity_files] = | 1303 | _PATH_SSH_CLIENT_IDENTITY, 0); |
1285 | xmalloc(len); | ||
1286 | snprintf(options->identity_files[options->num_identity_files++], | ||
1287 | len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY); | ||
1288 | } | 1304 | } |
1289 | if (options->protocol & SSH_PROTO_2) { | 1305 | if (options->protocol & SSH_PROTO_2) { |
1290 | len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1; | 1306 | add_identity_file(options, "~/", |
1291 | options->identity_files[options->num_identity_files] = | 1307 | _PATH_SSH_CLIENT_ID_RSA, 0); |
1292 | xmalloc(len); | 1308 | add_identity_file(options, "~/", |
1293 | snprintf(options->identity_files[options->num_identity_files++], | 1309 | _PATH_SSH_CLIENT_ID_DSA, 0); |
1294 | len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA); | ||
1295 | |||
1296 | len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1; | ||
1297 | options->identity_files[options->num_identity_files] = | ||
1298 | xmalloc(len); | ||
1299 | snprintf(options->identity_files[options->num_identity_files++], | ||
1300 | len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA); | ||
1301 | #ifdef OPENSSL_HAS_ECC | 1310 | #ifdef OPENSSL_HAS_ECC |
1302 | len = 2 + strlen(_PATH_SSH_CLIENT_ID_ECDSA) + 1; | 1311 | add_identity_file(options, "~/", |
1303 | options->identity_files[options->num_identity_files] = | 1312 | _PATH_SSH_CLIENT_ID_ECDSA, 0); |
1304 | xmalloc(len); | ||
1305 | snprintf(options->identity_files[options->num_identity_files++], | ||
1306 | len, "~/%.100s", _PATH_SSH_CLIENT_ID_ECDSA); | ||
1307 | #endif | 1313 | #endif |
1308 | } | 1314 | } |
1309 | } | 1315 | } |