diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-01-19 21:36:06 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-01-20 09:02:36 +1100 |
commit | 25b2ed667216314471bb66752442c55b95792dc3 (patch) | |
tree | 097d6cb701930d021d408ce9e7f0caae85ac625a | |
parent | e3128b38623eef2fa8d6e7ae934d3bd08c7e973e (diff) |
upstream: convert ssh.c to new packet API
with & ok markus@
OpenBSD-Commit-ID: eb146878b24e85c2a09ee171afa6797c166a2e21
-rw-r--r-- | ssh.c | 67 |
1 files changed, 41 insertions, 26 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh.c,v 1.498 2019/01/19 21:31:32 djm Exp $ */ | 1 | /* $OpenBSD: ssh.c,v 1.499 2019/01/19 21:36:06 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 |
@@ -113,8 +113,7 @@ | |||
113 | #include "ssh-pkcs11.h" | 113 | #include "ssh-pkcs11.h" |
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | #include "opacket.h" /* XXX */ | 116 | extern struct ssh *active_state; /* XXX remove after sshconnect2.c updated */ |
117 | extern struct ssh *active_state; /* XXX move here */ | ||
118 | 117 | ||
119 | extern char *__progname; | 118 | extern char *__progname; |
120 | 119 | ||
@@ -653,8 +652,8 @@ main(int ac, char **av) | |||
653 | */ | 652 | */ |
654 | if ((ssh = ssh_alloc_session_state()) == NULL) | 653 | if ((ssh = ssh_alloc_session_state()) == NULL) |
655 | fatal("Couldn't allocate session state"); | 654 | fatal("Couldn't allocate session state"); |
655 | active_state = ssh; /* XXX */ | ||
656 | channel_init_channels(ssh); | 656 | channel_init_channels(ssh); |
657 | active_state = ssh; /* XXX legacy API compat */ | ||
658 | 657 | ||
659 | /* Parse command-line arguments. */ | 658 | /* Parse command-line arguments. */ |
660 | host = NULL; | 659 | host = NULL; |
@@ -1351,7 +1350,7 @@ main(int ac, char **av) | |||
1351 | int sock; | 1350 | int sock; |
1352 | if ((sock = muxclient(options.control_path)) >= 0) { | 1351 | if ((sock = muxclient(options.control_path)) >= 0) { |
1353 | ssh_packet_set_connection(ssh, sock, sock); | 1352 | ssh_packet_set_connection(ssh, sock, sock); |
1354 | packet_set_mux(); | 1353 | ssh_packet_set_mux(ssh); |
1355 | goto skip_connect; | 1354 | goto skip_connect; |
1356 | } | 1355 | } |
1357 | } | 1356 | } |
@@ -1378,11 +1377,9 @@ main(int ac, char **av) | |||
1378 | if (addrs != NULL) | 1377 | if (addrs != NULL) |
1379 | freeaddrinfo(addrs); | 1378 | freeaddrinfo(addrs); |
1380 | 1379 | ||
1381 | packet_set_timeout(options.server_alive_interval, | 1380 | ssh_packet_set_timeout(ssh, options.server_alive_interval, |
1382 | options.server_alive_count_max); | 1381 | options.server_alive_count_max); |
1383 | 1382 | ||
1384 | ssh = active_state; /* XXX */ | ||
1385 | |||
1386 | if (timeout_ms > 0) | 1383 | if (timeout_ms > 0) |
1387 | debug3("timeout: %d ms remain after connect", timeout_ms); | 1384 | debug3("timeout: %d ms remain after connect", timeout_ms); |
1388 | 1385 | ||
@@ -1496,7 +1493,7 @@ main(int ac, char **av) | |||
1496 | ssh_login(ssh, &sensitive_data, host, (struct sockaddr *)&hostaddr, | 1493 | ssh_login(ssh, &sensitive_data, host, (struct sockaddr *)&hostaddr, |
1497 | options.port, pw, timeout_ms); | 1494 | options.port, pw, timeout_ms); |
1498 | 1495 | ||
1499 | if (packet_connection_is_on_socket()) { | 1496 | if (ssh_packet_connection_is_on_socket(ssh)) { |
1500 | verbose("Authenticated to %s ([%s]:%d).", host, | 1497 | verbose("Authenticated to %s ([%s]:%d).", host, |
1501 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh)); | 1498 | ssh_remote_ipaddr(ssh), ssh_remote_port(ssh)); |
1502 | } else { | 1499 | } else { |
@@ -1530,7 +1527,7 @@ main(int ac, char **av) | |||
1530 | 1527 | ||
1531 | skip_connect: | 1528 | skip_connect: |
1532 | exit_status = ssh_session2(ssh, pw); | 1529 | exit_status = ssh_session2(ssh, pw); |
1533 | packet_close(); | 1530 | ssh_packet_close(ssh); |
1534 | 1531 | ||
1535 | if (options.control_path != NULL && muxserver_sock != -1) | 1532 | if (options.control_path != NULL && muxserver_sock != -1) |
1536 | unlink(options.control_path); | 1533 | unlink(options.control_path); |
@@ -1605,6 +1602,8 @@ static void | |||
1605 | ssh_confirm_remote_forward(struct ssh *ssh, int type, u_int32_t seq, void *ctxt) | 1602 | ssh_confirm_remote_forward(struct ssh *ssh, int type, u_int32_t seq, void *ctxt) |
1606 | { | 1603 | { |
1607 | struct Forward *rfwd = (struct Forward *)ctxt; | 1604 | struct Forward *rfwd = (struct Forward *)ctxt; |
1605 | u_int port; | ||
1606 | int r; | ||
1608 | 1607 | ||
1609 | /* XXX verbose() on failure? */ | 1608 | /* XXX verbose() on failure? */ |
1610 | debug("remote forward %s for: listen %s%s%d, connect %s:%d", | 1609 | debug("remote forward %s for: listen %s%s%d, connect %s:%d", |
@@ -1616,12 +1615,25 @@ ssh_confirm_remote_forward(struct ssh *ssh, int type, u_int32_t seq, void *ctxt) | |||
1616 | rfwd->connect_host, rfwd->connect_port); | 1615 | rfwd->connect_host, rfwd->connect_port); |
1617 | if (rfwd->listen_path == NULL && rfwd->listen_port == 0) { | 1616 | if (rfwd->listen_path == NULL && rfwd->listen_port == 0) { |
1618 | if (type == SSH2_MSG_REQUEST_SUCCESS) { | 1617 | if (type == SSH2_MSG_REQUEST_SUCCESS) { |
1619 | rfwd->allocated_port = packet_get_int(); | 1618 | if ((r = sshpkt_get_u32(ssh, &port)) != 0) |
1620 | logit("Allocated port %u for remote forward to %s:%d", | 1619 | fatal("%s: %s", __func__, ssh_err(r)); |
1621 | rfwd->allocated_port, | 1620 | if (port > 65535) { |
1622 | rfwd->connect_host, rfwd->connect_port); | 1621 | error("Invalid allocated port %u for remote " |
1623 | channel_update_permission(ssh, | 1622 | "forward to %s:%d", port, |
1624 | rfwd->handle, rfwd->allocated_port); | 1623 | rfwd->connect_host, rfwd->connect_port); |
1624 | /* Ensure failure processing runs below */ | ||
1625 | type = SSH2_MSG_REQUEST_FAILURE; | ||
1626 | channel_update_permission(ssh, | ||
1627 | rfwd->handle, -1); | ||
1628 | } else { | ||
1629 | rfwd->allocated_port = (int)port; | ||
1630 | logit("Allocated port %u for remote " | ||
1631 | "forward to %s:%d", | ||
1632 | rfwd->allocated_port, rfwd->connect_host, | ||
1633 | rfwd->connect_port); | ||
1634 | channel_update_permission(ssh, | ||
1635 | rfwd->handle, rfwd->allocated_port); | ||
1636 | } | ||
1625 | } else { | 1637 | } else { |
1626 | channel_update_permission(ssh, rfwd->handle, -1); | 1638 | channel_update_permission(ssh, rfwd->handle, -1); |
1627 | } | 1639 | } |
@@ -1778,7 +1790,7 @@ ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg) | |||
1778 | { | 1790 | { |
1779 | extern char **environ; | 1791 | extern char **environ; |
1780 | const char *display; | 1792 | const char *display; |
1781 | int interactive = tty_flag; | 1793 | int r, interactive = tty_flag; |
1782 | char *proto = NULL, *data = NULL; | 1794 | char *proto = NULL, *data = NULL; |
1783 | 1795 | ||
1784 | if (!success) | 1796 | if (!success) |
@@ -1804,11 +1816,12 @@ ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg) | |||
1804 | if (options.forward_agent) { | 1816 | if (options.forward_agent) { |
1805 | debug("Requesting authentication agent forwarding."); | 1817 | debug("Requesting authentication agent forwarding."); |
1806 | channel_request_start(ssh, id, "auth-agent-req@openssh.com", 0); | 1818 | channel_request_start(ssh, id, "auth-agent-req@openssh.com", 0); |
1807 | packet_send(); | 1819 | if ((r = sshpkt_send(ssh)) != 0) |
1820 | fatal("%s: %s", __func__, ssh_err(r)); | ||
1808 | } | 1821 | } |
1809 | 1822 | ||
1810 | /* Tell the packet module whether this is an interactive session. */ | 1823 | /* Tell the packet module whether this is an interactive session. */ |
1811 | packet_set_interactive(interactive, | 1824 | ssh_packet_set_interactive(ssh, interactive, |
1812 | options.ip_qos_interactive, options.ip_qos_bulk); | 1825 | options.ip_qos_interactive, options.ip_qos_bulk); |
1813 | 1826 | ||
1814 | client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"), | 1827 | client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"), |
@@ -1865,7 +1878,7 @@ ssh_session2_open(struct ssh *ssh) | |||
1865 | static int | 1878 | static int |
1866 | ssh_session2(struct ssh *ssh, struct passwd *pw) | 1879 | ssh_session2(struct ssh *ssh, struct passwd *pw) |
1867 | { | 1880 | { |
1868 | int devnull, id = -1; | 1881 | int r, devnull, id = -1; |
1869 | char *cp, *tun_fwd_ifname = NULL; | 1882 | char *cp, *tun_fwd_ifname = NULL; |
1870 | 1883 | ||
1871 | /* XXX should be pre-session */ | 1884 | /* XXX should be pre-session */ |
@@ -1895,7 +1908,7 @@ ssh_session2(struct ssh *ssh, struct passwd *pw) | |||
1895 | } | 1908 | } |
1896 | 1909 | ||
1897 | /* Start listening for multiplex clients */ | 1910 | /* Start listening for multiplex clients */ |
1898 | if (!packet_get_mux()) | 1911 | if (!ssh_packet_get_mux(ssh)) |
1899 | muxserver_listen(ssh); | 1912 | muxserver_listen(ssh); |
1900 | 1913 | ||
1901 | /* | 1914 | /* |
@@ -1929,7 +1942,7 @@ ssh_session2(struct ssh *ssh, struct passwd *pw) | |||
1929 | if (!no_shell_flag) | 1942 | if (!no_shell_flag) |
1930 | id = ssh_session2_open(ssh); | 1943 | id = ssh_session2_open(ssh); |
1931 | else { | 1944 | else { |
1932 | packet_set_interactive( | 1945 | ssh_packet_set_interactive(ssh, |
1933 | options.control_master == SSHCTL_MASTER_NO, | 1946 | options.control_master == SSHCTL_MASTER_NO, |
1934 | options.ip_qos_interactive, options.ip_qos_bulk); | 1947 | options.ip_qos_interactive, options.ip_qos_bulk); |
1935 | } | 1948 | } |
@@ -1938,10 +1951,12 @@ ssh_session2(struct ssh *ssh, struct passwd *pw) | |||
1938 | if (options.control_master == SSHCTL_MASTER_NO && | 1951 | if (options.control_master == SSHCTL_MASTER_NO && |
1939 | (datafellows & SSH_NEW_OPENSSH)) { | 1952 | (datafellows & SSH_NEW_OPENSSH)) { |
1940 | debug("Requesting no-more-sessions@openssh.com"); | 1953 | debug("Requesting no-more-sessions@openssh.com"); |
1941 | packet_start(SSH2_MSG_GLOBAL_REQUEST); | 1954 | if ((r = sshpkt_start(ssh, SSH2_MSG_GLOBAL_REQUEST)) != 0 || |
1942 | packet_put_cstring("no-more-sessions@openssh.com"); | 1955 | (r = sshpkt_put_cstring(ssh, |
1943 | packet_put_char(0); | 1956 | "no-more-sessions@openssh.com")) != 0 || |
1944 | packet_send(); | 1957 | (r = sshpkt_put_u8(ssh, 0)) != 0 || |
1958 | (r = sshpkt_send(ssh)) != 0) | ||
1959 | fatal("%s: %s", __func__, ssh_err(r)); | ||
1945 | } | 1960 | } |
1946 | 1961 | ||
1947 | /* Execute a local command */ | 1962 | /* Execute a local command */ |