dmitry          Thu Mar  1 07:51:07 2007 UTC

  Modified files:              (Branch: PHP_4_4)
    /php-src/sapi/cgi/libfcgi   fcgiapp.c os_win32.c 
    /php-src/sapi/cgi/libfcgi/include   fcgios.h 
  Log:
  Impersonation fix
  
  
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/libfcgi/fcgiapp.c?r1=1.1.4.3.2.2&r2=1.1.4.3.2.3&diff_format=u
Index: php-src/sapi/cgi/libfcgi/fcgiapp.c
diff -u php-src/sapi/cgi/libfcgi/fcgiapp.c:1.1.4.3.2.2 
php-src/sapi/cgi/libfcgi/fcgiapp.c:1.1.4.3.2.3
--- php-src/sapi/cgi/libfcgi/fcgiapp.c:1.1.4.3.2.2      Tue Feb 27 15:15:56 2007
+++ php-src/sapi/cgi/libfcgi/fcgiapp.c  Thu Mar  1 07:51:07 2007
@@ -11,7 +11,7 @@
  *
  */
 #ifndef lint
-static const char rcsid[] = "$Id: fcgiapp.c,v 1.1.4.3.2.2 2007/02/27 15:15:56 
dmitry Exp $";
+static const char rcsid[] = "$Id: fcgiapp.c,v 1.1.4.3.2.3 2007/03/01 07:51:07 
dmitry Exp $";
 #endif /* not lint */
 
 #include <assert.h>
@@ -2061,6 +2061,10 @@
         OS_IpcClose(request->ipcFd, ! request->detached);
         request->ipcFd = -1;
         request->detached = 0;
+#ifdef _WIN32
+    } else {
+        OS_StopImpersonation();
+#endif
     }
 }
 
@@ -2225,6 +2229,10 @@
             if (reqDataPtr->ipcFd < 0) {
                 return (errno > 0) ? (0 - errno) : -9999;
             }
+#ifdef _WIN32
+               } else if (!OS_StartImpersonation()) {
+                       FCGX_Free(reqDataPtr, 1);
+#endif
         }
         /*
          * A connection is open.  Read from the connection in order to
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/libfcgi/os_win32.c?r1=1.6.2.1.4.2&r2=1.6.2.1.4.3&diff_format=u
Index: php-src/sapi/cgi/libfcgi/os_win32.c
diff -u php-src/sapi/cgi/libfcgi/os_win32.c:1.6.2.1.4.2 
php-src/sapi/cgi/libfcgi/os_win32.c:1.6.2.1.4.3
--- php-src/sapi/cgi/libfcgi/os_win32.c:1.6.2.1.4.2     Tue Feb 27 15:15:56 2007
+++ php-src/sapi/cgi/libfcgi/os_win32.c Thu Mar  1 07:51:07 2007
@@ -17,7 +17,7 @@
  *  significantly more enjoyable.)
  */
 #ifndef lint
-static const char rcsid[] = "$Id: os_win32.c,v 1.6.2.1.4.2 2007/02/27 15:15:56 
dmitry Exp $";
+static const char rcsid[] = "$Id: os_win32.c,v 1.6.2.1.4.3 2007/03/01 07:51:07 
dmitry Exp $";
 #endif /* not lint */
 
 #define WIN32_LEAN_AND_MEAN 
@@ -306,6 +306,18 @@
        return 0;
 }
 
+int OS_StartImpersonation(void)
+{
+       return (!bImpersonate ||
+               ((hListen != INVALID_HANDLE_VALUE) && 
+                !ImpersonateNamedPipeClient(hListen)));
+}
+
+void OS_StopImpersonation(void)
+{
+       if (bImpersonate) RevertToSelf();
+}
+
 /*
  *--------------------------------------------------------------
  *
@@ -596,7 +608,7 @@
     if (stdioHandles[0] != INVALID_HANDLE_VALUE) {
                DisconnectNamedPipe(hListen);
                CancelIo(hListen);
-               if (bImpersonate) RevertToSelf();
+               OS_StopImpersonation();
        }
 
     WSACleanup();
@@ -1763,14 +1775,14 @@
     //
     // impersonate the client
     //
-    if(bImpersonate && !ImpersonateNamedPipeClient(hListen)) {
+    if(bImpersonate && OS_StartImpersonation()) {
         DisconnectNamedPipe(hListen);
     } else {
                ipcFd = Win32NewDescriptor(FD_PIPE_SYNC, (int) hListen, -1);
                if (ipcFd == -1) 
                {
                        DisconnectNamedPipe(hListen);
-                       if (bImpersonate) RevertToSelf();
+                       OS_StopImpersonation();
                }
        }
 
@@ -1975,7 +1987,7 @@
 
         if (! DisconnectNamedPipe(fdTable[ipcFd].fid.fileHandle)) return -1;
 
-        if (bImpersonate) RevertToSelf();
+               OS_StopImpersonation();
 
         /* fall through */
     case FD_SOCKET_SYNC:
@@ -2049,4 +2061,3 @@
     }
     return;
 }
-
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/libfcgi/include/fcgios.h?r1=1.2.4.2.4.2&r2=1.2.4.2.4.3&diff_format=u
Index: php-src/sapi/cgi/libfcgi/include/fcgios.h
diff -u php-src/sapi/cgi/libfcgi/include/fcgios.h:1.2.4.2.4.2 
php-src/sapi/cgi/libfcgi/include/fcgios.h:1.2.4.2.4.3
--- php-src/sapi/cgi/libfcgi/include/fcgios.h:1.2.4.2.4.2       Tue Feb 27 
15:15:56 2007
+++ php-src/sapi/cgi/libfcgi/include/fcgios.h   Thu Mar  1 07:51:07 2007
@@ -129,6 +129,8 @@
 
 #ifdef _WIN32
 DLLAPI int OS_SetImpersonate(void);
+int OS_StartImpersonation(void);
+void OS_StopImpersonation(void);
 #endif
 
 #if defined (__cplusplus) || defined (c_plusplus)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to