summaryrefslogtreecommitdiff
path: root/clientloop.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2014-07-18 14:11:24 +1000
committerDamien Miller <djm@mindrot.org>2014-07-18 14:11:24 +1000
commit7acefbbcbeab725420ea07397ae35992f505f702 (patch)
treebfb07917715d425438dab987a47ccd7a8d7f118b /clientloop.c
parent6262d760e00714523633bd989d62e273a3dca99a (diff)
- millert@cvs.openbsd.org 2014/07/15 15:54:14
[PROTOCOL auth-options.c auth-passwd.c auth-rh-rsa.c auth-rhosts.c] [auth-rsa.c auth.c auth1.c auth2-hostbased.c auth2-kbdint.c auth2-none.c] [auth2-passwd.c auth2-pubkey.c auth2.c canohost.c channels.c channels.h] [clientloop.c misc.c misc.h monitor.c mux.c packet.c readconf.c] [readconf.h servconf.c servconf.h serverloop.c session.c ssh-agent.c] [ssh.c ssh_config.5 sshconnect.c sshconnect1.c sshconnect2.c sshd.c] [sshd_config.5 sshlogin.c] Add support for Unix domain socket forwarding. A remote TCP port may be forwarded to a local Unix domain socket and vice versa or both ends may be a Unix domain socket. This is a reimplementation of the streamlocal patches by William Ahern from: http://www.25thandclement.com/~william/projects/streamlocal.html OK djm@ markus@
Diffstat (limited to 'clientloop.c')
-rw-r--r--clientloop.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/clientloop.c b/clientloop.c
index 02510e26d..397c96532 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: clientloop.c,v 1.260 2014/06/27 16:41:56 markus Exp $ */ 1/* $OpenBSD: clientloop.c,v 1.261 2014/07/15 15:54:14 millert 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
@@ -100,13 +100,13 @@
100#include "cipher.h" 100#include "cipher.h"
101#include "kex.h" 101#include "kex.h"
102#include "log.h" 102#include "log.h"
103#include "misc.h"
103#include "readconf.h" 104#include "readconf.h"
104#include "clientloop.h" 105#include "clientloop.h"
105#include "sshconnect.h" 106#include "sshconnect.h"
106#include "authfd.h" 107#include "authfd.h"
107#include "atomicio.h" 108#include "atomicio.h"
108#include "sshpty.h" 109#include "sshpty.h"
109#include "misc.h"
110#include "match.h" 110#include "match.h"
111#include "msg.h" 111#include "msg.h"
112#include "roaming.h" 112#include "roaming.h"
@@ -871,13 +871,11 @@ static void
871process_cmdline(void) 871process_cmdline(void)
872{ 872{
873 void (*handler)(int); 873 void (*handler)(int);
874 char *s, *cmd, *cancel_host; 874 char *s, *cmd;
875 int delete = 0, local = 0, remote = 0, dynamic = 0; 875 int ok, delete = 0, local = 0, remote = 0, dynamic = 0;
876 int cancel_port, ok; 876 struct Forward fwd;
877 Forward fwd;
878 877
879 memset(&fwd, 0, sizeof(fwd)); 878 memset(&fwd, 0, sizeof(fwd));
880 fwd.listen_host = fwd.connect_host = NULL;
881 879
882 leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE); 880 leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE);
883 handler = signal(SIGINT, SIG_IGN); 881 handler = signal(SIGINT, SIG_IGN);
@@ -943,29 +941,20 @@ process_cmdline(void)
943 941
944 /* XXX update list of forwards in options */ 942 /* XXX update list of forwards in options */
945 if (delete) { 943 if (delete) {
946 cancel_port = 0; 944 /* We pass 1 for dynamicfwd to restrict to 1 or 2 fields. */
947 cancel_host = hpdelim(&s); /* may be NULL */ 945 if (!parse_forward(&fwd, s, 1, 0)) {
948 if (s != NULL) { 946 logit("Bad forwarding close specification.");
949 cancel_port = a2port(s);
950 cancel_host = cleanhostname(cancel_host);
951 } else {
952 cancel_port = a2port(cancel_host);
953 cancel_host = NULL;
954 }
955 if (cancel_port <= 0) {
956 logit("Bad forwarding close port");
957 goto out; 947 goto out;
958 } 948 }
959 if (remote) 949 if (remote)
960 ok = channel_request_rforward_cancel(cancel_host, 950 ok = channel_request_rforward_cancel(&fwd) == 0;
961 cancel_port) == 0;
962 else if (dynamic) 951 else if (dynamic)
963 ok = channel_cancel_lport_listener(cancel_host, 952 ok = channel_cancel_lport_listener(&fwd,
964 cancel_port, 0, options.gateway_ports) > 0; 953 0, &options.fwd_opts) > 0;
965 else 954 else
966 ok = channel_cancel_lport_listener(cancel_host, 955 ok = channel_cancel_lport_listener(&fwd,
967 cancel_port, CHANNEL_CANCEL_PORT_STATIC, 956 CHANNEL_CANCEL_PORT_STATIC,
968 options.gateway_ports) > 0; 957 &options.fwd_opts) > 0;
969 if (!ok) { 958 if (!ok) {
970 logit("Unkown port forwarding."); 959 logit("Unkown port forwarding.");
971 goto out; 960 goto out;
@@ -977,16 +966,13 @@ process_cmdline(void)
977 goto out; 966 goto out;
978 } 967 }
979 if (local || dynamic) { 968 if (local || dynamic) {
980 if (!channel_setup_local_fwd_listener(fwd.listen_host, 969 if (!channel_setup_local_fwd_listener(&fwd,
981 fwd.listen_port, fwd.connect_host, 970 &options.fwd_opts)) {
982 fwd.connect_port, options.gateway_ports)) {
983 logit("Port forwarding failed."); 971 logit("Port forwarding failed.");
984 goto out; 972 goto out;
985 } 973 }
986 } else { 974 } else {
987 if (channel_request_remote_forwarding(fwd.listen_host, 975 if (channel_request_remote_forwarding(&fwd) < 0) {
988 fwd.listen_port, fwd.connect_host,
989 fwd.connect_port) < 0) {
990 logit("Port forwarding failed."); 976 logit("Port forwarding failed.");
991 goto out; 977 goto out;
992 } 978 }
@@ -999,7 +985,9 @@ out:
999 enter_raw_mode(options.request_tty == REQUEST_TTY_FORCE); 985 enter_raw_mode(options.request_tty == REQUEST_TTY_FORCE);
1000 free(cmd); 986 free(cmd);
1001 free(fwd.listen_host); 987 free(fwd.listen_host);
988 free(fwd.listen_path);
1002 free(fwd.connect_host); 989 free(fwd.connect_host);
990 free(fwd.connect_path);
1003} 991}
1004 992
1005/* reasons to suppress output of an escape command in help output */ 993/* reasons to suppress output of an escape command in help output */
@@ -1845,9 +1833,8 @@ client_request_forwarded_tcpip(const char *request_type, int rchan)
1845 originator_port = packet_get_int(); 1833 originator_port = packet_get_int();
1846 packet_check_eom(); 1834 packet_check_eom();
1847 1835
1848 debug("client_request_forwarded_tcpip: listen %s port %d, " 1836 debug("%s: listen %s port %d, originator %s port %d", __func__,
1849 "originator %s port %d", listen_address, listen_port, 1837 listen_address, listen_port, originator_address, originator_port);
1850 originator_address, originator_port);
1851 1838
1852 c = channel_connect_by_listen_address(listen_address, listen_port, 1839 c = channel_connect_by_listen_address(listen_address, listen_port,
1853 "forwarded-tcpip", originator_address); 1840 "forwarded-tcpip", originator_address);
@@ -1858,6 +1845,27 @@ client_request_forwarded_tcpip(const char *request_type, int rchan)
1858} 1845}
1859 1846
1860static Channel * 1847static Channel *
1848client_request_forwarded_streamlocal(const char *request_type, int rchan)
1849{
1850 Channel *c = NULL;
1851 char *listen_path;
1852
1853 /* Get the remote path. */
1854 listen_path = packet_get_string(NULL);
1855 /* XXX: Skip reserved field for now. */
1856 if (packet_get_string_ptr(NULL) == NULL)
1857 fatal("%s: packet_get_string_ptr failed", __func__);
1858 packet_check_eom();
1859
1860 debug("%s: %s", __func__, listen_path);
1861
1862 c = channel_connect_by_listen_path(listen_path,
1863 "forwarded-streamlocal@openssh.com", "forwarded-streamlocal");
1864 free(listen_path);
1865 return c;
1866}
1867
1868static Channel *
1861client_request_x11(const char *request_type, int rchan) 1869client_request_x11(const char *request_type, int rchan)
1862{ 1870{
1863 Channel *c = NULL; 1871 Channel *c = NULL;
@@ -1984,6 +1992,8 @@ client_input_channel_open(int type, u_int32_t seq, void *ctxt)
1984 1992
1985 if (strcmp(ctype, "forwarded-tcpip") == 0) { 1993 if (strcmp(ctype, "forwarded-tcpip") == 0) {
1986 c = client_request_forwarded_tcpip(ctype, rchan); 1994 c = client_request_forwarded_tcpip(ctype, rchan);
1995 } else if (strcmp(ctype, "forwarded-streamlocal@openssh.com") == 0) {
1996 c = client_request_forwarded_streamlocal(ctype, rchan);
1987 } else if (strcmp(ctype, "x11") == 0) { 1997 } else if (strcmp(ctype, "x11") == 0) {
1988 c = client_request_x11(ctype, rchan); 1998 c = client_request_x11(ctype, rchan);
1989 } else if (strcmp(ctype, "auth-agent@openssh.com") == 0) { 1999 } else if (strcmp(ctype, "auth-agent@openssh.com") == 0) {