#ifndef NO_WRITEV
static int ssl_io_hook_writev(BUFF *fb, const struct iovec *iov, int iovcnt);
#endif
-#ifdef WIN32
-static int ssl_io_hook_recvwithtimeout(BUFF *fb, char *buf, int len);
-static int ssl_io_hook_sendwithtimeout(BUFF *fb, const char *buf, int len);
-#endif /* WIN32 */
void ssl_io_register(void)
{
ap_hook_register("ap::buff::write", ssl_io_hook_write, AP_HOOK_NOCTX);
#ifndef NO_WRITEV
ap_hook_register("ap::buff::writev", ssl_io_hook_writev, AP_HOOK_NOCTX);
-#endif
-#ifdef WIN32
- ap_hook_register("ap::buff::recvwithtimeout",
- ssl_io_hook_recvwithtimeout, AP_HOOK_NOCTX);
- ap_hook_register("ap::buff::sendwithtimeout",
- ssl_io_hook_sendwithtimeout, AP_HOOK_NOCTX);
#endif
return;
}
ap_hook_unregister("ap::buff::write", ssl_io_hook_write);
#ifndef NO_WRITEV
ap_hook_unregister("ap::buff::writev", ssl_io_hook_writev);
-#endif
-#ifdef WIN32
- ap_hook_unregister("ap::buff::recvwithtimeout", ssl_io_hook_recvwithtimeout);
- ap_hook_unregister("ap::buff::sendwithtimeout", ssl_io_hook_sendwithtimeout);
#endif
return;
}
}
#endif
-#ifdef WIN32
-
-/* these two functions are exported from buff.c under WIN32 */
-API_EXPORT(int) sendwithtimeout(int sock, const char *buf, int len, int flags);
-API_EXPORT(int) recvwithtimeout(int sock, char *buf, int len, int flags);
-
-/* and the prototypes for our SSL_xxx variants */
-static int SSL_sendwithtimeout(BUFF *fb, const char *buf, int len);
-static int SSL_recvwithtimeout(BUFF *fb, char *buf, int len);
-
-static int ssl_io_hook_recvwithtimeout(BUFF *fb, char *buf, int len)
-{
- SSL *ssl;
- int rc;
-
- if ((ssl = ap_ctx_get(fb->ctx, "ssl")) != NULL)
- rc = SSL_recvwithtimeout(fb, buf, len);
- else
- rc = recvwithtimeout(fb->fd, buf, len, 0);
- return rc;
-}
-
-static int ssl_io_hook_sendwithtimeout(BUFF *fb, const char *buf, int len)
-{
- SSL *ssl;
- int rc;
-
- if ((ssl = ap_ctx_get(fb->ctx, "ssl")) != NULL)
- rc = SSL_sendwithtimeout(fb, buf, len);
- else
- rc = sendwithtimeout(fb->fd, buf, len, 0);
- return rc;
-}
-
-#endif /* WIN32 */
-
/* _________________________________________________________________
**
** Special Functions for OpenSSL
** _________________________________________________________________
*/
-#ifdef WIN32
-
-static int SSL_sendwithtimeout(BUFF *fb, const char *buf, int len)
-{
- int iostate = 1;
- fd_set fdset;
- struct timeval tv;
- int err = WSAEWOULDBLOCK;
- int rv;
- int retry;
- int sock = fb->fd;
- SSL *ssl;
-
- ssl = ap_ctx_get(fb->ctx, "ssl");
-
- if (!(tv.tv_sec = ap_check_alarm()))
- return (SSL_write(ssl, (char*)buf, len));
-
- rv = ioctlsocket(sock, FIONBIO, &iostate);
- iostate = 0;
- if (rv) {
- err = WSAGetLastError();
- ap_assert(0);
- }
- rv = SSL_write(ssl, (char*)buf, len);
- if (rv <= 0) {
- if (BIO_sock_should_retry(rv)) {
- do {
- retry = 0;
- FD_ZERO(&fdset);
- FD_SET((unsigned int)sock, &fdset);
- tv.tv_usec = 0;
- rv = select(FD_SETSIZE, NULL, &fdset, NULL, &tv);
- if (rv == SOCKET_ERROR)
- err = WSAGetLastError();
- else if (rv == 0) {
- ioctlsocket(sock, FIONBIO, &iostate);
- if(ap_check_alarm() < 0) {
- WSASetLastError(EINTR); /* Simulate an alarm() */
- return (SOCKET_ERROR);
- }
- }
- else {
- rv = SSL_write(ssl, (char*)buf, len);
- if (BIO_sock_should_retry(rv)) {
- ap_log_error(APLOG_MARK,APLOG_DEBUG, NULL,
- "select claimed we could write, "
- "but in fact we couldn't. "
- "This is a bug in Windows.");
- retry = 1;
- Sleep(100);
- }
- }
- } while(retry);
- }
- }
- ioctlsocket(sock, FIONBIO, &iostate);
- if (rv == SOCKET_ERROR)
- WSASetLastError(err);
- return (rv);
-}
-
-static int SSL_recvwithtimeout(BUFF *fb, char *buf, int len)
-{
- int iostate = 1;
- fd_set fdset;
- struct timeval tv;
- int err = WSAEWOULDBLOCK;
- int rv;
- int sock = fb->fd_in;
- SSL *ssl;
- int retry;
-
- ssl = ap_ctx_get(fb->ctx, "ssl");
-
- if (!(tv.tv_sec = ap_check_alarm()))
- return (SSL_read(ssl, buf, len));
-
- rv = ioctlsocket(sock, FIONBIO, &iostate);
- iostate = 0;
- ap_assert(!rv);
- rv = SSL_read(ssl, buf, len);
- if (rv <= 0) {
- if (BIO_sock_should_retry(rv)) {
- do {
- retry = 0;
- FD_ZERO(&fdset);
- FD_SET((unsigned int)sock, &fdset);
- tv.tv_usec = 0;
- rv = select(FD_SETSIZE, &fdset, NULL, NULL, &tv);
- if (rv == SOCKET_ERROR)
- err = WSAGetLastError();
- else if (rv == 0) {
- ioctlsocket(sock, FIONBIO, &iostate);
- ap_check_alarm();
- WSASetLastError(WSAEWOULDBLOCK);
- return (SOCKET_ERROR);
- }
- else {
- rv = SSL_read(ssl, buf, len);
- if (rv == SOCKET_ERROR) {
- if (BIO_sock_should_retry(rv)) {
- ap_log_error(APLOG_MARK,APLOG_DEBUG, NULL,
- "select claimed we could read, "
- "but in fact we couldn't. "
- "This is a bug in Windows.");
- retry = 1;
- Sleep(100);
- }
- else {
- err = WSAGetLastError();
- }
- }
- }
- } while(retry);
- }
- }
- ioctlsocket(sock, FIONBIO, &iostate);
- if (rv == SOCKET_ERROR)
- WSASetLastError(err);
- return (rv);
-}
-
-#endif /*WIN32*/
-
/*
* There is no SSL_writev() provided by OpenSSL. The reason is mainly because
* OpenSSL has to fragment the data itself again for the SSL record layer, so a
/*
* Exec() the child program
*/
-#if defined(WIN32)
- /* MS Windows */
- {
- char pCommand[MAX_STRING_LEN];
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
-
- ap_snprintf(pCommand, sizeof(pCommand), "%s /C %s", SHELL_PATH, cmd);
-
- memset(&si, 0, sizeof(si));
- memset(&pi, 0, sizeof(pi));
-
- si.cb = sizeof(si);
- si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
- si.wShowWindow = SW_HIDE;
- si.hStdInput = pinfo->hPipeInputRead;
- si.hStdOutput = pinfo->hPipeOutputWrite;
- si.hStdError = pinfo->hPipeErrorWrite;
-
- if (CreateProcess(NULL, pCommand, NULL, NULL, TRUE, 0,
- environ, NULL, &si, &pi)) {
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- child_pid = pi.dwProcessId;
- }
- }
-#elif defined(OS2)
- /* IBM OS/2 */
- spawnl(P_NOWAIT, SHELL_PATH, SHELL_PATH, "/c", (char *)cmd, NULL);
-#else
- /* Standard Unix */
execl(SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, NULL);
-#endif
return (child_pid);
}