VirtualBox

Ignore:
Timestamp:
Dec 22, 2009 4:30:25 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56251
Message:

VBoxHeadless: ExtraData option to terminate RDP connection if the user logs out of the guest OS (xTracker 4294)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r25448 r25573  
    116116        refcnt = 0;
    117117#endif
     118        mfNoLoggedInUsers = true;
    118119    }
    119120
     
    197198    STDMETHOD(OnGuestPropertyChange)(IN_BSTR machineId, IN_BSTR key, IN_BSTR value, IN_BSTR flags)
    198199    {
     200#ifdef VBOX_WITH_GUEST_PROPS
     201        Utf8Str utf8Key = key;
     202        if (utf8Key == "/VirtualBox/GuestInfo/OS/NoLoggedInUsers")
     203        {
     204            /* Check if the "disconnect on logout feature" is enabled. */
     205            BOOL fDisconnectOnGuestLogout = FALSE;
     206            ComPtr <IMachine> machine;
     207            HRESULT hrc = S_OK;
     208
     209            if (gConsole)
     210            {
     211                hrc = gConsole->COMGETTER(Machine)(machine.asOutParam());
     212                if (SUCCEEDED(hrc) && machine)
     213                {
     214                    Bstr value;
     215                    hrc = machine->GetExtraData(Bstr("VRDP/DisconnectOnGuestLogout"), value.asOutParam());
     216                    if (SUCCEEDED(hrc) && value == "1")
     217                    {
     218                        fDisconnectOnGuestLogout = TRUE;
     219                    }
     220                }
     221            }
     222
     223            if (fDisconnectOnGuestLogout)
     224            {
     225                Utf8Str utf8Value = value;
     226                if (utf8Value == "true")
     227                {
     228                    if (!mfNoLoggedInUsers) /* Only if the property really changes. */
     229                    {
     230                        mfNoLoggedInUsers = true;
     231
     232                        /* If there is a VRDP connection, drop it. */
     233                        ComPtr<IRemoteDisplayInfo> info;
     234                        hrc = gConsole->COMGETTER(RemoteDisplayInfo)(info.asOutParam());
     235                        if (SUCCEEDED(hrc) && info)
     236                        {
     237                            ULONG cClients = 0;
     238                            hrc = info->COMGETTER(NumberOfClients)(&cClients);
     239                            if (SUCCEEDED(hrc) && cClients > 0)
     240                            {
     241                                ComPtr <IVRDPServer> vrdpServer;
     242                                hrc = machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
     243                                if (SUCCEEDED(hrc) && vrdpServer)
     244                                {
     245                                    vrdpServer->COMSETTER(Enabled)(FALSE);
     246                                    vrdpServer->COMSETTER(Enabled)(TRUE);
     247                                }
     248                            }
     249                        }
     250                    }
     251                }
     252                else
     253                {
     254                    mfNoLoggedInUsers = false;
     255                }
     256            }
     257        }
     258#endif /* VBOX_WITH_GUEST_PROPS */
    199259        return S_OK;
    200260    }
     
    205265#endif
    206266
     267    bool mfNoLoggedInUsers;
    207268};
    208269
     
    10771138    while (0);
    10781139
     1140    /* No more access to the 'console' object, which will be uninitialized by the next session->Close call. */
     1141    gConsole = NULL;
     1142
    10791143    if (fSessionOpened)
    10801144    {
Note: See TracChangeset for help on using the changeset viewer.

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