]> andersk Git - gssapi-openssh.git/blob - openssh/ssh.c
http://www.psc.edu/networking/projects/hpn-ssh/openssh-5.2p1-hpn13v6.diff.gz committe...
[gssapi-openssh.git] / openssh / ssh.c
1 /* $OpenBSD: ssh.c,v 1.324 2009/02/12 03:00:56 djm Exp $ */
2 /*
3  * Author: Tatu Ylonen <ylo@cs.hut.fi>
4  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5  *                    All rights reserved
6  * Ssh client program.  This program can be used to log into a remote machine.
7  * The software supports strong authentication, encryption, and forwarding
8  * of X11, TCP/IP, and authentication connections.
9  *
10  * As far as I am concerned, the code I have written for this software
11  * can be used freely for any purpose.  Any derived versions of this
12  * software must be clearly marked as such, and if the derived work is
13  * incompatible with the protocol description in the RFC file, it must be
14  * called by a name other than "ssh" or "Secure Shell".
15  *
16  * Copyright (c) 1999 Niels Provos.  All rights reserved.
17  * Copyright (c) 2000, 2001, 2002, 2003 Markus Friedl.  All rights reserved.
18  *
19  * Modified to work with SSL by Niels Provos <provos@citi.umich.edu>
20  * in Canada (German citizen).
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the above copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
32  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  */
42
43 #include "includes.h"
44
45 #include <sys/types.h>
46 #ifdef HAVE_SYS_STAT_H
47 # include <sys/stat.h>
48 #endif
49 #include <sys/resource.h>
50 #include <sys/ioctl.h>
51 #include <sys/socket.h>
52
53 #include <ctype.h>
54 #include <errno.h>
55 #include <fcntl.h>
56 #include <netdb.h>
57 #ifdef HAVE_PATHS_H
58 #include <paths.h>
59 #endif
60 #include <pwd.h>
61 #include <signal.h>
62 #include <stdarg.h>
63 #include <stddef.h>
64 #include <stdio.h>
65 #include <stdlib.h>
66 #include <string.h>
67 #include <unistd.h>
68
69 #include <netinet/in.h>
70 #include <arpa/inet.h>
71
72 #include <openssl/evp.h>
73 #include <openssl/err.h>
74 #include "openbsd-compat/openssl-compat.h"
75 #include "openbsd-compat/sys-queue.h"
76
77 #include "xmalloc.h"
78 #include "ssh.h"
79 #include "ssh1.h"
80 #include "ssh2.h"
81 #include "compat.h"
82 #include "cipher.h"
83 #include "packet.h"
84 #include "buffer.h"
85 #include "channels.h"
86 #include "key.h"
87 #include "authfd.h"
88 #include "authfile.h"
89 #include "pathnames.h"
90 #include "dispatch.h"
91 #include "clientloop.h"
92 #include "log.h"
93 #include "readconf.h"
94 #include "sshconnect.h"
95 #include "misc.h"
96 #include "kex.h"
97 #include "mac.h"
98 #include "sshpty.h"
99 #include "match.h"
100 #include "msg.h"
101 #include "uidswap.h"
102 #include "version.h"
103
104 #ifdef SMARTCARD
105 #include "scard.h"
106 #endif
107
108 extern char *__progname;
109
110 /* Flag indicating whether debug mode is on.  May be set on the command line. */
111 int debug_flag = 0;
112
113 /* Flag indicating whether a tty should be allocated */
114 int tty_flag = 0;
115 int no_tty_flag = 0;
116 int force_tty_flag = 0;
117
118 /* don't exec a shell */
119 int no_shell_flag = 0;
120
121 /*
122  * Flag indicating that nothing should be read from stdin.  This can be set
123  * on the command line.
124  */
125 int stdin_null_flag = 0;
126
127 /*
128  * Flag indicating that ssh should fork after authentication.  This is useful
129  * so that the passphrase can be entered manually, and then ssh goes to the
130  * background.
131  */
132 int fork_after_authentication_flag = 0;
133
134 /*
135  * General data structure for command line options and options configurable
136  * in configuration files.  See readconf.h.
137  */
138 Options options;
139
140 /* optional user configfile */
141 char *config = NULL;
142
143 /*
144  * Name of the host we are connecting to.  This is the name given on the
145  * command line, or the HostName specified for the user-supplied name in a
146  * configuration file.
147  */
148 char *host;
149
150 /* socket address the host resolves to */
151 struct sockaddr_storage hostaddr;
152
153 /* Private host keys. */
154 Sensitive sensitive_data;
155
156 /* Original real UID. */
157 uid_t original_real_uid;
158 uid_t original_effective_uid;
159
160 /* command to be executed */
161 Buffer command;
162
163 /* Should we execute a command or invoke a subsystem? */
164 int subsystem_flag = 0;
165
166 /* # of replies received for global requests */
167 static int remote_forward_confirms_received = 0;
168
169 /* pid of proxycommand child process */
170 pid_t proxy_command_pid = 0;
171
172 /* mux.c */
173 extern int muxserver_sock;
174 extern u_int muxclient_command;
175
176 /* Prints a help message to the user.  This function never returns. */
177
178 static void
179 usage(void)
180 {
181         fprintf(stderr,
182 "usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]\n"
183 "           [-D [bind_address:]port] [-e escape_char] [-F configfile]\n"
184 "           [-i identity_file] [-L [bind_address:]port:host:hostport]\n"
185 "           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]\n"
186 "           [-R [bind_address:]port:host:hostport] [-S ctl_path]\n"
187 "           [-w local_tun[:remote_tun]] [user@]hostname [command]\n"
188         );
189         exit(255);
190 }
191
192 static int ssh_session(void);
193 static int ssh_session2(void);
194 static void load_public_identity_files(void);
195
196 /* from muxclient.c */
197 void muxclient(const char *);
198 void muxserver_listen(void);
199
200 /*
201  * Main program for the ssh client.
202  */
203 int
204 main(int ac, char **av)
205 {
206         int i, opt, exit_status, use_syslog;
207         char *p, *cp, *line, buf[256];
208         struct stat st;
209         struct passwd *pw;
210         int dummy, timeout_ms;
211         extern int optind, optreset;
212         extern char *optarg;
213         struct servent *sp;
214         Forward fwd;
215
216         /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
217         sanitise_stdfd();
218
219         __progname = ssh_get_progname(av[0]);
220         init_rng();
221
222         /*
223          * Save the original real uid.  It will be needed later (uid-swapping
224          * may clobber the real uid).
225          */
226         original_real_uid = getuid();
227         original_effective_uid = geteuid();
228
229         /*
230          * Use uid-swapping to give up root privileges for the duration of
231          * option processing.  We will re-instantiate the rights when we are
232          * ready to create the privileged port, and will permanently drop
233          * them when the port has been created (actually, when the connection
234          * has been made, as we may need to create the port several times).
235          */
236         PRIV_END;
237
238 #ifdef HAVE_SETRLIMIT
239         /* If we are installed setuid root be careful to not drop core. */
240         if (original_real_uid != original_effective_uid) {
241                 struct rlimit rlim;
242                 rlim.rlim_cur = rlim.rlim_max = 0;
243                 if (setrlimit(RLIMIT_CORE, &rlim) < 0)
244                         fatal("setrlimit failed: %.100s", strerror(errno));
245         }
246 #endif
247         /* Get user data. */
248         pw = getpwuid(original_real_uid);
249         if (!pw) {
250                 logit("You don't exist, go away!");
251                 exit(255);
252         }
253         /* Take a copy of the returned structure. */
254         pw = pwcopy(pw);
255
256         /*
257          * Set our umask to something reasonable, as some files are created
258          * with the default umask.  This will make them world-readable but
259          * writable only by the owner, which is ok for all files for which we
260          * don't set the modes explicitly.
261          */
262         umask(022);
263
264         /*
265          * Initialize option structure to indicate that no values have been
266          * set.
267          */
268         initialize_options(&options);
269
270         /* Parse command-line arguments. */
271         host = NULL;
272         use_syslog = 0;
273
274  again:
275         while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx"
276             "ACD:F:I:KL:MNO:PR:S:TVw:XYy")) != -1) {
277                 switch (opt) {
278                 case '1':
279                         options.protocol = SSH_PROTO_1;
280                         break;
281                 case '2':
282                         options.protocol = SSH_PROTO_2;
283                         break;
284                 case '4':
285                         options.address_family = AF_INET;
286                         break;
287                 case '6':
288                         options.address_family = AF_INET6;
289                         break;
290                 case 'n':
291                         stdin_null_flag = 1;
292                         break;
293                 case 'f':
294                         fork_after_authentication_flag = 1;
295                         stdin_null_flag = 1;
296                         break;
297                 case 'x':
298                         options.forward_x11 = 0;
299                         break;
300                 case 'X':
301                         options.forward_x11 = 1;
302                         break;
303                 case 'y':
304                         use_syslog = 1;
305                         break;
306                 case 'Y':
307                         options.forward_x11 = 1;
308                         options.forward_x11_trusted = 1;
309                         break;
310                 case 'g':
311                         options.gateway_ports = 1;
312                         break;
313                 case 'O':
314                         if (strcmp(optarg, "check") == 0)
315                                 muxclient_command = SSHMUX_COMMAND_ALIVE_CHECK;
316                         else if (strcmp(optarg, "exit") == 0)
317                                 muxclient_command = SSHMUX_COMMAND_TERMINATE;
318                         else
319                                 fatal("Invalid multiplex command.");
320                         break;
321                 case 'P':       /* deprecated */
322                         options.use_privileged_port = 0;
323                         break;
324                 case 'a':
325                         options.forward_agent = 0;
326                         break;
327                 case 'A':
328                         options.forward_agent = 1;
329                         break;
330                 case 'k':
331                         options.gss_deleg_creds = 0;
332                         break;
333                 case 'K':
334                         options.gss_authentication = 1;
335                         options.gss_deleg_creds = 1;
336                         break;
337                 case 'i':
338                         if (stat(optarg, &st) < 0) {
339                                 fprintf(stderr, "Warning: Identity file %s "
340                                     "not accessible: %s.\n", optarg,
341                                     strerror(errno));
342                                 break;
343                         }
344                         if (options.num_identity_files >=
345                             SSH_MAX_IDENTITY_FILES)
346                                 fatal("Too many identity files specified "
347                                     "(max %d)", SSH_MAX_IDENTITY_FILES);
348                         options.identity_files[options.num_identity_files++] =
349                             xstrdup(optarg);
350                         break;
351                 case 'I':
352 #ifdef SMARTCARD
353                         options.smartcard_device = xstrdup(optarg);
354 #else
355                         fprintf(stderr, "no support for smartcards.\n");
356 #endif
357                         break;
358                 case 't':
359                         if (tty_flag)
360                                 force_tty_flag = 1;
361                         tty_flag = 1;
362                         break;
363                 case 'v':
364                         if (debug_flag == 0) {
365                                 debug_flag = 1;
366                                 options.log_level = SYSLOG_LEVEL_DEBUG1;
367                         } else {
368                                 if (options.log_level < SYSLOG_LEVEL_DEBUG3)
369                                         options.log_level++;
370                                 break;
371                         }
372                         /* FALLTHROUGH */
373                 case 'V':
374                         fprintf(stderr, "%s, %s\n",
375                             SSH_RELEASE, SSLeay_version(SSLEAY_VERSION));
376                         if (opt == 'V')
377                                 exit(0);
378                         break;
379                 case 'w':
380                         if (options.tun_open == -1)
381                                 options.tun_open = SSH_TUNMODE_DEFAULT;
382                         options.tun_local = a2tun(optarg, &options.tun_remote);
383                         if (options.tun_local == SSH_TUNID_ERR) {
384                                 fprintf(stderr,
385                                     "Bad tun device '%s'\n", optarg);
386                                 exit(255);
387                         }
388                         break;
389                 case 'q':
390                         options.log_level = SYSLOG_LEVEL_QUIET;
391                         break;
392                 case 'e':
393                         if (optarg[0] == '^' && optarg[2] == 0 &&
394                             (u_char) optarg[1] >= 64 &&
395                             (u_char) optarg[1] < 128)
396                                 options.escape_char = (u_char) optarg[1] & 31;
397                         else if (strlen(optarg) == 1)
398                                 options.escape_char = (u_char) optarg[0];
399                         else if (strcmp(optarg, "none") == 0)
400                                 options.escape_char = SSH_ESCAPECHAR_NONE;
401                         else {
402                                 fprintf(stderr, "Bad escape character '%s'.\n",
403                                     optarg);
404                                 exit(255);
405                         }
406                         break;
407                 case 'c':
408                         if (ciphers_valid(optarg)) {
409                                 /* SSH2 only */
410                                 options.ciphers = xstrdup(optarg);
411                                 options.cipher = SSH_CIPHER_INVALID;
412                         } else {
413                                 /* SSH1 only */
414                                 options.cipher = cipher_number(optarg);
415                                 if (options.cipher == -1) {
416                                         fprintf(stderr,
417                                             "Unknown cipher type '%s'\n",
418                                             optarg);
419                                         exit(255);
420                                 }
421                                 if (options.cipher == SSH_CIPHER_3DES)
422                                         options.ciphers = "3des-cbc";
423                                 else if (options.cipher == SSH_CIPHER_BLOWFISH)
424                                         options.ciphers = "blowfish-cbc";
425                                 else
426                                         options.ciphers = (char *)-1;
427                         }
428                         break;
429                 case 'm':
430                         if (mac_valid(optarg))
431                                 options.macs = xstrdup(optarg);
432                         else {
433                                 fprintf(stderr, "Unknown mac type '%s'\n",
434                                     optarg);
435                                 exit(255);
436                         }
437                         break;
438                 case 'M':
439                         if (options.control_master == SSHCTL_MASTER_YES)
440                                 options.control_master = SSHCTL_MASTER_ASK;
441                         else
442                                 options.control_master = SSHCTL_MASTER_YES;
443                         break;
444                 case 'p':
445                         options.port = a2port(optarg);
446                         if (options.port <= 0) {
447                                 fprintf(stderr, "Bad port '%s'\n", optarg);
448                                 exit(255);
449                         }
450                         break;
451                 case 'l':
452                         options.user = optarg;
453                         break;
454
455                 case 'L':
456                         if (parse_forward(&fwd, optarg, 0, 0))
457                                 add_local_forward(&options, &fwd);
458                         else {
459                                 fprintf(stderr,
460                                     "Bad local forwarding specification '%s'\n",
461                                     optarg);
462                                 exit(255);
463                         }
464                         break;
465
466                 case 'R':
467                         if (parse_forward(&fwd, optarg, 0, 1)) {
468                                 add_remote_forward(&options, &fwd);
469                         } else {
470                                 fprintf(stderr,
471                                     "Bad remote forwarding specification "
472                                     "'%s'\n", optarg);
473                                 exit(255);
474                         }
475                         break;
476
477                 case 'D':
478                         if (parse_forward(&fwd, optarg, 1, 0)) {
479                                 add_local_forward(&options, &fwd);
480                         } else {
481                                 fprintf(stderr,
482                                     "Bad dynamic forwarding specification "
483                                     "'%s'\n", optarg);
484                                 exit(255);
485                         }
486                         break;
487
488                 case 'C':
489                         options.compression = 1;
490                         break;
491                 case 'N':
492                         no_shell_flag = 1;
493                         no_tty_flag = 1;
494                         break;
495                 case 'o':
496                         dummy = 1;
497                         line = xstrdup(optarg);
498                         if (process_config_line(&options, host ? host : "",
499                             line, "command-line", 0, &dummy) != 0)
500                                 exit(255);
501                         xfree(line);
502                         break;
503                 case 'T':
504                         no_tty_flag = 1;
505                         /* ensure that the user doesn't try to backdoor a */
506                         /* null cipher switch on an interactive session */
507                         /* so explicitly disable it no matter what */
508                         options.none_switch=0;
509                         break;
510                 case 's':
511                         subsystem_flag = 1;
512                         break;
513                 case 'S':
514                         if (options.control_path != NULL)
515                                 free(options.control_path);
516                         options.control_path = xstrdup(optarg);
517                         break;
518                 case 'b':
519                         options.bind_address = optarg;
520                         break;
521                 case 'F':
522                         config = optarg;
523                         break;
524                 default:
525                         usage();
526                 }
527         }
528
529         ac -= optind;
530         av += optind;
531
532         if (ac > 0 && !host && **av != '-') {
533                 if (strrchr(*av, '@')) {
534                         p = xstrdup(*av);
535                         cp = strrchr(p, '@');
536                         if (cp == NULL || cp == p)
537                                 usage();
538                         options.user = p;
539                         *cp = '\0';
540                         host = ++cp;
541                 } else
542                         host = *av;
543                 if (ac > 1) {
544                         optind = optreset = 1;
545                         goto again;
546                 }
547                 ac--, av++;
548         }
549
550         /* Check that we got a host name. */
551         if (!host)
552                 usage();
553
554         SSLeay_add_all_algorithms();
555         ERR_load_crypto_strings();
556
557         /* Initialize the command to execute on remote host. */
558         buffer_init(&command);
559
560         /*
561          * Save the command to execute on the remote host in a buffer. There
562          * is no limit on the length of the command, except by the maximum
563          * packet size.  Also sets the tty flag if there is no command.
564          */
565         if (!ac) {
566                 /* No command specified - execute shell on a tty. */
567                 tty_flag = 1;
568                 if (subsystem_flag) {
569                         fprintf(stderr,
570                             "You must specify a subsystem to invoke.\n");
571                         usage();
572                 }
573         } else {
574                 /* A command has been specified.  Store it into the buffer. */
575                 for (i = 0; i < ac; i++) {
576                         if (i)
577                                 buffer_append(&command, " ", 1);
578                         buffer_append(&command, av[i], strlen(av[i]));
579                 }
580         }
581
582         /* Cannot fork to background if no command. */
583         if (fork_after_authentication_flag && buffer_len(&command) == 0 &&
584             !no_shell_flag)
585                 fatal("Cannot fork into background without a command "
586                     "to execute.");
587
588         /* Allocate a tty by default if no command specified. */
589         if (buffer_len(&command) == 0)
590                 tty_flag = 1;
591
592         /* Force no tty */
593         if (no_tty_flag)
594                 tty_flag = 0;
595         /* Do not allocate a tty if stdin is not a tty. */
596         if ((!isatty(fileno(stdin)) || stdin_null_flag) && !force_tty_flag) {
597                 if (tty_flag)
598                         logit("Pseudo-terminal will not be allocated because "
599                             "stdin is not a terminal.");
600                 tty_flag = 0;
601         }
602
603         /*
604          * Initialize "log" output.  Since we are the client all output
605          * actually goes to stderr.
606          */
607         log_init(av[0],
608             options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
609             SYSLOG_FACILITY_USER, !use_syslog);
610
611         /*
612          * Read per-user configuration file.  Ignore the system wide config
613          * file if the user specifies a config file on the command line.
614          */
615         if (config != NULL) {
616                 if (!read_config_file(config, host, &options, 0))
617                         fatal("Can't open user config file %.100s: "
618                             "%.100s", config, strerror(errno));
619         } else {
620                 snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir,
621                     _PATH_SSH_USER_CONFFILE);
622                 (void)read_config_file(buf, host, &options, 1);
623
624                 /* Read systemwide configuration file after use config. */
625                 (void)read_config_file(_PATH_HOST_CONFIG_FILE, host,
626                     &options, 0);
627         }
628
629         /* Fill configuration defaults. */
630         fill_default_options(&options);
631
632         channel_set_af(options.address_family);
633
634         /* reinit */
635         log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, !use_syslog);
636
637         seed_rng();
638
639         if (options.user == NULL)
640                 options.user = xstrdup(pw->pw_name);
641
642         /* Get default port if port has not been set. */
643         if (options.port == 0) {
644                 sp = getservbyname(SSH_SERVICE_NAME, "tcp");
645                 options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
646         }
647
648         if (options.local_command != NULL) {
649                 char thishost[NI_MAXHOST];
650
651                 if (gethostname(thishost, sizeof(thishost)) == -1)
652                         fatal("gethostname: %s", strerror(errno));
653                 snprintf(buf, sizeof(buf), "%d", options.port);
654                 debug3("expanding LocalCommand: %s", options.local_command);
655                 cp = options.local_command;
656                 options.local_command = percent_expand(cp, "d", pw->pw_dir,
657                     "h", options.hostname? options.hostname : host,
658                     "l", thishost, "n", host, "r", options.user, "p", buf,
659                     "u", pw->pw_name, (char *)NULL);
660                 debug3("expanded LocalCommand: %s", options.local_command);
661                 xfree(cp);
662         }
663
664         if (options.hostname != NULL)
665                 host = options.hostname;
666
667         /* force lowercase for hostkey matching */
668         if (options.host_key_alias != NULL) {
669                 for (p = options.host_key_alias; *p; p++)
670                         if (isupper(*p))
671                                 *p = (char)tolower(*p);
672         }
673
674         if (options.proxy_command != NULL &&
675             strcmp(options.proxy_command, "none") == 0) {
676                 xfree(options.proxy_command);
677                 options.proxy_command = NULL;
678         }
679         if (options.control_path != NULL &&
680             strcmp(options.control_path, "none") == 0) {
681                 xfree(options.control_path);
682                 options.control_path = NULL;
683         }
684
685         if (options.control_path != NULL) {
686                 char thishost[NI_MAXHOST];
687
688                 if (gethostname(thishost, sizeof(thishost)) == -1)
689                         fatal("gethostname: %s", strerror(errno));
690                 snprintf(buf, sizeof(buf), "%d", options.port);
691                 cp = tilde_expand_filename(options.control_path,
692                     original_real_uid);
693                 xfree(options.control_path);
694                 options.control_path = percent_expand(cp, "p", buf, "h", host,
695                     "r", options.user, "l", thishost, (char *)NULL);
696                 xfree(cp);
697         }
698         if (muxclient_command != 0 && options.control_path == NULL)
699                 fatal("No ControlPath specified for \"-O\" command");
700         if (options.control_path != NULL)
701                 muxclient(options.control_path);
702
703         timeout_ms = options.connection_timeout * 1000;
704
705         /* Open a connection to the remote host. */
706         if (ssh_connect(host, &hostaddr, options.port,
707             options.address_family, options.connection_attempts, &timeout_ms,
708             options.tcp_keep_alive, 
709 #ifdef HAVE_CYGWIN
710             options.use_privileged_port,
711 #else
712             original_effective_uid == 0 && options.use_privileged_port,
713 #endif
714             options.proxy_command) != 0)
715                 exit(255);
716
717         if (timeout_ms > 0)
718                 debug3("timeout: %d ms remain after connect", timeout_ms);
719
720         /*
721          * If we successfully made the connection, load the host private key
722          * in case we will need it later for combined rsa-rhosts
723          * authentication. This must be done before releasing extra
724          * privileges, because the file is only readable by root.
725          * If we cannot access the private keys, load the public keys
726          * instead and try to execute the ssh-keysign helper instead.
727          */
728         sensitive_data.nkeys = 0;
729         sensitive_data.keys = NULL;
730         sensitive_data.external_keysign = 0;
731         if (options.rhosts_rsa_authentication ||
732             options.hostbased_authentication) {
733                 sensitive_data.nkeys = 3;
734                 sensitive_data.keys = xcalloc(sensitive_data.nkeys,
735                     sizeof(Key));
736
737                 PRIV_START;
738                 sensitive_data.keys[0] = key_load_private_type(KEY_RSA1,
739                     _PATH_HOST_KEY_FILE, "", NULL, NULL);
740                 sensitive_data.keys[1] = key_load_private_type(KEY_DSA,
741                     _PATH_HOST_DSA_KEY_FILE, "", NULL, NULL);
742                 sensitive_data.keys[2] = key_load_private_type(KEY_RSA,
743                     _PATH_HOST_RSA_KEY_FILE, "", NULL, NULL);
744                 PRIV_END;
745
746                 if (options.hostbased_authentication == 1 &&
747                     sensitive_data.keys[0] == NULL &&
748                     sensitive_data.keys[1] == NULL &&
749                     sensitive_data.keys[2] == NULL) {
750                         sensitive_data.keys[1] = key_load_public(
751                             _PATH_HOST_DSA_KEY_FILE, NULL);
752                         sensitive_data.keys[2] = key_load_public(
753                             _PATH_HOST_RSA_KEY_FILE, NULL);
754                         sensitive_data.external_keysign = 1;
755                 }
756         }
757         /*
758          * Get rid of any extra privileges that we may have.  We will no
759          * longer need them.  Also, extra privileges could make it very hard
760          * to read identity files and other non-world-readable files from the
761          * user's home directory if it happens to be on a NFS volume where
762          * root is mapped to nobody.
763          */
764         if (original_effective_uid == 0) {
765                 PRIV_START;
766                 permanently_set_uid(pw);
767         }
768
769         /*
770          * Now that we are back to our own permissions, create ~/.ssh
771          * directory if it doesn't already exist.
772          */
773         snprintf(buf, sizeof buf, "%.100s%s%.100s", pw->pw_dir,
774             strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
775         if (stat(buf, &st) < 0)
776                 if (mkdir(buf, 0700) < 0)
777                         error("Could not create directory '%.200s'.", buf);
778
779         /* load options.identity_files */
780         load_public_identity_files();
781
782         /* Expand ~ in known host file names. */
783         /* XXX mem-leaks: */
784         options.system_hostfile =
785             tilde_expand_filename(options.system_hostfile, original_real_uid);
786         options.user_hostfile =
787             tilde_expand_filename(options.user_hostfile, original_real_uid);
788         options.system_hostfile2 =
789             tilde_expand_filename(options.system_hostfile2, original_real_uid);
790         options.user_hostfile2 =
791             tilde_expand_filename(options.user_hostfile2, original_real_uid);
792
793         signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE early */
794
795         /* Log into the remote system.  Never returns if the login fails. */
796         ssh_login(&sensitive_data, host, (struct sockaddr *)&hostaddr,
797             pw, timeout_ms);
798
799         /* We no longer need the private host keys.  Clear them now. */
800         if (sensitive_data.nkeys != 0) {
801                 for (i = 0; i < sensitive_data.nkeys; i++) {
802                         if (sensitive_data.keys[i] != NULL) {
803                                 /* Destroys contents safely */
804                                 debug3("clear hostkey %d", i);
805                                 key_free(sensitive_data.keys[i]);
806                                 sensitive_data.keys[i] = NULL;
807                         }
808                 }
809                 xfree(sensitive_data.keys);
810         }
811         for (i = 0; i < options.num_identity_files; i++) {
812                 if (options.identity_files[i]) {
813                         xfree(options.identity_files[i]);
814                         options.identity_files[i] = NULL;
815                 }
816                 if (options.identity_keys[i]) {
817                         key_free(options.identity_keys[i]);
818                         options.identity_keys[i] = NULL;
819                 }
820         }
821
822         exit_status = compat20 ? ssh_session2() : ssh_session();
823         packet_close();
824
825         if (options.control_path != NULL && muxserver_sock != -1)
826                 unlink(options.control_path);
827
828         /*
829          * Send SIGHUP to proxy command if used. We don't wait() in
830          * case it hangs and instead rely on init to reap the child
831          */
832         if (proxy_command_pid > 1)
833                 kill(proxy_command_pid, SIGHUP);
834
835         return exit_status;
836 }
837
838 /* Callback for remote forward global requests */
839 static void
840 ssh_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
841 {
842         Forward *rfwd = (Forward *)ctxt;
843
844         /* XXX verbose() on failure? */
845         debug("remote forward %s for: listen %d, connect %s:%d",
846             type == SSH2_MSG_REQUEST_SUCCESS ? "success" : "failure",
847             rfwd->listen_port, rfwd->connect_host, rfwd->connect_port);
848         if (type == SSH2_MSG_REQUEST_SUCCESS && rfwd->listen_port == 0) {
849                 logit("Allocated port %u for remote forward to %s:%d",
850                         packet_get_int(),
851                         rfwd->connect_host, rfwd->connect_port);
852         }
853         
854         if (type == SSH2_MSG_REQUEST_FAILURE) {
855                 if (options.exit_on_forward_failure)
856                         fatal("Error: remote port forwarding failed for "
857                             "listen port %d", rfwd->listen_port);
858                 else
859                         logit("Warning: remote port forwarding failed for "
860                             "listen port %d", rfwd->listen_port);
861         }
862         if (++remote_forward_confirms_received == options.num_remote_forwards) {
863                 debug("All remote forwarding requests processed");
864                 if (fork_after_authentication_flag) {
865                         fork_after_authentication_flag = 0;
866                         if (daemon(1, 1) < 0)
867                                 fatal("daemon() failed: %.200s",
868                                     strerror(errno));
869                 }
870         }
871 }
872
873 static void
874 ssh_init_forwarding(void)
875 {
876         int success = 0;
877         int i;
878
879         /* Initiate local TCP/IP port forwardings. */
880         for (i = 0; i < options.num_local_forwards; i++) {
881                 debug("Local connections to %.200s:%d forwarded to remote "
882                     "address %.200s:%d",
883                     (options.local_forwards[i].listen_host == NULL) ?
884                     (options.gateway_ports ? "*" : "LOCALHOST") :
885                     options.local_forwards[i].listen_host,
886                     options.local_forwards[i].listen_port,
887                     options.local_forwards[i].connect_host,
888                     options.local_forwards[i].connect_port);
889                 success += channel_setup_local_fwd_listener(
890                     options.local_forwards[i].listen_host,
891                     options.local_forwards[i].listen_port,
892                     options.local_forwards[i].connect_host,
893                     options.local_forwards[i].connect_port,
894                     options.gateway_ports);
895         }
896         if (i > 0 && success != i && options.exit_on_forward_failure)
897                 fatal("Could not request local forwarding.");
898         if (i > 0 && success == 0)
899                 error("Could not request local forwarding.");
900
901         /* Initiate remote TCP/IP port forwardings. */
902         for (i = 0; i < options.num_remote_forwards; i++) {
903                 debug("Remote connections from %.200s:%d forwarded to "
904                     "local address %.200s:%d",
905                     (options.remote_forwards[i].listen_host == NULL) ?
906                     "LOCALHOST" : options.remote_forwards[i].listen_host,
907                     options.remote_forwards[i].listen_port,
908                     options.remote_forwards[i].connect_host,
909                     options.remote_forwards[i].connect_port);
910                 if (channel_request_remote_forwarding(
911                     options.remote_forwards[i].listen_host,
912                     options.remote_forwards[i].listen_port,
913                     options.remote_forwards[i].connect_host,
914                     options.remote_forwards[i].connect_port) < 0) {
915                         if (options.exit_on_forward_failure)
916                                 fatal("Could not request remote forwarding.");
917                         else
918                                 logit("Warning: Could not request remote "
919                                     "forwarding.");
920                 }
921                 client_register_global_confirm(ssh_confirm_remote_forward,
922                     &options.remote_forwards[i]);
923         }
924
925         /* Initiate tunnel forwarding. */
926         if (options.tun_open != SSH_TUNMODE_NO) {
927                 if (client_request_tun_fwd(options.tun_open,
928                     options.tun_local, options.tun_remote) == -1) {
929                         if (options.exit_on_forward_failure)
930                                 fatal("Could not request tunnel forwarding.");
931                         else
932                                 error("Could not request tunnel forwarding.");
933                 }
934         }                       
935 }
936
937 static void
938 check_agent_present(void)
939 {
940         if (options.forward_agent) {
941                 /* Clear agent forwarding if we don't have an agent. */
942                 if (!ssh_agent_present())
943                         options.forward_agent = 0;
944         }
945 }
946
947 static int
948 ssh_session(void)
949 {
950         int type;
951         int interactive = 0;
952         int have_tty = 0;
953         struct winsize ws;
954         char *cp;
955         const char *display;
956
957         /* Enable compression if requested. */
958         if (options.compression) {
959                 debug("Requesting compression at level %d.",
960                     options.compression_level);
961
962                 if (options.compression_level < 1 ||
963                     options.compression_level > 9)
964                         fatal("Compression level must be from 1 (fast) to "
965                             "9 (slow, best).");
966
967                 /* Send the request. */
968                 packet_start(SSH_CMSG_REQUEST_COMPRESSION);
969                 packet_put_int(options.compression_level);
970                 packet_send();
971                 packet_write_wait();
972                 type = packet_read();
973                 if (type == SSH_SMSG_SUCCESS)
974                         packet_start_compression(options.compression_level);
975                 else if (type == SSH_SMSG_FAILURE)
976                         logit("Warning: Remote host refused compression.");
977                 else
978                         packet_disconnect("Protocol error waiting for "
979                             "compression response.");
980         }
981         /* Allocate a pseudo tty if appropriate. */
982         if (tty_flag) {
983                 debug("Requesting pty.");
984
985                 /* Start the packet. */
986                 packet_start(SSH_CMSG_REQUEST_PTY);
987
988                 /* Store TERM in the packet.  There is no limit on the
989                    length of the string. */
990                 cp = getenv("TERM");
991                 if (!cp)
992                         cp = "";
993                 packet_put_cstring(cp);
994
995                 /* Store window size in the packet. */
996                 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
997                         memset(&ws, 0, sizeof(ws));
998                 packet_put_int((u_int)ws.ws_row);
999                 packet_put_int((u_int)ws.ws_col);
1000                 packet_put_int((u_int)ws.ws_xpixel);
1001                 packet_put_int((u_int)ws.ws_ypixel);
1002
1003                 /* Store tty modes in the packet. */
1004                 tty_make_modes(fileno(stdin), NULL);
1005
1006                 /* Send the packet, and wait for it to leave. */
1007                 packet_send();
1008                 packet_write_wait();
1009
1010                 /* Read response from the server. */
1011                 type = packet_read();
1012                 if (type == SSH_SMSG_SUCCESS) {
1013                         interactive = 1;
1014                         have_tty = 1;
1015                 } else if (type == SSH_SMSG_FAILURE)
1016                         logit("Warning: Remote host failed or refused to "
1017                             "allocate a pseudo tty.");
1018                 else
1019                         packet_disconnect("Protocol error waiting for pty "
1020                             "request response.");
1021         }
1022         /* Request X11 forwarding if enabled and DISPLAY is set. */
1023         display = getenv("DISPLAY");
1024         if (options.forward_x11 && display != NULL) {
1025                 char *proto, *data;
1026                 /* Get reasonable local authentication information. */
1027                 client_x11_get_proto(display, options.xauth_location,
1028                     options.forward_x11_trusted, &proto, &data);
1029                 /* Request forwarding with authentication spoofing. */
1030                 debug("Requesting X11 forwarding with authentication "
1031                     "spoofing.");
1032                 x11_request_forwarding_with_spoofing(0, display, proto, data);
1033
1034                 /* Read response from the server. */
1035                 type = packet_read();
1036                 if (type == SSH_SMSG_SUCCESS) {
1037                         interactive = 1;
1038                 } else if (type == SSH_SMSG_FAILURE) {
1039                         logit("Warning: Remote host denied X11 forwarding.");
1040                 } else {
1041                         packet_disconnect("Protocol error waiting for X11 "
1042                             "forwarding");
1043                 }
1044         }
1045         /* Tell the packet module whether this is an interactive session. */
1046         packet_set_interactive(interactive);
1047
1048         /* Request authentication agent forwarding if appropriate. */
1049         check_agent_present();
1050
1051         if (options.forward_agent) {
1052                 debug("Requesting authentication agent forwarding.");
1053                 auth_request_forwarding();
1054
1055                 /* Read response from the server. */
1056                 type = packet_read();
1057                 packet_check_eom();
1058                 if (type != SSH_SMSG_SUCCESS)
1059                         logit("Warning: Remote host denied authentication agent forwarding.");
1060         }
1061
1062         /* Initiate port forwardings. */
1063         ssh_init_forwarding();
1064
1065         /* Execute a local command */
1066         if (options.local_command != NULL &&
1067             options.permit_local_command)
1068                 ssh_local_cmd(options.local_command);
1069
1070         /*
1071          * If requested and we are not interested in replies to remote
1072          * forwarding requests, then let ssh continue in the background.
1073          */
1074         if (fork_after_authentication_flag &&
1075             (!options.exit_on_forward_failure ||
1076             options.num_remote_forwards == 0)) {
1077                 fork_after_authentication_flag = 0;
1078                 if (daemon(1, 1) < 0)
1079                         fatal("daemon() failed: %.200s", strerror(errno));
1080         }
1081
1082         /*
1083          * If a command was specified on the command line, execute the
1084          * command now. Otherwise request the server to start a shell.
1085          */
1086         if (buffer_len(&command) > 0) {
1087                 int len = buffer_len(&command);
1088                 if (len > 900)
1089                         len = 900;
1090                 debug("Sending command: %.*s", len,
1091                     (u_char *)buffer_ptr(&command));
1092                 packet_start(SSH_CMSG_EXEC_CMD);
1093                 packet_put_string(buffer_ptr(&command), buffer_len(&command));
1094                 packet_send();
1095                 packet_write_wait();
1096         } else {
1097                 debug("Requesting shell.");
1098                 packet_start(SSH_CMSG_EXEC_SHELL);
1099                 packet_send();
1100                 packet_write_wait();
1101         }
1102
1103         /* Enter the interactive session. */
1104         return client_loop(have_tty, tty_flag ?
1105             options.escape_char : SSH_ESCAPECHAR_NONE, 0);
1106 }
1107
1108 /* request pty/x11/agent/tcpfwd/shell for channel */
1109 static void
1110 ssh_session2_setup(int id, void *arg)
1111 {
1112         extern char **environ;
1113         const char *display;
1114         int interactive = tty_flag;
1115
1116         display = getenv("DISPLAY");
1117         if (options.forward_x11 && display != NULL) {
1118                 char *proto, *data;
1119                 /* Get reasonable local authentication information. */
1120                 client_x11_get_proto(display, options.xauth_location,
1121                     options.forward_x11_trusted, &proto, &data);
1122                 /* Request forwarding with authentication spoofing. */
1123                 debug("Requesting X11 forwarding with authentication "
1124                     "spoofing.");
1125                 x11_request_forwarding_with_spoofing(id, display, proto, data);
1126                 interactive = 1;
1127                 /* XXX wait for reply */
1128         }
1129
1130         check_agent_present();
1131         if (options.forward_agent) {
1132                 debug("Requesting authentication agent forwarding.");
1133                 channel_request_start(id, "auth-agent-req@openssh.com", 0);
1134                 packet_send();
1135         }
1136
1137         client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"),
1138             NULL, fileno(stdin), &command, environ);
1139
1140         packet_set_interactive(interactive);
1141 }
1142
1143 /* open new channel for a session */
1144 static int
1145 ssh_session2_open(void)
1146 {
1147         Channel *c;
1148         int window, packetmax, in, out, err;
1149         int sock;
1150         int socksize;
1151         int socksizelen = sizeof(int);
1152
1153         if (stdin_null_flag) {
1154                 in = open(_PATH_DEVNULL, O_RDONLY);
1155         } else {
1156                 in = dup(STDIN_FILENO);
1157         }
1158         out = dup(STDOUT_FILENO);
1159         err = dup(STDERR_FILENO);
1160
1161         if (in < 0 || out < 0 || err < 0)
1162                 fatal("dup() in/out/err failed");
1163
1164         /* enable nonblocking unless tty */
1165         if (!isatty(in))
1166                 set_nonblock(in);
1167         if (!isatty(out))
1168                 set_nonblock(out);
1169         if (!isatty(err))
1170                 set_nonblock(err);
1171
1172         /* we need to check to see if what they want to do about buffer */
1173         /* sizes here. In a hpn to nonhpn connection we want to limit */
1174         /* the window size to something reasonable in case the far side */
1175         /* has the large window bug. In hpn to hpn connection we want to */
1176         /* use the max window size but allow the user to override it */
1177         /* lastly if they disabled hpn then use the ssh std window size */
1178
1179         /* so why don't we just do a getsockopt() here and set the */
1180         /* ssh window to that? In the case of a autotuning receive */
1181         /* window the window would get stuck at the initial buffer */
1182         /* size generally less than 96k. Therefore we need to set the */
1183         /* maximum ssh window size to the maximum hpn buffer size */
1184         /* unless the user has specifically set the tcprcvbufpoll */
1185         /* to no. In which case we *can* just set the window to the */
1186         /* minimum of the hpn buffer size and tcp receive buffer size */
1187         
1188         if (tty_flag)
1189                 options.hpn_buffer_size = CHAN_SES_WINDOW_DEFAULT;
1190         else
1191                 options.hpn_buffer_size = 2*1024*1024;
1192
1193         if (datafellows & SSH_BUG_LARGEWINDOW) 
1194         {
1195                 debug("HPN to Non-HPN Connection");
1196         } 
1197         else 
1198         {
1199                 if (options.tcp_rcv_buf_poll <= 0) 
1200                 {
1201                         sock = socket(AF_INET, SOCK_STREAM, 0);
1202                         getsockopt(sock, SOL_SOCKET, SO_RCVBUF, 
1203                                    &socksize, &socksizelen);
1204                         close(sock);
1205                         debug("socksize %d", socksize);
1206                         options.hpn_buffer_size = socksize;
1207                         debug ("HPNBufferSize set to TCP RWIN: %d", options.hpn_buffer_size);
1208                 } 
1209                 else
1210                 {
1211                         if (options.tcp_rcv_buf > 0) 
1212                         {
1213                                 /*create a socket but don't connect it */
1214                                 /* we use that the get the rcv socket size */
1215                                 sock = socket(AF_INET, SOCK_STREAM, 0);
1216                                 /* if they are using the tcp_rcv_buf option */
1217                                 /* attempt to set the buffer size to that */
1218                                 if (options.tcp_rcv_buf) 
1219                                         setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void *)&options.tcp_rcv_buf, 
1220                                                    sizeof(options.tcp_rcv_buf));
1221                                 getsockopt(sock, SOL_SOCKET, SO_RCVBUF, 
1222                                            &socksize, &socksizelen);
1223                                 close(sock);
1224                                 debug("socksize %d", socksize);
1225                                 options.hpn_buffer_size = socksize;
1226                                 debug ("HPNBufferSize set to user TCPRcvBuf: %d", options.hpn_buffer_size);
1227                         }
1228                 }
1229                 
1230         }
1231
1232         debug("Final hpn_buffer_size = %d", options.hpn_buffer_size);
1233
1234         window = options.hpn_buffer_size;
1235
1236         channel_set_hpn(options.hpn_disabled, options.hpn_buffer_size);
1237
1238         packetmax = CHAN_SES_PACKET_DEFAULT;
1239         if (tty_flag) {
1240                 window = 4*CHAN_SES_PACKET_DEFAULT;
1241                 window >>= 1;
1242                 packetmax >>= 1;
1243         }
1244         c = channel_new(
1245             "session", SSH_CHANNEL_OPENING, in, out, err,
1246             window, packetmax, CHAN_EXTENDED_WRITE,
1247             "client-session", /*nonblock*/0);
1248         if ((options.tcp_rcv_buf_poll > 0) && (!options.hpn_disabled)) {
1249                 c->dynamic_window = 1;
1250                 debug ("Enabled Dynamic Window Scaling\n");
1251         }
1252         debug3("ssh_session2_open: channel_new: %d", c->self);
1253
1254         channel_send_open(c->self);
1255         if (!no_shell_flag)
1256                 channel_register_open_confirm(c->self,
1257                     ssh_session2_setup, NULL);
1258
1259         return c->self;
1260 }
1261
1262 static int
1263 ssh_session2(void)
1264 {
1265         int id = -1;
1266
1267         /* XXX should be pre-session */
1268         ssh_init_forwarding();
1269
1270         if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN))
1271                 id = ssh_session2_open();
1272
1273         /* If we don't expect to open a new session, then disallow it */
1274         if (options.control_master == SSHCTL_MASTER_NO &&
1275             (datafellows & SSH_NEW_OPENSSH)) {
1276                 debug("Requesting no-more-sessions@openssh.com");
1277                 packet_start(SSH2_MSG_GLOBAL_REQUEST);
1278                 packet_put_cstring("no-more-sessions@openssh.com");
1279                 packet_put_char(0);
1280                 packet_send();
1281         }
1282
1283         /* Execute a local command */
1284         if (options.local_command != NULL &&
1285             options.permit_local_command)
1286                 ssh_local_cmd(options.local_command);
1287
1288         /* Start listening for multiplex clients */
1289         muxserver_listen();
1290
1291         /* If requested, let ssh continue in the background. */
1292         if (fork_after_authentication_flag) {
1293                 fork_after_authentication_flag = 0;
1294                 if (daemon(1, 1) < 0)
1295                         fatal("daemon() failed: %.200s", strerror(errno));
1296         }
1297
1298         return client_loop(tty_flag, tty_flag ?
1299             options.escape_char : SSH_ESCAPECHAR_NONE, id);
1300 }
1301
1302 static void
1303 load_public_identity_files(void)
1304 {
1305         char *filename, *cp, thishost[NI_MAXHOST];
1306         char *pwdir = NULL, *pwname = NULL;
1307         int i = 0;
1308         Key *public;
1309         struct passwd *pw;
1310 #ifdef SMARTCARD
1311         Key **keys;
1312
1313         if (options.smartcard_device != NULL &&
1314             options.num_identity_files < SSH_MAX_IDENTITY_FILES &&
1315             (keys = sc_get_keys(options.smartcard_device, NULL)) != NULL) {
1316                 int count = 0;
1317                 for (i = 0; keys[i] != NULL; i++) {
1318                         count++;
1319                         memmove(&options.identity_files[1],
1320                             &options.identity_files[0],
1321                             sizeof(char *) * (SSH_MAX_IDENTITY_FILES - 1));
1322                         memmove(&options.identity_keys[1],
1323                             &options.identity_keys[0],
1324                             sizeof(Key *) * (SSH_MAX_IDENTITY_FILES - 1));
1325                         options.num_identity_files++;
1326                         options.identity_keys[0] = keys[i];
1327                         options.identity_files[0] = sc_get_key_label(keys[i]);
1328                 }
1329                 if (options.num_identity_files > SSH_MAX_IDENTITY_FILES)
1330                         options.num_identity_files = SSH_MAX_IDENTITY_FILES;
1331                 i = count;
1332                 xfree(keys);
1333         }
1334 #endif /* SMARTCARD */
1335         if ((pw = getpwuid(original_real_uid)) == NULL)
1336                 fatal("load_public_identity_files: getpwuid failed");
1337         pwname = xstrdup(pw->pw_name);
1338         pwdir = xstrdup(pw->pw_dir);
1339         if (gethostname(thishost, sizeof(thishost)) == -1)
1340                 fatal("load_public_identity_files: gethostname: %s",
1341                     strerror(errno));
1342         for (; i < options.num_identity_files; i++) {
1343                 cp = tilde_expand_filename(options.identity_files[i],
1344                     original_real_uid);
1345                 filename = percent_expand(cp, "d", pwdir,
1346                     "u", pwname, "l", thishost, "h", host,
1347                     "r", options.user, (char *)NULL);
1348                 xfree(cp);
1349                 public = key_load_public(filename, NULL);
1350                 debug("identity file %s type %d", filename,
1351                     public ? public->type : -1);
1352                 xfree(options.identity_files[i]);
1353                 options.identity_files[i] = filename;
1354                 options.identity_keys[i] = public;
1355         }
1356         bzero(pwname, strlen(pwname));
1357         xfree(pwname);
1358         bzero(pwdir, strlen(pwdir));
1359         xfree(pwdir);
1360 }
This page took 1.129777 seconds and 5 git commands to generate.