X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=socket.c;h=1655bf3cdb31c42c4539eebd6963bbf5327a4121;hb=fcf6c62bd9054d5c01c290fa9adc24a173440209;hp=5039ac5ff8cdc974c9e1c7a9ae8a86bffdd1e50e;hpb=aa404982fe7cb8339247fc104e99b05dbca47204;p=~andy%2Ffetchmail diff --git a/socket.c b/socket.c index 5039ac5f..1655bf3c 100644 --- a/socket.c +++ b/socket.c @@ -101,6 +101,7 @@ static char *const *parse_plugin(const char *plugin, const char *host, const cha if (!argvec) { report(stderr, GT_("fetchmail: malloc failed\n")); + free(plugin_copy); return NULL; } memset(argvec, 0, s); @@ -135,10 +136,6 @@ static int handle_plugin(const char *host, report(stderr, GT_("fetchmail: socketpair failed\n")); return -1; } - - if (SockTimeout(fds[0], mytimeout)) return -1; - if (SockTimeout(fds[1], mytimeout)) return -1; - switch (fork()) { case -1: /* error */ @@ -170,32 +167,6 @@ static int handle_plugin(const char *host, return fds[1]; } -static int setsocktimeout(int sock, int which, int timeout) { - struct timeval tv; - int rc; - - tv.tv_sec = timeout; - tv.tv_usec = 0; - rc = setsockopt(sock, SOL_SOCKET, which, &tv, sizeof(tv)); - if (rc) { - report(stderr, GT_("setsockopt(%d, SOL_SOCKET) failed: %s"), sock, strerror(errno)); - } - return rc; -} - -/** Configure socket options such as send/receive timeout at the socket - * level, to avoid network-induced stalls. \return 0 for success, 1 for - * error. - */ -int SockTimeout(int sock, int timeout) -{ - int err = 0; - - if (setsocktimeout(sock, SO_RCVTIMEO, timeout)) err = 1; - if (setsocktimeout(sock, SO_SNDTIMEO, timeout)) err = 1; - return err; -} - /** Set socket to SO_KEEPALIVE. \return 0 for success. */ int SockKeepalive(int sock) { int keepalive = 1; @@ -217,14 +188,12 @@ int UnixOpen(const char *path) return -1; } - SockTimeout(sock, mytimeout); + /* Socket opened saved. Useful if connect timeout + * because it can be closed. + */ + mailserver_socket_temp = sock; - /* 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) + if (connect(sock, (struct sockaddr *) &ad, sizeof(ad)) < 0) { int olderr = errno; fm_close(sock); /* don't use SockClose, no traffic yet */ @@ -232,9 +201,9 @@ int UnixOpen(const char *path) errno = olderr; sock = -1; } - - /* No connect timeout, then no need to set mailserver_socket_temp */ - mailserver_socket_temp = -1; + + /* No connect timeout, then no need to set mailserver_socket_temp */ + mailserver_socket_temp = -1; return sock; } @@ -296,7 +265,6 @@ int SockOpen(const char *host, const char *service, continue; } - SockTimeout(i, mytimeout); SockKeepalive(i); /* Save socket descriptor. @@ -340,11 +308,6 @@ int SockOpen(const char *host, const char *service, return i; } -<<<<<<< HEAD -#if defined(HAVE_STDARG_H) -======= - ->>>>>>> before-cpp int SockPrintf(int sock, const char* format, ...) { va_list ap; @@ -357,6 +320,7 @@ int SockPrintf(int sock, const char* format, ...) } #ifdef SSL_ENABLE +#define OPENSSL_NO_SSL_INTERN 1 #include #include #include @@ -573,7 +537,7 @@ static int SSL_verify_callback( int ok_return, X509_STORE_CTX *ctx, int strict ) if (outlevel >= O_VERBOSE) { if (depth == 0 && SSLverbose) - report(stderr, GT_("Server certificate:\n")); + report(stdout, GT_("Server certificate:\n")); else { if (_firstrun) { _firstrun = 0; @@ -844,14 +808,21 @@ int SSLOpen(int sock, char *mycert, char *mykey, const char *myproto, int certck /* Make sure a connection referring to an older context is not left */ _ssl_context[sock] = NULL; if(myproto) { - if(!strcasecmp("ssl3",myproto)) { + if(!strcasecmp("ssl2",myproto)) { +#if HAVE_DECL_SSLV2_CLIENT_METHOD + 0 > 0 + _ctx[sock] = SSL_CTX_new(SSLv2_client_method()); +#else + report(stderr, GT_("Your operating system does not support SSLv2.\n")); + return -1; +#endif + } else if(!strcasecmp("ssl3",myproto)) { _ctx[sock] = SSL_CTX_new(SSLv3_client_method()); } else if(!strcasecmp("tls1",myproto)) { _ctx[sock] = SSL_CTX_new(TLSv1_client_method()); } else if (!strcasecmp("ssl23",myproto)) { myproto = NULL; } else { - fprintf(stderr,GT_("Invalid SSL protocol '%s' specified, using default (SSL23).\n"), myproto); + fprintf(stderr,GT_("Invalid SSL protocol '%s' specified, using default (SSLv23).\n"), myproto); myproto = NULL; } } @@ -863,7 +834,7 @@ int SSLOpen(int sock, char *mycert, char *mykey, const char *myproto, int certck return(-1); } - SSL_CTX_set_options(_ctx[sock], SSL_OP_ALL | SSL_OP_NO_SSLv2); + SSL_CTX_set_options(_ctx[sock], (SSL_OP_ALL | SSL_OP_NO_SSLv2) & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS); if (certck) { SSL_CTX_set_verify(_ctx[sock], SSL_VERIFY_PEER, SSL_ck_verify_callback);