diff options
author | Damien Miller <djm@mindrot.org> | 2014-07-18 14:11:24 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2014-07-18 14:11:24 +1000 |
commit | 7acefbbcbeab725420ea07397ae35992f505f702 (patch) | |
tree | bfb07917715d425438dab987a47ccd7a8d7f118b /misc.c | |
parent | 6262d760e00714523633bd989d62e273a3dca99a (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 'misc.c')
-rw-r--r-- | misc.c | 49 |
1 files changed, 48 insertions, 1 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.93 2014/04/20 02:30:25 djm Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.94 2014/07/15 15:54:14 millert Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -29,6 +29,7 @@ | |||
29 | #include <sys/types.h> | 29 | #include <sys/types.h> |
30 | #include <sys/ioctl.h> | 30 | #include <sys/ioctl.h> |
31 | #include <sys/socket.h> | 31 | #include <sys/socket.h> |
32 | #include <sys/un.h> | ||
32 | #include <sys/param.h> | 33 | #include <sys/param.h> |
33 | 34 | ||
34 | #include <stdarg.h> | 35 | #include <stdarg.h> |
@@ -1056,6 +1057,52 @@ lowercase(char *s) | |||
1056 | for (; *s; s++) | 1057 | for (; *s; s++) |
1057 | *s = tolower((u_char)*s); | 1058 | *s = tolower((u_char)*s); |
1058 | } | 1059 | } |
1060 | |||
1061 | int | ||
1062 | unix_listener(const char *path, int backlog, int unlink_first) | ||
1063 | { | ||
1064 | struct sockaddr_un sunaddr; | ||
1065 | int saved_errno, sock; | ||
1066 | |||
1067 | memset(&sunaddr, 0, sizeof(sunaddr)); | ||
1068 | sunaddr.sun_family = AF_UNIX; | ||
1069 | if (strlcpy(sunaddr.sun_path, path, sizeof(sunaddr.sun_path)) >= sizeof(sunaddr.sun_path)) { | ||
1070 | error("%s: \"%s\" too long for Unix domain socket", __func__, | ||
1071 | path); | ||
1072 | errno = ENAMETOOLONG; | ||
1073 | return -1; | ||
1074 | } | ||
1075 | |||
1076 | sock = socket(PF_UNIX, SOCK_STREAM, 0); | ||
1077 | if (sock < 0) { | ||
1078 | saved_errno = errno; | ||
1079 | error("socket: %.100s", strerror(errno)); | ||
1080 | errno = saved_errno; | ||
1081 | return -1; | ||
1082 | } | ||
1083 | if (unlink_first == 1) { | ||
1084 | if (unlink(path) != 0 && errno != ENOENT) | ||
1085 | error("unlink(%s): %.100s", path, strerror(errno)); | ||
1086 | } | ||
1087 | if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) < 0) { | ||
1088 | saved_errno = errno; | ||
1089 | error("bind: %.100s", strerror(errno)); | ||
1090 | close(sock); | ||
1091 | error("%s: cannot bind to path: %s", __func__, path); | ||
1092 | errno = saved_errno; | ||
1093 | return -1; | ||
1094 | } | ||
1095 | if (listen(sock, backlog) < 0) { | ||
1096 | saved_errno = errno; | ||
1097 | error("listen: %.100s", strerror(errno)); | ||
1098 | close(sock); | ||
1099 | unlink(path); | ||
1100 | error("%s: cannot listen on path: %s", __func__, path); | ||
1101 | errno = saved_errno; | ||
1102 | return -1; | ||
1103 | } | ||
1104 | return sock; | ||
1105 | } | ||
1059 | void | 1106 | void |
1060 | sock_set_v6only(int s) | 1107 | sock_set_v6only(int s) |
1061 | { | 1108 | { |