From: Pierre Joye Date: Tue, 1 Sep 2009 22:51:31 +0000 (+0000) Subject: - #27051, create process as impersonated user X-Git-Tag: php-5.4.0alpha1~191^2~2708 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cef4372ce34d110b98d5f1a241693d853e6e7e0;p=php - #27051, create process as impersonated user --- diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 2e38f1b357..688c43178e 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -312,6 +312,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, SECURITY_ATTRIBUTES security; HANDLE in, out; DWORD dwCreateFlags = 0; + BOOL res; process_pair *proc; char *cmd; int i; @@ -353,7 +354,6 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, read = (type[0] == 'r') ? TRUE : FALSE; mode = ((type_len == 2) && (type[1] == 'b')) ? O_BINARY : O_TEXT; - if (read) { in = dupHandle(in, FALSE); startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE); @@ -372,12 +372,17 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2); sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command); - if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process)) { - free(cmd); - return NULL; + if(TWG(impersonation_token) == NULL) { + res = CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process); + } else { + res = CreateProcessAsUser(TWG(impersonation_token), NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process); } free(cmd); + if (!res) { + return NULL; + } + CloseHandle(process.hThread); proc = process_get(NULL TSRMLS_CC);