summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authorKevin Steves <stevesk@pobox.com>2001-12-19 17:58:01 +0000
committerKevin Steves <stevesk@pobox.com>2001-12-19 17:58:01 +0000
commit366298c696e8c5b27bd27d683ea7b8bf30564362 (patch)
tree0bc22c3d8df006b97799a6ff491fe15ed6da8cdd /channels.c
parent73f57be5003c6c36d74c90a14156e2f88946ee6c (diff)
- (stevesk) OpenBSD CVS sync X11 localhost display
- stevesk@cvs.openbsd.org 2001/11/29 14:10:51 [channels.h channels.c session.c] 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@ - stevesk@cvs.openbsd.org 2001/12/19 08:43:11 [includes.h session.c] handle utsname.nodename case for FamilyLocal X authorization; ok markus@
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c67
1 files changed, 11 insertions, 56 deletions
diff --git a/channels.c b/channels.c
index 694b7cc78..40a86dccb 100644
--- a/channels.c
+++ b/channels.c
@@ -2400,19 +2400,17 @@ channel_connect_to(const char *host, u_short port)
2400 2400
2401/* 2401/*
2402 * Creates an internet domain socket for listening for X11 connections. 2402 * Creates an internet domain socket for listening for X11 connections.
2403 * Returns a suitable value for the DISPLAY variable, or NULL if an error 2403 * Returns a suitable display number for the DISPLAY variable, or -1 if
2404 * occurs. 2404 * an error occurs.
2405 */ 2405 */
2406char * 2406int
2407x11_create_display_inet(int screen_number, int x11_display_offset) 2407x11_create_display_inet(int x11_display_offset, int gateway_ports)
2408{ 2408{
2409 int display_number, sock; 2409 int display_number, sock;
2410 u_short port; 2410 u_short port;
2411 struct addrinfo hints, *ai, *aitop; 2411 struct addrinfo hints, *ai, *aitop;
2412 char strport[NI_MAXSERV]; 2412 char strport[NI_MAXSERV];
2413 int gaierr, n, num_socks = 0, socks[NUM_SOCKS]; 2413 int gaierr, n, num_socks = 0, socks[NUM_SOCKS];
2414 char display[512];
2415 char hostname[MAXHOSTNAMELEN];
2416 2414
2417 for (display_number = x11_display_offset; 2415 for (display_number = x11_display_offset;
2418 display_number < MAX_DISPLAYS; 2416 display_number < MAX_DISPLAYS;
@@ -2420,12 +2418,12 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
2420 port = 6000 + display_number; 2418 port = 6000 + display_number;
2421 memset(&hints, 0, sizeof(hints)); 2419 memset(&hints, 0, sizeof(hints));
2422 hints.ai_family = IPv4or6; 2420 hints.ai_family = IPv4or6;
2423 hints.ai_flags = AI_PASSIVE; /* XXX loopback only ? */ 2421 hints.ai_flags = gateway_ports ? AI_PASSIVE : 0;
2424 hints.ai_socktype = SOCK_STREAM; 2422 hints.ai_socktype = SOCK_STREAM;
2425 snprintf(strport, sizeof strport, "%d", port); 2423 snprintf(strport, sizeof strport, "%d", port);
2426 if ((gaierr = getaddrinfo(NULL, strport, &hints, &aitop)) != 0) { 2424 if ((gaierr = getaddrinfo(NULL, strport, &hints, &aitop)) != 0) {
2427 error("getaddrinfo: %.100s", gai_strerror(gaierr)); 2425 error("getaddrinfo: %.100s", gai_strerror(gaierr));
2428 return NULL; 2426 return -1;
2429 } 2427 }
2430 for (ai = aitop; ai; ai = ai->ai_next) { 2428 for (ai = aitop; ai; ai = ai->ai_next) {
2431 if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) 2429 if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
@@ -2434,7 +2432,7 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
2434 if (sock < 0) { 2432 if (sock < 0) {
2435 if ((errno != EINVAL) && (errno != EAFNOSUPPORT)) { 2433 if ((errno != EINVAL) && (errno != EAFNOSUPPORT)) {
2436 error("socket: %.100s", strerror(errno)); 2434 error("socket: %.100s", strerror(errno));
2437 return NULL; 2435 return -1;
2438 } else { 2436 } else {
2439 debug("x11_create_display_inet: Socket family %d not supported", 2437 debug("x11_create_display_inet: Socket family %d not supported",
2440 ai->ai_family); 2438 ai->ai_family);
@@ -2468,7 +2466,7 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
2468 } 2466 }
2469 if (display_number >= MAX_DISPLAYS) { 2467 if (display_number >= MAX_DISPLAYS) {
2470 error("Failed to allocate internet-domain X11 display socket."); 2468 error("Failed to allocate internet-domain X11 display socket.");
2471 return NULL; 2469 return -1;
2472 } 2470 }
2473 /* Start listening for connections on the socket. */ 2471 /* Start listening for connections on the socket. */
2474 for (n = 0; n < num_socks; n++) { 2472 for (n = 0; n < num_socks; n++) {
@@ -2476,52 +2474,9 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
2476 if (listen(sock, 5) < 0) { 2474 if (listen(sock, 5) < 0) {
2477 error("listen: %.100s", strerror(errno)); 2475 error("listen: %.100s", strerror(errno));
2478 close(sock); 2476 close(sock);
2479 return NULL; 2477 return -1;
2480 }
2481 }
2482
2483 /* Set up a suitable value for the DISPLAY variable. */
2484 if (gethostname(hostname, sizeof(hostname)) < 0)
2485 fatal("gethostname: %.100s", strerror(errno));
2486
2487#ifdef IPADDR_IN_DISPLAY
2488 /*
2489 * HPUX detects the local hostname in the DISPLAY variable and tries
2490 * to set up a shared memory connection to the server, which it
2491 * incorrectly supposes to be local.
2492 *
2493 * The workaround - as used in later $$H and other programs - is
2494 * is to set display to the host's IP address.
2495 */
2496 {
2497 struct hostent *he;
2498 struct in_addr my_addr;
2499
2500 he = gethostbyname(hostname);
2501 if (he == NULL) {
2502 error("[X11-broken-fwd-hostname-workaround] Could not get "
2503 "IP address for hostname %s.", hostname);
2504
2505 packet_send_debug("[X11-broken-fwd-hostname-workaround]"
2506 "Could not get IP address for hostname %s.", hostname);
2507
2508 shutdown(sock, SHUT_RDWR);
2509 close(sock);
2510
2511 return NULL;
2512 } 2478 }
2513
2514 memcpy(&my_addr, he->h_addr_list[0], sizeof(struct in_addr));
2515
2516 /* Set DISPLAY to <ip address>:screen.display */
2517 snprintf(display, sizeof(display), "%.50s:%d.%d", inet_ntoa(my_addr),
2518 display_number, screen_number);
2519 } 2479 }
2520#else /* IPADDR_IN_DISPLAY */
2521 /* Just set DISPLAY to hostname:screen.display */
2522 snprintf(display, sizeof display, "%.400s:%d.%d", hostname,
2523 display_number, screen_number);
2524#endif /* IPADDR_IN_DISPLAY */
2525 2480
2526 /* Allocate a channel for each socket. */ 2481 /* Allocate a channel for each socket. */
2527 for (n = 0; n < num_socks; n++) { 2482 for (n = 0; n < num_socks; n++) {
@@ -2532,8 +2487,8 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
2532 0, xstrdup("X11 inet listener"), 1); 2487 0, xstrdup("X11 inet listener"), 1);
2533 } 2488 }
2534 2489
2535 /* Return a suitable value for the DISPLAY environment variable. */ 2490 /* Return the display number for the DISPLAY environment variable. */
2536 return xstrdup(display); 2491 return display_number;
2537} 2492}
2538 2493
2539#ifndef X_UNIX_PATH 2494#ifndef X_UNIX_PATH