From: Dmitry Stogov Date: Tue, 5 Dec 2006 08:55:34 +0000 (+0000) Subject: Fixed FastCGI impersonation for persistent connections on Windows X-Git-Tag: RELEASE_1_0_0RC1~813 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65f8f4569245a4d17fb2b0f539f8590b508be7fd;p=php Fixed FastCGI impersonation for persistent connections on Windows --- diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c index 1d0569f14a..381e1ddcec 100644 --- a/sapi/cgi/fastcgi.c +++ b/sapi/cgi/fastcgi.c @@ -616,6 +616,13 @@ static inline void fcgi_close(fcgi_request *req, int force, int destroy) if (destroy) { zend_hash_destroy(&req->env); } + +#ifdef _WIN32 + if (is_impersonate) { + RevertToSelf(); + } +#endif + if ((force || !req->keep) && req->fd >= 0) { #ifdef _WIN32 HANDLE pipe = (HANDLE)_get_osfhandle(req->fd); @@ -624,9 +631,6 @@ static inline void fcgi_close(fcgi_request *req, int force, int destroy) FlushFileBuffers(pipe); } DisconnectNamedPipe(pipe); - if (is_impersonate) { - RevertToSelf(); - } #else if (!force) { char buf[8]; @@ -673,12 +677,7 @@ int fcgi_accept_request(fcgi_request *req) } } CloseHandle(ov.hEvent); - if (is_impersonate && !ImpersonateNamedPipeClient(pipe)) { - DisconnectNamedPipe(pipe); - req->fd = -1; - } else { - req->fd = req->listen_socket; - } + req->fd = req->listen_socket; FCGI_UNLOCK(req->listen_socket); #else { @@ -718,6 +717,15 @@ try_again: return -1; } if (fcgi_read_request(req)) { +#ifdef _WIN32 + if (is_impersonate) { + pipe = (HANDLE)_get_osfhandle(req->fd); + if (!ImpersonateNamedPipeClient(pipe)) { + fcgi_close(req, 1, 1); + continue; + } + } +#endif return req->fd; } else { fcgi_close(req, 1, 1);