summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/channels.c
diff options
context:
space:
mode:
authorKevin Steves <stevesk@cvs.openbsd.org>2001-11-29 21:10:52 +0000
committerKevin Steves <stevesk@cvs.openbsd.org>2001-11-29 21:10:52 +0000
commit100e8d04434204f9d6dcbea2c610e7752994d246 (patch)
tree7ee27e0fdac190be058562c754f288d013b27606 /usr.bin/ssh/channels.c
parent523e34e5d6a452d9f21398d28e11148ae2701d28 (diff)
sshd X11 fake server will now listen on localhost by default:
$ echo $DISPLAY localhost:12.0 $ netstat -an|grep 6012 tcp 0 0 127.0.0.1.6012 *.* LISTEN tcp6 0 0 ::1.6012 *.* LISTEN sshd_config gatewayports=yes can be used to revert back to the old behavior. will control this with another option later. ok markus@
Diffstat (limited to 'usr.bin/ssh/channels.c')
-rw-r--r--usr.bin/ssh/channels.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c
index 3e7ba4c7e28..f93e4850e13 100644
--- a/usr.bin/ssh/channels.c
+++ b/usr.bin/ssh/channels.c
@@ -39,7 +39,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: channels.c,v 1.140 2001/10/10 22:18:47 markus Exp $");
+RCSID("$OpenBSD: channels.c,v 1.141 2001/11/29 21:10:51 stevesk Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -2390,19 +2390,17 @@ channel_connect_to(const char *host, u_short port)
/*
* Creates an internet domain socket for listening for X11 connections.
- * Returns a suitable value for the DISPLAY variable, or NULL if an error
- * occurs.
+ * Returns a suitable display number for the DISPLAY variable, or -1 if
+ * an error occurs.
*/
-char *
-x11_create_display_inet(int screen_number, int x11_display_offset)
+int
+x11_create_display_inet(int x11_display_offset, int gateway_ports)
{
int display_number, sock;
u_short port;
struct addrinfo hints, *ai, *aitop;
char strport[NI_MAXSERV];
int gaierr, n, num_socks = 0, socks[NUM_SOCKS];
- char display[512];
- char hostname[MAXHOSTNAMELEN];
for (display_number = x11_display_offset;
display_number < MAX_DISPLAYS;
@@ -2410,12 +2408,12 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
port = 6000 + display_number;
memset(&hints, 0, sizeof(hints));
hints.ai_family = IPv4or6;
- hints.ai_flags = AI_PASSIVE; /* XXX loopback only ? */
+ hints.ai_flags = gateway_ports ? AI_PASSIVE : 0;
hints.ai_socktype = SOCK_STREAM;
snprintf(strport, sizeof strport, "%d", port);
if ((gaierr = getaddrinfo(NULL, strport, &hints, &aitop)) != 0) {
error("getaddrinfo: %.100s", gai_strerror(gaierr));
- return NULL;
+ return -1;
}
for (ai = aitop; ai; ai = ai->ai_next) {
if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
@@ -2423,7 +2421,7 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
sock = socket(ai->ai_family, SOCK_STREAM, 0);
if (sock < 0) {
error("socket: %.100s", strerror(errno));
- return NULL;
+ return -1;
}
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
debug("bind port %d: %.100s", port, strerror(errno));
@@ -2446,7 +2444,7 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
}
if (display_number >= MAX_DISPLAYS) {
error("Failed to allocate internet-domain X11 display socket.");
- return NULL;
+ return -1;
}
/* Start listening for connections on the socket. */
for (n = 0; n < num_socks; n++) {
@@ -2455,16 +2453,10 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
error("listen: %.100s", strerror(errno));
shutdown(sock, SHUT_RDWR);
close(sock);
- return NULL;
+ return -1;
}
}
- /* Set up a suitable value for the DISPLAY variable. */
- if (gethostname(hostname, sizeof(hostname)) < 0)
- fatal("gethostname: %.100s", strerror(errno));
- snprintf(display, sizeof display, "%.400s:%d.%d", hostname,
- display_number, screen_number);
-
/* Allocate a channel for each socket. */
for (n = 0; n < num_socks; n++) {
sock = socks[n];
@@ -2474,8 +2466,8 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
0, xstrdup("X11 inet listener"), 1);
}
- /* Return a suitable value for the DISPLAY environment variable. */
- return xstrdup(display);
+ /* Return the display number for the DISPLAY environment variable. */
+ return display_number;
}
#ifndef X_UNIX_PATH