VirtualBox

Changeset 39106 in vbox


Ignore:
Timestamp:
Oct 25, 2011 9:45:40 AM (13 years ago)
Author:
vboxsync
Message:

VBoxService/VMInfo: Hook CTRL_LOGOFF_EVENT to re-trigger user enumeration on Windows guests to get immediate disconnects from VRDP when a user has been logged out.

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp

    r38946 r39106  
    7272*   Prototypes
    7373*******************************************************************************/
    74 bool VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs);
     74uint32_t VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs);
    7575bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession);
    7676int  VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount);
     
    251251 * Determines whether the specified session has processes on the system.
    252252 *
    253  * @returns true if it has, false if it doesn't.
     253 * @returns Number of processes found for a specified session.
    254254 * @param   pSession        The session.
    255255 * @param   paProcs         The process snapshot.
    256256 * @param   cProcs          The number of processes in the snaphot.
    257257 */
    258 bool VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs)
     258uint32_t VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, VBOXSERVICEVMINFOPROC const *paProcs, DWORD cProcs)
    259259{
    260260    if (!pSession)
    261261    {
    262262        VBoxServiceVerbose(1, "VMInfo/Users: Session became invalid while enumerating!\n");
    263         return false;
     263        return 0;
    264264    }
    265265
     
    269269    {
    270270        VBoxServiceError("VMInfo/Users: Could not get logon session data! rcNt=%#x", rcNt);
    271         return false;
     271        return 0;
    272272    }
    273273
     
    292292    }
    293293
    294     VBoxServiceVerbose(3, "VMInfo/Users: Session %u has %u processes\n",
    295                        pSessionData->Session, cNumProcs);
     294    if (g_cVerbosity >= 4)
     295        VBoxServiceVerbose(3, "VMInfo/Users: Session %u has %u processes\n",
     296                           pSessionData->Session, cNumProcs);
     297    else
     298        VBoxServiceVerbose(3, "VMInfo/Users: Session %u has at least one process\n",
     299                           pSessionData->Session);
    296300
    297301    LsaFreeReturnBuffer(pSessionData);
    298     return cNumProcs ? true : false;
     302    return cNumProcs;
    299303}
    300304
     
    560564                if (VBoxServiceVMInfoWinIsLoggedIn(&UserInfo, &paSessions[i]))
    561565                {
    562                     VBoxServiceVMInfoWinSessionHasProcesses(&paSessions[i], paProcs, cProcs);
     566                    uint32_t cSessionProcs = VBoxServiceVMInfoWinSessionHasProcesses(&paSessions[i], paProcs, cProcs);
     567                    if (!cSessionProcs)
     568                        continue;
    563569
    564570                    bool fFoundUser = false;
     
    573579                             * we detected a stale session. */
    574580                            if (   pUserInfo[i].ulNumProcs > 0
    575                                 && !cProcs)
     581                                && !cSessionProcs)
    576582                            {
    577583                                VBoxServiceVerbose(3, "VMInfo/Users: Stale session for user=%ls detected! Old processes: %u, new: %u\n",
    578                                                    pUserInfo[i].wszUser, pUserInfo[i].ulNumProcs, cProcs);
     584                                                   pUserInfo[i].wszUser, pUserInfo[i].ulNumProcs, cSessionProcs);
    579585                            }
    580586
    581587                            VBoxServiceVerbose(4, "VMInfo/Users: Updating user=%ls to %u processes\n",
    582                                                UserInfo.wszUser, cProcs);
    583 
    584                             pUserInfo[i].ulNumProcs = cProcs;
     588                                               UserInfo.wszUser, cSessionProcs);
     589
     590                            pUserInfo[i].ulNumProcs = cSessionProcs;
    585591                            fFoundUser = true;
    586592                            break;
     
    591597                    {
    592598                        VBoxServiceVerbose(4, "VMInfo/Users: Adding new user=%ls with %u processes\n",
    593                                            UserInfo.wszUser, cProcs);
    594 
    595                         memcpy(&pUserInfo[cUniqueUsers++], &UserInfo, sizeof(VBOXSERVICEVMINFOUSER));
     599                                           UserInfo.wszUser, cSessionProcs);
     600
     601                        memcpy(&pUserInfo[cUniqueUsers], &UserInfo, sizeof(VBOXSERVICEVMINFOUSER));
     602                        pUserInfo[cUniqueUsers++].ulNumProcs = cSessionProcs;
    596603                        Assert(cUniqueUsers <= cSessions);
    597604                    }
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r38224 r39106  
    8383
    8484
     85#ifdef RT_OS_WINDOWS
     86static BOOL WINAPI VBoxServiceVMInfoConsoleControlHandler(DWORD dwCtrlType)
     87{
     88    int rc = VINF_SUCCESS;
     89    bool fEventHandled = FALSE;
     90    switch (dwCtrlType)
     91    {
     92        case CTRL_LOGOFF_EVENT:
     93            VBoxServiceVerbose(2, "VMInfo: Received logged-off event\n");
     94            /* Trigger a re-enumeration of all logged-in users by unblocking
     95             * the multi event semaphore of the VMInfo thread. */
     96            if (g_hVMInfoEvent)
     97                rc = RTSemEventMultiSignal(g_hVMInfoEvent);
     98            fEventHandled = TRUE;
     99            break;
     100        default:
     101            break;
     102        /** @todo Add other events here. */
     103    }
     104
     105    if (RT_FAILURE(rc))
     106        VBoxServiceError("VMInfo: Event %ld handled with error rc=%Rrc\n",
     107                         dwCtrlType, rc);
     108    return fEventHandled;
     109}
     110#endif /* RT_OS_WINDOWS */
     111
     112
    85113/** @copydoc VBOXSERVICE::pfnPreInit */
    86114static DECLCALLBACK(int) VBoxServiceVMInfoPreInit(void)
     
    154182        VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count",
    155183                                        VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, NULL /* Delete on exit */);
     184
     185#ifdef RT_OS_WINDOWS
     186# ifndef RT_OS_NT4
     187    /* Install console control handler. */
     188    if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)VBoxServiceVMInfoConsoleControlHandler, TRUE /* Add handler */))
     189    {
     190        VBoxServiceError("VMInfo: Unable to add console control handler, error=%ld\n", GetLastError());
     191        /* Just skip this error, not critical. */
     192    }
     193# endif /* !RT_OS_NT4 */
     194#endif /* RT_OS_WINDOWS */
    156195    }
    157196    return rc;
     
    812851            break;
    813852        }
     853        else if (RT_LIKELY(RT_SUCCESS(rc2)))
     854        {
     855            /* Reset event semaphore if it got triggered. */
     856            rc2 = RTSemEventMultiReset(g_hVMInfoEvent);
     857            if (RT_FAILURE(rc2))
     858                rc2 = VBoxServiceError("VMInfo: RTSemEventMultiReset failed; rc2=%Rrc\n", rc2);
     859        }
    814860    }
    815861
     
    833879{
    834880    int rc;
     881
     882#ifdef RT_OS_WINDOWS
     883# ifndef RT_OS_NT4
     884    /* Install console control handler. */
     885    if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)NULL, FALSE /* Remove handler */))
     886    {
     887        VBoxServiceError("VMInfo: Unable to remove console control handler, error=%ld\n", GetLastError());
     888        /* Just skip this error, not critical. */
     889    }
     890# endif /* !RT_OS_NT4 */
     891#endif
    835892
    836893    if (g_hVMInfoEvent != NIL_RTSEMEVENTMULTI)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette