Changeset 27473 in vbox for trunk/src/VBox
- Timestamp:
- Mar 18, 2010 10:51:28 AM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r27345 r27473 1022 1022 VBoxRT_LIBS.win = \ 1023 1023 $(PATH_SDK_W2K3DDK_LIB)/vccomsup.lib \ 1024 $(PATH_SDK_W2K3DDK_LIB)/wbemuuid.lib 1024 $(PATH_SDK_W2K3DDK_LIB)/wbemuuid.lib \ 1025 $(PATH_SDK_W2K3DDK_LIB)/Userenv.lib 1025 1026 VBoxRT_LDFLAGS.darwin = -framework IOKit -framework CoreFoundation -install_name $(VBOX_DYLD_EXECUTABLE_PATH)/VBoxRT.dylib 1026 1027 ifdef VBOX_USE_VCC80 -
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r27451 r27473 35 35 #define LOG_GROUP RTLOGGROUP_PROCESS 36 36 37 #include <Userenv.h> 37 38 #include <Windows.h> 38 39 #include <process.h> … … 47 48 #include <iprt/env.h> 48 49 #include <iprt/getopt.h> 50 #include <iprt/ldr.h> 49 51 #include <iprt/pipe.h> 50 52 #include <iprt/string.h> … … 80 82 ProcessWow64Information = 26 81 83 } PROCESSINFOCLASS; 84 85 typedef WINADVAPI BOOL WINAPI CREATEPROCESSWITHLOGON(LPCWSTR, 86 LPCWSTR, 87 LPCWSTR, 88 DWORD, 89 LPCWSTR, 90 LPWSTR, 91 DWORD, 92 LPVOID, 93 LPCWSTR, 94 LPSTARTUPINFOW, 95 LPPROCESS_INFORMATION); 96 97 typedef CREATEPROCESSWITHLOGON *PCREATEPROCESSWITHLOGON; 82 98 83 99 extern "C" LONG WINAPI … … 194 210 StartupInfo.cb = sizeof(StartupInfo); 195 211 StartupInfo.dwFlags = STARTF_USESTDHANDLES; 212 /* Use WTSEnumerateSessions() for getting a list of sessions (WTS_SESSION_INFO array), 213 * get wanted user with WTSQuerySessionInformation() and get session ID token with 214 * WTSQueryUserToken() to use with CreateProcessAsUser(). */ 215 StartupInfo.lpDesktop = L"Winsta0\\Default"; 196 216 #if 1 /* The CRT should keep the standard handles up to date. */ 197 217 StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); … … 302 322 if (fRc) 303 323 { 304 fRc = CreateProcessAsUserW(hToken, 305 pwszExec, 306 pwszCmdLine, 307 NULL, /* pProcessAttributes */ 308 NULL, /* pThreadAttributes */ 309 TRUE, /* fInheritHandles */ 310 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 311 pwszzBlock, 312 NULL, /* pCurrentDirectory */ 313 &StartupInfo, 314 &ProcInfo); 315 if (!fRc) 324 PROFILEINFOW profileInfo; 325 RT_ZERO(profileInfo); 326 profileInfo.dwSize = sizeof(PROFILEINFOW); 327 profileInfo.lpUserName = pwszUser; 328 fRc = LoadUserProfileW(hToken, &profileInfo); 329 if (fRc) 316 330 { 317 /* CreateProcessWithLogonW is not available on NT4 ... so enabling the following code 318 * would blow up compatibility but is a legitim fallback if the above method isn't working. */ 331 fRc = CreateProcessAsUserW(hToken, 332 pwszExec, 333 pwszCmdLine, 334 NULL, /* pProcessAttributes */ 335 NULL, /* pThreadAttributes */ 336 TRUE, /* fInheritHandles */ 337 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 338 pwszzBlock, 339 NULL, /* pCurrentDirectory */ 340 &StartupInfo, 341 &ProcInfo); 342 if (!fRc) 343 { 344 DWORD dwErr = GetLastError(); 345 346 /* 347 * If we don't hold enough priviledges to spawn a new 348 * process with different credentials we have to use 349 * CreateProcessWithLogonW here. 350 * 351 * Note that NT4 does *not* support this API, thus we have 352 * to load it dynamically (W2K+) to not blow up things. 353 * 354 * @todo Use fFlags to either use this feature or just fail. 355 */ 356 if (ERROR_PRIVILEGE_NOT_HELD == dwErr) 357 { 319 358 #if 0 320 DWORD dwErr = GetLastError(); 321 322 /* 323 * If we don't hold enough priviledges to spawn a new 324 * process with different credentials we have to use 325 * CreateProcessWithLogonW here. 326 * 327 * @todo Use fFlags to either use this feature or just fail. 328 */ 329 if (ERROR_PRIVILEGE_NOT_HELD == dwErr) 330 { 331 fRc = CreateProcessWithLogonW(pwszUser, 332 NULL, /* lpDomain*/ 333 pwszPassword, 334 LOGON_WITH_PROFILE, /* dwLogonFlags */ 335 pwszExec, 336 pwszCmdLine, 337 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 338 pwszzBlock, 339 NULL, /* pCurrentDirectory */ 340 &StartupInfo, 341 &ProcInfo); 359 RTLDRMOD modAdvAPI32; 360 rc = RTLdrLoad("Advapi32.dll", &modAdvAPI32); 361 PCREATEPROCESSWITHLOGON pfnCreateProcessWithLogonW; 362 if (RT_SUCCESS(rc)) 363 { 364 rc = RTLdrGetSymbol(modAdvAPI32, "CreateProcessWithLogonW", (void**)&pfnCreateProcessWithLogonW); 365 if (RT_SUCCESS(rc)) 366 { 367 #endif 368 fRc = ImpersonateLoggedOnUser(hToken); 369 if (fRc) 370 { 371 fRc = CreateProcessW(pwszExec, 372 pwszCmdLine, 373 NULL, /* pProcessAttributes */ 374 NULL, /* pThreadAttributes */ 375 TRUE, /* fInheritHandles */ 376 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 377 pwszzBlock, 378 NULL, /* pCurrentDirectory */ 379 &StartupInfo, 380 &ProcInfo); 381 RevertToSelf(); 382 } 383 #if 0 384 fRc = pfnCreateProcessWithLogonW(pwszUser, 385 NULL, /* lpDomain*/ 386 pwszPassword, 387 0 /*LOGON_WITH_PROFILE*/, /* dwLogonFlags */ 388 pwszExec, 389 pwszCmdLine, 390 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 391 pwszzBlock, 392 NULL, /* pCurrentDirectory */ 393 &StartupInfo, 394 &ProcInfo); 395 } 396 RTLdrClose(modAdvAPI32); 397 } 398 #endif 399 } 342 400 } 343 #endif344 401 } 345 402 CloseHandle(hToken);
Note:
See TracChangeset
for help on using the changeset viewer.