summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Steves <stevesk@cvs.openbsd.org>2001-12-19 15:43:12 +0000
committerKevin Steves <stevesk@cvs.openbsd.org>2001-12-19 15:43:12 +0000
commitba3279677c973b07f7831a44f14b8a6394531f11 (patch)
treede25223cb3123951bed30b42a67d55b01d765fb4
parentd8afae924f4db99650aa0df115c6ae66ed02b950 (diff)
handle utsname.nodename case for FamilyLocal X authorization; ok markus@
-rw-r--r--usr.bin/ssh/includes.h3
-rw-r--r--usr.bin/ssh/session.c49
2 files changed, 41 insertions, 11 deletions
diff --git a/usr.bin/ssh/includes.h b/usr.bin/ssh/includes.h
index 9f98937165b..a7fea6cc55f 100644
--- a/usr.bin/ssh/includes.h
+++ b/usr.bin/ssh/includes.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: includes.h,v 1.15 2001/06/08 15:25:40 markus Exp $ */
+/* $OpenBSD: includes.h,v 1.16 2001/12/19 15:43:11 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -30,6 +30,7 @@ static /**/const char *const rcsid[] = { (char *)rcsid, "\100(#)" msg }
#include <sys/time.h>
#include <sys/un.h>
#include <sys/resource.h>
+#include <sys/utsname.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
diff --git a/usr.bin/ssh/session.c b/usr.bin/ssh/session.c
index e9978bff72a..01cdd76bfc1 100644
--- a/usr.bin/ssh/session.c
+++ b/usr.bin/ssh/session.c
@@ -33,7 +33,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.112 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: session.c,v 1.113 2001/12/19 15:43:11 stevesk Exp $");
#include "ssh.h"
#include "ssh1.h"
@@ -76,7 +76,7 @@ struct Session {
int display_number;
char *display;
int screen;
- char *auth_display;
+ char *auth_display[2];
char *auth_proto;
char *auth_data;
int single_connection;
@@ -1035,20 +1035,29 @@ do_child(Session *s, const char *command)
_PATH_SSH_SYSTEM_RC);
} else if (do_xauth && options.xauth_location != NULL) {
/* Add authority data to .Xauthority if appropriate. */
-
if (debug_flag) {
fprintf(stderr,
"Running %.100s add "
"%.100s %.100s %.100s\n",
- options.xauth_location, s->auth_display,
+ options.xauth_location, s->auth_display[0],
s->auth_proto, s->auth_data);
+ if (s->auth_display[1])
+ fprintf(stderr,
+ "add %.100s %.100s %.100s\n",
+ s->auth_display[1],
+ s->auth_proto, s->auth_data);
}
snprintf(cmd, sizeof cmd, "%s -q -",
options.xauth_location);
f = popen(cmd, "w");
if (f) {
- fprintf(f, "add %s %s %s\n", s->auth_display,
- s->auth_proto, s->auth_data);
+ fprintf(f, "add %s %s %s\n",
+ s->auth_display[0], s->auth_proto,
+ s->auth_data);
+ if (s->auth_display[1])
+ fprintf(f, "add %s %s %s\n",
+ s->auth_display[1], s->auth_proto,
+ s->auth_data);
pclose(f);
} else {
fprintf(stderr, "Could not run %s\n",
@@ -1540,8 +1549,10 @@ session_close(Session *s)
xfree(s->term);
if (s->display)
xfree(s->display);
- if (s->auth_display)
- xfree(s->auth_display);
+ if (s->auth_display[0])
+ xfree(s->auth_display[0]);
+ if (s->auth_display[1])
+ xfree(s->auth_display[1]);
if (s->auth_data)
xfree(s->auth_data);
if (s->auth_proto)
@@ -1677,18 +1688,36 @@ session_setup_x11fwd(Session *s)
* authorization entry is added with xauth(1). This will be
* different than the DISPLAY string for localhost displays.
*/
+ s->auth_display[1] = NULL;
if (!options.gateway_ports) {
+ struct utsname uts;
+
snprintf(display, sizeof display, "localhost:%d.%d",
s->display_number, s->screen);
snprintf(auth_display, sizeof auth_display, "%.400s/unix:%d.%d",
hostname, s->display_number, s->screen);
s->display = xstrdup(display);
- s->auth_display = xstrdup(auth_display);
+ s->auth_display[0] = xstrdup(auth_display);
+ /*
+ * Xlib may use gethostbyname() or uname() hostname to
+ * look up authorization data for FamilyLocal; see:
+ * xc/lib/xtrans/Xtrans.c:TRANS(GetHostname)
+ * We just add authorization entries with both
+ * hostname and nodename if they are different.
+ */
+ if (uname(&uts) == -1)
+ fatal("uname: %.100s", strerror(errno));
+ if (strcmp(hostname, uts.nodename) != 0) {
+ snprintf(auth_display, sizeof auth_display,
+ "%.400s/unix:%d.%d", uts.nodename,
+ s->display_number, s->screen);
+ s->auth_display[1] = xstrdup(auth_display);
+ }
} else {
snprintf(display, sizeof display, "%.400s:%d.%d", hostname,
s->display_number, s->screen);
s->display = xstrdup(display);
- s->auth_display = xstrdup(display);
+ s->auth_display[0] = xstrdup(display);
}
return 1;