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