Skip to content

Commit

Permalink
Fixed FastCGI impersonation for persistent connections on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Dec 5, 2006
1 parent 8f5786b commit 7389f59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2007, PHP 5.2.1
- Fixed FastCGI impersonation for persistent connections on Windows. (Dmitry)
- Added a meta tag to phpinfo() output to prevent search engines from indexing
the page. (Ilia)
- Added missing object support to file_put_contents(). (Ilia)
Expand Down
26 changes: 17 additions & 9 deletions sapi/cgi/fastcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -718,6 +717,15 @@ int fcgi_accept_request(fcgi_request *req)
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);
Expand Down

0 comments on commit 7389f59

Please sign in to comment.