]> granicus.if.org Git - php/commitdiff
- #27051, create process as impersonated user
authorPierre Joye <pajoye@php.net>
Tue, 1 Sep 2009 22:51:31 +0000 (22:51 +0000)
committerPierre Joye <pajoye@php.net>
Tue, 1 Sep 2009 22:51:31 +0000 (22:51 +0000)
TSRM/tsrm_win32.c

index 2e38f1b357df4615038a25cbe6ff1404401c182d..688c43178e3e11b7301c5829b65d6e842d3ca908 100644 (file)
@@ -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);