From b6d5b81c1ca9126d06af63cfe0752c062415dd75 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Tue, 25 Jun 2002 22:33:12 +0000 Subject: [PATCH] * kcmd.c (setup_secondary_channel): Use select to time out after 10 minutes, or notice the primary channel being closed or receiving data while we wait for the secondary one to be set up. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14578 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/ChangeLog | 4 ++++ src/appl/bsd/kcmd.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index e7d289378..026ef603a 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,5 +1,9 @@ 2002-06-25 Ken Raeburn + * kcmd.c (setup_secondary_channel): Use select to time out after + 10 minutes, or notice the primary channel being closed or + receiving data while we wait for the secondary one to be set up. + * compat_recv.c: New file, moved from lib/krb5util. * Makefile.in (SRCS, OBJS): Include it. (rcp, kshd, klogind): Link against it instead of krb5util diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c index 0ad0c9d83..74a56b3e0 100644 --- a/src/appl/bsd/kcmd.c +++ b/src/appl/bsd/kcmd.c @@ -71,6 +71,9 @@ #include #include #include +#ifdef _AIX +#include +#endif #ifndef POSIX_SIGNALS #ifndef sigmask @@ -292,11 +295,19 @@ setup_secondary_channel (int s, int *fd2p, int *lportp, int *addrfamilyp, int len = sizeof (*fromp); size_t slen; int s2 = getport(lportp, addrfamilyp), s3; + fd_set rfds, xfds; + struct timeval waitlen; + int n; *fd2p = -1; if (s2 < 0) return -1; + FD_ZERO(&rfds); + FD_ZERO(&xfds); + FD_SET(s, &rfds); + FD_SET(s, &xfds); listen(s2, 1); + FD_SET(s2, &rfds); (void) sprintf(num, "%d", *lportp); slen = strlen(num)+1; if (write(s, num, slen) != slen) { @@ -304,6 +315,25 @@ setup_secondary_channel (int s, int *fd2p, int *lportp, int *addrfamilyp, (void) close(s2); return -1; } + waitlen.tv_sec = 600; /* long, but better than infinite */ + waitlen.tv_usec = 0; + n = (s < s2) ? s2 : s; + n = select(n+1, &rfds, 0, &xfds, &waitlen); + if (n <= 0) { + /* timeout or error */ + fprintf(stderr, "timeout in circuit setup\n"); + close(s2); + *fd2p = -1; + return -1; + } else { + if (FD_ISSET(s, &rfds) || FD_ISSET(s, &xfds)) { + fprintf(stderr, "socket: protocol error or closed connection in circuit setup\n"); + close(s2); + *fd2p = -1; + return -1; + } + /* ready to accept a connection; yay! */ + } s3 = accept(s2, (struct sockaddr *)fromp, &len); (void) close(s2); if (s3 < 0) { -- 2.26.2