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 a34cbe707..0b26a6735 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
@@ -344,6 +344,26 @@ clear_forwardings(Options *options)
344 options->tun_open = SSH_TUNMODE_NO; 344 options->tun_open = SSH_TUNMODE_NO;
345} 345}
346 346
347void
348add_identity_file(Options *options, const char *dir, const char *filename,
349 int userprovided)
350{
351 char *path;
352
353 if (options->num_identity_files >= SSH_MAX_IDENTITY_FILES)
354 fatal("Too many identity files specified (max %d)",
355 SSH_MAX_IDENTITY_FILES);
356
357 if (dir == NULL) /* no dir, filename is absolute */
358 path = xstrdup(filename);
359 else
360 (void)xasprintf(&path, "%.100s%.100s", dir, filename);
361
362 options->identity_file_userprovided[options->num_identity_files] =
363 userprovided;
364 options->identity_files[options->num_identity_files++] = path;
365}
366
347/* 367/*
348 * Returns the number of the token pointed to by cp or oBadOption. 368 * Returns the number of the token pointed to by cp or oBadOption.
349 */ 369 */
@@ -371,7 +391,7 @@ parse_token(const char *cp, const char *filename, int linenum)
371int 391int
372process_config_line(Options *options, const char *host, 392process_config_line(Options *options, const char *host,
373 char *line, const char *filename, int linenum, 393 char *line, const char *filename, int linenum,
374 int *activep) 394 int *activep, int userconfig)
375{ 395{
376 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2; 396 char *s, **charptr, *endofnumber, *keyword, *arg, *arg2;
377 char **cpptr, fwdarg[256]; 397 char **cpptr, fwdarg[256];
@@ -628,9 +648,7 @@ parse_yesnoask:
628 if (*intptr >= SSH_MAX_IDENTITY_FILES) 648 if (*intptr >= SSH_MAX_IDENTITY_FILES)
629 fatal("%.200s line %d: Too many identity files specified (max %d).", 649 fatal("%.200s line %d: Too many identity files specified (max %d).",
630 filename, linenum, SSH_MAX_IDENTITY_FILES); 650 filename, linenum, SSH_MAX_IDENTITY_FILES);
631 charptr = &options->identity_files[*intptr]; 651 add_identity_file(options, NULL, arg, userconfig);
632 *charptr = xstrdup(arg);
633 *intptr = *intptr + 1;
634 } 652 }
635 break; 653 break;
636 654
@@ -1119,7 +1137,7 @@ parse_int:
1119 1137
1120int 1138int
1121read_config_file(const char *filename, const char *host, Options *options, 1139read_config_file(const char *filename, const char *host, Options *options,
1122 int checkperm) 1140 int flags)
1123{ 1141{
1124 FILE *f; 1142 FILE *f;
1125 char line[1024]; 1143 char line[1024];
@@ -1129,7 +1147,7 @@ read_config_file(const char *filename, const char *host, Options *options,
1129 if ((f = fopen(filename, "r")) == NULL) 1147 if ((f = fopen(filename, "r")) == NULL)
1130 return 0; 1148 return 0;
1131 1149
1132 if (checkperm) { 1150 if (flags & SSHCONF_CHECKPERM) {
1133 struct stat sb; 1151 struct stat sb;
1134 1152
1135 if (fstat(fileno(f), &sb) == -1) 1153 if (fstat(fileno(f), &sb) == -1)
@@ -1149,7 +1167,8 @@ read_config_file(const char *filename, const char *host, Options *options,
1149 while (fgets(line, sizeof(line), f)) { 1167 while (fgets(line, sizeof(line), f)) {
1150 /* Update line number counter. */ 1168 /* Update line number counter. */
1151 linenum++; 1169 linenum++;
1152 if (process_config_line(options, host, line, filename, linenum, &active) != 0) 1170 if (process_config_line(options, host, line, filename, linenum,
1171 &active, flags & SSHCONF_USERCONF) != 0)
1153 bad_options++; 1172 bad_options++;
1154 } 1173 }
1155 fclose(f); 1174 fclose(f);
@@ -1337,30 +1356,17 @@ fill_default_options(Options * options)
1337 options->protocol = SSH_PROTO_2; 1356 options->protocol = SSH_PROTO_2;
1338 if (options->num_identity_files == 0) { 1357 if (options->num_identity_files == 0) {
1339 if (options->protocol & SSH_PROTO_1) { 1358 if (options->protocol & SSH_PROTO_1) {
1340 len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1; 1359 add_identity_file(options, "~/",
1341 options->identity_files[options->num_identity_files] = 1360 _PATH_SSH_CLIENT_IDENTITY, 0);
1342 xmalloc(len);
1343 snprintf(options->identity_files[options->num_identity_files++],
1344 len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);
1345 } 1361 }
1346 if (options->protocol & SSH_PROTO_2) { 1362 if (options->protocol & SSH_PROTO_2) {
1347 len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1; 1363 add_identity_file(options, "~/",
1348 options->identity_files[options->num_identity_files] = 1364 _PATH_SSH_CLIENT_ID_RSA, 0);
1349 xmalloc(len); 1365 add_identity_file(options, "~/",
1350 snprintf(options->identity_files[options->num_identity_files++], 1366 _PATH_SSH_CLIENT_ID_DSA, 0);
1351 len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);
1352
1353 len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;
1354 options->identity_files[options->num_identity_files] =
1355 xmalloc(len);
1356 snprintf(options->identity_files[options->num_identity_files++],
1357 len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);
1358#ifdef OPENSSL_HAS_ECC 1367#ifdef OPENSSL_HAS_ECC
1359 len = 2 + strlen(_PATH_SSH_CLIENT_ID_ECDSA) + 1; 1368 add_identity_file(options, "~/",
1360 options->identity_files[options->num_identity_files] = 1369 _PATH_SSH_CLIENT_ID_ECDSA, 0);
1361 xmalloc(len);
1362 snprintf(options->identity_files[options->num_identity_files++],
1363 len, "~/%.100s", _PATH_SSH_CLIENT_ID_ECDSA);
1364#endif 1370#endif
1365 } 1371 }
1366 } 1372 }