Annotation of src/usr.bin/ssh/readconf.c, Revision 1.30
1.1 deraadt 1: /*
1.26 markus 2: *
1.18 deraadt 3: * readconf.c
1.26 markus 4: *
1.18 deraadt 5: * Author: Tatu Ylonen <ylo@cs.hut.fi>
1.26 markus 6: *
1.18 deraadt 7: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8: * All rights reserved
1.26 markus 9: *
1.18 deraadt 10: * Created: Sat Apr 22 00:03:10 1995 ylo
1.26 markus 11: *
1.18 deraadt 12: * Functions for reading the configuration files.
1.26 markus 13: *
1.18 deraadt 14: */
1.1 deraadt 15:
16: #include "includes.h"
1.30 ! markus 17: RCSID("$Id: readconf.c,v 1.29 2000/05/02 22:18:04 markus Exp $");
1.1 deraadt 18:
19: #include "ssh.h"
20: #include "cipher.h"
21: #include "readconf.h"
1.24 markus 22: #include "match.h"
1.1 deraadt 23: #include "xmalloc.h"
1.25 markus 24: #include "compat.h"
1.1 deraadt 25:
26: /* Format of the configuration file:
27:
28: # Configuration data is parsed as follows:
29: # 1. command line options
30: # 2. user-specific file
31: # 3. system-wide file
32: # Any configuration value is only changed the first time it is set.
33: # Thus, host-specific definitions should be at the beginning of the
34: # configuration file, and defaults at the end.
35:
36: # Host-specific declarations. These may override anything above. A single
37: # host may match multiple declarations; these are processed in the order
38: # that they are given in.
39:
40: Host *.ngs.fi ngs.fi
41: FallBackToRsh no
42:
43: Host fake.com
44: HostName another.host.name.real.org
45: User blaah
46: Port 34289
47: ForwardX11 no
48: ForwardAgent no
49:
50: Host books.com
51: RemoteForward 9999 shadows.cs.hut.fi:9999
52: Cipher 3des
53:
54: Host fascist.blob.com
55: Port 23123
56: User tylonen
57: RhostsAuthentication no
58: PasswordAuthentication no
59:
60: Host puukko.hut.fi
61: User t35124p
62: ProxyCommand ssh-proxy %h %p
63:
64: Host *.fr
65: UseRsh yes
66:
67: Host *.su
68: Cipher none
69: PasswordAuthentication no
70:
71: # Defaults for various options
72: Host *
73: ForwardAgent no
74: ForwardX11 yes
75: RhostsAuthentication yes
76: PasswordAuthentication yes
77: RSAAuthentication yes
78: RhostsRSAAuthentication yes
79: FallBackToRsh no
80: UseRsh no
81: StrictHostKeyChecking yes
82: KeepAlives no
83: IdentityFile ~/.ssh/identity
84: Port 22
85: EscapeChar ~
86:
87: */
88:
89: /* Keyword tokens. */
90:
1.17 markus 91: typedef enum {
92: oBadOption,
93: oForwardAgent, oForwardX11, oGatewayPorts, oRhostsAuthentication,
94: oPasswordAuthentication, oRSAAuthentication, oFallBackToRsh, oUseRsh,
95: oSkeyAuthentication,
1.1 deraadt 96: #ifdef KRB4
1.17 markus 97: oKerberosAuthentication,
1.1 deraadt 98: #endif /* KRB4 */
99: #ifdef AFS
1.17 markus 100: oKerberosTgtPassing, oAFSTokenPassing,
1.1 deraadt 101: #endif
1.17 markus 102: oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
103: oUser, oHost, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
104: oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
105: oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
106: oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts, oTISAuthentication,
1.27 markus 107: oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oIdentityFile2,
1.30 ! markus 108: oGlobalKnownHostsFile2, oUserKnownHostsFile2, oDSAAuthentication
1.1 deraadt 109: } OpCodes;
110:
111: /* Textual representations of the tokens. */
112:
1.17 markus 113: static struct {
114: const char *name;
115: OpCodes opcode;
116: } keywords[] = {
117: { "forwardagent", oForwardAgent },
118: { "forwardx11", oForwardX11 },
119: { "gatewayports", oGatewayPorts },
120: { "useprivilegedport", oUsePrivilegedPort },
121: { "rhostsauthentication", oRhostsAuthentication },
122: { "passwordauthentication", oPasswordAuthentication },
123: { "rsaauthentication", oRSAAuthentication },
1.30 ! markus 124: { "dsaauthentication", oDSAAuthentication },
1.17 markus 125: { "skeyauthentication", oSkeyAuthentication },
1.1 deraadt 126: #ifdef KRB4
1.17 markus 127: { "kerberosauthentication", oKerberosAuthentication },
1.1 deraadt 128: #endif /* KRB4 */
1.5 dugsong 129: #ifdef AFS
1.17 markus 130: { "kerberostgtpassing", oKerberosTgtPassing },
131: { "afstokenpassing", oAFSTokenPassing },
1.1 deraadt 132: #endif
1.17 markus 133: { "fallbacktorsh", oFallBackToRsh },
134: { "usersh", oUseRsh },
135: { "identityfile", oIdentityFile },
1.27 markus 136: { "identityfile2", oIdentityFile2 },
1.17 markus 137: { "hostname", oHostName },
138: { "proxycommand", oProxyCommand },
139: { "port", oPort },
140: { "cipher", oCipher },
1.25 markus 141: { "ciphers", oCiphers },
142: { "protocol", oProtocol },
1.17 markus 143: { "remoteforward", oRemoteForward },
144: { "localforward", oLocalForward },
145: { "user", oUser },
146: { "host", oHost },
147: { "escapechar", oEscapeChar },
148: { "rhostsrsaauthentication", oRhostsRSAAuthentication },
149: { "globalknownhostsfile", oGlobalKnownHostsFile },
150: { "userknownhostsfile", oUserKnownHostsFile },
1.27 markus 151: { "globalknownhostsfile2", oGlobalKnownHostsFile2 },
152: { "userknownhostsfile2", oUserKnownHostsFile2 },
1.17 markus 153: { "connectionattempts", oConnectionAttempts },
154: { "batchmode", oBatchMode },
155: { "checkhostip", oCheckHostIP },
156: { "stricthostkeychecking", oStrictHostKeyChecking },
157: { "compression", oCompression },
158: { "compressionlevel", oCompressionLevel },
159: { "keepalive", oKeepAlives },
160: { "numberofpasswordprompts", oNumberOfPasswordPrompts },
161: { "tisauthentication", oTISAuthentication },
162: { "loglevel", oLogLevel },
163: { NULL, 0 }
1.13 markus 164: };
165:
1.1 deraadt 166: /* Characters considered whitespace in strtok calls. */
167: #define WHITESPACE " \t\r\n"
168:
169:
1.19 markus 170: /*
171: * Adds a local TCP/IP port forward to options. Never returns if there is an
172: * error.
173: */
1.1 deraadt 174:
1.26 markus 175: void
1.22 markus 176: add_local_forward(Options *options, u_short port, const char *host,
177: u_short host_port)
1.1 deraadt 178: {
1.17 markus 179: Forward *fwd;
180: extern uid_t original_real_uid;
181: if (port < IPPORT_RESERVED && original_real_uid != 0)
182: fatal("Privileged ports can only be forwarded by root.\n");
183: if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
184: fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
185: fwd = &options->local_forwards[options->num_local_forwards++];
186: fwd->port = port;
187: fwd->host = xstrdup(host);
188: fwd->host_port = host_port;
1.1 deraadt 189: }
190:
1.19 markus 191: /*
192: * Adds a remote TCP/IP port forward to options. Never returns if there is
193: * an error.
194: */
1.1 deraadt 195:
1.26 markus 196: void
1.22 markus 197: add_remote_forward(Options *options, u_short port, const char *host,
198: u_short host_port)
1.1 deraadt 199: {
1.17 markus 200: Forward *fwd;
201: if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
202: fatal("Too many remote forwards (max %d).",
203: SSH_MAX_FORWARDS_PER_DIRECTION);
204: fwd = &options->remote_forwards[options->num_remote_forwards++];
205: fwd->port = port;
206: fwd->host = xstrdup(host);
207: fwd->host_port = host_port;
1.1 deraadt 208: }
209:
1.19 markus 210: /*
211: * Returns the number of the token pointed to by cp of length len. Never
212: * returns if the token is not known.
213: */
1.1 deraadt 214:
1.26 markus 215: static OpCodes
1.17 markus 216: parse_token(const char *cp, const char *filename, int linenum)
1.1 deraadt 217: {
1.17 markus 218: unsigned int i;
1.1 deraadt 219:
1.17 markus 220: for (i = 0; keywords[i].name; i++)
1.20 markus 221: if (strcasecmp(cp, keywords[i].name) == 0)
1.17 markus 222: return keywords[i].opcode;
223:
224: fprintf(stderr, "%s: line %d: Bad configuration option: %s\n",
225: filename, linenum, cp);
226: return oBadOption;
1.1 deraadt 227: }
228:
1.19 markus 229: /*
230: * Processes a single option line as used in the configuration files. This
231: * only sets those values that have not already been set.
232: */
1.1 deraadt 233:
1.14 markus 234: int
235: process_config_line(Options *options, const char *host,
1.17 markus 236: char *line, const char *filename, int linenum,
237: int *activep)
1.1 deraadt 238: {
1.21 markus 239: char buf[256], *cp, *string, **charptr, *cp2;
1.22 markus 240: int opcode, *intptr, value;
241: u_short fwd_port, fwd_host_port;
1.1 deraadt 242:
1.17 markus 243: /* Skip leading whitespace. */
244: cp = line + strspn(line, WHITESPACE);
245: if (!*cp || *cp == '\n' || *cp == '#')
246: return 0;
247:
1.19 markus 248: /* Get the keyword. (Each line is supposed to begin with a keyword). */
1.17 markus 249: cp = strtok(cp, WHITESPACE);
250: opcode = parse_token(cp, filename, linenum);
251:
252: switch (opcode) {
253: case oBadOption:
1.19 markus 254: /* don't panic, but count bad options */
255: return -1;
1.17 markus 256: /* NOTREACHED */
257: case oForwardAgent:
258: intptr = &options->forward_agent;
259: parse_flag:
260: cp = strtok(NULL, WHITESPACE);
261: if (!cp)
262: fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
263: value = 0; /* To avoid compiler warning... */
264: if (strcmp(cp, "yes") == 0 || strcmp(cp, "true") == 0)
265: value = 1;
266: else if (strcmp(cp, "no") == 0 || strcmp(cp, "false") == 0)
267: value = 0;
268: else
269: fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
270: if (*activep && *intptr == -1)
271: *intptr = value;
272: break;
273:
274: case oForwardX11:
275: intptr = &options->forward_x11;
276: goto parse_flag;
277:
278: case oGatewayPorts:
279: intptr = &options->gateway_ports;
280: goto parse_flag;
281:
282: case oUsePrivilegedPort:
283: intptr = &options->use_privileged_port;
284: goto parse_flag;
285:
286: case oRhostsAuthentication:
287: intptr = &options->rhosts_authentication;
288: goto parse_flag;
289:
290: case oPasswordAuthentication:
291: intptr = &options->password_authentication;
292: goto parse_flag;
293:
1.30 ! markus 294: case oDSAAuthentication:
! 295: intptr = &options->dsa_authentication;
! 296: goto parse_flag;
! 297:
1.17 markus 298: case oRSAAuthentication:
299: intptr = &options->rsa_authentication;
300: goto parse_flag;
301:
302: case oRhostsRSAAuthentication:
303: intptr = &options->rhosts_rsa_authentication;
304: goto parse_flag;
305:
306: case oTISAuthentication:
307: /* fallthrough, there is no difference on the client side */
308: case oSkeyAuthentication:
309: intptr = &options->skey_authentication;
310: goto parse_flag;
1.16 markus 311:
1.1 deraadt 312: #ifdef KRB4
1.17 markus 313: case oKerberosAuthentication:
314: intptr = &options->kerberos_authentication;
315: goto parse_flag;
1.1 deraadt 316: #endif /* KRB4 */
317:
1.5 dugsong 318: #ifdef AFS
1.17 markus 319: case oKerberosTgtPassing:
320: intptr = &options->kerberos_tgt_passing;
321: goto parse_flag;
322:
323: case oAFSTokenPassing:
324: intptr = &options->afs_token_passing;
325: goto parse_flag;
1.1 deraadt 326: #endif
1.17 markus 327:
328: case oFallBackToRsh:
329: intptr = &options->fallback_to_rsh;
330: goto parse_flag;
331:
332: case oUseRsh:
333: intptr = &options->use_rsh;
334: goto parse_flag;
335:
336: case oBatchMode:
337: intptr = &options->batch_mode;
338: goto parse_flag;
339:
340: case oCheckHostIP:
341: intptr = &options->check_host_ip;
342: goto parse_flag;
343:
344: case oStrictHostKeyChecking:
345: intptr = &options->strict_host_key_checking;
346: cp = strtok(NULL, WHITESPACE);
347: if (!cp)
348: fatal("%.200s line %d: Missing yes/no argument.",
349: filename, linenum);
350: value = 0; /* To avoid compiler warning... */
351: if (strcmp(cp, "yes") == 0 || strcmp(cp, "true") == 0)
352: value = 1;
353: else if (strcmp(cp, "no") == 0 || strcmp(cp, "false") == 0)
354: value = 0;
355: else if (strcmp(cp, "ask") == 0)
356: value = 2;
357: else
358: fatal("%.200s line %d: Bad yes/no/ask argument.", filename, linenum);
359: if (*activep && *intptr == -1)
360: *intptr = value;
361: break;
362:
363: case oCompression:
364: intptr = &options->compression;
365: goto parse_flag;
366:
367: case oKeepAlives:
368: intptr = &options->keepalives;
369: goto parse_flag;
370:
371: case oNumberOfPasswordPrompts:
372: intptr = &options->number_of_password_prompts;
373: goto parse_int;
374:
375: case oCompressionLevel:
376: intptr = &options->compression_level;
377: goto parse_int;
378:
379: case oIdentityFile:
1.27 markus 380: case oIdentityFile2:
1.17 markus 381: cp = strtok(NULL, WHITESPACE);
382: if (!cp)
383: fatal("%.200s line %d: Missing argument.", filename, linenum);
384: if (*activep) {
1.27 markus 385: intptr = (opcode == oIdentityFile) ?
386: &options->num_identity_files :
387: &options->num_identity_files2;
388: if (*intptr >= SSH_MAX_IDENTITY_FILES)
1.17 markus 389: fatal("%.200s line %d: Too many identity files specified (max %d).",
390: filename, linenum, SSH_MAX_IDENTITY_FILES);
1.27 markus 391: charptr = (opcode == oIdentityFile) ?
392: &options->identity_files[*intptr] :
393: &options->identity_files2[*intptr];
394: *charptr = xstrdup(cp);
395: *intptr = *intptr + 1;
1.17 markus 396: }
397: break;
398:
399: case oUser:
400: charptr = &options->user;
401: parse_string:
402: cp = strtok(NULL, WHITESPACE);
403: if (!cp)
404: fatal("%.200s line %d: Missing argument.", filename, linenum);
405: if (*activep && *charptr == NULL)
406: *charptr = xstrdup(cp);
407: break;
408:
409: case oGlobalKnownHostsFile:
410: charptr = &options->system_hostfile;
411: goto parse_string;
412:
413: case oUserKnownHostsFile:
414: charptr = &options->user_hostfile;
415: goto parse_string;
416:
1.27 markus 417: case oGlobalKnownHostsFile2:
418: charptr = &options->system_hostfile2;
419: goto parse_string;
420:
421: case oUserKnownHostsFile2:
422: charptr = &options->user_hostfile2;
423: goto parse_string;
424:
1.17 markus 425: case oHostName:
426: charptr = &options->hostname;
427: goto parse_string;
428:
429: case oProxyCommand:
430: charptr = &options->proxy_command;
431: string = xstrdup("");
432: while ((cp = strtok(NULL, WHITESPACE)) != NULL) {
433: string = xrealloc(string, strlen(string) + strlen(cp) + 2);
434: strcat(string, " ");
435: strcat(string, cp);
436: }
437: if (*activep && *charptr == NULL)
438: *charptr = string;
439: else
440: xfree(string);
441: return 0;
442:
443: case oPort:
444: intptr = &options->port;
445: parse_int:
446: cp = strtok(NULL, WHITESPACE);
447: if (!cp)
448: fatal("%.200s line %d: Missing argument.", filename, linenum);
449: if (cp[0] < '0' || cp[0] > '9')
450: fatal("%.200s line %d: Bad number.", filename, linenum);
1.21 markus 451:
452: /* Octal, decimal, or hex format? */
453: value = strtol(cp, &cp2, 0);
454: if (cp == cp2)
455: fatal("%.200s line %d: Bad number.", filename, linenum);
1.17 markus 456: if (*activep && *intptr == -1)
457: *intptr = value;
458: break;
459:
460: case oConnectionAttempts:
461: intptr = &options->connection_attempts;
462: goto parse_int;
463:
464: case oCipher:
465: intptr = &options->cipher;
466: cp = strtok(NULL, WHITESPACE);
467: value = cipher_number(cp);
468: if (value == -1)
469: fatal("%.200s line %d: Bad cipher '%s'.",
470: filename, linenum, cp ? cp : "<NONE>");
471: if (*activep && *intptr == -1)
472: *intptr = value;
473: break;
474:
1.25 markus 475: case oCiphers:
476: cp = strtok(NULL, WHITESPACE);
477: if (!ciphers_valid(cp))
478: fatal("%.200s line %d: Bad cipher spec '%s'.",
479: filename, linenum, cp ? cp : "<NONE>");
480: if (*activep && options->ciphers == NULL)
481: options->ciphers = xstrdup(cp);
482: break;
483:
484: case oProtocol:
485: intptr = &options->protocol;
486: cp = strtok(NULL, WHITESPACE);
487: value = proto_spec(cp);
488: if (value == SSH_PROTO_UNKNOWN)
489: fatal("%.200s line %d: Bad protocol spec '%s'.",
490: filename, linenum, cp ? cp : "<NONE>");
491: if (*activep && *intptr == SSH_PROTO_UNKNOWN)
492: *intptr = value;
493: break;
494:
1.17 markus 495: case oLogLevel:
496: intptr = (int *) &options->log_level;
497: cp = strtok(NULL, WHITESPACE);
498: value = log_level_number(cp);
499: if (value == (LogLevel) - 1)
500: fatal("%.200s line %d: unsupported log level '%s'\n",
501: filename, linenum, cp ? cp : "<NONE>");
502: if (*activep && (LogLevel) * intptr == -1)
503: *intptr = (LogLevel) value;
504: break;
505:
506: case oRemoteForward:
507: cp = strtok(NULL, WHITESPACE);
508: if (!cp)
509: fatal("%.200s line %d: Missing argument.", filename, linenum);
510: if (cp[0] < '0' || cp[0] > '9')
511: fatal("%.200s line %d: Badly formatted port number.",
512: filename, linenum);
513: fwd_port = atoi(cp);
514: cp = strtok(NULL, WHITESPACE);
515: if (!cp)
516: fatal("%.200s line %d: Missing second argument.",
517: filename, linenum);
1.22 markus 518: if (sscanf(cp, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
1.17 markus 519: fatal("%.200s line %d: Badly formatted host:port.",
520: filename, linenum);
521: if (*activep)
522: add_remote_forward(options, fwd_port, buf, fwd_host_port);
523: break;
524:
525: case oLocalForward:
526: cp = strtok(NULL, WHITESPACE);
527: if (!cp)
528: fatal("%.200s line %d: Missing argument.", filename, linenum);
529: if (cp[0] < '0' || cp[0] > '9')
530: fatal("%.200s line %d: Badly formatted port number.",
531: filename, linenum);
532: fwd_port = atoi(cp);
533: cp = strtok(NULL, WHITESPACE);
534: if (!cp)
535: fatal("%.200s line %d: Missing second argument.",
536: filename, linenum);
1.22 markus 537: if (sscanf(cp, "%255[^:]:%hu", buf, &fwd_host_port) != 2)
1.17 markus 538: fatal("%.200s line %d: Badly formatted host:port.",
539: filename, linenum);
540: if (*activep)
541: add_local_forward(options, fwd_port, buf, fwd_host_port);
542: break;
543:
544: case oHost:
545: *activep = 0;
546: while ((cp = strtok(NULL, WHITESPACE)) != NULL)
547: if (match_pattern(host, cp)) {
548: debug("Applying options for %.100s", cp);
549: *activep = 1;
550: break;
551: }
1.19 markus 552: /* Avoid garbage check below, as strtok already returned NULL. */
1.17 markus 553: return 0;
554:
555: case oEscapeChar:
556: intptr = &options->escape_char;
557: cp = strtok(NULL, WHITESPACE);
558: if (!cp)
559: fatal("%.200s line %d: Missing argument.", filename, linenum);
560: if (cp[0] == '^' && cp[2] == 0 &&
561: (unsigned char) cp[1] >= 64 && (unsigned char) cp[1] < 128)
562: value = (unsigned char) cp[1] & 31;
563: else if (strlen(cp) == 1)
564: value = (unsigned char) cp[0];
565: else if (strcmp(cp, "none") == 0)
566: value = -2;
567: else {
568: fatal("%.200s line %d: Bad escape character.",
569: filename, linenum);
570: /* NOTREACHED */
571: value = 0; /* Avoid compiler warning. */
572: }
573: if (*activep && *intptr == -1)
574: *intptr = value;
575: break;
576:
577: default:
578: fatal("process_config_line: Unimplemented opcode %d", opcode);
579: }
580:
581: /* Check that there is no garbage at end of line. */
582: if (strtok(NULL, WHITESPACE) != NULL)
583: fatal("%.200s line %d: garbage at end of line.",
584: filename, linenum);
585: return 0;
1.1 deraadt 586: }
587:
588:
1.19 markus 589: /*
590: * Reads the config file and modifies the options accordingly. Options
591: * should already be initialized before this call. This never returns if
592: * there is an error. If the file does not exist, this returns immediately.
593: */
1.1 deraadt 594:
1.26 markus 595: void
1.17 markus 596: read_config_file(const char *filename, const char *host, Options *options)
1.1 deraadt 597: {
1.17 markus 598: FILE *f;
599: char line[1024];
600: int active, linenum;
601: int bad_options = 0;
602:
603: /* Open the file. */
604: f = fopen(filename, "r");
605: if (!f)
606: return;
607:
608: debug("Reading configuration data %.200s", filename);
609:
1.19 markus 610: /*
611: * Mark that we are now processing the options. This flag is turned
612: * on/off by Host specifications.
613: */
1.17 markus 614: active = 1;
615: linenum = 0;
616: while (fgets(line, sizeof(line), f)) {
617: /* Update line number counter. */
618: linenum++;
619: if (process_config_line(options, host, line, filename, linenum, &active) != 0)
620: bad_options++;
621: }
622: fclose(f);
623: if (bad_options > 0)
624: fatal("%s: terminating, %d bad configuration options\n",
625: filename, bad_options);
1.1 deraadt 626: }
627:
1.19 markus 628: /*
629: * Initializes options to special values that indicate that they have not yet
630: * been set. Read_config_file will only set options with this value. Options
631: * are processed in the following order: command line, user config file,
632: * system config file. Last, fill_default_options is called.
633: */
1.1 deraadt 634:
1.26 markus 635: void
1.17 markus 636: initialize_options(Options * options)
1.1 deraadt 637: {
1.17 markus 638: memset(options, 'X', sizeof(*options));
639: options->forward_agent = -1;
640: options->forward_x11 = -1;
641: options->gateway_ports = -1;
642: options->use_privileged_port = -1;
643: options->rhosts_authentication = -1;
644: options->rsa_authentication = -1;
1.30 ! markus 645: options->dsa_authentication = -1;
1.17 markus 646: options->skey_authentication = -1;
1.1 deraadt 647: #ifdef KRB4
1.17 markus 648: options->kerberos_authentication = -1;
1.1 deraadt 649: #endif
1.5 dugsong 650: #ifdef AFS
1.17 markus 651: options->kerberos_tgt_passing = -1;
652: options->afs_token_passing = -1;
1.1 deraadt 653: #endif
1.17 markus 654: options->password_authentication = -1;
655: options->rhosts_rsa_authentication = -1;
656: options->fallback_to_rsh = -1;
657: options->use_rsh = -1;
658: options->batch_mode = -1;
659: options->check_host_ip = -1;
660: options->strict_host_key_checking = -1;
661: options->compression = -1;
662: options->keepalives = -1;
663: options->compression_level = -1;
664: options->port = -1;
665: options->connection_attempts = -1;
666: options->number_of_password_prompts = -1;
667: options->cipher = -1;
1.25 markus 668: options->ciphers = NULL;
669: options->protocol = SSH_PROTO_UNKNOWN;
1.17 markus 670: options->num_identity_files = 0;
1.27 markus 671: options->num_identity_files2 = 0;
1.17 markus 672: options->hostname = NULL;
673: options->proxy_command = NULL;
674: options->user = NULL;
675: options->escape_char = -1;
676: options->system_hostfile = NULL;
677: options->user_hostfile = NULL;
1.27 markus 678: options->system_hostfile2 = NULL;
679: options->user_hostfile2 = NULL;
1.17 markus 680: options->num_local_forwards = 0;
681: options->num_remote_forwards = 0;
682: options->log_level = (LogLevel) - 1;
1.1 deraadt 683: }
684:
1.19 markus 685: /*
686: * Called after processing other sources of option data, this fills those
687: * options for which no value has been specified with their default values.
688: */
1.1 deraadt 689:
1.26 markus 690: void
1.17 markus 691: fill_default_options(Options * options)
1.1 deraadt 692: {
1.17 markus 693: if (options->forward_agent == -1)
694: options->forward_agent = 1;
695: if (options->forward_x11 == -1)
1.23 markus 696: options->forward_x11 = 0;
1.17 markus 697: if (options->gateway_ports == -1)
698: options->gateway_ports = 0;
699: if (options->use_privileged_port == -1)
700: options->use_privileged_port = 1;
701: if (options->rhosts_authentication == -1)
702: options->rhosts_authentication = 1;
703: if (options->rsa_authentication == -1)
704: options->rsa_authentication = 1;
1.30 ! markus 705: if (options->dsa_authentication == -1)
! 706: options->dsa_authentication = 1;
1.17 markus 707: if (options->skey_authentication == -1)
708: options->skey_authentication = 0;
1.1 deraadt 709: #ifdef KRB4
1.17 markus 710: if (options->kerberos_authentication == -1)
711: options->kerberos_authentication = 1;
1.5 dugsong 712: #endif /* KRB4 */
713: #ifdef AFS
1.17 markus 714: if (options->kerberos_tgt_passing == -1)
715: options->kerberos_tgt_passing = 1;
716: if (options->afs_token_passing == -1)
717: options->afs_token_passing = 1;
1.5 dugsong 718: #endif /* AFS */
1.17 markus 719: if (options->password_authentication == -1)
720: options->password_authentication = 1;
721: if (options->rhosts_rsa_authentication == -1)
722: options->rhosts_rsa_authentication = 1;
723: if (options->fallback_to_rsh == -1)
724: options->fallback_to_rsh = 1;
725: if (options->use_rsh == -1)
726: options->use_rsh = 0;
727: if (options->batch_mode == -1)
728: options->batch_mode = 0;
729: if (options->check_host_ip == -1)
730: options->check_host_ip = 1;
731: if (options->strict_host_key_checking == -1)
732: options->strict_host_key_checking = 2; /* 2 is default */
733: if (options->compression == -1)
734: options->compression = 0;
735: if (options->keepalives == -1)
736: options->keepalives = 1;
737: if (options->compression_level == -1)
738: options->compression_level = 6;
739: if (options->port == -1)
740: options->port = 0; /* Filled in ssh_connect. */
741: if (options->connection_attempts == -1)
742: options->connection_attempts = 4;
743: if (options->number_of_password_prompts == -1)
744: options->number_of_password_prompts = 3;
745: /* Selected in ssh_login(). */
746: if (options->cipher == -1)
747: options->cipher = SSH_CIPHER_NOT_SET;
1.25 markus 748: if (options->protocol == SSH_PROTO_UNKNOWN)
1.28 markus 749: options->protocol = SSH_PROTO_1|SSH_PROTO_2|SSH_PROTO_1_PREFERRED;
1.17 markus 750: if (options->num_identity_files == 0) {
751: options->identity_files[0] =
752: xmalloc(2 + strlen(SSH_CLIENT_IDENTITY) + 1);
753: sprintf(options->identity_files[0], "~/%.100s", SSH_CLIENT_IDENTITY);
754: options->num_identity_files = 1;
755: }
1.27 markus 756: if (options->num_identity_files2 == 0) {
757: options->identity_files2[0] =
1.29 markus 758: xmalloc(2 + strlen(SSH_CLIENT_ID_DSA) + 1);
759: sprintf(options->identity_files2[0], "~/%.100s", SSH_CLIENT_ID_DSA);
1.27 markus 760: options->num_identity_files2 = 1;
761: }
1.17 markus 762: if (options->escape_char == -1)
763: options->escape_char = '~';
764: if (options->system_hostfile == NULL)
765: options->system_hostfile = SSH_SYSTEM_HOSTFILE;
766: if (options->user_hostfile == NULL)
767: options->user_hostfile = SSH_USER_HOSTFILE;
1.27 markus 768: if (options->system_hostfile2 == NULL)
769: options->system_hostfile2 = SSH_SYSTEM_HOSTFILE2;
770: if (options->user_hostfile2 == NULL)
771: options->user_hostfile2 = SSH_USER_HOSTFILE2;
1.17 markus 772: if (options->log_level == (LogLevel) - 1)
773: options->log_level = SYSLOG_LEVEL_INFO;
774: /* options->proxy_command should not be set by default */
775: /* options->user will be set in the main program if appropriate */
776: /* options->hostname will be set in the main program if appropriate */
1.1 deraadt 777: }