VirtualBox

Changeset 25354 in vbox for trunk/src


Ignore:
Timestamp:
Dec 14, 2009 10:15:38 AM (15 years ago)
Author:
vboxsync
Message:

GuestProperties/service.cpp: only return VINF_PERMISSION_DENIED when the requesting side has been globally made read-only.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r25347 r25354  
    226226    /**
    227227     * Check whether we have permission to change a property.
    228      * @returns VINF_SUCCESS if we do, VERR_PERMISSION_DENIED otherwise
     228     *
     229     * @returns Strict VBox status code.
     230     * @retval  VINF_SUCCESS if we do.
     231     * @retval  VERR_PERMISSION_DENIED if the value is read-only for the requesting
     232     *          side.
     233     * @retval  VINF_PERMISSION_DENIED if the side is globally marked read-only.
     234     *
    229235     * @param   eFlags   the flags on the property in question
    230236     * @param   isGuest  is the guest or the host trying to make the change?
     
    232238    int checkPermission(ePropFlags eFlags, bool isGuest)
    233239    {
    234         if (   (isGuest && (eFlags & RDONLYGUEST))
    235             || (isGuest && (meGlobalFlags & RDONLYGUEST))
    236             || (!isGuest && (eFlags & RDONLYHOST))
    237            )
     240        if (eFlags & (isGuest ? RDONLYGUEST : RDONLYHOST))
     241            return VERR_PERMISSION_DENIED;
     242        if (isGuest && (meGlobalFlags & RDONLYGUEST))
    238243            return VINF_PERMISSION_DENIED;
    239 
    240244        return VINF_SUCCESS;
    241245    }
     
    649653    if ((3 == cParms) && RT_SUCCESS(rc))
    650654        rc = validateFlags(pcszFlags, &fFlags);
    651 
    652     /*
    653      * If the property already exists, check its flags to see if we are allowed
    654      * to change it.
    655      */
    656     PropertyList::iterator it;
    657     bool found = false;
    658     if (RT_SUCCESS(rc))
     655    if (RT_SUCCESS(rc))
     656    {
     657        /*
     658         * If the property already exists, check its flags to see if we are allowed
     659         * to change it.
     660         */
     661        PropertyList::iterator it;
     662        bool found = false;
    659663        for (it = mProperties.begin(); it != mProperties.end(); ++it)
    660664            if (it->mName.compare(pcszName) == 0)
     
    663667                break;
    664668            }
    665     if (RT_SUCCESS(rc))
     669
    666670        rc = checkPermission(found ? (ePropFlags)it->mFlags : NILFLAG,
    667671                             isGuest);
    668 
    669     if (rc == VINF_PERMISSION_DENIED)
    670         return rc;
    671 
    672     /*
    673      * Set the actual value
    674      */
    675     if (RT_SUCCESS(rc))
    676     {
    677         if (found)
    678         {
    679             it->mValue = pcszValue;
    680             it->mTimestamp = u64TimeNano;
    681             it->mFlags = fFlags;
     672        if (rc == VINF_SUCCESS)
     673        {
     674            /*
     675             * Set the actual value
     676             */
     677            if (found)
     678            {
     679                it->mValue = pcszValue;
     680                it->mTimestamp = u64TimeNano;
     681                it->mFlags = fFlags;
     682            }
     683            else  /* This can throw.  No problem as we have nothing to roll back. */
     684                mProperties.push_back(Property(pcszName, pcszValue, u64TimeNano, fFlags));
     685
     686            /*
     687             * Send a notification to the host and return.
     688             */
     689            // if (isGuest)  /* Notify the host even for properties that the host
     690            //                * changed.  Less efficient, but ensures consistency. */
     691                doNotifications(pcszName, u64TimeNano);
     692            Log2(("Set string %s, rc=%Rrc, value=%s\n", pcszName, rc, pcszValue));
    682693        }
    683         else  /* This can throw.  No problem as we have nothing to roll back. */
    684             mProperties.push_back(Property(pcszName, pcszValue, u64TimeNano, fFlags));
    685     }
    686 
    687     /*
    688      * Send a notification to the host and return.
    689      */
    690     if (RT_SUCCESS(rc))
    691     {
    692         // if (isGuest)  /* Notify the host even for properties that the host
    693         //                * changed.  Less efficient, but ensures consistency. */
    694             doNotifications(pcszName, u64TimeNano);
    695         Log2(("Set string %s, rc=%Rrc, value=%s\n", pcszName, rc, pcszValue));
    696     }
     694    }
     695
    697696    LogFlowThisFunc(("rc = %Rrc\n", rc));
    698697    return rc;
     
    727726    else
    728727        rc = VERR_INVALID_PARAMETER;
    729 
    730     /*
    731      * If the property exists, check its flags to see if we are allowed
    732      * to change it.
    733      */
    734     PropertyList::iterator it;
    735     bool found = false;
    736     if (RT_SUCCESS(rc))
     728    if (RT_SUCCESS(rc))
     729    {
     730        /*
     731         * If the property exists, check its flags to see if we are allowed
     732         * to change it.
     733         */
     734        PropertyList::iterator it;
     735        bool found = false;
    737736        for (it = mProperties.begin(); it != mProperties.end(); ++it)
    738737            if (it->mName.compare(pcszName) == 0)
     
    741740                break;
    742741            }
    743     if (RT_SUCCESS(rc))
    744         rc = checkPermission(found ? (ePropFlags)it->mFlags :
    745                              NILFLAG, isGuest);
    746 
    747     if (rc == VINF_PERMISSION_DENIED)
    748         return rc;
    749 
    750     /*
    751      * And delete the property if all is well.
    752      */
    753     if (RT_SUCCESS(rc) && found)
    754     {
    755         RTTIMESPEC time;
    756         uint64_t u64Timestamp = RTTimeSpecGetNano(RTTimeNow(&time));
    757         mProperties.erase(it);
    758         // if (isGuest)  /* Notify the host even for properties that the host
    759         //                * changed.  Less efficient, but ensures consistency. */
    760             doNotifications(pcszName, u64Timestamp);
    761     }
     742        rc = checkPermission(found ? (ePropFlags)it->mFlags : NILFLAG,
     743                             isGuest);
     744
     745        /*
     746         * And delete the property if all is well.
     747         */
     748        if (rc == VINF_SUCCESS && found)
     749        {
     750            RTTIMESPEC time;
     751            uint64_t u64Timestamp = RTTimeSpecGetNano(RTTimeNow(&time));
     752            mProperties.erase(it);
     753            // if (isGuest)  /* Notify the host even for properties that the host
     754            //                * changed.  Less efficient, but ensures consistency. */
     755                doNotifications(pcszName, u64Timestamp);
     756        }
     757    }
     758
    762759    LogFlowThisFunc(("rc = %Rrc\n", rc));
    763760    return rc;
     
    10691066                if (prop.Matches(pszPatterns))
    10701067                {
    1071                     GuestCall call = *it;
    1072                     int rc2 = getNotificationWriteOut(call.mParms, prop);
     1068                    GuestCall curCall = *it;
     1069                    int rc2 = getNotificationWriteOut(curCall.mParms, prop);
    10731070                    if (RT_SUCCESS(rc2))
    1074                         rc2 = call.mRc;
    1075                     mpHelpers->pfnCallComplete (call.mHandle, rc2);
     1071                        rc2 = curCall.mRc;
     1072                    mpHelpers->pfnCallComplete(curCall.mHandle, rc2);
    10761073                    it = mGuestWaiters.erase(it);
    10771074                }
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