Changeset 57917 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Sep 27, 2015 8:38:16 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTProcCreateEx.cpp
r57906 r57917 339 339 static int tstRTCreateProcEx5Child(int argc, char **argv) 340 340 { 341 int rc = RTR3InitExe NoArguments(0);341 int rc = RTR3InitExe(argc, &argv, 0); 342 342 if (RT_FAILURE(rc)) 343 343 return RTMsgInitFailure(rc); 344 344 345 uint32_t cErrors = 0; 346 347 /* Check that the OS thinks we're running as the user we're supposed to. */ 348 char *pszUser; 349 rc = RTProcQueryUsernameA(NIL_RTPROCESS, &pszUser); 350 if (RT_SUCCESS(rc)) 351 { 345 352 #ifdef RT_OS_WINDOWS 346 char szUser[_1K]; 347 DWORD cbLen = sizeof(szUser); 348 /** @todo Does not yet handle ERROR_MORE_DATA for user names longer than 32767. */ 349 if (!GetUserName(szUser, &cbLen)) 350 { 351 RTPrintf("GetUserName failed with last error=%ld\n", GetLastError()); 352 return RTEXITCODE_FAILURE; 353 } 354 # if 0 /* Does not work on NT4 (yet). */ 355 DWORD cbSid = 0; 356 DWORD cbDomain = 0; 357 SID_NAME_USE sidUse; 358 /* First try to figure out how much space for SID + domain name we need. */ 359 BOOL bRet = LookupAccountName(NULL /* current system*/, 360 szUser, 361 NULL, 362 &cbSid, 363 NULL, 364 &cbDomain, 365 &sidUse); 366 if (!bRet) 367 { 368 DWORD dwErr = GetLastError(); 369 if (dwErr != ERROR_INSUFFICIENT_BUFFER) 370 { 371 RTPrintf("LookupAccountName(1) failed with last error=%ld\n", dwErr); 372 return RTEXITCODE_FAILURE; 373 } 374 } 375 376 /* Now try getting the real SID + domain name. */ 377 SID *pSid = (SID *)RTMemAlloc(cbSid); 378 AssertPtr(pSid); 379 char *pszDomain = (char *)RTMemAlloc(cbDomain); /* Size in TCHAR! */ 380 AssertPtr(pszDomain); 381 382 if (!LookupAccountName(NULL /* Current system */, 383 szUser, 384 pSid, 385 &cbSid, 386 pszDomain, 387 &cbDomain, 388 &sidUse)) 389 { 390 RTPrintf("LookupAccountName(2) failed with last error=%ld\n", GetLastError()); 391 return RTEXITCODE_FAILURE; 392 } 393 RTMemFree(pSid); 394 RTMemFree(pszDomain); 395 # endif 353 if (RTStrICmp(pszUser, argv[2]) != 0) 396 354 #else 397 /** @todo Lookup UID/effective UID, maybe GID? */355 if (RTStrCmp(pszUser, argv[2]) != 0) 398 356 #endif 399 return RTEXITCODE_SUCCESS; 357 { 358 RTStrmPrintf(g_pStdErr, "child4: user name is '%s', expected '%s'\n", pszUser, argv[2]); 359 cErrors++; 360 } 361 RTStrFree(pszUser); 362 } 363 else 364 { 365 RTStrmPrintf(g_pStdErr, "child4: RTProcQueryUsernameA failed: %Rrc\n", rc); 366 cErrors++; 367 } 368 369 return cErrors == 0 ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 400 370 } 401 371 … … 403 373 { 404 374 RTTestISubF("As user \"%s\" with password \"%s\"", pszUser, pszPassword); 405 406 const char * apszArgs[3] = 375 RTTESTI_CHECK_RETV(pszUser && *pszUser); 376 377 const char * apszArgs[] = 407 378 { 408 379 "test", /* user name */ 409 380 "--testcase-child-5", 381 pszUser, 410 382 NULL 411 383 }; 412 384 385 /* Test for invalid logons. */ 413 386 RTPROCESS hProc; 414 415 /* Test for invalid logons. */416 387 int rc = RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL, NULL, NULL, 417 388 "non-existing-user", "wrong-password", &hProc); … … 422 393 RTTESTI_CHECK_RC(RTProcCreateEx("non-existing-app", apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL, 423 394 NULL, NULL, NULL, NULL, &hProc), VERR_FILE_NOT_FOUND); 395 424 396 /* Test a (hopefully) valid user/password logon (given by parameters of this function). */ 425 397 RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL, … … 679 651 if (argc >= 5 && !strcmp(argv[1], "--testcase-child-4")) 680 652 return tstRTCreateProcEx4Child(argc, argv); 681 if (argc == 2 && !strcmp(argv[1], "--testcase-child-5"))653 if (argc >= 2 && !strcmp(argv[1], "--testcase-child-5")) 682 654 return tstRTCreateProcEx5Child(argc, argv); 683 655 if (argc >= 2 && !strcmp(argv[1], "--testcase-child-6")) 684 656 return tstRTCreateProcEx6Child(argc, argv); 685 686 657 687 658 /*
Note:
See TracChangeset
for help on using the changeset viewer.