summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-04-30 23:13:25 +0000
committerDamien Miller <djm@mindrot.org>2017-05-01 09:42:37 +1000
commit97f4d3083b036ce3e68d6346a6140a22123d5864 (patch)
tree301c95453934721eca9855cd01b1d0da089e3246 /ssh.c
parent99f95ba82673d33215dce17bfa1512b57f54ec09 (diff)
upstream commit
remove compat20/compat13/compat15 variables ok markus@ Upstream-ID: 43802c035ceb3fef6c50c400e4ecabf12354691c
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c174
1 files changed, 2 insertions, 172 deletions
diff --git a/ssh.c b/ssh.c
index 766a1790d..a682ce91a 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.454 2017/04/30 23:11:45 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.455 2017/04/30 23:13:25 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -209,7 +209,6 @@ usage(void)
209 exit(255); 209 exit(255);
210} 210}
211 211
212static int ssh_session(void);
213static int ssh_session2(void); 212static int ssh_session2(void);
214static void load_public_identity_files(void); 213static void load_public_identity_files(void);
215static void main_sigchld_handler(int); 214static void main_sigchld_handler(int);
@@ -1243,7 +1242,6 @@ main(int ac, char **av)
1243 if ((sock = muxclient(options.control_path)) >= 0) { 1242 if ((sock = muxclient(options.control_path)) >= 0) {
1244 packet_set_connection(sock, sock); 1243 packet_set_connection(sock, sock);
1245 ssh = active_state; /* XXX */ 1244 ssh = active_state; /* XXX */
1246 enable_compat20(); /* XXX */
1247 packet_set_mux(); 1245 packet_set_mux();
1248 goto skip_connect; 1246 goto skip_connect;
1249 } 1247 }
@@ -1447,7 +1445,7 @@ main(int ac, char **av)
1447 } 1445 }
1448 1446
1449 skip_connect: 1447 skip_connect:
1450 exit_status = compat20 ? ssh_session2() : ssh_session(); 1448 exit_status = ssh_session2();
1451 packet_close(); 1449 packet_close();
1452 1450
1453 if (options.control_path != NULL && muxserver_sock != -1) 1451 if (options.control_path != NULL && muxserver_sock != -1)
@@ -1591,8 +1589,6 @@ ssh_init_stdio_forwarding(void)
1591 1589
1592 if (options.stdio_forward_host == NULL) 1590 if (options.stdio_forward_host == NULL)
1593 return; 1591 return;
1594 if (!compat20)
1595 fatal("stdio forwarding require Protocol 2");
1596 1592
1597 debug3("%s: %s:%d", __func__, options.stdio_forward_host, 1593 debug3("%s: %s:%d", __func__, options.stdio_forward_host,
1598 options.stdio_forward_port); 1594 options.stdio_forward_port);
@@ -1691,172 +1687,6 @@ check_agent_present(void)
1691 } 1687 }
1692} 1688}
1693 1689
1694static int
1695ssh_session(void)
1696{
1697 int type;
1698 int interactive = 0;
1699 int have_tty = 0;
1700 struct winsize ws;
1701 char *cp;
1702 const char *display;
1703 char *proto = NULL, *data = NULL;
1704
1705 /* Enable compression if requested. */
1706 if (options.compression) {
1707 debug("Requesting compression at level %d.",
1708 options.compression_level);
1709
1710 if (options.compression_level < 1 ||
1711 options.compression_level > 9)
1712 fatal("Compression level must be from 1 (fast) to "
1713 "9 (slow, best).");
1714
1715 /* Send the request. */
1716 packet_start(SSH_CMSG_REQUEST_COMPRESSION);
1717 packet_put_int(options.compression_level);
1718 packet_send();
1719 packet_write_wait();
1720 type = packet_read();
1721 if (type == SSH_SMSG_SUCCESS)
1722 packet_start_compression(options.compression_level);
1723 else if (type == SSH_SMSG_FAILURE)
1724 logit("Warning: Remote host refused compression.");
1725 else
1726 packet_disconnect("Protocol error waiting for "
1727 "compression response.");
1728 }
1729 /* Allocate a pseudo tty if appropriate. */
1730 if (tty_flag) {
1731 debug("Requesting pty.");
1732
1733 /* Start the packet. */
1734 packet_start(SSH_CMSG_REQUEST_PTY);
1735
1736 /* Store TERM in the packet. There is no limit on the
1737 length of the string. */
1738 cp = getenv("TERM");
1739 if (!cp)
1740 cp = "";
1741 packet_put_cstring(cp);
1742
1743 /* Store window size in the packet. */
1744 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
1745 memset(&ws, 0, sizeof(ws));
1746 packet_put_int((u_int)ws.ws_row);
1747 packet_put_int((u_int)ws.ws_col);
1748 packet_put_int((u_int)ws.ws_xpixel);
1749 packet_put_int((u_int)ws.ws_ypixel);
1750
1751 /* Store tty modes in the packet. */
1752 tty_make_modes(fileno(stdin), NULL);
1753
1754 /* Send the packet, and wait for it to leave. */
1755 packet_send();
1756 packet_write_wait();
1757
1758 /* Read response from the server. */
1759 type = packet_read();
1760 if (type == SSH_SMSG_SUCCESS) {
1761 interactive = 1;
1762 have_tty = 1;
1763 } else if (type == SSH_SMSG_FAILURE)
1764 logit("Warning: Remote host failed or refused to "
1765 "allocate a pseudo tty.");
1766 else
1767 packet_disconnect("Protocol error waiting for pty "
1768 "request response.");
1769 }
1770 /* Request X11 forwarding if enabled and DISPLAY is set. */
1771 display = getenv("DISPLAY");
1772 if (display == NULL && options.forward_x11)
1773 debug("X11 forwarding requested but DISPLAY not set");
1774 if (options.forward_x11 && client_x11_get_proto(display,
1775 options.xauth_location, options.forward_x11_trusted,
1776 options.forward_x11_timeout, &proto, &data) == 0) {
1777 /* Request forwarding with authentication spoofing. */
1778 debug("Requesting X11 forwarding with authentication "
1779 "spoofing.");
1780 x11_request_forwarding_with_spoofing(0, display, proto,
1781 data, 0);
1782 /* Read response from the server. */
1783 type = packet_read();
1784 if (type == SSH_SMSG_SUCCESS) {
1785 interactive = 1;
1786 } else if (type == SSH_SMSG_FAILURE) {
1787 logit("Warning: Remote host denied X11 forwarding.");
1788 } else {
1789 packet_disconnect("Protocol error waiting for X11 "
1790 "forwarding");
1791 }
1792 }
1793 /* Tell the packet module whether this is an interactive session. */
1794 packet_set_interactive(interactive,
1795 options.ip_qos_interactive, options.ip_qos_bulk);
1796
1797 /* Request authentication agent forwarding if appropriate. */
1798 check_agent_present();
1799
1800 if (options.forward_agent) {
1801 debug("Requesting authentication agent forwarding.");
1802 auth_request_forwarding();
1803
1804 /* Read response from the server. */
1805 type = packet_read();
1806 packet_check_eom();
1807 if (type != SSH_SMSG_SUCCESS)
1808 logit("Warning: Remote host denied authentication agent forwarding.");
1809 }
1810
1811 /* Initiate port forwardings. */
1812 ssh_init_stdio_forwarding();
1813 ssh_init_forwarding();
1814
1815 /* Execute a local command */
1816 if (options.local_command != NULL &&
1817 options.permit_local_command)
1818 ssh_local_cmd(options.local_command);
1819
1820 /*
1821 * If requested and we are not interested in replies to remote
1822 * forwarding requests, then let ssh continue in the background.
1823 */
1824 if (fork_after_authentication_flag) {
1825 if (options.exit_on_forward_failure &&
1826 options.num_remote_forwards > 0) {
1827 debug("deferring postauth fork until remote forward "
1828 "confirmation received");
1829 } else
1830 fork_postauth();
1831 }
1832
1833 /*
1834 * If a command was specified on the command line, execute the
1835 * command now. Otherwise request the server to start a shell.
1836 */
1837 if (buffer_len(&command) > 0) {
1838 int len = buffer_len(&command);
1839 if (len > 900)
1840 len = 900;
1841 debug("Sending command: %.*s", len,
1842 (u_char *)buffer_ptr(&command));
1843 packet_start(SSH_CMSG_EXEC_CMD);
1844 packet_put_string(buffer_ptr(&command), buffer_len(&command));
1845 packet_send();
1846 packet_write_wait();
1847 } else {
1848 debug("Requesting shell.");
1849 packet_start(SSH_CMSG_EXEC_SHELL);
1850 packet_send();
1851 packet_write_wait();
1852 }
1853
1854 /* Enter the interactive session. */
1855 return client_loop(have_tty, tty_flag ?
1856 options.escape_char : SSH_ESCAPECHAR_NONE, 0);
1857}
1858
1859/* request pty/x11/agent/tcpfwd/shell for channel */
1860static void 1690static void
1861ssh_session2_setup(int id, int success, void *arg) 1691ssh_session2_setup(int id, int success, void *arg)
1862{ 1692{