Changeset 27451 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Mar 17, 2010 3:06:44 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r27416 r27451 169 169 RTR3DECL(int) RTProcCreateEx(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags, 170 170 PCRTHANDLE phStdIn, PCRTHANDLE phStdOut, PCRTHANDLE phStdErr, const char *pszAsUser, 171 PRTPROCESS phProcess)171 const char *pszPassword, PRTPROCESS phProcess) 172 172 { 173 173 #if 1 /* needs more work... dinner time. */ … … 183 183 AssertPtrReturn(papszArgs, VERR_INVALID_PARAMETER); 184 184 /** @todo search the PATH (add flag for this). */ 185 AssertPtrNullReturn(pszAsUser, VERR_INVALID_POINTER);186 185 187 186 /* … … 253 252 if (RT_SUCCESS(rc)) 254 253 { 255 HANDLE hToken = INVALID_HANDLE_VALUE; 256 if (pszAsUser) 254 /* 255 * Get going... 256 */ 257 PROCESS_INFORMATION ProcInfo; 258 RT_ZERO(ProcInfo); 259 BOOL fRc; 260 if (pszAsUser == NULL) 261 fRc = CreateProcessW(pwszExec, 262 pwszCmdLine, 263 NULL, /* pProcessAttributes */ 264 NULL, /* pThreadAttributes */ 265 TRUE, /* fInheritHandles */ 266 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 267 pwszzBlock, 268 NULL, /* pCurrentDirectory */ 269 &StartupInfo, 270 &ProcInfo); 271 else 257 272 { 258 /** @todo - Maybe use CreateProcessWithLoginW? That'll require a password, but 259 * we may need that anyway because it looks like LogonUserW is the only 260 * way to get a hToken. FIXME */ 261 rc = VERR_NOT_IMPLEMENTED; 273 HANDLE hToken = INVALID_HANDLE_VALUE; 274 PRTUTF16 pwszUser; 275 276 rc = RTStrToUtf16(pszAsUser, &pwszUser); 277 if (RT_SUCCESS(rc)) 278 { 279 PRTUTF16 pwszPassword; 280 rc = RTStrToUtf16(pszPassword, &pwszPassword); 281 if (RT_SUCCESS(rc)) 282 { 283 /* 284 * User needs to be specified in UPN format because we 285 * don't fill a domain name. 286 */ 287 288 /* 289 * The following rights are needed in order to use 290 * LogonUserW and CreateProcessAsUserW: 291 * 292 * - SE_ASSIGNPRIMARYTOKEN_NAME 293 * - SE_INCREASE_QUOTA_NAME 294 * - SE_TCB_NAME 295 */ 296 fRc = LogonUserW(pwszUser, 297 NULL, /* lpDomain */ 298 pszPassword ? pwszPassword : L"", 299 LOGON32_LOGON_INTERACTIVE, 300 LOGON32_PROVIDER_DEFAULT, 301 &hToken); 302 if (fRc) 303 { 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) 316 { 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. */ 319 #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); 342 } 343 #endif 344 } 345 CloseHandle(hToken); 346 } 347 RTUtf16Free(pwszPassword); 348 } 349 RTUtf16Free(pwszUser); 350 } 262 351 } 263 if (RT_SUCCESS(rc)) 352 353 if (fRc) 264 354 { 265 /* 266 * Get going... 267 */ 268 PROCESS_INFORMATION ProcInfo; 269 RT_ZERO(ProcInfo); 270 BOOL fRc; 271 if (hToken == INVALID_HANDLE_VALUE) 272 fRc = CreateProcessW(pwszExec, 273 pwszCmdLine, 274 NULL, /* pProcessAttributes */ 275 NULL, /* pThreadAttributes */ 276 TRUE, /* fInheritHandles */ 277 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 278 pwszzBlock, 279 NULL, /* pCurrentDirectory */ 280 &StartupInfo, 281 &ProcInfo); 282 else 283 fRc = CreateProcessAsUserW(hToken, 284 pwszExec, 285 pwszCmdLine, 286 NULL, /* pProcessAttributes */ 287 NULL, /* pThreadAttributes */ 288 TRUE, /* fInheritHandles */ 289 CREATE_UNICODE_ENVIRONMENT, /* dwCreationFlags */ 290 pwszzBlock, 291 NULL, /* pCurrentDirectory */ 292 &StartupInfo, 293 &ProcInfo); 294 295 if (fRc) 355 CloseHandle(ProcInfo.hThread); 356 if (phProcess) 296 357 { 297 CloseHandle(ProcInfo.hThread); 298 if (phProcess) 299 { 300 /** @todo Remember the process handle and pick it up in RTProcWait. */ 301 *phProcess = ProcInfo.dwProcessId; 302 } 303 else 304 CloseHandle(ProcInfo.hProcess); 305 rc = VINF_SUCCESS; 358 /** @todo Remember the process handle and pick it up in RTProcWait. */ 359 *phProcess = ProcInfo.dwProcessId; 306 360 } 307 361 else 308 rc = RTErrConvertFromWin32(GetLastError()); 309 310 if (hToken != INVALID_HANDLE_VALUE) 311 CloseHandle(hToken); 362 CloseHandle(ProcInfo.hProcess); 363 rc = VINF_SUCCESS; 312 364 } 365 else 366 rc = RTErrConvertFromWin32(GetLastError()); 313 367 RTUtf16Free(pwszExec); 314 368 } -
trunk/src/VBox/Runtime/testcase/tstRTProcCreateEx.cpp
r27437 r27451 130 130 return VERR_AUTHENTICATION_FAILURE; 131 131 } 132 else133 {134 RTPrintf("NameSamCompatible: %s\n"135 "DomainName: %s\n",136 pszDomain, szUser);137 }138 132 RTMemFree(pSid); 139 133 RTMemFree(pszDomain); … … 147 141 static void tstRTCreateProcEx5(void) 148 142 { 149 RTTestISub("Impersonation (as user )");143 RTTestISub("Impersonation (as user \"test\")"); 150 144 151 145 const char * apszArgs[3] = … … 158 152 RTPROCESS hProc; 159 153 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL, 160 NULL, NULL, NULL, &hProc), VINF_SUCCESS);154 NULL, NULL, "testcase", "test", &hProc), VINF_SUCCESS); 161 155 RTPROCSTATUS ProcStatus = { -1, RTPROCEXITREASON_ABEND }; 162 156 RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS); … … 193 187 RTPROCESS hProc; 194 188 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, g_apszArgs4, RTENV_DEFAULT, 0 /*fFlags*/, NULL, 195 NULL, NULL, NULL, &hProc), VINF_SUCCESS);189 NULL, NULL, NULL, NULL, &hProc), VINF_SUCCESS); 196 190 RTPROCSTATUS ProcStatus = { -1, RTPROCEXITREASON_ABEND }; 197 191 RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS); … … 236 230 RTPROCESS hProc; 237 231 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL, 238 &Handle, &Handle, NULL, &hProc), VINF_SUCCESS);232 &Handle, &Handle, NULL, NULL, &hProc), VINF_SUCCESS); 239 233 RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS); 240 234 … … 303 297 RTPROCESS hProc; 304 298 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL, 305 NULL, &Handle, NULL, &hProc), VINF_SUCCESS);299 NULL, &Handle, NULL, NULL, &hProc), VINF_SUCCESS); 306 300 RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS); 307 301 … … 369 363 RTPROCESS hProc; 370 364 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL, 371 &Handle, NULL, NULL, &hProc), VINF_SUCCESS);365 &Handle, NULL, NULL, NULL, &hProc), VINF_SUCCESS); 372 366 RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS); 373 367
Note:
See TracChangeset
for help on using the changeset viewer.