Skip to content

Commit ef1452a

Browse files
Fix more ident lookup bugs
Found by: michaelortmann Patch by: michaelortmann
1 parent 9d0320e commit ef1452a

7 files changed

Lines changed: 65 additions & 75 deletions

File tree

aclocal.m4

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -809,15 +809,10 @@ AC_DEFUN([EGG_CHECK_OS],
809809
AC_DEFINE(BIND_8_COMPAT, 1, [Define if running on macOS with dns.mod.])
810810
;;
811811
*)
812-
if test -r /mach; then
813-
# At this point, we're guessing this is NeXT Step.
814-
AC_DEFINE(BORGCUBES, 1, [Define if running on NeXT Step.])
815-
else
816-
if test -r /cmds; then
817-
# Probably QNX.
818-
SHLIB_LD="ld -shared"
819-
SHLIB_STRIP="touch"
820-
fi
812+
if test -r /cmds; then
813+
# Probably QNX.
814+
SHLIB_LD="ld -shared"
815+
SHLIB_STRIP="touch"
821816
fi
822817
;;
823818
esac

config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
/* Define if running on macOS with dns.mod. */
2929
#undef BIND_8_COMPAT
3030

31-
/* Define if running on NeXT Step. */
32-
#undef BORGCUBES
33-
3431
/* Define to use Eggdrop's snprintf functions regardless of HAVE_SNPRINTF. */
3532
#undef BROKEN_SNPRINTF
3633

configure

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6727,17 +6727,10 @@ printf "%s\n" "#define BIND_8_COMPAT 1" >>confdefs.h
67276727

67286728
;;
67296729
*)
6730-
if test -r /mach; then
6731-
# At this point, we're guessing this is NeXT Step.
6732-
6733-
printf "%s\n" "#define BORGCUBES 1" >>confdefs.h
6734-
6735-
else
6736-
if test -r /cmds; then
6737-
# Probably QNX.
6738-
SHLIB_LD="ld -shared"
6739-
SHLIB_STRIP="touch"
6740-
fi
6730+
if test -r /cmds; then
6731+
# Probably QNX.
6732+
SHLIB_LD="ld -shared"
6733+
SHLIB_STRIP="touch"
67416734
fi
67426735
;;
67436736
esac

src/dcc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,14 +1363,12 @@ void dcc_telnet_hostresolved2(int i, int idx) {
13631363
if (bind(dcc[j].sock, &name.addr.sa, name.addrlen) < 0)
13641364
debug2("dcc: dcc_telnet_hostresolved(): bind() socket %ld error %s", dcc[j].sock, strerror(errno));
13651365
setsnport(dcc[j].sockname, 113);
1366-
if (connect(dcc[j].sock, &dcc[j].sockname.addr.sa,
1367-
dcc[j].sockname.addrlen) < 0 && (errno != EINPROGRESS)) {
1366+
if ((sock = connect_nonblock(dcc[j].sock, &dcc[j].sockname, 0)) < 0) {
1367+
putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, strerror(errno));
13681368
killsock(dcc[j].sock);
13691369
lostdcc(j);
1370-
putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, strerror(errno));
1371-
j = 0;
1370+
j = -1;
13721371
}
1373-
sock = dcc[j].sock;
13741372
}
13751373
}
13761374
if (j < 0) {

src/main.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_LOST, DCC_SCRIPT, DCC_BOT_NEW,
125125
(x) = newsplit(&(x)); \
126126
} while (0)
127127

128-
#ifdef BORGCUBES
129-
# define O_NONBLOCK 00000004 /* POSIX non-blocking I/O */
130-
#endif /* BORGCUBES */
131-
132128
/* Handle for the user that's used when starting eggdrop with -t */
133129
#define EGG_BG_HANDLE "-HQ"
134130
/* Default recommended flags for this user, use | as splitter */

src/net.c

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,57 @@ static int get_port_from_addr(const sockname_t *addr)
530530
#endif
531531
}
532532

