Annotation of src/usr.bin/ssh/ssh.c, Revision 1.134
1.1 deraadt 1: /*
1.32 deraadt 2: * Author: Tatu Ylonen <ylo@cs.hut.fi>
3: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4: * All rights reserved
5: * Ssh client program. This program can be used to log into a remote machine.
6: * The software supports strong authentication, encryption, and forwarding
7: * of X11, TCP/IP, and authentication connections.
8: *
1.64 deraadt 9: * As far as I am concerned, the code I have written for this software
10: * can be used freely for any purpose. Any derived versions of this
11: * software must be clearly marked as such, and if the derived work is
12: * incompatible with the protocol description in the RFC file, it must be
13: * called by a name other than "ssh" or "Secure Shell".
14: *
15: * Copyright (c) 1999 Niels Provos. All rights reserved.
16: *
17: * Modified to work with SSL by Niels Provos <provos@citi.umich.edu>
18: * in Canada (German citizen).
19: *
20: * Redistribution and use in source and binary forms, with or without
21: * modification, are permitted provided that the following conditions
22: * are met:
23: * 1. Redistributions of source code must retain the above copyright
24: * notice, this list of conditions and the following disclaimer.
25: * 2. Redistributions in binary form must reproduce the above copyright
26: * notice, this list of conditions and the following disclaimer in the
27: * documentation and/or other materials provided with the distribution.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.32 deraadt 39: */
1.1 deraadt 40:
41: #include "includes.h"
1.134 ! markus 42: RCSID("$OpenBSD: ssh.c,v 1.133 2001/08/01 22:03:33 markus Exp $");
1.49 markus 43:
44: #include <openssl/evp.h>
1.72 markus 45: #include <openssl/err.h>
1.1 deraadt 46:
1.84 markus 47: #include "ssh.h"
48: #include "ssh1.h"
49: #include "ssh2.h"
50: #include "compat.h"
51: #include "cipher.h"
1.1 deraadt 52: #include "xmalloc.h"
53: #include "packet.h"
54: #include "buffer.h"
55: #include "uidswap.h"
1.123 markus 56: #include "channels.h"
1.49 markus 57: #include "key.h"
1.58 markus 58: #include "authfd.h"
1.49 markus 59: #include "authfile.h"
1.83 markus 60: #include "pathnames.h"
1.81 markus 61: #include "clientloop.h"
1.84 markus 62: #include "log.h"
63: #include "readconf.h"
64: #include "sshconnect.h"
65: #include "tildexpand.h"
1.89 markus 66: #include "dispatch.h"
1.84 markus 67: #include "misc.h"
1.95 markus 68: #include "kex.h"
69: #include "mac.h"
1.115 stevesk 70: #include "sshtty.h"
1.49 markus 71:
1.127 markus 72: #ifdef SMARTCARD
73: #include <openssl/engine.h>
74: #include "scard.h"
75: #endif
76:
1.49 markus 77: extern char *__progname;
1.1 deraadt 78:
1.37 markus 79: /* Flag indicating whether IPv4 or IPv6. This can be set on the command line.
80: Default value is AF_UNSPEC means both IPv4 and IPv6. */
81: int IPv4or6 = AF_UNSPEC;
82:
1.31 markus 83: /* Flag indicating whether debug mode is on. This can be set on the command line. */
1.1 deraadt 84: int debug_flag = 0;
85:
1.46 markus 86: /* Flag indicating whether a tty should be allocated */
1.1 deraadt 87: int tty_flag = 0;
1.79 markus 88: int no_tty_flag = 0;
89: int force_tty_flag = 0;
1.1 deraadt 90:
1.45 markus 91: /* don't exec a shell */
92: int no_shell_flag = 0;
93:
1.33 markus 94: /*
95: * Flag indicating that nothing should be read from stdin. This can be set
96: * on the command line.
97: */
1.1 deraadt 98: int stdin_null_flag = 0;
99:
1.33 markus 100: /*
101: * Flag indicating that ssh should fork after authentication. This is useful
102: * so that the pasphrase can be entered manually, and then ssh goes to the
103: * background.
104: */
1.1 deraadt 105: int fork_after_authentication_flag = 0;
106:
1.33 markus 107: /*
108: * General data structure for command line options and options configurable
109: * in configuration files. See readconf.h.
110: */
1.1 deraadt 111: Options options;
112:
1.33 markus 113: /*
114: * Name of the host we are connecting to. This is the name given on the
115: * command line, or the HostName specified for the user-supplied name in a
116: * configuration file.
117: */
1.1 deraadt 118: char *host;
119:
1.22 provos 120: /* socket address the host resolves to */
1.37 markus 121: struct sockaddr_storage hostaddr;
1.22 provos 122:
1.33 markus 123: /*
124: * Flag to indicate that we have received a window change signal which has
125: * not yet been processed. This will cause a message indicating the new
126: * window size to be sent to the server a little later. This is volatile
127: * because this is updated in a signal handler.
128: */
1.1 deraadt 129: volatile int received_window_change_signal = 0;
130:
1.112 markus 131: /* Private host keys. */
132: struct {
133: Key **keys;
134: int nkeys;
135: } sensitive_data;
1.1 deraadt 136:
1.10 dugsong 137: /* Original real UID. */
138: uid_t original_real_uid;
1.1 deraadt 139:
1.45 markus 140: /* command to be executed */
141: Buffer command;
142:
1.85 djm 143: /* Should we execute a command or invoke a subsystem? */
144: int subsystem_flag = 0;
145:
1.1 deraadt 146: /* Prints a help message to the user. This function never returns. */
147:
1.126 itojun 148: static void
1.93 itojun 149: usage(void)
1.1 deraadt 150: {
1.76 markus 151: fprintf(stderr, "Usage: %s [options] host [command]\n", __progname);
1.31 markus 152: fprintf(stderr, "Options:\n");
153: fprintf(stderr, " -l user Log in using this user name.\n");
1.93 itojun 154: fprintf(stderr, " -n Redirect input from " _PATH_DEVNULL ".\n");
1.53 markus 155: fprintf(stderr, " -A Enable authentication agent forwarding.\n");
1.120 markus 156: fprintf(stderr, " -a Disable authentication agent forwarding (default).\n");
1.9 dugsong 157: #ifdef AFS
1.31 markus 158: fprintf(stderr, " -k Disable Kerberos ticket and AFS token forwarding.\n");
159: #endif /* AFS */
1.88 stevesk 160: fprintf(stderr, " -X Enable X11 connection forwarding.\n");
1.120 markus 161: fprintf(stderr, " -x Disable X11 connection forwarding (default).\n");
1.99 deraadt 162: fprintf(stderr, " -i file Identity for public key authentication "
163: "(default: ~/.ssh/identity)\n");
1.31 markus 164: fprintf(stderr, " -t Tty; allocate a tty even if command is given.\n");
1.45 markus 165: fprintf(stderr, " -T Do not allocate a tty.\n");
1.31 markus 166: fprintf(stderr, " -v Verbose; display verbose debugging messages.\n");
1.66 markus 167: fprintf(stderr, " Multiple -v increases verbosity.\n");
1.31 markus 168: fprintf(stderr, " -V Display version number only.\n");
169: fprintf(stderr, " -P Don't allocate a privileged port.\n");
170: fprintf(stderr, " -q Quiet; don't display any warning messages.\n");
171: fprintf(stderr, " -f Fork into background after authentication.\n");
172: fprintf(stderr, " -e char Set escape character; ``none'' = disable (default: ~).\n");
173:
1.120 markus 174: fprintf(stderr, " -c cipher Select encryption algorithm\n");
1.102 stevesk 175: fprintf(stderr, " -m macs Specify MAC algorithms for protocol version 2.\n");
1.31 markus 176: fprintf(stderr, " -p port Connect to this port. Server must be on the same port.\n");
177: fprintf(stderr, " -L listen-port:host:port Forward local port to remote address\n");
178: fprintf(stderr, " -R listen-port:host:port Forward remote port to local address\n");
1.76 markus 179: fprintf(stderr, " These cause %s to listen for connections on a port, and\n", __progname);
1.31 markus 180: fprintf(stderr, " forward them to the other side by connecting to host:port.\n");
181: fprintf(stderr, " -C Enable compression.\n");
1.45 markus 182: fprintf(stderr, " -N Do not execute a shell or command.\n");
1.31 markus 183: fprintf(stderr, " -g Allow remote hosts to connect to forwarded ports.\n");
1.92 jakob 184: fprintf(stderr, " -1 Force protocol version 1.\n");
185: fprintf(stderr, " -2 Force protocol version 2.\n");
1.37 markus 186: fprintf(stderr, " -4 Use IPv4 only.\n");
187: fprintf(stderr, " -6 Use IPv6 only.\n");
1.31 markus 188: fprintf(stderr, " -o 'option' Process the option as if it was read from a configuration file.\n");
1.85 djm 189: fprintf(stderr, " -s Invoke command (mandatory) as SSH2 subsystem.\n");
1.120 markus 190: fprintf(stderr, " -b addr Local IP address.\n");
1.31 markus 191: exit(1);
1.1 deraadt 192: }
193:
1.32 deraadt 194: /*
195: * Connects to the given host using rsh (or prints an error message and exits
196: * if rsh is not available). This function never returns.
197: */
1.126 itojun 198: static void
1.31 markus 199: rsh_connect(char *host, char *user, Buffer * command)
1.1 deraadt 200: {
1.31 markus 201: char *args[10];
202: int i;
203:
204: log("Using rsh. WARNING: Connection will not be encrypted.");
205: /* Build argument list for rsh. */
206: i = 0;
207: args[i++] = _PATH_RSH;
208: /* host may have to come after user on some systems */
209: args[i++] = host;
210: if (user) {
211: args[i++] = "-l";
212: args[i++] = user;
213: }
214: if (buffer_len(command) > 0) {
215: buffer_append(command, "\0", 1);
216: args[i++] = buffer_ptr(command);
217: }
218: args[i++] = NULL;
219: if (debug_flag) {
220: for (i = 0; args[i]; i++) {
221: if (i != 0)
222: fprintf(stderr, " ");
223: fprintf(stderr, "%s", args[i]);
224: }
225: fprintf(stderr, "\n");
226: }
227: execv(_PATH_RSH, args);
228: perror(_PATH_RSH);
229: exit(1);
1.1 deraadt 230: }
231:
1.126 itojun 232: static int ssh_session(void);
233: static int ssh_session2(void);
234: static void load_public_identity_files(void);
1.45 markus 235:
1.32 deraadt 236: /*
237: * Main program for the ssh client.
238: */
1.2 provos 239: int
240: main(int ac, char **av)
1.1 deraadt 241: {
1.130 markus 242: int i, opt, exit_status, cerr;
1.35 markus 243: u_short fwd_port, fwd_host_port;
1.128 fgsch 244: char *p, *cp, buf[256];
1.31 markus 245: struct stat st;
1.98 markus 246: struct passwd *pw;
1.45 markus 247: int dummy;
1.31 markus 248: uid_t original_effective_uid;
249:
1.33 markus 250: /*
251: * Save the original real uid. It will be needed later (uid-swapping
252: * may clobber the real uid).
253: */
1.31 markus 254: original_real_uid = getuid();
255: original_effective_uid = geteuid();
256:
257: /* If we are installed setuid root be careful to not drop core. */
258: if (original_real_uid != original_effective_uid) {
259: struct rlimit rlim;
260: rlim.rlim_cur = rlim.rlim_max = 0;
261: if (setrlimit(RLIMIT_CORE, &rlim) < 0)
262: fatal("setrlimit failed: %.100s", strerror(errno));
1.1 deraadt 263: }
1.107 markus 264: /* Get user data. */
265: pw = getpwuid(original_real_uid);
266: if (!pw) {
267: log("You don't exist, go away!");
268: exit(1);
269: }
270: /* Take a copy of the returned structure. */
271: pw = pwcopy(pw);
272:
1.33 markus 273: /*
274: * Use uid-swapping to give up root privileges for the duration of
275: * option processing. We will re-instantiate the rights when we are
276: * ready to create the privileged port, and will permanently drop
277: * them when the port has been created (actually, when the connection
278: * has been made, as we may need to create the port several times).
279: */
1.107 markus 280: temporarily_use_uid(pw);
1.31 markus 281:
1.33 markus 282: /*
283: * Set our umask to something reasonable, as some files are created
284: * with the default umask. This will make them world-readable but
285: * writable only by the owner, which is ok for all files for which we
286: * don't set the modes explicitly.
287: */
1.31 markus 288: umask(022);
289:
290: /* Initialize option structure to indicate that no values have been set. */
291: initialize_options(&options);
292:
293: /* Parse command-line arguments. */
294: host = NULL;
295:
1.128 fgsch 296: again:
297: while ((opt = getopt(ac, av,
1.129 markus 298: "1246ab:c:e:fgi:kl:m:no:p:qstvxACD:I:L:NPR:TVX")) != -1) {
1.31 markus 299: switch (opt) {
1.91 jakob 300: case '1':
301: options.protocol = SSH_PROTO_1;
302: break;
1.47 markus 303: case '2':
304: options.protocol = SSH_PROTO_2;
305: break;
1.37 markus 306: case '4':
307: IPv4or6 = AF_INET;
308: break;
309: case '6':
310: IPv4or6 = AF_INET6;
311: break;
1.31 markus 312: case 'n':
313: stdin_null_flag = 1;
314: break;
315: case 'f':
316: fork_after_authentication_flag = 1;
317: stdin_null_flag = 1;
318: break;
319: case 'x':
320: options.forward_x11 = 0;
321: break;
322: case 'X':
323: options.forward_x11 = 1;
324: break;
325: case 'g':
326: options.gateway_ports = 1;
327: break;
328: case 'P':
329: options.use_privileged_port = 0;
330: break;
331: case 'a':
332: options.forward_agent = 0;
1.53 markus 333: break;
334: case 'A':
335: options.forward_agent = 1;
1.31 markus 336: break;
1.9 dugsong 337: #ifdef AFS
1.31 markus 338: case 'k':
339: options.kerberos_tgt_passing = 0;
340: options.afs_token_passing = 0;
341: break;
1.1 deraadt 342: #endif
1.31 markus 343: case 'i':
344: if (stat(optarg, &st) < 0) {
1.128 fgsch 345: fprintf(stderr, "Warning: Identity file %s "
346: "does not exist.\n", optarg);
1.31 markus 347: break;
348: }
1.128 fgsch 349: if (options.num_identity_files >=
350: SSH_MAX_IDENTITY_FILES)
351: fatal("Too many identity files specified "
352: "(max %d)", SSH_MAX_IDENTITY_FILES);
353: options.identity_files[options.num_identity_files++] =
354: xstrdup(optarg);
1.31 markus 355: break;
1.127 markus 356: case 'I':
357: #ifdef SMARTCARD
1.133 markus 358: options.smartcard_device = xstrdup(optarg);
1.127 markus 359: #else
360: fprintf(stderr, "no support for smartcards.\n");
361: #endif
362: break;
1.31 markus 363: case 't':
1.79 markus 364: if (tty_flag)
365: force_tty_flag = 1;
1.31 markus 366: tty_flag = 1;
367: break;
368: case 'v':
1.66 markus 369: if (0 == debug_flag) {
370: debug_flag = 1;
371: options.log_level = SYSLOG_LEVEL_DEBUG1;
372: } else if (options.log_level < SYSLOG_LEVEL_DEBUG3) {
373: options.log_level++;
374: break;
1.128 fgsch 375: } else
1.103 millert 376: fatal("Too high debugging level.");
1.66 markus 377: /* fallthrough */
1.31 markus 378: case 'V':
1.96 deraadt 379: fprintf(stderr,
380: "%s, SSH protocols %d.%d/%d.%d, OpenSSL 0x%8.8lx\n",
1.46 markus 381: SSH_VERSION,
382: PROTOCOL_MAJOR_1, PROTOCOL_MINOR_1,
1.96 deraadt 383: PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2,
384: SSLeay());
1.31 markus 385: if (opt == 'V')
386: exit(0);
387: break;
388: case 'q':
389: options.log_level = SYSLOG_LEVEL_QUIET;
390: break;
391: case 'e':
392: if (optarg[0] == '^' && optarg[2] == 0 &&
1.128 fgsch 393: (u_char) optarg[1] >= 64 &&
394: (u_char) optarg[1] < 128)
1.78 markus 395: options.escape_char = (u_char) optarg[1] & 31;
1.31 markus 396: else if (strlen(optarg) == 1)
1.78 markus 397: options.escape_char = (u_char) optarg[0];
1.31 markus 398: else if (strcmp(optarg, "none") == 0)
1.119 stevesk 399: options.escape_char = SSH_ESCAPECHAR_NONE;
1.31 markus 400: else {
1.128 fgsch 401: fprintf(stderr, "Bad escape character '%s'.\n",
402: optarg);
1.31 markus 403: exit(1);
404: }
405: break;
406: case 'c':
1.49 markus 407: if (ciphers_valid(optarg)) {
408: /* SSH2 only */
409: options.ciphers = xstrdup(optarg);
1.51 markus 410: options.cipher = SSH_CIPHER_ILLEGAL;
1.49 markus 411: } else {
412: /* SSH1 only */
1.74 markus 413: options.cipher = cipher_number(optarg);
414: if (options.cipher == -1) {
1.128 fgsch 415: fprintf(stderr,
416: "Unknown cipher type '%s'\n",
417: optarg);
1.49 markus 418: exit(1);
419: }
1.128 fgsch 420: if (options.cipher == SSH_CIPHER_3DES)
1.74 markus 421: options.ciphers = "3des-cbc";
1.128 fgsch 422: else if (options.cipher == SSH_CIPHER_BLOWFISH)
1.74 markus 423: options.ciphers = "blowfish-cbc";
1.128 fgsch 424: else
1.74 markus 425: options.ciphers = (char *)-1;
1.95 markus 426: }
427: break;
428: case 'm':
429: if (mac_valid(optarg))
430: options.macs = xstrdup(optarg);
431: else {
1.128 fgsch 432: fprintf(stderr, "Unknown mac type '%s'\n",
433: optarg);
1.95 markus 434: exit(1);
1.31 markus 435: }
436: break;
437: case 'p':
1.113 stevesk 438: options.port = a2port(optarg);
439: if (options.port == 0) {
1.109 markus 440: fprintf(stderr, "Bad port '%s'\n", optarg);
441: exit(1);
442: }
1.31 markus 443: break;
444: case 'l':
445: options.user = optarg;
446: break;
447: case 'R':
1.37 markus 448: if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf,
449: &fwd_host_port) != 3 &&
450: sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf,
451: &fwd_host_port) != 3) {
1.128 fgsch 452: fprintf(stderr,
453: "Bad forwarding specification '%s'.\n",
454: optarg);
1.31 markus 455: usage();
456: /* NOTREACHED */
457: }
1.128 fgsch 458: add_remote_forward(&options, fwd_port, buf,
459: fwd_host_port);
1.31 markus 460: break;
461: case 'L':
1.37 markus 462: if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf,
463: &fwd_host_port) != 3 &&
464: sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf,
465: &fwd_host_port) != 3) {
1.128 fgsch 466: fprintf(stderr,
467: "Bad forwarding specification '%s'.\n",
468: optarg);
1.31 markus 469: usage();
470: /* NOTREACHED */
471: }
1.128 fgsch 472: add_local_forward(&options, fwd_port, buf,
473: fwd_host_port);
1.31 markus 474: break;
1.108 markus 475:
476: case 'D':
1.113 stevesk 477: fwd_port = a2port(optarg);
478: if (fwd_port == 0) {
1.128 fgsch 479: fprintf(stderr, "Bad dynamic port '%s'\n",
480: optarg);
1.109 markus 481: exit(1);
482: }
1.108 markus 483: add_local_forward(&options, fwd_port, "socks4", 0);
484: break;
485:
1.31 markus 486: case 'C':
487: options.compression = 1;
488: break;
1.45 markus 489: case 'N':
490: no_shell_flag = 1;
491: no_tty_flag = 1;
492: break;
493: case 'T':
494: no_tty_flag = 1;
495: break;
1.31 markus 496: case 'o':
497: dummy = 1;
1.128 fgsch 498: if (process_config_line(&options, host ? host : "",
499: optarg, "command-line", 0, &dummy) != 0)
1.31 markus 500: exit(1);
501: break;
1.85 djm 502: case 's':
503: subsystem_flag = 1;
1.117 markus 504: break;
505: case 'b':
506: options.bind_address = optarg;
1.85 djm 507: break;
1.31 markus 508: default:
509: usage();
1.1 deraadt 510: }
1.31 markus 511: }
512:
1.128 fgsch 513: ac -= optind;
514: av += optind;
515:
516: if (ac > 0 && !host && **av != '-') {
517: if (strchr(*av, '@')) {
518: p = xstrdup(*av);
519: cp = strchr(p, '@');
520: if (cp == NULL || cp == p)
521: usage();
522: options.user = p;
523: *cp = '\0';
524: host = ++cp;
525: } else
526: host = *av;
527: ac--, av++;
528: if (ac > 0) {
529: optind = 0;
530: optreset = 1;
531: goto again;
532: }
533: }
534:
1.31 markus 535: /* Check that we got a host name. */
536: if (!host)
537: usage();
538:
1.54 markus 539: SSLeay_add_all_algorithms();
1.72 markus 540: ERR_load_crypto_strings();
1.31 markus 541:
542: /* Initialize the command to execute on remote host. */
543: buffer_init(&command);
1.1 deraadt 544:
1.33 markus 545: /*
546: * Save the command to execute on the remote host in a buffer. There
547: * is no limit on the length of the command, except by the maximum
548: * packet size. Also sets the tty flag if there is no command.
549: */
1.128 fgsch 550: if (!ac) {
1.31 markus 551: /* No command specified - execute shell on a tty. */
552: tty_flag = 1;
1.85 djm 553: if (subsystem_flag) {
1.128 fgsch 554: fprintf(stderr,
555: "You must specify a subsystem to invoke.\n");
1.85 djm 556: usage();
557: }
1.31 markus 558: } else {
1.128 fgsch 559: /* A command has been specified. Store it into the buffer. */
560: for (i = 0; i < ac; i++) {
561: if (i)
1.31 markus 562: buffer_append(&command, " ", 1);
563: buffer_append(&command, av[i], strlen(av[i]));
564: }
565: }
566:
567: /* Cannot fork to background if no command. */
1.63 markus 568: if (fork_after_authentication_flag && buffer_len(&command) == 0 && !no_shell_flag)
1.31 markus 569: fatal("Cannot fork into background without a command to execute.");
570:
571: /* Allocate a tty by default if no command specified. */
572: if (buffer_len(&command) == 0)
573: tty_flag = 1;
574:
1.75 markus 575: /* Force no tty*/
576: if (no_tty_flag)
577: tty_flag = 0;
1.31 markus 578: /* Do not allocate a tty if stdin is not a tty. */
1.79 markus 579: if (!isatty(fileno(stdin)) && !force_tty_flag) {
1.31 markus 580: if (tty_flag)
1.103 millert 581: log("Pseudo-terminal will not be allocated because stdin is not a terminal.");
1.31 markus 582: tty_flag = 0;
583: }
1.45 markus 584:
1.101 markus 585: /*
586: * Initialize "log" output. Since we are the client all output
587: * actually goes to stderr.
588: */
1.111 markus 589: log_init(av[0], options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
590: SYSLOG_FACILITY_USER, 1);
1.31 markus 591:
592: /* Read per-user configuration file. */
1.83 markus 593: snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, _PATH_SSH_USER_CONFFILE);
1.31 markus 594: read_config_file(buf, host, &options);
595:
596: /* Read systemwide configuration file. */
1.83 markus 597: read_config_file(_PATH_HOST_CONFIG_FILE, host, &options);
1.31 markus 598:
599: /* Fill configuration defaults. */
600: fill_default_options(&options);
601:
602: /* reinit */
1.101 markus 603: log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 1);
1.31 markus 604:
605: if (options.user == NULL)
606: options.user = xstrdup(pw->pw_name);
607:
608: if (options.hostname != NULL)
609: host = options.hostname;
610:
611: /* Disable rhosts authentication if not running as root. */
612: if (original_effective_uid != 0 || !options.use_privileged_port) {
1.77 markus 613: debug("Rhosts Authentication disabled, "
1.71 markus 614: "originating port will not be trusted.");
1.31 markus 615: options.rhosts_authentication = 0;
616: }
1.33 markus 617: /*
618: * If using rsh has been selected, exec it now (without trying
619: * anything else). Note that we must release privileges first.
620: */
1.31 markus 621: if (options.use_rsh) {
1.33 markus 622: /*
623: * Restore our superuser privileges. This must be done
624: * before permanently setting the uid.
625: */
1.31 markus 626: restore_uid();
627:
628: /* Switch to the original uid permanently. */
1.107 markus 629: permanently_set_uid(pw);
1.31 markus 630:
631: /* Execute rsh. */
632: rsh_connect(host, options.user, &command);
633: fatal("rsh_connect returned");
634: }
635: /* Restore our superuser privileges. */
636: restore_uid();
637:
1.77 markus 638: /* Open a connection to the remote host. */
1.31 markus 639:
1.130 markus 640: cerr = ssh_connect(host, &hostaddr, options.port,
1.77 markus 641: options.connection_attempts,
642: original_effective_uid != 0 || !options.use_privileged_port,
1.107 markus 643: pw, options.proxy_command);
1.31 markus 644:
1.33 markus 645: /*
646: * If we successfully made the connection, load the host private key
647: * in case we will need it later for combined rsa-rhosts
648: * authentication. This must be done before releasing extra
649: * privileges, because the file is only readable by root.
650: */
1.112 markus 651: sensitive_data.nkeys = 0;
652: sensitive_data.keys = NULL;
1.130 markus 653: if (!cerr && (options.rhosts_rsa_authentication ||
1.112 markus 654: options.hostbased_authentication)) {
655: sensitive_data.nkeys = 3;
656: sensitive_data.keys = xmalloc(sensitive_data.nkeys*sizeof(Key));
657: sensitive_data.keys[0] = key_load_private_type(KEY_RSA1,
1.105 markus 658: _PATH_HOST_KEY_FILE, "", NULL);
1.112 markus 659: sensitive_data.keys[1] = key_load_private_type(KEY_DSA,
660: _PATH_HOST_DSA_KEY_FILE, "", NULL);
661: sensitive_data.keys[2] = key_load_private_type(KEY_RSA,
662: _PATH_HOST_RSA_KEY_FILE, "", NULL);
1.31 markus 663: }
1.33 markus 664: /*
665: * Get rid of any extra privileges that we may have. We will no
666: * longer need them. Also, extra privileges could make it very hard
667: * to read identity files and other non-world-readable files from the
668: * user's home directory if it happens to be on a NFS volume where
669: * root is mapped to nobody.
670: */
671:
672: /*
673: * Note that some legacy systems need to postpone the following call
674: * to permanently_set_uid() until the private hostkey is destroyed
675: * with RSA_free(). Otherwise the calling user could ptrace() the
676: * process, read the private hostkey and impersonate the host.
677: * OpenBSD does not allow ptracing of setuid processes.
678: */
1.107 markus 679: permanently_set_uid(pw);
1.31 markus 680:
1.33 markus 681: /*
682: * Now that we are back to our own permissions, create ~/.ssh
683: * directory if it doesn\'t already exist.
684: */
1.83 markus 685: snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, _PATH_SSH_USER_DIR);
1.31 markus 686: if (stat(buf, &st) < 0)
1.57 djm 687: if (mkdir(buf, 0700) < 0)
1.31 markus 688: error("Could not create directory '%.200s'.", buf);
689:
690: /* Check if the connection failed, and try "rsh" if appropriate. */
1.130 markus 691: if (cerr) {
692: if (!options.fallback_to_rsh)
693: exit(1);
1.31 markus 694: if (options.port != 0)
1.130 markus 695: log("Secure connection to %.100s on port %hu refused; "
696: "reverting to insecure method",
697: host, options.port);
1.31 markus 698: else
1.130 markus 699: log("Secure connection to %.100s refused; "
700: "reverting to insecure method.", host);
1.31 markus 701:
1.130 markus 702: rsh_connect(host, options.user, &command);
703: fatal("rsh_connect returned");
1.31 markus 704: }
1.104 markus 705: /* load options.identity_files */
706: load_public_identity_files();
707:
708: /* Expand ~ in known host file names. */
709: /* XXX mem-leaks: */
1.72 markus 710: options.system_hostfile =
711: tilde_expand_filename(options.system_hostfile, original_real_uid);
712: options.user_hostfile =
713: tilde_expand_filename(options.user_hostfile, original_real_uid);
714: options.system_hostfile2 =
715: tilde_expand_filename(options.system_hostfile2, original_real_uid);
716: options.user_hostfile2 =
717: tilde_expand_filename(options.user_hostfile2, original_real_uid);
1.31 markus 718:
719: /* Log into the remote system. This never returns if the login fails. */
1.112 markus 720: ssh_login(sensitive_data.keys, sensitive_data.nkeys,
721: host, (struct sockaddr *)&hostaddr, pw);
1.31 markus 722:
1.112 markus 723: /* We no longer need the private host keys. Clear them now. */
724: if (sensitive_data.nkeys != 0) {
725: for (i = 0; i < sensitive_data.nkeys; i++) {
726: if (sensitive_data.keys[i] != NULL) {
727: /* Destroys contents safely */
728: debug3("clear hostkey %d", i);
729: key_free(sensitive_data.keys[i]);
730: sensitive_data.keys[i] = NULL;
731: }
732: }
733: xfree(sensitive_data.keys);
1.134 ! markus 734: }
! 735: for (i = 0; i < options.num_identity_files; i++) {
! 736: if (options.identity_files[i]) {
! 737: xfree(options.identity_files[i]);
! 738: options.identity_files[i] = NULL;
! 739: }
! 740: if (options.identity_keys[i]) {
! 741: key_free(options.identity_keys[i]);
! 742: options.identity_keys[i] = NULL;
! 743: }
1.112 markus 744: }
1.31 markus 745:
1.45 markus 746: exit_status = compat20 ? ssh_session2() : ssh_session();
747: packet_close();
748: return exit_status;
749: }
750:
1.126 itojun 751: static void
1.50 markus 752: x11_get_proto(char *proto, int proto_len, char *data, int data_len)
753: {
754: char line[512];
755: FILE *f;
756: int got_data = 0, i;
757:
1.55 markus 758: if (options.xauth_location) {
759: /* Try to get Xauthority information for the display. */
1.93 itojun 760: snprintf(line, sizeof line, "%.100s list %.200s 2>" _PATH_DEVNULL,
1.55 markus 761: options.xauth_location, getenv("DISPLAY"));
762: f = popen(line, "r");
763: if (f && fgets(line, sizeof(line), f) &&
764: sscanf(line, "%*s %s %s", proto, data) == 2)
765: got_data = 1;
766: if (f)
767: pclose(f);
768: }
1.50 markus 769: /*
770: * If we didn't get authentication data, just make up some
771: * data. The forwarding code will check the validity of the
772: * response anyway, and substitute this data. The X11
773: * server, however, will ignore this fake data and use
774: * whatever authentication mechanisms it was using otherwise
775: * for the local connection.
776: */
777: if (!got_data) {
778: u_int32_t rand = 0;
779:
780: strlcpy(proto, "MIT-MAGIC-COOKIE-1", proto_len);
781: for (i = 0; i < 16; i++) {
782: if (i % 4 == 0)
783: rand = arc4random();
784: snprintf(data + 2 * i, data_len - 2 * i, "%02x", rand & 0xff);
785: rand >>= 8;
786: }
787: }
788: }
789:
1.126 itojun 790: static void
1.70 markus 791: ssh_init_forwarding(void)
792: {
1.86 markus 793: int success = 0;
1.70 markus 794: int i;
1.86 markus 795:
1.70 markus 796: /* Initiate local TCP/IP port forwardings. */
797: for (i = 0; i < options.num_local_forwards; i++) {
798: debug("Connections to local port %d forwarded to remote address %.200s:%d",
799: options.local_forwards[i].port,
800: options.local_forwards[i].host,
801: options.local_forwards[i].host_port);
1.86 markus 802: success += channel_request_local_forwarding(
1.70 markus 803: options.local_forwards[i].port,
804: options.local_forwards[i].host,
805: options.local_forwards[i].host_port,
806: options.gateway_ports);
807: }
1.86 markus 808: if (i > 0 && success == 0)
809: error("Could not request local forwarding.");
1.70 markus 810:
811: /* Initiate remote TCP/IP port forwardings. */
812: for (i = 0; i < options.num_remote_forwards; i++) {
813: debug("Connections to remote port %d forwarded to local address %.200s:%d",
814: options.remote_forwards[i].port,
815: options.remote_forwards[i].host,
816: options.remote_forwards[i].host_port);
817: channel_request_remote_forwarding(
818: options.remote_forwards[i].port,
819: options.remote_forwards[i].host,
820: options.remote_forwards[i].host_port);
821: }
822: }
823:
1.126 itojun 824: static void
1.70 markus 825: check_agent_present(void)
826: {
827: if (options.forward_agent) {
828: /* Clear agent forwarding if we don\'t have an agent. */
829: int authfd = ssh_get_authentication_socket();
830: if (authfd < 0)
831: options.forward_agent = 0;
832: else
833: ssh_close_authentication_socket(authfd);
834: }
835: }
836:
1.126 itojun 837: static int
1.45 markus 838: ssh_session(void)
839: {
840: int type;
841: int plen;
842: int interactive = 0;
843: int have_tty = 0;
844: struct winsize ws;
845: char *cp;
846:
1.31 markus 847: /* Enable compression if requested. */
848: if (options.compression) {
849: debug("Requesting compression at level %d.", options.compression_level);
850:
851: if (options.compression_level < 1 || options.compression_level > 9)
852: fatal("Compression level must be from 1 (fast) to 9 (slow, best).");
853:
854: /* Send the request. */
855: packet_start(SSH_CMSG_REQUEST_COMPRESSION);
856: packet_put_int(options.compression_level);
857: packet_send();
858: packet_write_wait();
859: type = packet_read(&plen);
860: if (type == SSH_SMSG_SUCCESS)
861: packet_start_compression(options.compression_level);
862: else if (type == SSH_SMSG_FAILURE)
863: log("Warning: Remote host refused compression.");
864: else
865: packet_disconnect("Protocol error waiting for compression response.");
866: }
867: /* Allocate a pseudo tty if appropriate. */
868: if (tty_flag) {
869: debug("Requesting pty.");
870:
871: /* Start the packet. */
872: packet_start(SSH_CMSG_REQUEST_PTY);
873:
874: /* Store TERM in the packet. There is no limit on the
875: length of the string. */
876: cp = getenv("TERM");
877: if (!cp)
878: cp = "";
1.124 markus 879: packet_put_cstring(cp);
1.31 markus 880:
881: /* Store window size in the packet. */
882: if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
883: memset(&ws, 0, sizeof(ws));
884: packet_put_int(ws.ws_row);
885: packet_put_int(ws.ws_col);
886: packet_put_int(ws.ws_xpixel);
887: packet_put_int(ws.ws_ypixel);
888:
889: /* Store tty modes in the packet. */
1.115 stevesk 890: tty_make_modes(fileno(stdin), NULL);
1.31 markus 891:
892: /* Send the packet, and wait for it to leave. */
893: packet_send();
894: packet_write_wait();
895:
896: /* Read response from the server. */
897: type = packet_read(&plen);
1.43 markus 898: if (type == SSH_SMSG_SUCCESS) {
1.31 markus 899: interactive = 1;
1.45 markus 900: have_tty = 1;
1.43 markus 901: } else if (type == SSH_SMSG_FAILURE)
1.31 markus 902: log("Warning: Remote host failed or refused to allocate a pseudo tty.");
903: else
904: packet_disconnect("Protocol error waiting for pty request response.");
905: }
906: /* Request X11 forwarding if enabled and DISPLAY is set. */
907: if (options.forward_x11 && getenv("DISPLAY") != NULL) {
1.50 markus 908: char proto[512], data[512];
909: /* Get reasonable local authentication information. */
910: x11_get_proto(proto, sizeof proto, data, sizeof data);
911: /* Request forwarding with authentication spoofing. */
1.31 markus 912: debug("Requesting X11 forwarding with authentication spoofing.");
1.50 markus 913: x11_request_forwarding_with_spoofing(0, proto, data);
1.31 markus 914:
915: /* Read response from the server. */
916: type = packet_read(&plen);
917: if (type == SSH_SMSG_SUCCESS) {
918: interactive = 1;
1.50 markus 919: } else if (type == SSH_SMSG_FAILURE) {
1.31 markus 920: log("Warning: Remote host denied X11 forwarding.");
1.50 markus 921: } else {
1.31 markus 922: packet_disconnect("Protocol error waiting for X11 forwarding");
1.50 markus 923: }
1.31 markus 924: }
925: /* Tell the packet module whether this is an interactive session. */
1.80 markus 926: packet_set_interactive(interactive);
1.31 markus 927:
928: /* Request authentication agent forwarding if appropriate. */
1.70 markus 929: check_agent_present();
930:
1.31 markus 931: if (options.forward_agent) {
932: debug("Requesting authentication agent forwarding.");
933: auth_request_forwarding();
934:
935: /* Read response from the server. */
936: type = packet_read(&plen);
937: packet_integrity_check(plen, 0, type);
938: if (type != SSH_SMSG_SUCCESS)
939: log("Warning: Remote host denied authentication agent forwarding.");
940: }
941:
1.70 markus 942: /* Initiate port forwardings. */
943: ssh_init_forwarding();
1.34 markus 944:
945: /* If requested, let ssh continue in the background. */
1.48 markus 946: if (fork_after_authentication_flag)
1.34 markus 947: if (daemon(1, 1) < 0)
948: fatal("daemon() failed: %.200s", strerror(errno));
1.31 markus 949:
1.33 markus 950: /*
951: * If a command was specified on the command line, execute the
952: * command now. Otherwise request the server to start a shell.
953: */
1.31 markus 954: if (buffer_len(&command) > 0) {
955: int len = buffer_len(&command);
956: if (len > 900)
957: len = 900;
958: debug("Sending command: %.*s", len, buffer_ptr(&command));
959: packet_start(SSH_CMSG_EXEC_CMD);
960: packet_put_string(buffer_ptr(&command), buffer_len(&command));
961: packet_send();
962: packet_write_wait();
963: } else {
964: debug("Requesting shell.");
965: packet_start(SSH_CMSG_EXEC_SHELL);
966: packet_send();
967: packet_write_wait();
968: }
969:
970: /* Enter the interactive session. */
1.119 stevesk 971: return client_loop(have_tty, tty_flag ?
972: options.escape_char : SSH_ESCAPECHAR_NONE, 0);
1.45 markus 973: }
974:
1.126 itojun 975: static void
1.89 markus 976: client_subsystem_reply(int type, int plen, void *ctxt)
977: {
978: int id, len;
979:
980: id = packet_get_int();
981: len = buffer_len(&command);
1.100 markus 982: if (len > 900)
983: len = 900;
1.89 markus 984: packet_done();
985: if (type == SSH2_MSG_CHANNEL_FAILURE)
986: fatal("Request for subsystem '%.*s' failed on channel %d",
987: len, buffer_ptr(&command), id);
988: }
989:
1.126 itojun 990: static void
1.70 markus 991: ssh_session2_callback(int id, void *arg)
1.45 markus 992: {
993: int len;
1.80 markus 994: int interactive = 0;
1.115 stevesk 995: struct termios tio;
1.80 markus 996:
1.87 deraadt 997: debug("client_init id %d arg %ld", id, (long)arg);
1.31 markus 998:
1.45 markus 999: if (tty_flag) {
1000: struct winsize ws;
1001: char *cp;
1002: cp = getenv("TERM");
1003: if (!cp)
1004: cp = "";
1005: /* Store window size in the packet. */
1006: if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
1007: memset(&ws, 0, sizeof(ws));
1008:
1009: channel_request_start(id, "pty-req", 0);
1010: packet_put_cstring(cp);
1011: packet_put_int(ws.ws_col);
1012: packet_put_int(ws.ws_row);
1013: packet_put_int(ws.ws_xpixel);
1014: packet_put_int(ws.ws_ypixel);
1.115 stevesk 1015: tio = get_saved_tio();
1016: tty_make_modes(/*ignored*/ 0, &tio);
1.45 markus 1017: packet_send();
1.80 markus 1018: interactive = 1;
1.45 markus 1019: /* XXX wait for reply */
1020: }
1.50 markus 1021: if (options.forward_x11 &&
1022: getenv("DISPLAY") != NULL) {
1023: char proto[512], data[512];
1024: /* Get reasonable local authentication information. */
1025: x11_get_proto(proto, sizeof proto, data, sizeof data);
1026: /* Request forwarding with authentication spoofing. */
1027: debug("Requesting X11 forwarding with authentication spoofing.");
1028: x11_request_forwarding_with_spoofing(id, proto, data);
1.80 markus 1029: interactive = 1;
1.50 markus 1030: /* XXX wait for reply */
1031: }
1032:
1.70 markus 1033: check_agent_present();
1034: if (options.forward_agent) {
1035: debug("Requesting authentication agent forwarding.");
1036: channel_request_start(id, "auth-agent-req@openssh.com", 0);
1037: packet_send();
1038: }
1039:
1.45 markus 1040: len = buffer_len(&command);
1041: if (len > 0) {
1042: if (len > 900)
1043: len = 900;
1.85 djm 1044: if (subsystem_flag) {
1045: debug("Sending subsystem: %.*s", len, buffer_ptr(&command));
1.89 markus 1046: channel_request_start(id, "subsystem", /*want reply*/ 1);
1047: /* register callback for reply */
1048: /* XXX we asume that client_loop has already been called */
1049: dispatch_set(SSH2_MSG_CHANNEL_FAILURE, &client_subsystem_reply);
1050: dispatch_set(SSH2_MSG_CHANNEL_SUCCESS, &client_subsystem_reply);
1.85 djm 1051: } else {
1052: debug("Sending command: %.*s", len, buffer_ptr(&command));
1053: channel_request_start(id, "exec", 0);
1054: }
1.100 markus 1055: packet_put_string(buffer_ptr(&command), buffer_len(&command));
1.45 markus 1056: packet_send();
1057: } else {
1058: channel_request(id, "shell", 0);
1059: }
1060: /* channel_callback(id, SSH2_MSG_OPEN_CONFIGMATION, client_init, 0); */
1.90 markus 1061:
1.45 markus 1062: /* register different callback, etc. XXX */
1.80 markus 1063: packet_set_interactive(interactive);
1.45 markus 1064: }
1065:
1.126 itojun 1066: static int
1.106 markus 1067: ssh_session2_command(void)
1.45 markus 1068: {
1.118 markus 1069: Channel *c;
1070: int window, packetmax, in, out, err;
1.60 markus 1071:
1.62 markus 1072: if (stdin_null_flag) {
1.93 itojun 1073: in = open(_PATH_DEVNULL, O_RDONLY);
1.62 markus 1074: } else {
1075: in = dup(STDIN_FILENO);
1076: }
1.60 markus 1077: out = dup(STDOUT_FILENO);
1078: err = dup(STDERR_FILENO);
1.45 markus 1079:
1080: if (in < 0 || out < 0 || err < 0)
1.62 markus 1081: fatal("dup() in/out/err failed");
1.45 markus 1082:
1.69 markus 1083: /* enable nonblocking unless tty */
1084: if (!isatty(in))
1085: set_nonblock(in);
1086: if (!isatty(out))
1087: set_nonblock(out);
1088: if (!isatty(err))
1089: set_nonblock(err);
1090:
1.65 markus 1091: window = CHAN_SES_WINDOW_DEFAULT;
1092: packetmax = CHAN_SES_PACKET_DEFAULT;
1093: if (!tty_flag) {
1.45 markus 1094: window *= 2;
1.65 markus 1095: packetmax *=2;
1.45 markus 1096: }
1.118 markus 1097: c = channel_new(
1.45 markus 1098: "session", SSH_CHANNEL_OPENING, in, out, err,
1.65 markus 1099: window, packetmax, CHAN_EXTENDED_WRITE,
1.69 markus 1100: xstrdup("client-session"), /*nonblock*/0);
1.118 markus 1101: if (c == NULL)
1102: fatal("ssh_session2_command: channel_new failed");
1.45 markus 1103:
1.118 markus 1104: debug3("ssh_session2_command: channel_new: %d", c->self);
1.106 markus 1105:
1.122 markus 1106: channel_send_open(c->self);
1.118 markus 1107: channel_register_callback(c->self, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
1.70 markus 1108: ssh_session2_callback, (void *)0);
1.106 markus 1109:
1.118 markus 1110: return c->self;
1.106 markus 1111: }
1112:
1.126 itojun 1113: static int
1.106 markus 1114: ssh_session2(void)
1115: {
1116: int id;
1117:
1118: /* XXX should be pre-session */
1119: ssh_init_forwarding();
1120:
1121: id = no_shell_flag ? -1 : ssh_session2_command();
1122:
1123: /* If requested, let ssh continue in the background. */
1124: if (fork_after_authentication_flag)
1125: if (daemon(1, 1) < 0)
1126: fatal("daemon() failed: %.200s", strerror(errno));
1.31 markus 1127:
1.119 stevesk 1128: return client_loop(tty_flag, tty_flag ?
1129: options.escape_char : SSH_ESCAPECHAR_NONE, id);
1.72 markus 1130: }
1131:
1.126 itojun 1132: static void
1.104 markus 1133: load_public_identity_files(void)
1134: {
1135: char *filename;
1136: Key *public;
1.131 millert 1137: int i = 0;
1.104 markus 1138:
1.127 markus 1139: #ifdef SMARTCARD
1.133 markus 1140: if (options.smartcard_device != NULL &&
1.127 markus 1141: options.num_identity_files + 1 < SSH_MAX_IDENTITY_FILES &&
1.132 jakob 1142: (public = sc_get_key(options.smartcard_device)) != NULL ) {
1.127 markus 1143: Key *new;
1144:
1.131 millert 1145: if (options.num_identity_files + 2 > SSH_MAX_IDENTITY_FILES)
1146: options.num_identity_files = SSH_MAX_IDENTITY_FILES - 2;
1147: memmove(&options.identity_files[2], &options.identity_files[0],
1148: sizeof(char *) * options.num_identity_files);
1149: options.num_identity_files += 2;
1150: i = 2;
1151:
1.127 markus 1152: /* XXX ssh1 vs ssh2 */
1153: new = key_new(KEY_RSA);
1154: new->flags = KEY_FLAG_EXT;
1155: BN_copy(new->rsa->n, public->rsa->n);
1156: BN_copy(new->rsa->e, public->rsa->e);
1157: RSA_set_method(new->rsa, sc_get_engine());
1.131 millert 1158: options.identity_keys[0] = new;
1159: options.identity_files[0] = xstrdup("smartcard rsa key");;
1.127 markus 1160:
1161: new = key_new(KEY_RSA1);
1162: new->flags = KEY_FLAG_EXT;
1163: BN_copy(new->rsa->n, public->rsa->n);
1164: BN_copy(new->rsa->e, public->rsa->e);
1165: RSA_set_method(new->rsa, sc_get_engine());
1.131 millert 1166: options.identity_keys[1] = new;
1167: options.identity_files[1] = xstrdup("smartcard rsa1 key");
1.127 markus 1168:
1169: key_free(public);
1170: }
1171: #endif
1.131 millert 1172: for (; i < options.num_identity_files; i++) {
1173: filename = tilde_expand_filename(options.identity_files[i],
1174: original_real_uid);
1175: public = key_load_public(filename, NULL);
1176: debug("identity file %s type %d", filename,
1177: public ? public->type : -1);
1178: xfree(options.identity_files[i]);
1179: options.identity_files[i] = filename;
1180: options.identity_keys[i] = public;
1181: }
1.1 deraadt 1182: }