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