533+
/* Check for O_NONBLOCK connect() EINPROGRESS could be ECONNREFUSED
534+
* eggdrop sockets are always O_NONBLOCK, see setsock()
535+
*/
536+
int connect_nonblock(int s, sockname_t *addr, int check_tcl_event_ident) {
537+
int rc, res, e;
538+
struct timeval tv;
539+
fd_set sockset;
540+
socklen_t res_len;
541+
542+
rc = connect(s, &addr->addr.sa, addr->addrlen);
543+
/* To minimize a proven race condition, call ident here (especially when
544+
* rc < 0 and errno == EINPROGRESS)
545+
*/
546+
if (check_tcl_event_ident) {
547+
/* push/pop errno, better safe than sorry */
548+
e = errno;
549+
check_tcl_event("ident");
550+
errno = e;
551+
}
552+
if (rc < 0) {
553+
if (errno == EINPROGRESS) {
554+
/* Async connection... don't return socket descriptor
555+
* until after we confirm if it was successful or not */
556+
tv.tv_sec = 0;
557+
tv.tv_usec = 500000; /* 0.5 second timeout, more than enough to detect
558+
* ECONNREFUSED */
559+
FD_ZERO(&sockset);
560+
FD_SET(s, &sockset);
561+
select(s + 1, NULL, &sockset, NULL, &tv);
562+
res_len = sizeof(res);
563+
getsockopt(s, SOL_SOCKET, SO_ERROR, &res, &res_len);
564+
if (res == EINPROGRESS) /* Operation now in progress */
565+
return s; /* This could probably fail somewhere */
566+
if (res == ECONNREFUSED) { /* Connection refused */
567+
debug2("net: attempted socket connection refused: %s:%i",
568+
iptostr(&addr->addr.sa), get_port_from_addr(addr));
569+
errno = res;
570+
return -4;
571+
}
572+
if (res != 0) {
573+
debug1("net: getsockopt error %d", res);
574+
return -1;
575+
}
576+
return s; /* async success! */
577+
}
578+
debug2("net: check_connect(): socket %i error %s", s, strerror(errno));
579+
return -1;
580+
}
581+
return s;
582+
}
583+
533584
/* Starts a connection attempt through a socket
534585
*
535586
* The server address should be filled in addr by setsockname() or by the
@@ -540,11 +591,8 @@ static int get_port_from_addr(const sockname_t *addr)
540591
*/
541592
int open_telnet_raw(int sock, sockname_t *addr)
542593
{
594+
int i, j;
543595
sockname_t name;
544-
socklen_t res_len;
545-
fd_set sockset;
546-
struct timeval tv;
547-
int i, j, rc, errno_tmp, res;
548596
struct threaddata *td = threaddata();
549597

550598
for (i = 0; i < dcc_total; i++)
@@ -568,45 +616,7 @@ int open_telnet_raw(int sock, sockname_t *addr)
568616
}
569617
if (addr->family == AF_INET && firewall[0])
570618
return proxy_connect(sock, addr);
571-
rc = connect(sock, &addr->addr.sa, addr->addrlen);
572-
/* To minimize a proven race condition, call ident here (especially when
573-
* rc < 0 and errno == EINPROGRESS)
574-
*/
575-
if (dcc[i].status & STAT_SERV) {
576-
errno_tmp = errno;
577-
check_tcl_event("ident");
578-
errno = errno_tmp;
579-
}
580-
if (rc < 0) {
581-
if (errno == EINPROGRESS) {
582-
/* Async connection... don't return socket descriptor
583-
* until after we confirm if it was successful or not */
584-
tv.tv_sec = 1;
585-
tv.tv_usec = 0;
586-
FD_ZERO(&sockset);
587-
FD_SET(sock, &sockset);
588-
select(sock + 1, NULL, &sockset, NULL, &tv);
589-
res_len = sizeof(res);
590-
getsockopt(sock, SOL_SOCKET, SO_ERROR, &res, &res_len);
591-
if (res == EINPROGRESS) /* Operation now in progress */
592-
return sock; /* This could probably fail somewhere */
593-
if (res == ECONNREFUSED) { /* Connection refused */
594-
debug2("net: attempted socket connection refused: %s:%i",
595-
iptostr(&addr->addr.sa), get_port_from_addr(addr));
596-
errno = res;
597-
return -4;
598-
}
599-
if (res != 0) {
600-
debug1("net: getsockopt error %d", res);
601-
return -1;
602-
}
603-
return sock; /* async success! */
604-
}
605-
else {
606-
return -1;
607-
}
608-
}
609-
return sock;
619+
return connect_nonblock(sock, addr, dcc[i].status & STAT_SERV);
610620
}
611621

612622
/* Ordinary non-binary connection attempt

src/proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ int open_listen(int *);
287287
void getvhost(sockname_t *, int);
288288
int setsockname(sockname_t *, char *, int, int);
289289
int open_address_listen(sockname_t *);
290+
int connect_nonblock(int, sockname_t *, int);
290291
int open_telnet_raw(int, sockname_t *);
291292
int open_telnet(int, char *, int);
292293
int answer(int, sockname_t *, uint16_t *, int);

0 commit comments

Comments
 (0)