summaryrefslogtreecommitdiff
path: root/readconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'readconf.c')
-rw-r--r--readconf.c64
1 files changed, 35 insertions, 29 deletions
diff --git a/readconf.c b/readconf.c
index 99c04a9de..375ca32cc 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
@@ -337,6 +337,26 @@ clear_forwardings(Options *options)
337 options->tun_open = SSH_TUNMODE_NO; 337 options->tun_open = SSH_TUNMODE_NO;
338} 338}
339 339
340void
341add_identity_file(Options *options, const char *dir, const char *filename,
342 int userprovided)
343{
344 char *path;
345
346 if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
347 fatal("Too many identity files specified (max %d)",
348 SSH_MAX_IDENTITY_FILES);
349
350 if (dir == NULL) /* no dir, filename is absolute */
351 path = xstrdup(filename);
352 else
353 (void)xasprintf(&path, "%.100s%.100s", dir, filename);
354
355 options->identity_file_userprovided[options->num_identity_files] =
356 userprovided;
357 options->identity_files[options->num_identity_files++] = path;
358}
359
340/* 360/*
341 * Returns the number of the token pointed to by cp or oBadOption. 361 * Returns the number of the token pointed to by cp or oBadOption.
342 */ 362 */
@@ -364,7 +384,7 @@ parse_token(const char *cp, const char *filename, int linenum)
364int 384int
365process_config_line(Options *options, const char *host, 385process_config_line(Options *options, const char *host,
366 char *line, const char *filename, int linenum, 386 char *line, const char *filename, int linenum,
367 int *activep) 387 int *activep, int userconfig)
368{ 388{
369 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2; 389 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
370 char **cpptr, fwdarg[256]; 390 char **cpptr, fwdarg[256];
@@ -617,9 +637,7 @@ parse_yesnoask:
617 if (*intptr >= SSH_MAX_IDENTITY_FILES) 637 if (*intptr >= SSH_MAX_IDENTITY_FILES)
618 fatal("%.200s line %d: Too many identity files specified (max %d).", 638 fatal("%.200s line %d: Too many identity files specified (max %d).",
619 filename, linenum, SSH_MAX_IDENTITY_FILES); 639 filename, linenum, SSH_MAX_IDENTITY_FILES);
620 charptr = &options->identity_files[*intptr]; 640 add_identity_file(options, NULL, arg, userconfig);
621 *charptr = xstrdup(arg);
622 *intptr = *intptr + 1;
623 } 641 }
624 break; 642 break;
625 643
@@ -1106,7 +1124,7 @@ parse_int:
1106 1124
1107int 1125int
1108read_config_file(const char *filename, const char *host, Options *options, 1126read_config_file(const char *filename, const char *host, Options *options,
1109 int checkperm) 1127 int flags)
1110{ 1128{
1111 FILE *f; 1129 FILE *f;
1112 char line[1024]; 1130 char line[1024];
@@ -1116,7 +1134,7 @@ read_config_file(const char *filename, const char *host, Options *options,
1116 if ((f = fopen(filename, "r")) == NULL) 1134 if ((f = fopen(filename, "r")) == NULL)
1117 return 0; 1135 return 0;
1118 1136
1119 if (checkperm) { 1137 if (flags & SSHCONF_CHECKPERM) {
1120 struct stat sb; 1138 struct stat sb;
1121 1139
1122 if (fstat(fileno(f), &sb) == -1) 1140 if (fstat(fileno(f), &sb) == -1)
@@ -1137,7 +1155,8 @@ read_config_file(const char *filename, const char *host, Options *options,
1137 while (fgets(line, sizeof(line), f)) { 1155 while (fgets(line, sizeof(line), f)) {
1138 /* Update line number counter. */ 1156 /* Update line number counter. */
1139 linenum++; 1157 linenum++;
1140 if (process_config_line(options, host, line, filename, linenum, &active) != 0) 1158 if (process_config_line(options, host, line, filename, linenum,
1159 &active, flags & SSHCONF_USERCONF) != 0)
1141 bad_options++; 1160 bad_options++;
1142 } 1161 }
1143 fclose(f); 1162 fclose(f);
@@ -1322,30 +1341,17 @@ fill_default_options(Options * options)
1322 options->protocol = SSH_PROTO_2; 1341 options->protocol = SSH_PROTO_2;
1323 if (options->num_identity_files == 0) { 1342 if (options->num_identity_files == 0) {
1324 if (options->protocol & SSH_PROTO_1) { 1343 if (options->protocol & SSH_PROTO_1) {
1325 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1; 1344 add_identity_file(options, "~/",
1326 options->identity_files[options->num_identity_files] = 1345 _PATH_SSH_CLIENT_IDENTITY, 0);
1327 xmalloc(len);
1328 snprintf(options->identity_files[options->num_identity_files++],
1329 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
1330 } 1346 }
1331 if (options->protocol & SSH_PROTO_2) { 1347 if (options->protocol & SSH_PROTO_2) {
1332 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1; 1348 add_identity_file(options, "~/",
1333 options->identity_files[options->num_identity_files] = 1349 _PATH_SSH_CLIENT_ID_RSA, 0);
1334 xmalloc(len); 1350 add_identity_file(options, "~/",
1335 snprintf(options->identity_files[options->num_identity_files++], 1351 _PATH_SSH_CLIENT_ID_DSA, 0);
1336 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
1337
1338 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
1339 options->identity_files[options->num_identity_files] =
1340 xmalloc(len);
1341 snprintf(options->identity_files[options->num_identity_files++],
1342 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
1343#ifdef OPENSSL_HAS_ECC 1352#ifdef OPENSSL_HAS_ECC
1344 len = 2 + strlen(_PATH_SSH_CLIENT_ID_ECDSA) + 1; 1353 add_identity_file(options, "~/",
1345 options->identity_files[options->num_identity_files] = 1354 _PATH_SSH_CLIENT_ID_ECDSA, 0);
1346 xmalloc(len);
1347 snprintf(options->identity_files[options->num_identity_files++],
1348 len, "~/%.100s", _PATH_SSH_CLIENT_ID_ECDSA);
1349#endif 1355#endif
1350 } 1356 }
1351 } 1357 }