diff options
author | Pierre Joye <pajoye@php.net> | 2009-09-03 19:16:50 +0000 |
---|---|---|
committer | Pierre Joye <pajoye@php.net> | 2009-09-03 19:16:50 +0000 |
commit | 511c923785724b082a2efd4073e89027d8c6c92b (patch) | |
tree | 4bb9161f160f5c800a7ab0c9079087537b4214fe /TSRM | |
parent | 4016bfcd719171b128f20196a2a6eda8b3d8dd0e (diff) | |
download | php-git-511c923785724b082a2efd4073e89027d8c6c92b.tar.gz |
- #27051, improve fix on xp/2k3
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/tsrm_win32.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index c96ffb687d..589ee1e1ef 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -318,6 +318,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) { @@ -373,13 +375,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) { |