VirtualBox

Changeset 81147 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Oct 8, 2019 11:54:10 AM (5 years ago)
Author:
vboxsync
Message:

IPRT/process-win.cpp: Don't try open the thread token when RTPROC_FLAGS_AS_IMPERSONATED_TOKEN isn't specified, as there might not be one to open and it will all fail. Instead, open the process when p[w]szUser is NULL. bugref:8078

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/process-win.cpp

    r80569 r81147  
    442442
    443443/**
    444  * Get the token assigned to specified thread indicated by @a hThread.
     444 * Get the token assigned to the thread indicated by @a hThread.
    445445 *
    446446 * Only used when RTPROC_FLAGS_AS_IMPERSONATED_TOKEN is in effect and the
     
    466466        rc = rtProcWinDuplicateToken(hTokenThread, phToken);
    467467        CloseHandle(hTokenThread);
     468    }
     469    else
     470        rc = RTErrConvertFromWin32(GetLastError());
     471    return rc;
     472}
     473
     474
     475/**
     476 * Get the token assigned the process indicated by @a hProcess.
     477 *
     478 * Only used when pwszUser is NULL and RTPROC_FLAGS_AS_IMPERSONATED_TOKEN isn't
     479 * set.
     480 *
     481 * @returns IPRT status code.
     482 * @param   hProcess        The process handle (current process).
     483 * @param   phToken         Where to return the a duplicate of the thread token
     484 *                          handle on success. (The caller closes it.)
     485 */
     486static int rtProcWinGetProcessTokenHandle(HANDLE hProcess, PHANDLE phToken)
     487{
     488    AssertPtr(phToken);
     489
     490    int     rc;
     491    HANDLE hTokenProcess;
     492    if (OpenProcessToken(hProcess,
     493                         TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_DUPLICATE
     494                         | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_SESSIONID | TOKEN_READ | TOKEN_WRITE,
     495                         &hTokenProcess))
     496    {
     497        rc = rtProcWinDuplicateToken(hTokenProcess, phToken); /* not sure if this is strictly necessary */
     498        CloseHandle(hTokenProcess);
    468499    }
    469500    else
     
    16121643    HANDLE  hTokenLogon = INVALID_HANDLE_VALUE;
    16131644    int rc;
    1614     if ((fFlags & RTPROC_FLAGS_AS_IMPERSONATED_TOKEN) || pwszUser == NULL)
     1645    if (fFlags & RTPROC_FLAGS_AS_IMPERSONATED_TOKEN)
    16151646        rc = rtProcWinGetThreadTokenHandle(GetCurrentThread(), &hTokenLogon);
     1647    else if (pwszUser == NULL)
     1648        rc = rtProcWinGetProcessTokenHandle(GetCurrentProcess(), &hTokenLogon);
    16161649    else
    16171650        rc = rtProcWinUserLogon(pwszUser, pwszPassword, &hTokenLogon);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette