]> granicus.if.org Git - php/commitdiff
- #27051, improve fix on xp/2k3
authorPierre Joye <pajoye@php.net>
Thu, 3 Sep 2009 19:16:17 +0000 (19:16 +0000)
committerPierre Joye <pajoye@php.net>
Thu, 3 Sep 2009 19:16:17 +0000 (19:16 +0000)
TSRM/tsrm_win32.c

index 7389665b9e83f18c93286b34a2f6806a12f15507..d8d4214b914865b0df905a9b859aab7067cc45fb 100644 (file)
@@ -319,6 +319,8 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
        char *ptype = (char *)type;
        HANDLE thread_token = NULL;
        HANDLE token_user = NULL;
+       BOOL asuser = FALSE;
+
        TSRMLS_FETCH();
 
        if (!type) {
@@ -374,13 +376,22 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
        /* Get a token with the impersonated user. */
        if(OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &thread_token)) {
                DuplicateTokenEx(thread_token, MAXIMUM_ALLOWED, &security, SecurityImpersonation, TokenPrimary, &token_user);
+       } else {
+               DWORD err = GetLastError();
+               if (err == ERROR_NO_TOKEN) {
+                       asuser = FALSE;
+               }
+
        }
 
        cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2);
        sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command);
-
-       res = CreateProcessAsUser(token_user, NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process);
-       CloseHandle(token_user);
+       if (asuser) {
+               res = CreateProcessAsUser(token_user, NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process);
+               CloseHandle(token_user);
+       } else {
+               res = CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process);
+       }
        free(cmd);
 
        if (!res) {