Changeset 38946 in vbox for trunk/src/VBox
- Timestamp:
- Oct 5, 2011 4:52:03 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
r38131 r38946 50 50 WCHAR wszAuthenticationPackage[_MAX_PATH]; 51 51 WCHAR wszLogonDomain[_MAX_PATH]; 52 /** Number of assigned user processes. */ 53 ULONG ulNumProcs; 52 54 } VBOXSERVICEVMINFOUSER, *PVBOXSERVICEVMINFOUSER; 53 55 … … 380 382 || (SECURITY_LOGON_TYPE)pSessionData->LogonType == CachedRemoteInteractive)) 381 383 { 382 VBoxServiceVerbose(3, "VMInfo/Users: Session data: Name=%ls, Len=%d, SID=%s, LogonID=%ld,%ld \n",384 VBoxServiceVerbose(3, "VMInfo/Users: Session data: Name=%ls, Len=%d, SID=%s, LogonID=%ld,%ld, LogonType=%ld\n", 383 385 pSessionData->UserName.Buffer, 384 386 pSessionData->UserName.Length, 385 387 pSessionData->Sid != NULL ? "1" : "0", 386 pSessionData->LogonId.HighPart, pSessionData->LogonId.LowPart); 388 pSessionData->LogonId.HighPart, pSessionData->LogonId.LowPart, 389 pSessionData->LogonType); 387 390 388 391 /* … … 503 506 { 504 507 PLUID paSessions = NULL; 505 ULONG cSession = 0;508 ULONG cSessions = 0; 506 509 507 510 /* This function can report stale or orphaned interactive logon sessions 508 511 of already logged off users (especially in Windows 2000). */ 509 NTSTATUS rcNt = LsaEnumerateLogonSessions(&cSession , &paSessions);512 NTSTATUS rcNt = LsaEnumerateLogonSessions(&cSessions, &paSessions); 510 513 if (rcNt != STATUS_SUCCESS) 511 514 { … … 514 517 { 515 518 case ERROR_NOT_ENOUGH_MEMORY: 516 VBoxService Verbose(3,"VMInfo/Users: Not enough memory to enumerate logon sessions!\n");519 VBoxServiceError("VMInfo/Users: Not enough memory to enumerate logon sessions!\n"); 517 520 break; 518 521 … … 531 534 return RTErrConvertFromWin32(ulError); 532 535 } 533 VBoxServiceVerbose(3, "VMInfo/Users: Found %ld sessions\n", cSession );536 VBoxServiceVerbose(3, "VMInfo/Users: Found %ld sessions\n", cSessions); 534 537 535 538 PVBOXSERVICEVMINFOPROC paProcs; … … 539 542 { 540 543 if (rc == VERR_NO_MEMORY) 541 VBoxService Verbose(3,"VMInfo/Users: Not enough memory to enumerate processes for a session!\n");544 VBoxServiceError("VMInfo/Users: Not enough memory to enumerate processes for a session!\n"); 542 545 else 543 546 VBoxServiceError("VMInfo/Users: Failed to enumerate processes for a session, rc=%Rrc\n", rc); … … 545 548 else 546 549 { 547 *pcUsersInList = 0; 548 for (ULONG i = 0; i < cSession; i++) 549 { 550 VBOXSERVICEVMINFOUSER UserInfo; 551 if ( VBoxServiceVMInfoWinIsLoggedIn(&UserInfo, &paSessions[i]) 552 && VBoxServiceVMInfoWinSessionHasProcesses(&paSessions[i], paProcs, cProcs)) 550 PVBOXSERVICEVMINFOUSER pUserInfo; 551 pUserInfo = (PVBOXSERVICEVMINFOUSER)RTMemAllocZ(cSessions * sizeof(VBOXSERVICEVMINFOUSER) + 1); 552 if (!pUserInfo) 553 VBoxServiceError("VMInfo/Users: Not enough memory to store enumerated users!\n"); 554 else 555 { 556 ULONG cUniqueUsers = 0; 557 for (ULONG i = 0; i < cSessions; i++) 553 558 { 554 if (*pcUsersInList > 0) 559 VBOXSERVICEVMINFOUSER UserInfo; 560 if (VBoxServiceVMInfoWinIsLoggedIn(&UserInfo, &paSessions[i])) 555 561 { 556 rc = RTStrAAppend(ppszUserList, ","); 562 VBoxServiceVMInfoWinSessionHasProcesses(&paSessions[i], paProcs, cProcs); 563 564 bool fFoundUser = false; 565 for (ULONG i = 0; i < cUniqueUsers; i++) 566 { 567 if ( !wcscmp(UserInfo.wszUser, pUserInfo[i].wszUser) 568 && !wcscmp(UserInfo.wszLogonDomain, pUserInfo[i].wszLogonDomain) 569 && !wcscmp(UserInfo.wszAuthenticationPackage, pUserInfo[i].wszAuthenticationPackage)) 570 { 571 /* If the process-per-user count was higher than 0 before but another session was 572 * was detected which also belongs to this user but has no assigned processes anymore, 573 * we detected a stale session. */ 574 if ( pUserInfo[i].ulNumProcs > 0 575 && !cProcs) 576 { 577 VBoxServiceVerbose(3, "VMInfo/Users: Stale session for user=%ls detected! Old processes: %u, new: %u\n", 578 pUserInfo[i].wszUser, pUserInfo[i].ulNumProcs, cProcs); 579 } 580 581 VBoxServiceVerbose(4, "VMInfo/Users: Updating user=%ls to %u processes\n", 582 UserInfo.wszUser, cProcs); 583 584 pUserInfo[i].ulNumProcs = cProcs; 585 fFoundUser = true; 586 break; 587 } 588 } 589 590 if (!fFoundUser) 591 { 592 VBoxServiceVerbose(4, "VMInfo/Users: Adding new user=%ls with %u processes\n", 593 UserInfo.wszUser, cProcs); 594 595 memcpy(&pUserInfo[cUniqueUsers++], &UserInfo, sizeof(VBOXSERVICEVMINFOUSER)); 596 Assert(cUniqueUsers <= cSessions); 597 } 598 } 599 } 600 601 VBoxServiceVerbose(3, "VMInfo/Users: Found %u unique logged-in user(s) with processes\n", 602 cUniqueUsers); 603 604 *pcUsersInList = 0; 605 for (ULONG i = 0; i < cUniqueUsers; i++) 606 { 607 if (pUserInfo[i].ulNumProcs) 608 { 609 if (*pcUsersInList > 0) 610 { 611 rc = RTStrAAppend(ppszUserList, ","); 612 AssertRCBreakStmt(rc, RTStrFree(*ppszUserList)); 613 } 614 615 *pcUsersInList += 1; 616 617 char *pszTemp; 618 int rc2 = RTUtf16ToUtf8(pUserInfo[i].wszUser, &pszTemp); 619 if (RT_SUCCESS(rc2)) 620 { 621 rc = RTStrAAppend(ppszUserList, pszTemp); 622 RTMemFree(pszTemp); 623 } 624 else 625 rc = RTStrAAppend(ppszUserList, "<string-conversion-error>"); 557 626 AssertRCBreakStmt(rc, RTStrFree(*ppszUserList)); 558 627 } 559 560 *pcUsersInList += 1;561 562 char *pszTemp;563 int rc2 = RTUtf16ToUtf8(UserInfo.wszUser, &pszTemp);564 if (RT_SUCCESS(rc2))565 {566 rc = RTStrAAppend(ppszUserList, pszTemp);567 RTMemFree(pszTemp);568 }569 else570 rc = RTStrAAppend(ppszUserList, "<string-conversion-error>");571 AssertRCBreakStmt(rc, RTStrFree(*ppszUserList));572 628 } 629 630 RTMemFree(pUserInfo); 573 631 } 574 632 VBoxServiceVMInfoWinProcessesFree(paProcs);
Note:
See TracChangeset
for help on using the changeset viewer.