Index: driver.c =================================================================== RCS file: /home/cvs/debian/fetchmail/driver.c,v retrieving revision 1.1.1.27 retrieving revision 1.38 diff -u -r1.1.1.27 -r1.38 --- driver.c 10 Mar 2002 19:09:51 -0000 1.1.1.27 +++ driver.c 14 Mar 2002 00:24:44 -0000 1.38 @@ -64,6 +64,7 @@ int phase; /* where are we, for error-logging purposes? */ int batchcount; /* count of messages sent in current batch */ flag peek_capable; /* can we peek for better error recovery? */ +int mailserver_socket_temp; /* socket to free if connect timeout */ static int timeoutcount; /* count consecutive timeouts */ @@ -557,11 +558,6 @@ { if (suppress_readbody) { - /* When readheaders returns PS_TRUNCATED, - * the body (which has no content) - * has already been read by readheaders, - * so we say readbody returned PS_SUCCESS - */ err = PS_SUCCESS; } else @@ -746,7 +742,12 @@ sigfillset(&allsigs); sigprocmask(SIG_UNBLOCK, &allsigs, NULL); #endif /* HAVE_SIGPROCMASK */ - + + /* If there was a connect timeout, the socket should be closed. + * mailserver_socket_temp contains the socket to close. + */ + mailserver_socket = mailserver_socket_temp; + if (js == THROW_SIGPIPE) { signal(SIGPIPE, SIG_IGN); @@ -1008,10 +1009,14 @@ phase = oldphase; goto closeUp; } - set_timeout(0); - phase = oldphase; #ifdef SSL_ENABLE + /* Save the socket opened. Usefull if Fetchmail hangs on SSLOpen + * because the socket can be closed + */ + mailserver_socket_temp = mailserver_socket; + set_timeout(mytimeout); + /* perform initial SSL handshake on open connection */ /* Note: We pass the realhost name over for certificate verification. We may want to make this configurable */ @@ -1021,8 +1026,18 @@ report(stderr, GT_("SSL connection failed.\n")); goto closeUp; } + + /* Fetchmail didn't hang on SSLOpen, + * then no need to set mailserver_socket_temp + */ + mailserver_socket_temp = -1; #endif - + + /* A timeout is still defined before SSLOpen, + * then Fetchmail hanging on SSLOpen is handled. + */ + set_timeout(0); + phase = oldphase; #ifdef KERBEROS_V4 if (ctl->server.authenticate == A_KERBEROS_V4) { @@ -1311,7 +1326,7 @@ */ if (count > INT_MAX/sizeof(int)) { - report(stderr, "bogus message count!"); + report(stderr, GT_("bogus message count!")); return(PS_PROTOCOL); } @@ -1352,6 +1367,8 @@ continue; else if (ctl->server.base_protocol->is_old && (ctl->server.base_protocol->is_old)(mailserver_socket,ctl,num)) msgcodes[num-1] = MSGLEN_OLD; +/* else if (msgsizes[num-1] == 512) + msgcodes[num-1] = MSGLEN_OLD; (hmh) sample code to skip message */ } /* read, forward, and delete messages */ Index: socket.c =================================================================== RCS file: /home/cvs/debian/fetchmail/socket.c,v retrieving revision 1.1.1.17 retrieving revision 1.10 diff -u -r1.1.1.17 -r1.10 --- socket.c 9 Mar 2002 04:34:41 -0000 1.1.1.17 +++ socket.c 14 Mar 2002 00:16:11 -0000 1.10 @@ -36,7 +36,6 @@ #else #include #endif -#include #include "socket.h" #include "fetchmail.h" #include "i18n.h" @@ -68,6 +67,8 @@ #endif /* ndef h_errno */ +extern int mailserver_socket_temp; /* Socket to close if connect timeout */ + #if NET_SECURITY #include #endif /* NET_SECURITY */ @@ -219,10 +220,6 @@ int UnixOpen(const char *path) { -#ifdef HAVE_SIGPROCMASK - sigset_t allsigs; -#endif /* HAVE_SIGPROCMASK */ - int sock = -1; struct sockaddr_un ad; memset(&ad, 0, sizeof(ad)); @@ -236,13 +233,12 @@ return -1; } -#ifdef HAVE_SIGPROCMASK - /* avoid socket leak on alarm signal during connect(2) */ - sigfillset(&allsigs); - sigprocmask(SIG_BLOCK, &allsigs, NULL); -#endif /* HAVE_SIGPROCMASK */ - - if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0) + /* Socket opened saved. Usefull if connect timeout + * because it can be closed. + */ + mailserver_socket_temp = sock; + + if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0) { int olderr = errno; fm_close(sock); /* don't use SockClose, no traffic yet */ @@ -250,10 +246,9 @@ errno = olderr; sock = -1; } - -#ifdef HAVE_SIGPROCMASK - sigprocmask(SIG_UNBLOCK, &allsigs, NULL); -#endif /* HAVE_SIGPROCMASK */ + + /* No connect timeout, then no need to set mailserver_socket_temp */ + mailserver_socket_temp = -1; return sock; } @@ -262,10 +257,6 @@ int SockOpen(const char *host, const char *service, const char *options, const char *plugin) { -#ifdef HAVE_SIGPROCMASK - sigset_t allsigs; -#endif /* HAVE_SIGPROCMASK */ - struct addrinfo *ai, *ai0, req; int i; #if NET_SECURITY @@ -304,29 +295,29 @@ break; #else -#ifdef HAVE_SIGPROCMASK - /* avoid socket leak on alarm signal during connect(2) */ - sigfillset(&allsigs); - sigprocmask(SIG_BLOCK, &allsigs, NULL); -#endif /* HAVE_SIGPROCMASK */ - i = -1; for (ai = ai0; ai; ai = ai->ai_next) { i = socket(ai->ai_family, ai->ai_socktype, 0); if (i < 0) continue; + + /* Socket opened saved. Usefull if connect timeout + * because it can be closed. + */ + mailserver_socket_temp = i; + if (connect(i, (struct sockaddr *) ai->ai_addr, ai->ai_addrlen) < 0) { fm_close(i); i = -1; continue; } + + /* No connect timeout, then no need to set mailserver_socket_temp */ + mailserver_socket_temp = -1; + break; } -#ifdef HAVE_SIGPROCMASK - sigprocmask(SIG_UNBLOCK, &allsigs, NULL); -#endif /* HAVE_SIGPROCMASK */ - #endif #endif /* NET_SECURITY */ @@ -389,6 +380,12 @@ h_errno = 0; return -1; } + + /* Socket opened saved. Usefull if connect timeout because + * it can be closed + */ + mailserver_socket_temp = sock; + if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0) { int olderr = errno; @@ -397,6 +394,10 @@ errno = olderr; return -1; } + + /* No connect timeout, then no need to set mailserver_socket_temp */ + mailserver_socket_temp = -1; + #ifndef HAVE_INET_ATON } #else @@ -434,10 +435,19 @@ h_errno = 0; return -1; } + + /* Socket opened saved. Usefull if connect timeout because + * it can be closed + */ + mailserver_socket_temp = sock; + ad.sin_port = htons(clientPort); memcpy(&ad.sin_addr, *pptr, sizeof(struct in_addr)); - if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) == 0) - break; /* success */ + if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) == 0) { + /* No connect timeout, then no need to set mailserver_socket_temp */ + mailserver_socket_temp = -1; + break; /* success */ + } fm_close(sock); /* don't use SockClose, no traffic yet */ memset(&ad, 0, sizeof(ad)); ad.sin_family = AF_INET; @@ -804,11 +814,11 @@ } tp += esz; } - if (outlevel > O_SILENT) + if (outlevel > O_NORMAL) report(stdout, GT_("%s key fingerprint: %s\n"), _server_label, text); if (_check_digest != NULL) { if (strcmp(text, _check_digest) == 0) { - if (outlevel > O_SILENT) + if (outlevel > O_NORMAL) report(stdout, GT_("%s fingerprints match.\n"), _server_label); } else { if (outlevel > O_SILENT)