2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * Created: Sat Mar 18 16:36:11 1995 ylo
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.
10 * Modified to work with SSL by Niels Provos <provos@citi.umich.edu> in Canada.
16 #include <openssl/evp.h>
17 #include <openssl/dsa.h>
18 #include <openssl/rsa.h>
34 #ifdef HAVE___PROGNAME
35 extern char *__progname;
36 #else /* HAVE___PROGNAME */
37 const char *__progname = "ssh";
38 #endif /* HAVE___PROGNAME */
40 /* Flag indicating whether IPv4 or IPv6. This can be set on the command line.
41 Default value is AF_UNSPEC means both IPv4 and IPv6. */
43 int IPv4or6 = AF_INET;
45 int IPv4or6 = AF_UNSPEC;
48 /* Flag indicating whether debug mode is on. This can be set on the command line. */
51 /* Flag indicating whether a tty should be allocated */
54 /* don't exec a shell */
55 int no_shell_flag = 0;
59 * Flag indicating that nothing should be read from stdin. This can be set
60 * on the command line.
62 int stdin_null_flag = 0;
65 * Flag indicating that ssh should fork after authentication. This is useful
66 * so that the pasphrase can be entered manually, and then ssh goes to the
69 int fork_after_authentication_flag = 0;
72 * General data structure for command line options and options configurable
73 * in configuration files. See readconf.h.
78 * Name of the host we are connecting to. This is the name given on the
79 * command line, or the HostName specified for the user-supplied name in a
84 /* socket address the host resolves to */
85 struct sockaddr_storage hostaddr;
88 * Flag to indicate that we have received a window change signal which has
89 * not yet been processed. This will cause a message indicating the new
90 * window size to be sent to the server a little later. This is volatile
91 * because this is updated in a signal handler.
93 volatile int received_window_change_signal = 0;
95 /* Value of argv[0] (set in the main program). */
98 /* Flag indicating whether we have a valid host private key loaded. */
99 int host_private_key_loaded = 0;
101 /* Host private key. */
102 RSA *host_private_key = NULL;
104 /* Original real UID. */
105 uid_t original_real_uid;
107 /* command to be executed */
110 /* Prints a help message to the user. This function never returns. */
115 fprintf(stderr, "Usage: %s [options] host [command]\n", av0);
116 fprintf(stderr, "Options:\n");
117 fprintf(stderr, " -l user Log in using this user name.\n");
118 fprintf(stderr, " -n Redirect input from /dev/null.\n");
119 fprintf(stderr, " -a Disable authentication agent forwarding.\n");
121 fprintf(stderr, " -k Disable Kerberos ticket and AFS token forwarding.\n");
123 fprintf(stderr, " -x Disable X11 connection forwarding.\n");
124 fprintf(stderr, " -i file Identity for RSA authentication (default: ~/.ssh/identity).\n");
125 fprintf(stderr, " -t Tty; allocate a tty even if command is given.\n");
126 fprintf(stderr, " -T Do not allocate a tty.\n");
127 fprintf(stderr, " -v Verbose; display verbose debugging messages.\n");
128 fprintf(stderr, " -V Display version number only.\n");
129 fprintf(stderr, " -P Don't allocate a privileged port.\n");
130 fprintf(stderr, " -q Quiet; don't display any warning messages.\n");
131 fprintf(stderr, " -f Fork into background after authentication.\n");
132 fprintf(stderr, " -e char Set escape character; ``none'' = disable (default: ~).\n");
134 fprintf(stderr, " -c cipher Select encryption algorithm: "
137 fprintf(stderr, " -p port Connect to this port. Server must be on the same port.\n");
138 fprintf(stderr, " -L listen-port:host:port Forward local port to remote address\n");
139 fprintf(stderr, " -R listen-port:host:port Forward remote port to local address\n");
140 fprintf(stderr, " These cause %s to listen for connections on a port, and\n", av0);
141 fprintf(stderr, " forward them to the other side by connecting to host:port.\n");
142 fprintf(stderr, " -C Enable compression.\n");
143 fprintf(stderr, " -N Do not execute a shell or command.\n");
144 fprintf(stderr, " -g Allow remote hosts to connect to forwarded ports.\n");
145 fprintf(stderr, " -4 Use IPv4 only.\n");
146 fprintf(stderr, " -6 Use IPv6 only.\n");
147 fprintf(stderr, " -2 Force protocol version 2.\n");
148 fprintf(stderr, " -o 'option' Process the option as if it was read from a configuration file.\n");
153 * Connects to the given host using rsh (or prints an error message and exits
154 * if rsh is not available). This function never returns.
157 rsh_connect(char *host, char *user, Buffer * command)
162 log("Using rsh. WARNING: Connection will not be encrypted.");
163 /* Build argument list for rsh. */
165 args[i++] = _PATH_RSH;
166 /* host may have to come after user on some systems */
172 if (buffer_len(command) > 0) {
173 buffer_append(command, "\0", 1);
174 args[i++] = buffer_ptr(command);
178 for (i = 0; args[i]; i++) {
180 fprintf(stderr, " ");
181 fprintf(stderr, "%s", args[i]);
183 fprintf(stderr, "\n");
185 execv(_PATH_RSH, args);
190 int ssh_session(void);
191 int ssh_session2(void);
194 * Main program for the ssh client.
197 main(int ac, char **av)
199 int i, opt, optind, exit_status, ok;
200 u_short fwd_port, fwd_host_port;
201 char *optarg, *cp, buf[256];
203 struct passwd *pw, pwcopy;
205 uid_t original_effective_uid;
208 * Save the original real uid. It will be needed later (uid-swapping
209 * may clobber the real uid).
211 original_real_uid = getuid();
212 original_effective_uid = geteuid();
214 /* If we are installed setuid root be careful to not drop core. */
215 if (original_real_uid != original_effective_uid) {
217 rlim.rlim_cur = rlim.rlim_max = 0;
218 if (setrlimit(RLIMIT_CORE, &rlim) < 0)
219 fatal("setrlimit failed: %.100s", strerror(errno));
222 * Use uid-swapping to give up root privileges for the duration of
223 * option processing. We will re-instantiate the rights when we are
224 * ready to create the privileged port, and will permanently drop
225 * them when the port has been created (actually, when the connection
226 * has been made, as we may need to create the port several times).
228 temporarily_use_uid(original_real_uid);
231 * Set our umask to something reasonable, as some files are created
232 * with the default umask. This will make them world-readable but
233 * writable only by the owner, which is ok for all files for which we
234 * don't set the modes explicitly.
238 /* Save our own name. */
241 /* Initialize option structure to indicate that no values have been set. */
242 initialize_options(&options);
244 /* Parse command-line arguments. */
247 /* If program name is not one of the standard names, use it as host name. */
248 if (strchr(av0, '/'))
249 cp = strrchr(av0, '/') + 1;
252 if (strcmp(cp, "rsh") != 0 && strcmp(cp, "ssh") != 0 &&
253 strcmp(cp, "rlogin") != 0 && strcmp(cp, "slogin") != 0)
256 for (optind = 1; optind < ac; optind++) {
257 if (av[optind][0] != '-') {
260 if ((cp = strchr(av[optind], '@'))) {
263 options.user = av[optind];
273 if (strchr("eilcpLRo", opt)) { /* options with arguments */
274 optarg = av[optind] + 2;
275 if (strcmp(optarg, "") == 0) {
276 if (optind >= ac - 1)
278 optarg = av[++optind];
287 options.protocol = SSH_PROTO_2;
299 fork_after_authentication_flag = 1;
303 options.forward_x11 = 0;
306 options.forward_x11 = 1;
309 options.gateway_ports = 1;
312 options.use_privileged_port = 0;
315 options.forward_agent = 0;
319 options.kerberos_tgt_passing = 0;
320 options.afs_token_passing = 0;
324 if (stat(optarg, &st) < 0) {
325 fprintf(stderr, "Warning: Identity file %s does not exist.\n",
329 if (options.num_identity_files >= SSH_MAX_IDENTITY_FILES)
330 fatal("Too many identity files specified (max %d)",
331 SSH_MAX_IDENTITY_FILES);
332 options.identity_files[options.num_identity_files++] =
340 fprintf(stderr, "SSH Version %s, protocol versions %d.%d/%d.%d.\n",
342 PROTOCOL_MAJOR_1, PROTOCOL_MINOR_1,
343 PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2);
344 fprintf(stderr, "Compiled with SSL (0x%8.8lx).\n", SSLeay());
348 options.log_level = SYSLOG_LEVEL_DEBUG;
351 options.log_level = SYSLOG_LEVEL_QUIET;
354 if (optarg[0] == '^' && optarg[2] == 0 &&
355 (unsigned char) optarg[1] >= 64 && (unsigned char) optarg[1] < 128)
356 options.escape_char = (unsigned char) optarg[1] & 31;
357 else if (strlen(optarg) == 1)
358 options.escape_char = (unsigned char) optarg[0];
359 else if (strcmp(optarg, "none") == 0)
360 options.escape_char = -2;
362 fprintf(stderr, "Bad escape character '%s'.\n", optarg);
367 if (ciphers_valid(optarg)) {
369 options.ciphers = xstrdup(optarg);
372 options.cipher = cipher_number(optarg);
373 if (options.cipher == -1) {
374 fprintf(stderr, "Unknown cipher type '%s'\n", optarg);
380 options.port = atoi(optarg);
383 options.user = optarg;
386 if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf,
387 &fwd_host_port) != 3 &&
388 sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf,
389 &fwd_host_port) != 3) {
390 fprintf(stderr, "Bad forwarding specification '%s'.\n", optarg);
394 add_remote_forward(&options, fwd_port, buf, fwd_host_port);
397 if (sscanf(optarg, "%hu/%255[^/]/%hu", &fwd_port, buf,
398 &fwd_host_port) != 3 &&
399 sscanf(optarg, "%hu:%255[^:]:%hu", &fwd_port, buf,
400 &fwd_host_port) != 3) {
401 fprintf(stderr, "Bad forwarding specification '%s'.\n", optarg);
405 add_local_forward(&options, fwd_port, buf, fwd_host_port);
408 options.compression = 1;
419 if (process_config_line(&options, host ? host : "", optarg,
420 "command-line", 0, &dummy) != 0)
428 /* Check that we got a host name. */
432 /* Initialize the command to execute on remote host. */
433 buffer_init(&command);
435 OpenSSL_add_all_algorithms();
438 * Save the command to execute on the remote host in a buffer. There
439 * is no limit on the length of the command, except by the maximum
440 * packet size. Also sets the tty flag if there is no command.
443 /* No command specified - execute shell on a tty. */
446 /* A command has been specified. Store it into the
448 for (i = optind; i < ac; i++) {
450 buffer_append(&command, " ", 1);
451 buffer_append(&command, av[i], strlen(av[i]));
455 /* Cannot fork to background if no command. */
456 if (fork_after_authentication_flag && buffer_len(&command) == 0)
457 fatal("Cannot fork into background without a command to execute.");
459 /* Allocate a tty by default if no command specified. */
460 if (buffer_len(&command) == 0)
463 /* Do not allocate a tty if stdin is not a tty. */
464 if (!isatty(fileno(stdin))) {
466 fprintf(stderr, "Pseudo-terminal will not be allocated because stdin is not a terminal.\n");
474 pw = getpwuid(original_real_uid);
476 fprintf(stderr, "You don't exist, go away!\n");
479 /* Take a copy of the returned structure. */
480 memset(&pwcopy, 0, sizeof(pwcopy));
481 pwcopy.pw_name = xstrdup(pw->pw_name);
482 pwcopy.pw_passwd = xstrdup(pw->pw_passwd);
483 pwcopy.pw_uid = pw->pw_uid;
484 pwcopy.pw_gid = pw->pw_gid;
485 pwcopy.pw_dir = xstrdup(pw->pw_dir);
486 pwcopy.pw_shell = xstrdup(pw->pw_shell);
489 /* Initialize "log" output. Since we are the client all output
490 actually goes to the terminal. */
491 log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 0);
493 /* Read per-user configuration file. */
494 snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, SSH_USER_CONFFILE);
495 read_config_file(buf, host, &options);
497 /* Read systemwide configuration file. */
498 read_config_file(HOST_CONFIG_FILE, host, &options);
500 /* Fill configuration defaults. */
501 fill_default_options(&options);
504 log_init(av[0], options.log_level, SYSLOG_FACILITY_USER, 0);
506 /* check if RSA support exists */
507 if ((options.protocol & SSH_PROTO_1) &&
509 log("%s: no RSA support in libssl and libcrypto. See ssl(8).",
511 log("Disabling protocol version 1");
512 options.protocol &= ~ (SSH_PROTO_1|SSH_PROTO_1_PREFERRED);
514 if (! options.protocol & (SSH_PROTO_1|SSH_PROTO_2)) {
515 fprintf(stderr, "%s: No protocol version available.\n",
520 if (options.user == NULL)
521 options.user = xstrdup(pw->pw_name);
523 if (options.hostname != NULL)
524 host = options.hostname;
526 /* Find canonic host name. */
527 if (strchr(host, '.') == 0) {
528 struct addrinfo hints;
529 struct addrinfo *ai = NULL;
531 memset(&hints, 0, sizeof(hints));
532 hints.ai_family = IPv4or6;
533 hints.ai_flags = AI_CANONNAME;
534 hints.ai_socktype = SOCK_STREAM;
535 errgai = getaddrinfo(host, NULL, &hints, &ai);
537 if (ai->ai_canonname != NULL)
538 host = xstrdup(ai->ai_canonname);
542 /* Disable rhosts authentication if not running as root. */
543 if (original_effective_uid != 0 || !options.use_privileged_port) {
544 options.rhosts_authentication = 0;
545 options.rhosts_rsa_authentication = 0;
548 * If using rsh has been selected, exec it now (without trying
549 * anything else). Note that we must release privileges first.
551 if (options.use_rsh) {
553 * Restore our superuser privileges. This must be done
554 * before permanently setting the uid.
558 /* Switch to the original uid permanently. */
559 permanently_set_uid(original_real_uid);
562 rsh_connect(host, options.user, &command);
563 fatal("rsh_connect returned");
565 /* Restore our superuser privileges. */
569 * Open a connection to the remote host. This needs root privileges
570 * if rhosts_{rsa_}authentication is enabled.
573 ok = ssh_connect(host, &hostaddr, options.port,
574 options.connection_attempts,
575 !options.rhosts_authentication &&
576 !options.rhosts_rsa_authentication,
578 options.proxy_command);
581 * If we successfully made the connection, load the host private key
582 * in case we will need it later for combined rsa-rhosts
583 * authentication. This must be done before releasing extra
584 * privileges, because the file is only readable by root.
586 if (ok && (options.protocol & SSH_PROTO_1)) {
588 host_private_key = RSA_new();
590 k.rsa = host_private_key;
591 if (load_private_key(HOST_KEY_FILE, "", &k, NULL))
592 host_private_key_loaded = 1;
595 * Get rid of any extra privileges that we may have. We will no
596 * longer need them. Also, extra privileges could make it very hard
597 * to read identity files and other non-world-readable files from the
598 * user's home directory if it happens to be on a NFS volume where
599 * root is mapped to nobody.
603 * Note that some legacy systems need to postpone the following call
604 * to permanently_set_uid() until the private hostkey is destroyed
605 * with RSA_free(). Otherwise the calling user could ptrace() the
606 * process, read the private hostkey and impersonate the host.
607 * OpenBSD does not allow ptracing of setuid processes.
609 permanently_set_uid(original_real_uid);
612 * Now that we are back to our own permissions, create ~/.ssh
613 * directory if it doesn\'t already exist.
615 snprintf(buf, sizeof buf, "%.100s/%.100s", pw->pw_dir, SSH_USER_DIR);
616 if (stat(buf, &st) < 0)
617 if (mkdir(buf, 0755) < 0)
618 error("Could not create directory '%.200s'.", buf);
620 /* Check if the connection failed, and try "rsh" if appropriate. */
622 if (options.port != 0)
623 log("Secure connection to %.100s on port %hu refused%.100s.",
625 options.fallback_to_rsh ? "; reverting to insecure method" : "");
627 log("Secure connection to %.100s refused%.100s.", host,
628 options.fallback_to_rsh ? "; reverting to insecure method" : "");
630 if (options.fallback_to_rsh) {
631 rsh_connect(host, options.user, &command);
632 fatal("rsh_connect returned");
636 /* Expand ~ in options.identity_files. */
638 for (i = 0; i < options.num_identity_files; i++)
639 options.identity_files[i] =
640 tilde_expand_filename(options.identity_files[i], original_real_uid);
641 for (i = 0; i < options.num_identity_files2; i++)
642 options.identity_files2[i] =
643 tilde_expand_filename(options.identity_files2[i], original_real_uid);
644 /* Expand ~ in known host file names. */
645 options.system_hostfile = tilde_expand_filename(options.system_hostfile,
647 options.user_hostfile = tilde_expand_filename(options.user_hostfile,
649 options.system_hostfile2 = tilde_expand_filename(options.system_hostfile2,
651 options.user_hostfile2 = tilde_expand_filename(options.user_hostfile2,
654 /* Log into the remote system. This never returns if the login fails. */
655 ssh_login(host_private_key_loaded, host_private_key,
656 host, (struct sockaddr *)&hostaddr, original_real_uid);
658 /* We no longer need the host private key. Clear it now. */
659 if (host_private_key_loaded)
660 RSA_free(host_private_key); /* Destroys contents safely */
662 exit_status = compat20 ? ssh_session2() : ssh_session();
679 /* Enable compression if requested. */
680 if (options.compression) {
681 debug("Requesting compression at level %d.", options.compression_level);
683 if (options.compression_level < 1 || options.compression_level > 9)
684 fatal("Compression level must be from 1 (fast) to 9 (slow, best).");
686 /* Send the request. */
687 packet_start(SSH_CMSG_REQUEST_COMPRESSION);
688 packet_put_int(options.compression_level);
691 type = packet_read(&plen);
692 if (type == SSH_SMSG_SUCCESS)
693 packet_start_compression(options.compression_level);
694 else if (type == SSH_SMSG_FAILURE)
695 log("Warning: Remote host refused compression.");
697 packet_disconnect("Protocol error waiting for compression response.");
699 /* Allocate a pseudo tty if appropriate. */
701 debug("Requesting pty.");
703 /* Start the packet. */
704 packet_start(SSH_CMSG_REQUEST_PTY);
706 /* Store TERM in the packet. There is no limit on the
707 length of the string. */
711 packet_put_string(cp, strlen(cp));
713 /* Store window size in the packet. */
714 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
715 memset(&ws, 0, sizeof(ws));
716 packet_put_int(ws.ws_row);
717 packet_put_int(ws.ws_col);
718 packet_put_int(ws.ws_xpixel);
719 packet_put_int(ws.ws_ypixel);
721 /* Store tty modes in the packet. */
722 tty_make_modes(fileno(stdin));
724 /* Send the packet, and wait for it to leave. */
728 /* Read response from the server. */
729 type = packet_read(&plen);
730 if (type == SSH_SMSG_SUCCESS) {
733 } else if (type == SSH_SMSG_FAILURE)
734 log("Warning: Remote host failed or refused to allocate a pseudo tty.");
736 packet_disconnect("Protocol error waiting for pty request response.");
738 /* Request X11 forwarding if enabled and DISPLAY is set. */
739 if (options.forward_x11 && getenv("DISPLAY") != NULL) {
740 char line[512], proto[512], data[512];
742 int forwarded = 0, got_data = 0, i;
745 /* Try to get Xauthority information for the display. */
746 snprintf(line, sizeof line, "%.100s list %.200s 2>/dev/null",
747 XAUTH_PATH, getenv("DISPLAY"));
748 f = popen(line, "r");
749 if (f && fgets(line, sizeof(line), f) &&
750 sscanf(line, "%*s %s %s", proto, data) == 2)
754 #endif /* XAUTH_PATH */
756 * If we didn't get authentication data, just make up some
757 * data. The forwarding code will check the validity of the
758 * response anyway, and substitute this data. The X11
759 * server, however, will ignore this fake data and use
760 * whatever authentication mechanisms it was using otherwise
761 * for the local connection.
766 strlcpy(proto, "MIT-MAGIC-COOKIE-1", sizeof proto);
767 for (i = 0; i < 16; i++) {
770 snprintf(data + 2 * i, sizeof data - 2 * i, "%02x", rand & 0xff);
775 * Got local authentication reasonable information. Request
776 * forwarding with authentication spoofing.
778 debug("Requesting X11 forwarding with authentication spoofing.");
779 x11_request_forwarding_with_spoofing(proto, data);
781 /* Read response from the server. */
782 type = packet_read(&plen);
783 if (type == SSH_SMSG_SUCCESS) {
786 } else if (type == SSH_SMSG_FAILURE)
787 log("Warning: Remote host denied X11 forwarding.");
789 packet_disconnect("Protocol error waiting for X11 forwarding");
791 /* Tell the packet module whether this is an interactive session. */
792 packet_set_interactive(interactive, options.keepalives);
794 /* Clear agent forwarding if we don\'t have an agent. */
795 authfd = ssh_get_authentication_socket();
797 options.forward_agent = 0;
799 ssh_close_authentication_socket(authfd);
801 /* Request authentication agent forwarding if appropriate. */
802 if (options.forward_agent) {
803 debug("Requesting authentication agent forwarding.");
804 auth_request_forwarding();
806 /* Read response from the server. */
807 type = packet_read(&plen);
808 packet_integrity_check(plen, 0, type);
809 if (type != SSH_SMSG_SUCCESS)
810 log("Warning: Remote host denied authentication agent forwarding.");
812 /* Initiate local TCP/IP port forwardings. */
813 for (i = 0; i < options.num_local_forwards; i++) {
814 debug("Connections to local port %d forwarded to remote address %.200s:%d",
815 options.local_forwards[i].port,
816 options.local_forwards[i].host,
817 options.local_forwards[i].host_port);
818 channel_request_local_forwarding(options.local_forwards[i].port,
819 options.local_forwards[i].host,
820 options.local_forwards[i].host_port,
821 options.gateway_ports);
824 /* Initiate remote TCP/IP port forwardings. */
825 for (i = 0; i < options.num_remote_forwards; i++) {
826 debug("Connections to remote port %d forwarded to local address %.200s:%d",
827 options.remote_forwards[i].port,
828 options.remote_forwards[i].host,
829 options.remote_forwards[i].host_port);
830 channel_request_remote_forwarding(options.remote_forwards[i].port,
831 options.remote_forwards[i].host,
832 options.remote_forwards[i].host_port);
835 /* If requested, let ssh continue in the background. */
836 if (fork_after_authentication_flag)
837 if (daemon(1, 1) < 0)
838 fatal("daemon() failed: %.200s", strerror(errno));
841 * If a command was specified on the command line, execute the
842 * command now. Otherwise request the server to start a shell.
844 if (buffer_len(&command) > 0) {
845 int len = buffer_len(&command);
848 debug("Sending command: %.*s", len, buffer_ptr(&command));
849 packet_start(SSH_CMSG_EXEC_CMD);
850 packet_put_string(buffer_ptr(&command), buffer_len(&command));
854 debug("Requesting shell.");
855 packet_start(SSH_CMSG_EXEC_SHELL);
860 /* Enter the interactive session. */
861 return client_loop(have_tty, tty_flag ? options.escape_char : -1);
868 /* Initiate local TCP/IP port forwardings. */
869 for (i = 0; i < options.num_local_forwards; i++) {
870 debug("Connections to local port %d forwarded to remote address %.200s:%d",
871 options.local_forwards[i].port,
872 options.local_forwards[i].host,
873 options.local_forwards[i].host_port);
874 channel_request_local_forwarding(options.local_forwards[i].port,
875 options.local_forwards[i].host,
876 options.local_forwards[i].host_port,
877 options.gateway_ports);
881 extern void client_set_session_ident(int id);
884 client_init(int id, void *arg)
887 debug("client_init id %d arg %d", id, (int)arg);
898 /* Store window size in the packet. */
899 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
900 memset(&ws, 0, sizeof(ws));
902 channel_request_start(id, "pty-req", 0);
903 packet_put_cstring(cp);
904 packet_put_int(ws.ws_col);
905 packet_put_int(ws.ws_row);
906 packet_put_int(ws.ws_xpixel);
907 packet_put_int(ws.ws_ypixel);
908 packet_put_cstring(""); /* XXX: encode terminal modes */
910 /* XXX wait for reply */
912 len = buffer_len(&command);
916 debug("Sending command: %.*s", len, buffer_ptr(&command));
917 channel_request_start(id, "exec", 0);
918 packet_put_string(buffer_ptr(&command), len);
921 channel_request(id, "shell", 0);
923 /* channel_callback(id, SSH2_MSG_OPEN_CONFIGMATION, client_init, 0); */
925 /* register different callback, etc. XXX */
926 client_set_session_ident(id);
932 int window, packetmax, id;
933 int in = dup(STDIN_FILENO);
934 int out = dup(STDOUT_FILENO);
935 int err = dup(STDERR_FILENO);
937 if (in < 0 || out < 0 || err < 0)
938 fatal("dump in/out/err failed");
940 /* should be pre-session */
945 packetmax = window/8;
948 packetmax = window/2;
952 "session", SSH_CHANNEL_OPENING, in, out, err,
953 window, packetmax, CHAN_EXTENDED_WRITE, xstrdup("client-session"));
957 channel_register_callback(id, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, client_init, (void *)0);
959 return client_loop(tty_flag, tty_flag ? options.escape_char : -1);