summaryrefslogtreecommitdiff
path: root/readconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'readconf.c')
-rw-r--r--readconf.c152
1 files changed, 77 insertions, 75 deletions
diff --git a/readconf.c b/readconf.c
index 6d015a202..28aa0a8b8 100644
--- a/readconf.c
+++ b/readconf.c
@@ -14,7 +14,7 @@
14 */ 14 */
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$OpenBSD: readconf.c,v 1.37 2000/06/20 01:39:43 markus Exp $"); 17RCSID("$OpenBSD: readconf.c,v 1.40 2000/07/10 16:27:05 ho Exp $");
18 18
19#include "ssh.h" 19#include "ssh.h"
20#include "cipher.h" 20#include "cipher.h"
@@ -164,7 +164,7 @@ static struct {
164 { NULL, 0 } 164 { NULL, 0 }
165}; 165};
166 166
167/* Characters considered whitespace in strtok calls. */ 167/* Characters considered whitespace in strsep calls. */
168#define WHITESPACE " \t\r\n=" 168#define WHITESPACE " \t\r\n="
169 169
170 170
@@ -237,18 +237,18 @@ process_config_line(Options *options, const char *host,
237 char *line, const char *filename, int linenum, 237 char *line, const char *filename, int linenum,
238 int *activep) 238 int *activep)
239{ 239{
240 char buf[256], *cp, *string, **charptr, *cp2; 240 char buf[256], *s, *string, **charptr, *endofnumber, *keyword, *arg;
241 int opcode, *intptr, value; 241 int opcode, *intptr, value;
242 u_short fwd_port, fwd_host_port; 242 u_short fwd_port, fwd_host_port;
243 243
244 /* Skip leading whitespace. */ 244 /* Skip leading whitespace. */
245 cp = line + strspn(line, WHITESPACE); 245 s = line + strspn(line, WHITESPACE);
246 if (!*cp || *cp == '\n' || *cp == '#') 246 if (!*s || *s == '\n' || *s == '#')
247 return 0; 247 return 0;
248 248
249 /* Get the keyword. (Each line is supposed to begin with a keyword). */ 249 /* Get the keyword. (Each line is supposed to begin with a keyword). */
250 cp = strtok(cp, WHITESPACE); 250 keyword = strsep(&s, WHITESPACE);
251 opcode = parse_token(cp, filename, linenum); 251 opcode = parse_token(keyword, filename, linenum);
252 252
253 switch (opcode) { 253 switch (opcode) {
254 case oBadOption: 254 case oBadOption:
@@ -258,13 +258,13 @@ process_config_line(Options *options, const char *host,
258 case oForwardAgent: 258 case oForwardAgent:
259 intptr = &options->forward_agent; 259 intptr = &options->forward_agent;
260parse_flag: 260parse_flag:
261 cp = strtok(NULL, WHITESPACE); 261 arg = strsep(&s, WHITESPACE);
262 if (!cp) 262 if (!arg || *arg == '\0')
263 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum); 263 fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
264 value = 0; /* To avoid compiler warning... */ 264 value = 0; /* To avoid compiler warning... */
265 if (strcmp(cp, "yes") == 0 || strcmp(cp, "true") == 0) 265 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
266 value = 1; 266 value = 1;
267 else if (strcmp(cp, "no") == 0 || strcmp(cp, "false") == 0) 267 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
268 value = 0; 268 value = 0;
269 else 269 else
270 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum); 270 fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
@@ -344,16 +344,16 @@ parse_flag:
344 344
345 case oStrictHostKeyChecking: 345 case oStrictHostKeyChecking:
346 intptr = &options->strict_host_key_checking; 346 intptr = &options->strict_host_key_checking;
347 cp = strtok(NULL, WHITESPACE); 347 arg = strsep(&s, WHITESPACE);
348 if (!cp) 348 if (!arg || *arg == '\0')
349 fatal("%.200s line %d: Missing yes/no argument.", 349 fatal("%.200s line %d: Missing yes/no argument.",
350 filename, linenum); 350 filename, linenum);
351 value = 0; /* To avoid compiler warning... */ 351 value = 0; /* To avoid compiler warning... */
352 if (strcmp(cp, "yes") == 0 || strcmp(cp, "true") == 0) 352 if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
353 value = 1; 353 value = 1;
354 else if (strcmp(cp, "no") == 0 || strcmp(cp, "false") == 0) 354 else if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
355 value = 0; 355 value = 0;
356 else if (strcmp(cp, "ask") == 0) 356 else if (strcmp(arg, "ask") == 0)
357 value = 2; 357 value = 2;
358 else 358 else
359 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum); 359 fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
@@ -379,8 +379,8 @@ parse_flag:
379 379
380 case oIdentityFile: 380 case oIdentityFile:
381 case oIdentityFile2: 381 case oIdentityFile2:
382 cp = strtok(NULL, WHITESPACE); 382 arg = strsep(&s, WHITESPACE);
383 if (!cp) 383 if (!arg || *arg == '\0')
384 fatal("%.200s line %d: Missing argument.", filename, linenum); 384 fatal("%.200s line %d: Missing argument.", filename, linenum);
385 if (*activep) { 385 if (*activep) {
386 intptr = (opcode == oIdentityFile) ? 386 intptr = (opcode == oIdentityFile) ?
@@ -392,7 +392,7 @@ parse_flag:
392 charptr = (opcode == oIdentityFile) ? 392 charptr = (opcode == oIdentityFile) ?
393 &options->identity_files[*intptr] : 393 &options->identity_files[*intptr] :
394 &options->identity_files2[*intptr]; 394 &options->identity_files2[*intptr];
395 *charptr = xstrdup(cp); 395 *charptr = xstrdup(arg);
396 *intptr = *intptr + 1; 396 *intptr = *intptr + 1;
397 } 397 }
398 break; 398 break;
@@ -404,11 +404,11 @@ parse_flag:
404 case oUser: 404 case oUser:
405 charptr = &options->user; 405 charptr = &options->user;
406parse_string: 406parse_string:
407 cp = strtok(NULL, WHITESPACE); 407 arg = strsep(&s, WHITESPACE);
408 if (!cp) 408 if (!arg || *arg == '\0')
409 fatal("%.200s line %d: Missing argument.", filename, linenum); 409 fatal("%.200s line %d: Missing argument.", filename, linenum);
410 if (*activep && *charptr == NULL) 410 if (*activep && *charptr == NULL)
411 *charptr = xstrdup(cp); 411 *charptr = xstrdup(arg);
412 break; 412 break;
413 413
414 case oGlobalKnownHostsFile: 414 case oGlobalKnownHostsFile:
@@ -434,10 +434,10 @@ parse_string:
434 case oProxyCommand: 434 case oProxyCommand:
435 charptr = &options->proxy_command; 435 charptr = &options->proxy_command;
436 string = xstrdup(""); 436 string = xstrdup("");
437 while ((cp = strtok(NULL, WHITESPACE)) != NULL) { 437 while ((arg = strsep(&s, WHITESPACE)) != NULL && *arg != '\0') {
438 string = xrealloc(string, strlen(string) + strlen(cp) + 2); 438 string = xrealloc(string, strlen(string) + strlen(arg) + 2);
439 strcat(string, " "); 439 strcat(string, " ");
440 strcat(string, cp); 440 strcat(string, arg);
441 } 441 }
442 if (*activep && *charptr == NULL) 442 if (*activep && *charptr == NULL)
443 *charptr = string; 443 *charptr = string;
@@ -448,15 +448,15 @@ parse_string:
448 case oPort: 448 case oPort:
449 intptr = &options->port; 449 intptr = &options->port;
450parse_int: 450parse_int:
451 cp = strtok(NULL, WHITESPACE); 451 arg = strsep(&s, WHITESPACE);
452 if (!cp) 452 if (!arg || *arg == '\0')
453 fatal("%.200s line %d: Missing argument.", filename, linenum); 453 fatal("%.200s line %d: Missing argument.", filename, linenum);
454 if (cp[0] < '0' || cp[0] > '9') 454 if (arg[0] < '0' || arg[0] > '9')
455 fatal("%.200s line %d: Bad number.", filename, linenum); 455 fatal("%.200s line %d: Bad number.", filename, linenum);
456 456
457 /* Octal, decimal, or hex format? */ 457 /* Octal, decimal, or hex format? */
458 value = strtol(cp, &cp2, 0); 458 value = strtol(arg, &endofnumber, 0);
459 if (cp == cp2) 459 if (arg == endofnumber)
460 fatal("%.200s line %d: Bad number.", filename, linenum); 460 fatal("%.200s line %d: Bad number.", filename, linenum);
461 if (*activep && *intptr == -1) 461 if (*activep && *intptr == -1)
462 *intptr = value; 462 *intptr = value;
@@ -468,65 +468,65 @@ parse_int:
468 468
469 case oCipher: 469 case oCipher:
470 intptr = &options->cipher; 470 intptr = &options->cipher;
471 cp = strtok(NULL, WHITESPACE); 471 arg = strsep(&s, WHITESPACE);
472 if (!cp) 472 if (!arg || *arg == '\0')
473 fatal("%.200s line %d: Missing argument.", filename, linenum); 473 fatal("%.200s line %d: Missing argument.", filename, linenum);
474 value = cipher_number(cp); 474 value = cipher_number(arg);
475 if (value == -1) 475 if (value == -1)
476 fatal("%.200s line %d: Bad cipher '%s'.", 476 fatal("%.200s line %d: Bad cipher '%s'.",
477 filename, linenum, cp ? cp : "<NONE>"); 477 filename, linenum, arg ? arg : "<NONE>");
478 if (*activep && *intptr == -1) 478 if (*activep && *intptr == -1)
479 *intptr = value; 479 *intptr = value;
480 break; 480 break;
481 481
482 case oCiphers: 482 case oCiphers:
483 cp = strtok(NULL, WHITESPACE); 483 arg = strsep(&s, WHITESPACE);
484 if (!cp) 484 if (!arg || *arg == '\0')
485 fatal("%.200s line %d: Missing argument.", filename, linenum); 485 fatal("%.200s line %d: Missing argument.", filename, linenum);
486 if (!ciphers_valid(cp)) 486 if (!ciphers_valid(arg))
487 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.", 487 fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",
488 filename, linenum, cp ? cp : "<NONE>"); 488 filename, linenum, arg ? arg : "<NONE>");
489 if (*activep && options->ciphers == NULL) 489 if (*activep && options->ciphers == NULL)
490 options->ciphers = xstrdup(cp); 490 options->ciphers = xstrdup(arg);
491 break; 491 break;
492 492
493 case oProtocol: 493 case oProtocol:
494 intptr = &options->protocol; 494 intptr = &options->protocol;
495 cp = strtok(NULL, WHITESPACE); 495 arg = strsep(&s, WHITESPACE);
496 if (!cp) 496 if (!arg || *arg == '\0')
497 fatal("%.200s line %d: Missing argument.", filename, linenum); 497 fatal("%.200s line %d: Missing argument.", filename, linenum);
498 value = proto_spec(cp); 498 value = proto_spec(arg);
499 if (value == SSH_PROTO_UNKNOWN) 499 if (value == SSH_PROTO_UNKNOWN)
500 fatal("%.200s line %d: Bad protocol spec '%s'.", 500 fatal("%.200s line %d: Bad protocol spec '%s'.",
501 filename, linenum, cp ? cp : "<NONE>"); 501 filename, linenum, arg ? arg : "<NONE>");
502 if (*activep && *intptr == SSH_PROTO_UNKNOWN) 502 if (*activep && *intptr == SSH_PROTO_UNKNOWN)
503 *intptr = value; 503 *intptr = value;
504 break; 504 break;
505 505
506 case oLogLevel: 506 case oLogLevel:
507 intptr = (int *) &options->log_level; 507 intptr = (int *) &options->log_level;
508 cp = strtok(NULL, WHITESPACE); 508 arg = strsep(&s, WHITESPACE);
509 value = log_level_number(cp); 509 value = log_level_number(arg);
510 if (value == (LogLevel) - 1) 510 if (value == (LogLevel) - 1)
511 fatal("%.200s line %d: unsupported log level '%s'\n", 511 fatal("%.200s line %d: unsupported log level '%s'\n",
512 filename, linenum, cp ? cp : "<NONE>"); 512 filename, linenum, arg ? arg : "<NONE>");
513 if (*activep && (LogLevel) * intptr == -1) 513 if (*activep && (LogLevel) * intptr == -1)
514 *intptr = (LogLevel) value; 514 *intptr = (LogLevel) value;
515 break; 515 break;
516 516
517 case oRemoteForward: 517 case oRemoteForward:
518 cp = strtok(NULL, WHITESPACE); 518 arg = strsep(&s, WHITESPACE);
519 if (!cp) 519 if (!arg || *arg == '\0')
520 fatal("%.200s line %d: Missing argument.", filename, linenum); 520 fatal("%.200s line %d: Missing argument.", filename, linenum);
521 if (cp[0] < '0' || cp[0] > '9') 521 if (arg[0] < '0' || arg[0] > '9')
522 fatal("%.200s line %d: Badly formatted port number.", 522 fatal("%.200s line %d: Badly formatted port number.",
523 filename, linenum); 523 filename, linenum);
524 fwd_port = atoi(cp); 524 fwd_port = atoi(arg);
525 cp = strtok(NULL, WHITESPACE); 525 arg = strsep(&s, WHITESPACE);
526 if (!cp) 526 if (!arg || *arg == '\0')
527 fatal("%.200s line %d: Missing second argument.", 527 fatal("%.200s line %d: Missing second argument.",
528 filename, linenum); 528 filename, linenum);
529 if (sscanf(cp, "%255[^:]:%hu", buf, &fwd_host_port) != 2) 529 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
530 fatal("%.200s line %d: Badly formatted host:port.", 530 fatal("%.200s line %d: Badly formatted host:port.",
531 filename, linenum); 531 filename, linenum);
532 if (*activep) 532 if (*activep)
@@ -534,18 +534,18 @@ parse_int:
534 break; 534 break;
535 535
536 case oLocalForward: 536 case oLocalForward:
537 cp = strtok(NULL, WHITESPACE); 537 arg = strsep(&s, WHITESPACE);
538 if (!cp) 538 if (!arg || *arg == '\0')
539 fatal("%.200s line %d: Missing argument.", filename, linenum); 539 fatal("%.200s line %d: Missing argument.", filename, linenum);
540 if (cp[0] < '0' || cp[0] > '9') 540 if (arg[0] < '0' || arg[0] > '9')
541 fatal("%.200s line %d: Badly formatted port number.", 541 fatal("%.200s line %d: Badly formatted port number.",
542 filename, linenum); 542 filename, linenum);
543 fwd_port = atoi(cp); 543 fwd_port = atoi(arg);
544 cp = strtok(NULL, WHITESPACE); 544 arg = strsep(&s, WHITESPACE);
545 if (!cp) 545 if (!arg || *arg == '\0')
546 fatal("%.200s line %d: Missing second argument.", 546 fatal("%.200s line %d: Missing second argument.",
547 filename, linenum); 547 filename, linenum);
548 if (sscanf(cp, "%255[^:]:%hu", buf, &fwd_host_port) != 2) 548 if (sscanf(arg, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
549 fatal("%.200s line %d: Badly formatted host:port.", 549 fatal("%.200s line %d: Badly formatted host:port.",
550 filename, linenum); 550 filename, linenum);
551 if (*activep) 551 if (*activep)
@@ -554,26 +554,26 @@ parse_int:
554 554
555 case oHost: 555 case oHost:
556 *activep = 0; 556 *activep = 0;
557 while ((cp = strtok(NULL, WHITESPACE)) != NULL) 557 while ((arg = strsep(&s, WHITESPACE)) != NULL && *arg != '\0')
558 if (match_pattern(host, cp)) { 558 if (match_pattern(host, arg)) {
559 debug("Applying options for %.100s", cp); 559 debug("Applying options for %.100s", arg);
560 *activep = 1; 560 *activep = 1;
561 break; 561 break;
562 } 562 }
563 /* Avoid garbage check below, as strtok already returned NULL. */ 563 /* Avoid garbage check below, as strsep is done. */
564 return 0; 564 return 0;
565 565
566 case oEscapeChar: 566 case oEscapeChar:
567 intptr = &options->escape_char; 567 intptr = &options->escape_char;
568 cp = strtok(NULL, WHITESPACE); 568 arg = strsep(&s, WHITESPACE);
569 if (!cp) 569 if (!arg || *arg == '\0')
570 fatal("%.200s line %d: Missing argument.", filename, linenum); 570 fatal("%.200s line %d: Missing argument.", filename, linenum);
571 if (cp[0] == '^' && cp[2] == 0 && 571 if (arg[0] == '^' && arg[2] == 0 &&
572 (unsigned char) cp[1] >= 64 && (unsigned char) cp[1] < 128) 572 (unsigned char) arg[1] >= 64 && (unsigned char) arg[1] < 128)
573 value = (unsigned char) cp[1] & 31; 573 value = (unsigned char) arg[1] & 31;
574 else if (strlen(cp) == 1) 574 else if (strlen(arg) == 1)
575 value = (unsigned char) cp[0]; 575 value = (unsigned char) arg[0];
576 else if (strcmp(cp, "none") == 0) 576 else if (strcmp(arg, "none") == 0)
577 value = -2; 577 value = -2;
578 else { 578 else {
579 fatal("%.200s line %d: Bad escape character.", 579 fatal("%.200s line %d: Bad escape character.",
@@ -590,9 +590,11 @@ parse_int:
590 } 590 }
591 591
592 /* Check that there is no garbage at end of line. */ 592 /* Check that there is no garbage at end of line. */
593 if (strtok(NULL, WHITESPACE) != NULL) 593 if ((arg = strsep(&s, WHITESPACE)) != NULL && *arg != '\0')
594 fatal("%.200s line %d: garbage at end of line.", 594 {
595 filename, linenum); 595 fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
596 filename, linenum, arg);
597 }
596 return 0; 598 return 0;
597} 599}
598 600