Changeset 39864 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Jan 24, 2012 9:24:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r39863 r39864 343 343 { 344 344 PTOKEN_USER pTokenUser = (PTOKEN_USER)RTMemAlloc(dwSize); 345 AssertPtrReturn(pTokenUser, VERR_NO_MEMORY); 345 AssertPtrReturn(pTokenUser, VERR_NO_MEMORY); /** @todo r=bird: Leaking handles when we're out of memory... */ 346 346 RT_ZERO(*pTokenUser); 347 347 if ( GetTokenInformation(hTokenProc, … … 396 396 * @returns Success indicator. 397 397 * @param papszNames The process candidates, in prioritized order. 398 * @param pS IDThe secure identifier of the user.398 * @param pSid The secure identifier of the user. 399 399 * @param phToken Where to return the token handle - duplicate, 400 400 * caller closes it on success. 401 401 */ 402 static bool rtProcFindProcessByName(const char * const *papszNames, PSID pS ID, PHANDLE phToken)402 static bool rtProcFindProcessByName(const char * const *papszNames, PSID pSid, PHANDLE phToken) 403 403 { 404 404 AssertPtr(papszNames); 405 AssertPtr(pS ID);405 AssertPtr(pSid); 406 406 AssertPtr(phToken); 407 407 … … 441 441 { 442 442 if ( _stricmp(procEntry.szExeFile, papszNames[i]) == 0 443 && RT_SUCCESS(rtProcGetProcessHandle(procEntry.th32ProcessID, pS ID, phToken)))443 && RT_SUCCESS(rtProcGetProcessHandle(procEntry.th32ProcessID, pSid, phToken))) 444 444 { 445 445 fFound = true; … … 506 506 { 507 507 if ( _stricmp(pszProcName, papszNames[i]) == 0 508 && RT_SUCCESS(rtProcGetProcessHandle(adwPIDs[dwIdx], pS ID, phToken)))508 && RT_SUCCESS(rtProcGetProcessHandle(adwPIDs[dwIdx], pSid, phToken))) 509 509 { 510 510 fFound = true; … … 756 756 pProcInfo); 757 757 if (!fRc) 758 dwErr = GetLastError();758 rc = rtProcMapErrorCodes(GetLastError()); 759 759 rtProcEnvironmentDestroy(pwszzBlock); 760 760 } … … 768 768 * we're running as a Windows service? 769 769 */ 770 if ( RT_FAILURE(rc) /** @todo r=bird: you don't set rc when pfnCreateProcesswithLogonW fails... Using too many variables to control flow is confusing. */770 if ( RT_FAILURE(rc) 771 771 || (fFlags & RTPROC_FLAGS_SERVICE)) 772 772 { … … 807 807 if (fFlags & RTPROC_FLAGS_SERVICE) 808 808 { 809 DWORD cb Name= 0; /* Must be zero to query size! */810 DWORD c bDomain = 0;809 DWORD cbSid = 0; /* Must be zero to query size! */ 810 DWORD cchDomain = 0; 811 811 SID_NAME_USE sidNameUse = SidTypeUser; 812 812 fRc = LookupAccountNameW(NULL, 813 813 pwszUser, 814 814 NULL, 815 &cb Name,815 &cbSid, 816 816 NULL, 817 &c bDomain,817 &cchDomain, 818 818 &sidNameUse); 819 819 if (!fRc) … … 821 821 if ( !fRc 822 822 && dwErr == ERROR_INSUFFICIENT_BUFFER 823 && cb Name> 0)823 && cbSid > 0) 824 824 { 825 825 dwErr = NO_ERROR; 826 826 827 PSID pSID = (PSID)RTMemAlloc(cbName * sizeof(wchar_t)); 828 AssertPtrReturn(pSID, VERR_NO_MEMORY); 829 830 /** @todo No way to allocate a PRTUTF16 directly? */ 827 PSID pSid = (PSID)RTMemAlloc(cbSid * sizeof(wchar_t)); /** @todo r=bird: What's the relationship between wchar_t and PSID? */ 828 AssertPtrReturn(pSid, VERR_NO_MEMORY); /** @todo r=bird: Leaking token handles when we're out of memory... */ 829 831 830 PRTUTF16 pwszDomain = NULL; 832 if (c bDomain > 0)831 if (cchDomain > 0) 833 832 { 834 pwszDomain = (PRTUTF16)RTMemAlloc(c bDomain * sizeof(RTUTF16));835 AssertPtrReturn(pwszDomain, VERR_NO_MEMORY); 833 pwszDomain = (PRTUTF16)RTMemAlloc(cchDomain * sizeof(RTUTF16)); 834 AssertPtrReturn(pwszDomain, VERR_NO_MEMORY); /** @todo r=bird: Leaking token handles when we're out of memory... */ 836 835 } 837 836 … … 839 838 if ( LookupAccountNameW(NULL, /* lpSystemName */ 840 839 pwszUser, 841 pS ID,842 &cb Name,840 pSid, 841 &cbSid, 843 842 pwszDomain, 844 &c bDomain,843 &cchDomain, 845 844 &sidNameUse) 846 && IsValidSid(pS ID))845 && IsValidSid(pSid)) 847 846 { 848 847 /* Array of process names we want to look for. */ … … 855 854 NULL 856 855 }; 857 fFound = rtProcFindProcessByName(s_papszProcNames, pS ID, &hTokenUserDesktop);856 fFound = rtProcFindProcessByName(s_papszProcNames, pSid, &hTokenUserDesktop); 858 857 } 859 858 else 860 859 dwErr = GetLastError(); /* LookupAccountNameW() failed. */ 861 860 RTMemFree(pSID); 862 if (pwszDomain != NULL) 863 RTUtf16Free(pwszDomain); 861 RTMemFree(pwszDomain); 864 862 } 865 863 } … … 897 895 if (!(fFlags & RTPROC_FLAGS_NO_PROFILE)) 898 896 { 899 ZeroMemory(&profileInfo, sizeof(profileInfo));897 RT_ZERO(profileInfo); 900 898 profileInfo.dwSize = sizeof(profileInfo); 901 899 profileInfo.lpUserName = pwszUser;
Note:
See TracChangeset
for help on using the changeset viewer.