VirtualBox

Changeset 47620 in vbox for trunk/src


Ignore:
Timestamp:
Aug 8, 2013 8:09:42 PM (11 years ago)
Author:
vboxsync
Message:

GuestCtrl: Fixed per-session command filtering, added command to disable the filter again.

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestCtrl.cpp

    r45415 r47620  
    5050 *
    5151 * @returns VBox status code
    52  * @param   puClientId    Where to put the client id on success. The client id
     52 * @param   puClientId    Where to put The client ID on success. The client ID
    5353 *                        must be passed to all the other calls to the service.
    5454 */
     
    7777 *
    7878 * @returns VBox status code.
    79  * @param   uClientId     The client id returned by VbglR3GuestCtrlConnect().
     79 * @param   uClientId     The client ID returned by VbglR3GuestCtrlConnect().
    8080 */
    8181VBGLR3DECL(int) VbglR3GuestCtrlDisconnect(uint32_t uClientId)
     
    9797 *
    9898 * @returns VBox status code.
    99  * @param   uClientId       The client id returned by VbglR3GuestCtrlConnect().
     99 * @param   uClientId       The client ID returned by VbglR3GuestCtrlConnect().
    100100 * @param   puMsg           Where to store the message id.
    101101 * @param   puNumParms      Where to store the number  of parameters which will be received
     
    134134 * Asks the host guest control service to set a command filter to this
    135135 * client so that it only will receive certain commands in the future.
     136 * The filter(s) are a bitmask for the context IDs, served from the host.
    136137 *
    137138 * @return  IPRT status code.
    138  * @param   uClientId       The client id returned by VbglR3GuestCtrlConnect().
    139  * @param   uFilterAdd      Filter mask to add.
    140  * @param   uFilterRemove   Filter mask to remove.
    141  */
    142 VBGLR3DECL(int) VbglR3GuestCtrlMsgSetFilter(uint32_t uClientId,
     139 * @param   uClientId       The client ID returned by VbglR3GuestCtrlConnect().
     140 * @param   uFilterAdd      Context ID filter mask to add.
     141 * @param   uFilterRemove   Context ID filter mask to remove.
     142 */
     143VBGLR3DECL(int) VbglR3GuestCtrlMsgFilterSet(uint32_t uClientId,
    143144                                            uint32_t uFilterAdd, uint32_t uFilterRemove)
    144145{
    145     HGCMMsgCmdSetFilter Msg;
     146    HGCMMsgCmdFilterSet Msg;
    146147
    147148    Msg.hdr.result      = VERR_WRONG_ORDER;
    148149    Msg.hdr.u32ClientID = uClientId;
    149     Msg.hdr.u32Function = GUEST_MSG_FILTER; /* Tell the host we want to set a filter. */
    150     Msg.hdr.cParms      = 2;
     150    Msg.hdr.u32Function = GUEST_MSG_FILTER_SET; /* Tell the host we want to set a filter. */
     151    Msg.hdr.cParms      = 3;
    151152
    152153    VbglHGCMParmUInt32Set(&Msg.add, uFilterAdd);
    153154    VbglHGCMParmUInt32Set(&Msg.remove, uFilterRemove);
     155    VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
     156
     157    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     158    if (RT_SUCCESS(rc))
     159        rc = Msg.hdr.result;
     160    return rc;
     161}
     162
     163
     164/**
     165 * Disables a previously set message filter.
     166 *
     167 * @return  IPRT status code.
     168 * @param   uClientId       The client ID returned by VbglR3GuestCtrlConnect().
     169 */
     170VBGLR3DECL(int) VbglR3GuestCtrlMsgFilterUnset(uint32_t uClientId)
     171{
     172    HGCMMsgCmdFilterUnset Msg;
     173
     174    Msg.hdr.result      = VERR_WRONG_ORDER;
     175    Msg.hdr.u32ClientID = uClientId;
     176    Msg.hdr.u32Function = GUEST_MSG_FILTER_UNSET; /* Tell the host we want to unset the filter. */
     177    Msg.hdr.cParms      = 1;
     178
     179    VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
    154180
    155181    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     
    165191 *
    166192 * @return  IPRT status code.
    167  * @param   uClientId       The client id returned by VbglR3GuestCtrlConnect().
     193 * @param   uClientId       The client ID returned by VbglR3GuestCtrlConnect().
    168194 */
    169195VBGLR3DECL(int) VbglR3GuestCtrlMsgSkip(uint32_t uClientId)
     
    175201    Msg.hdr.u32Function = GUEST_MSG_SKIP; /* Tell the host we want to skip
    176202                                             the current assigned command. */
    177     Msg.hdr.cParms      = 0;              /* No parameters needed. */
     203    Msg.hdr.cParms      = 1;
     204
     205    VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
    178206
    179207    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     
    189217 *
    190218 * @returns VBox status code.
    191  * @param   uClientId     The client id returned by VbglR3GuestCtrlConnect().
     219 * @param   uClientId     The client ID returned by VbglR3GuestCtrlConnect().
    192220 */
    193221VBGLR3DECL(int) VbglR3GuestCtrlCancelPendingWaits(uint32_t uClientId)
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp

    r47551 r47620  
    10801080    if (RT_SUCCESS(rc))
    10811081    {
    1082         /* Set session filter. */
     1082        /* Set session filter. This prevents the guest control
     1083         * host service to send messages which belong to another
     1084         * session we don't want to handle. */
    10831085        uint32_t uFilterAdd =
    10841086            VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(pSession->StartupInfo.uSessionID);
    1085 
    1086         rc = VbglR3GuestCtrlMsgSetFilter(uClientID, uFilterAdd, 0 /* Filter remove */);
    1087         VBoxServiceVerbose(3, "Setting message filterAdd=%RU32 returned %Rrc\n",
     1087        uFilterAdd |= 0x7FFFFFF; /* We only want to filter for session IDs. */
     1088
     1089        rc = VbglR3GuestCtrlMsgFilterSet(uClientID, uFilterAdd, 0 /* Filter remove */);
     1090        VBoxServiceVerbose(3, "Setting message filterAdd=0x%x returned %Rrc\n",
    10881091                           uFilterAdd, rc);
    10891092
  • trunk/src/VBox/HostServices/GuestControl/service.cpp

    r47488 r47620  
    563563            return false;
    564564
    565 #ifdef DEBUG_andy
    566             LogFlowFunc(("[Client %RU32] mFlags=%x, mContextID=%RU32, mContextFilter=%x, filterRes=%x, sessionID=%RU32\n",
    567                          mID, mFlags, pHostCmd->mContextID, mContextFilter,
    568                          pHostCmd->mContextID & mContextFilter, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pHostCmd->mContextID)));
     565#ifdef DEBUG
     566        LogFlowFunc(("[Client %RU32] mFlags=0x%x, mContextID=%RU32 (session %RU32), mContextFilter=0x%x (result=%x -> %RTbool)\n",
     567                     mID, mFlags, pHostCmd->mContextID,
     568                     VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pHostCmd->mContextID),
     569                     mContextFilter,
     570                     pHostCmd->mContextID & pHostCmd->mContextID,
     571                     (pHostCmd->mContextID & mContextFilter) == pHostCmd->mContextID));
    569572#endif
    570573        /*
    571          * If a sesseion filter is set, only obey those sessions we're interested in.
     574         * If a sesseion filter is set, only obey those commands we're interested in
     575         * by applying our context ID filter mask and compare the result with the
     576         * original context ID.
    572577         */
    573         bool fWant = false;
     578        bool fWant;
    574579        if (mFlags & CLIENTSTATE_FLAG_CONTEXTFILTER)
    575580        {
    576             if ((pHostCmd->mContextID & mContextFilter) == mContextFilter)
    577                 fWant = true;
     581            fWant =
     582                (pHostCmd->mContextID & mContextFilter) == pHostCmd->mContextID;
    578583        }
    579584        else /* Client is interested in all commands. */
     
    9951000    int clientDisconnect(uint32_t u32ClientID, void *pvClient);
    9961001    int clientGetCommand(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    997     int clientSetMsgFilter(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
     1002    int clientSetMsgFilterSet(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
     1003    int clientSetMsgFilterUnset(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    9981004    int clientSkipMsg(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    9991005    int cancelHostCmd(uint32_t u32ContextID);
     
    11361142}
    11371143
    1138 int Service::clientSetMsgFilter(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle,
    1139                                 uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     1144int Service::clientSetMsgFilterSet(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle,
     1145                                   uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    11401146{
    11411147    /*
     
    11491155        return VERR_NOT_FOUND; /* Should never happen. */
    11501156
    1151     if (cParms != 2)
     1157    if (cParms != 3)
    11521158        return VERR_INVALID_PARAMETER;
    11531159
     
    11661172            clientState.mContextFilter &= ~uMaskRemove;
    11671173
    1168         LogFlowFunc(("Client ID=%RU32 now has filter=%x enabled (flags=%x, maskAdd=%x, maskRemove=%x)\n",
     1174        LogFlowFunc(("[Client %RU32] Setting message filter=0x%x set (flags=0x%x, maskAdd=0x%x, maskRemove=0x%x)\n",
    11691175                     u32ClientID, clientState.mContextFilter, clientState.mFlags,
    11701176                     uMaskAdd, uMaskRemove));
     
    11721178
    11731179    return rc;
     1180}
     1181
     1182int Service::clientSetMsgFilterUnset(uint32_t u32ClientID, VBOXHGCMCALLHANDLE callHandle,
     1183                                     uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     1184{
     1185    /*
     1186     * Lookup client in our list so that we can assign the context ID of
     1187     * a command to that client.
     1188     */
     1189    ClientStateMapIter itClientState = mClientStateMap.find(u32ClientID);
     1190    AssertMsg(itClientState != mClientStateMap.end(), ("Client with ID=%RU32 not found when it should be present\n",
     1191                                                       u32ClientID));
     1192    if (itClientState == mClientStateMap.end())
     1193        return VERR_NOT_FOUND; /* Should never happen. */
     1194
     1195    if (cParms != 1)
     1196        return VERR_INVALID_PARAMETER;
     1197
     1198    ClientState &clientState = itClientState->second;
     1199
     1200    clientState.mFlags &= ~CLIENTSTATE_FLAG_CONTEXTFILTER;
     1201    clientState.mContextFilter = 0;
     1202
     1203    LogFlowFunc(("[Client %RU32} Unset message filter\n", u32ClientID));
     1204    return VINF_SUCCESS;
    11741205}
    11751206
     
    11871218        return VERR_NOT_FOUND; /* Should never happen. */
    11881219
    1189     if (cParms != 0)
     1220    if (cParms != 1)
    11901221        return VERR_INVALID_PARAMETER;
    11911222
     
    13251356                    LogFlowFunc(("Waking up client ID=%RU32 failed with rc=%Rrc\n",
    13261357                                 itClientState->first, rc2));
    1327 #ifdef DEBUG_andy
     1358#ifdef DEBUG
    13281359                uClientsWokenUp++;
    13291360#endif
     
    13331364        }
    13341365
    1335 #ifdef DEBUG_andy
     1366#ifdef DEBUG
    13361367        LogFlowFunc(("%RU32 clients have been woken up\n", uClientsWokenUp));
    13371368#endif
     
    13851416                 * Since VBox 4.3+.
    13861417                 */
    1387                 case GUEST_MSG_FILTER:
    1388                     LogFlowFunc(("[Client %RU32] GUEST_MSG_FILTER\n", u32ClientID));
    1389                     rc = clientSetMsgFilter(u32ClientID, callHandle, cParms, paParms);
     1418                case GUEST_MSG_FILTER_SET:
     1419                    LogFlowFunc(("[Client %RU32] GUEST_MSG_FILTER_SET\n", u32ClientID));
     1420                    rc = clientSetMsgFilterSet(u32ClientID, callHandle, cParms, paParms);
     1421                    break;
     1422
     1423                /*
     1424                 * Unsetting the message filter flag.
     1425                 */
     1426                case GUEST_MSG_FILTER_UNSET:
     1427                    LogFlowFunc(("[Client %RU32] GUEST_MSG_FILTER_UNSET\n", u32ClientID));
     1428                    rc = clientSetMsgFilterUnset(u32ClientID, callHandle, cParms, paParms);
    13901429                    break;
    13911430
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