use new get_xsockets

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4602 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1998-03-18 22:30:53 +00:00
parent 698eb42a8f
commit 5b996a53ae
2 changed files with 62 additions and 49 deletions

View File

@@ -353,13 +353,15 @@ doit_active (char *host, char *user,
des_key_schedule schedule; des_key_schedule schedule;
des_cblock key; des_cblock key;
int otherside; int otherside;
int rendez_vous1 = 0, rendez_vous2 = 0; int nsockets;
struct x_socket *sockets;
struct sockaddr_in me, him; struct sockaddr_in me, him;
u_char msg[1024], *p; u_char msg[1024], *p;
int len = strlen(user); int len = strlen(user);
void *ret; void *ret;
u_int32_t tmp; u_int32_t tmp;
char *s; char *s;
int i;
otherside = connect_host (host, user, &key, schedule, port, otherside = connect_host (host, user, &key, schedule, port,
&me, &him); &me, &him);
@@ -415,8 +417,7 @@ doit_active (char *host, char *user,
} else } else
p++; p++;
tmp = get_xsockets (&rendez_vous1, tmp = get_xsockets (&nsockets, &sockets, tcpp);
tcpp ? &rendez_vous2 : NULL);
if (tmp < 0) if (tmp < 0)
return 1; return 1;
display_num = tmp; display_num = tmp;
@@ -430,23 +431,19 @@ doit_active (char *host, char *user,
for (;;) { for (;;) {
fd_set fdset; fd_set fdset;
pid_t child; pid_t child;
int fd, thisfd; int fd, thisfd = -1;
int zero = 0; int zero = 0;
FD_ZERO(&fdset); FD_ZERO(&fdset);
if (rendez_vous1) for (i = 0; i < nsockets; ++i)
FD_SET(rendez_vous1, &fdset); FD_SET(sockets[i].fd, &fdset);
if (rendez_vous2)
FD_SET(rendez_vous2, &fdset);
if (select(FD_SETSIZE, &fdset, NULL, NULL, NULL) <= 0) if (select(FD_SETSIZE, &fdset, NULL, NULL, NULL) <= 0)
continue; continue;
if (rendez_vous1 && FD_ISSET(rendez_vous1, &fdset)) for (i = 0; i < nsockets; ++i)
thisfd = rendez_vous1; if (FD_ISSET(sockets[i].fd, &fdset)) {
else if (rendez_vous2 && FD_ISSET(rendez_vous2, &fdset)) thisfd = sockets[i].fd;
thisfd = rendez_vous2; break;
else }
continue;
fd = accept (thisfd, NULL, &zero); fd = accept (thisfd, NULL, &zero);
if (fd < 0) if (fd < 0)
if (errno == EINTR) if (errno == EINTR)
@@ -484,10 +481,8 @@ doit_active (char *host, char *user,
int s; int s;
struct sockaddr_in addr; struct sockaddr_in addr;
if (rendez_vous1) for (i = 0; i < nsockets; ++i)
close (rendez_vous1); close (sockets[i].fd);
if (rendez_vous2)
close (rendez_vous2);
addr = him; addr = him;
close (otherside); close (otherside);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1995, 1996, 1997 Kungliga Tekniska H<>gskolan * Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -91,12 +91,18 @@ fatal (int fd, des_cblock *key, des_key_schedule schedule,
} }
static void static void
cleanup(void) cleanup(int nsockets, struct x_socket *sockets)
{ {
int i;
if(xauthfile[0]) if(xauthfile[0])
unlink(xauthfile); unlink(xauthfile);
if(x_socket[0]) for (i = 0; i < nsockets; ++i) {
unlink(x_socket); if (sockets[i].pathname != NULL) {
unlink (sockets[i].pathname);
free (sockets[i].pathname);
}
}
} }
static int static int
@@ -345,10 +351,11 @@ doit(int sock, int tcpp)
{ {
des_key_schedule schedule; des_key_schedule schedule;
des_cblock key; des_cblock key;
int localx, tcpx;
struct sockaddr_in me, him; struct sockaddr_in me, him;
int flags; int flags;
u_char msg[1024], *p; u_char msg[1024], *p;
struct x_socket *sockets;
int nsockets;
flags = recv_conn (sock, &key, schedule, &me, &him); flags = recv_conn (sock, &key, schedule, &me, &him);
@@ -356,7 +363,7 @@ doit(int sock, int tcpp)
int tmp; int tmp;
int len; int len;
tmp = get_xsockets (&localx, tcpp ? &tcpx : NULL); tmp = get_xsockets (&nsockets, &sockets, tcpp);
if (tmp < 0) if (tmp < 0)
return 1; return 1;
display_num = tmp; display_num = tmp;
@@ -370,7 +377,7 @@ doit(int sock, int tcpp)
fatal (sock, &key, schedule, &me, &him, fatal (sock, &key, schedule, &me, &him,
"Cookie-creation failed with: %s", "Cookie-creation failed with: %s",
strerror(errno)); strerror(errno));
cleanup(); cleanup(nsockets, sockets);
return 1; return 1;
} }
@@ -388,41 +395,53 @@ doit(int sock, int tcpp)
if(write_encrypted (sock, msg, p - msg, schedule, &key, if(write_encrypted (sock, msg, p - msg, schedule, &key,
&me, &him) < 0) { &me, &him) < 0) {
syslog (LOG_ERR, "write: %m"); syslog (LOG_ERR, "write: %m");
cleanup(); cleanup(nsockets, sockets);
return 1; return 1;
} }
for (;;) { for (;;) {
pid_t child; pid_t child;
int fd; int fd;
int zero = 0;
fd_set fds; fd_set fds;
int i;
int ret;
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(localx, &fds);
FD_SET(sock, &fds); FD_SET(sock, &fds);
if (tcpp) for (i = 0; i < nsockets; ++i)
FD_SET(tcpx, &fds); FD_SET(sockets[i].fd, &fds);
if(select(FD_SETSIZE, &fds, NULL, NULL, NULL) <=0) ret = select(FD_SETSIZE, &fds, NULL, NULL, NULL);
if(ret <= 0)
continue; continue;
if(FD_ISSET(sock, &fds)){ if(FD_ISSET(sock, &fds)){
/* there are no processes left on the remote side /* there are no processes left on the remote side
*/ */
cleanup(); cleanup(nsockets, sockets);
exit(0); exit(0);
} else if(FD_ISSET(localx, &fds)) } else if(ret) {
fd = accept (localx, NULL, &zero); for (i = 0; i < nsockets; ++i) {
else if(tcpp && FD_ISSET(tcpx, &fds)) { if (FD_ISSET(sockets[i].fd, &fds)) {
struct sockaddr_in peer; if (sockets[i].pathname == NULL) {
int len = sizeof(peer); struct sockaddr_in peer;
int len = sizeof(peer);
fd = accept (tcpx, (struct sockaddr *)&peer, &len); fd = accept (sockets[i].fd,
/* XXX */ (struct sockaddr *)&peer,
if (fd >= 0 && suspicious_address (fd, peer)) { &len);
close (fd); /* XXX */
continue; if (fd >= 0 && suspicious_address (fd, peer)) {
close (fd);
fd = -1;
errno = EINTR;
}
} else {
int zero = 0;
fd = accept (sockets[i].fd, NULL, &zero);
}
}
break;
} }
} else }
continue;
if (fd < 0) if (fd < 0)
if (errno == EINTR) if (errno == EINTR)
continue; continue;
@@ -436,9 +455,8 @@ doit(int sock, int tcpp)
syslog (LOG_ERR, "fork: %m"); syslog (LOG_ERR, "fork: %m");
return 1; return 1;
} else if (child == 0) { } else if (child == 0) {
close (localx); for (i = 0; i < nsockets; ++i)
if (tcpp) close (sockets[i].fd);
close (tcpx);
return doit_conn (fd, sock, flags, return doit_conn (fd, sock, flags,
&key, schedule, &me, &him); &key, schedule, &me, &him);
} else { } else {
@@ -479,7 +497,7 @@ doit(int sock, int tcpp)
syslog (LOG_ERR, "fork: %m"); syslog (LOG_ERR, "fork: %m");
return 1; return 1;
} else if (child == 0) { } else if (child == 0) {
return doit_conn (localx, sock, flags, return doit_conn (sock, sock, flags,
&key, schedule, &me, &him); &key, schedule, &me, &him);
} else { } else {
} }