Changeset 30093 in vbox for trunk/src/VBox/Runtime/r3/win/process-win.cpp
- Timestamp:
- Jun 8, 2010 2:30:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r30065 r30093 254 254 255 255 256 /** 257 * Get the process token (not the process handle like the name might indicate) 258 * of the process indicated by @a dwPID if the @a pSID matches. 259 * 260 * @returns IPRT status code. 261 * 262 * @param dwPID The process identifier. 263 * @param pSID The secure identifier of the user. 264 * @param phToken Where to return the token handle - duplicate, 265 * caller closes it on success. 266 */ 256 267 static int rtProcGetProcessHandle(DWORD dwPID, PSID pSID, PHANDLE phToken) 257 268 { … … 261 272 DWORD dwErr; 262 273 BOOL fRc; 263 BOOL fFound = FALSE;274 bool fFound = false; 264 275 HANDLE hProc = OpenProcess(MAXIMUM_ALLOWED, TRUE, dwPID); 265 276 if (hProc != NULL) … … 267 278 HANDLE hTokenProc; 268 279 fRc = OpenProcessToken(hProc, 269 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_DUPLICATE |270 TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_SESSIONID | TOKEN_READ | TOKEN_WRITE,280 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_DUPLICATE 281 | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_SESSIONID | TOKEN_READ | TOKEN_WRITE, 271 282 &hTokenProc); 272 283 if (fRc) … … 300 311 * the actual CreateProcessAsUserW() call then. 301 312 */ 302 fFound = TRUE;313 fFound = true; 303 314 } 304 315 else … … 328 339 329 340 330 static BOOL rtProcFindProcessByName(const char * const *papszNames, PSID pSID, PHANDLE phToken) 341 /** 342 * Finds a one of the processes in @a papszNames running with user @a pSID and 343 * returns a duplicate handle to its token. 344 * 345 * @returns Success indicator. 346 * @param papszNames The process candidates, in prioritized order. 347 * @param pSID The secure identifier of the user. 348 * @param phToken Where to return the token handle - duplicate, 349 * caller closes it on success. 350 */ 351 static bool rtProcFindProcessByName(const char * const *papszNames, PSID pSID, PHANDLE phToken) 331 352 { 332 353 AssertPtr(papszNames); … … 335 356 336 357 DWORD dwErr = NO_ERROR; 337 BOOL fFound = FALSE;358 bool fFound = false; 338 359 339 360 /* … … 365 386 procEntry.dwSize = sizeof(PROCESSENTRY32); 366 387 if (pfnProcess32First(hSnap, &procEntry)) 367 { 388 { 368 389 do 369 390 { … … 371 392 && RT_SUCCESS(rtProcGetProcessHandle(procEntry.th32ProcessID, pSID, phToken))) 372 393 { 373 fFound = TRUE; 394 fFound = true; 395 break; 374 396 } 375 } while (pfnProcess32Next(hSnap, &procEntry) && !fFound);397 } while (pfnProcess32Next(hSnap, &procEntry)); 376 398 } 377 399 else /* Process32First */ … … 407 429 { 408 430 /** @todo Retry if pBytesReturned equals cbBytes! */ 409 DWORD dwPIDs[4096]; /* Should be sufficient for now. */431 DWORD adwPIDs[4096]; /* Should be sufficient for now. */ 410 432 DWORD cbBytes = 0; 411 if (pfnEnumProcesses( dwPIDs, sizeof(dwPIDs), &cbBytes))433 if (pfnEnumProcesses(adwPIDs, sizeof(adwPIDs), &cbBytes)) 412 434 { 413 435 for (size_t i = 0; papszNames[i] && !fFound; i++) … … 416 438 { 417 439 HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 418 FALSE, dwPIDs[dwIdx]);440 FALSE, adwPIDs[dwIdx]); 419 441 if (hProc) 420 442 { … … 429 451 break; 430 452 } while (GetLastError() == ERROR_INSUFFICIENT_BUFFER); 431 453 432 454 if (pszProcName) 433 455 { 434 456 if ( _stricmp(pszProcName, papszNames[i]) == 0 435 && RT_SUCCESS(rtProcGetProcessHandle( dwPIDs[dwIdx], pSID, phToken)))457 && RT_SUCCESS(rtProcGetProcessHandle(adwPIDs[dwIdx], pSID, phToken))) 436 458 { 437 fFound = TRUE;459 fFound = true; 438 460 } 439 461 } … … 552 574 &hTokenLogon); 553 575 554 BOOL fFound = FALSE;576 bool fFound = false; 555 577 HANDLE hTokenUserDesktop = INVALID_HANDLE_VALUE; 556 578 if (fRc) … … 598 620 { 599 621 /* Array of process names we want to look for. */ 600 char *papszProcNames[] = 601 #ifdef VBOX 602 /* 603 * Add lookup for "explorer.exe" as a fallback in case the VBox 604 * Guest Additions are not (yet) installed, but prefer looking 605 * up "VBoxTray.exe" in the first place. 606 */ 607 { { "VBoxTray.exe" }, 608 { "explorer.exe" }, 609 NULL 610 }; 611 #else 612 { { "explorer.exe" }, 613 NULL 614 }; 615 #endif 616 fFound = rtProcFindProcessByName(papszProcNames, 617 pSID, &hTokenUserDesktop); 622 static const char * const s_papszProcNames[] = 623 { 624 #ifdef VBOX /* The explorer entry is a fallback in case GA aren't installed. */ 625 { "VBoxTray.exe" }, 626 #endif 627 { "explorer.exe" }, 628 NULL 629 }; 630 fFound = rtProcFindProcessByName(s_papszProcNames, pSID, &hTokenUserDesktop); 618 631 } 619 632 else … … 638 651 /* 639 652 * Useful KB articles: 640 * http://support.microsoft.com/kb/165194/641 * http://support.microsoft.com/kb/184802/642 * http://support.microsoft.com/kb/327618/653 * http://support.microsoft.com/kb/165194/ 654 * http://support.microsoft.com/kb/184802/ 655 * http://support.microsoft.com/kb/327618/ 643 656 */ 644 657 fRc = CreateProcessAsUserW(*phToken, … … 681 694 case ERROR_PASSWORD_EXPIRED: 682 695 case ERROR_ACCOUNT_RESTRICTION: /* See: http://support.microsoft.com/kb/303846/ */ 683 rc = VERR_ LOGON_FAILURE;696 rc = VERR_AUTHENTICATION_FAILURE; 684 697 break; 685 698 … … 818 831 * Get going... 819 832 */ 833 PROCESS_INFORMATION ProcInfo; 834 RT_ZERO(ProcInfo); 820 835 DWORD dwCreationFlags = CREATE_UNICODE_ENVIRONMENT; 821 836 if (fFlags & RTPROC_FLAGS_DETACHED) 822 837 dwCreationFlags |= DETACHED_PROCESS; 823 824 PROCESS_INFORMATION ProcInfo;825 RT_ZERO(ProcInfo);826 838 827 839 /*
Note:
See TracChangeset
for help on using the changeset viewer.