/// <summary>
        /// Checks whether the user has permission to export an object group to an OAR.
        /// </summary>
        /// <param name="user">The user</param>
        /// <param name="objGroup">The object group</param>
        /// <param name="filterContent">Which permissions to check: "C" = Copy, "T" = Transfer</param>
        /// <param name="permissionsModule">The scene's permissions module</param>
        /// <returns>Whether the user is allowed to export the object to an OAR</returns>
        private bool CanUserArchiveObject(UUID user, SceneObjectGroup objGroup, string filterContent, IPermissionsModule permissionsModule)
        {
            if (filterContent == null)
            {
                return(true);
            }

            if (permissionsModule == null)
            {
                return(true);    // this shouldn't happen
            }
            // Check whether the user is permitted to export all of the parts in the SOG. If any
            // part can't be exported then the entire SOG can't be exported.

            bool permitted = true;

            //int primNumber = 1;

            foreach (SceneObjectPart obj in objGroup.Parts)
            {
                uint            perm;
                PermissionClass permissionClass = permissionsModule.GetPermissionClass(user, obj);
                switch (permissionClass)
                {
                case PermissionClass.Owner:
                    perm = obj.BaseMask;
                    break;

                case PermissionClass.Group:
                    perm = obj.GroupMask | obj.EveryoneMask;
                    break;

                case PermissionClass.Everyone:
                default:
                    perm = obj.EveryoneMask;
                    break;
                }

                bool canCopy     = (perm & (uint)PermissionMask.Copy) != 0;
                bool canTransfer = (perm & (uint)PermissionMask.Transfer) != 0;

                // Special case: if Everyone can copy the object then this implies it can also be
                // Transferred.
                // However, if the user is the Owner then we don't check EveryoneMask, because it seems that the mask
                // always (incorrectly) includes the Copy bit set in this case. But that's a mistake: the viewer
                // does NOT show that the object has Everyone-Copy permissions, and doesn't allow it to be copied.
                if (permissionClass != PermissionClass.Owner)
                {
                    canTransfer |= (obj.EveryoneMask & (uint)PermissionMask.Copy) != 0;
                }

                bool partPermitted = true;
                if (filterContent.Contains("C") && !canCopy)
                {
                    partPermitted = false;
                }
                if (filterContent.Contains("T") && !canTransfer)
                {
                    partPermitted = false;
                }

                // If the user is the Creator of the object then it can always be included in the OAR
                bool creator = (obj.CreatorID.Guid == user.Guid);
                if (creator)
                {
                    partPermitted = true;
                }

                //string name = (objGroup.PrimCount == 1) ? objGroup.Name : string.Format("{0} ({1}/{2})", obj.Name, primNumber, objGroup.PrimCount);
                //m_log.DebugFormat("[ARCHIVER]: Object permissions: {0}: Base={1:X4}, Owner={2:X4}, Everyone={3:X4}, permissionClass={4}, checkPermissions={5}, canCopy={6}, canTransfer={7}, creator={8}, permitted={9}",
                //    name, obj.BaseMask, obj.OwnerMask, obj.EveryoneMask,
                //    permissionClass, checkPermissions, canCopy, canTransfer, creator, partPermitted);

                if (!partPermitted)
                {
                    permitted = false;
                    break;
                }

                //++primNumber;
            }

            return(permitted);
        }
        private void ArchiveOneRegion(Scene scene, string regionDir, Dictionary <UUID, sbyte> assetUuids,
                                      HashSet <UUID> failedIDs, HashSet <UUID> uncertainAssetsUUIDs)
        {
            m_log.InfoFormat("[ARCHIVER]: Writing region {0}", scene.Name);

            EntityBase[]            entities     = scene.GetEntities();
            List <SceneObjectGroup> sceneObjects = new List <SceneObjectGroup>();

            int numObjectsSkippedPermissions = 0;

            // Filter entities so that we only have scene objects.
            // FIXME: Would be nicer to have this as a proper list in SceneGraph, since lots of methods
            // end up having to do this
            IPermissionsModule permissionsModule = scene.RequestModuleInterface <IPermissionsModule>();

            foreach (EntityBase entity in entities)
            {
                if (entity is SceneObjectGroup)
                {
                    SceneObjectGroup sceneObject = entity as SceneObjectGroup;

                    if (!sceneObject.IsDeleted && !sceneObject.IsAttachment && !sceneObject.IsTemporary && !sceneObject.inTransit)
                    {
                        if (!CanUserArchiveObject(scene.RegionInfo.EstateSettings.EstateOwner, sceneObject, FilterContent, permissionsModule))
                        {
                            // The user isn't allowed to copy/transfer this object, so it will not be included in the OAR.
                            ++numObjectsSkippedPermissions;
                        }
                        else
                        {
                            sceneObjects.Add(sceneObject);
                        }
                    }
                }
            }

            if (SaveAssets)
            {
                UuidGatherer assetGatherer = new UuidGatherer(scene.AssetService, assetUuids, failedIDs, uncertainAssetsUUIDs);
                int          prevAssets    = assetUuids.Count;

                foreach (SceneObjectGroup sceneObject in sceneObjects)
                {
                    int curErrorCntr = assetGatherer.ErrorCount;
                    int possible     = assetGatherer.possibleNotAssetCount;
                    assetGatherer.AddForInspection(sceneObject);
                    assetGatherer.GatherAll();
                    curErrorCntr = assetGatherer.ErrorCount - curErrorCntr;
                    possible     = assetGatherer.possibleNotAssetCount - possible;
                    if (curErrorCntr > 0)
                    {
                        m_log.ErrorFormat("[ARCHIVER]: object {0} '{1}', at {2}, contains {3} references to missing or damaged assets",
                                          sceneObject.UUID, sceneObject.Name, sceneObject.AbsolutePosition.ToString(), curErrorCntr);
                        if (possible > 0)
                        {
                            m_log.WarnFormat("[ARCHIVER Warning]: object also contains {0} references that may not be assets or are missing", possible);
                        }
                    }
                    else if (possible > 0)
                    {
                        m_log.WarnFormat("[ARCHIVER Warning]: object {0} '{1}', at {2}, contains {3} references that may not be assets or are missing",
                                         sceneObject.UUID, sceneObject.Name, sceneObject.AbsolutePosition.ToString(), possible);
                    }
                }

                assetGatherer.GatherAll();

                GC.Collect();

                int errors = assetGatherer.FailedUUIDs.Count;
                m_log.DebugFormat(
                    "[ARCHIVER]: {0} region scene objects to save reference {1} possible assets",
                    sceneObjects.Count, assetUuids.Count - prevAssets + errors);
                if (errors > 0)
                {
                    m_log.DebugFormat("[ARCHIVER]: {0} of these have problems or are not assets and will be ignored", errors);
                }
            }

            if (numObjectsSkippedPermissions > 0)
            {
                m_log.DebugFormat(
                    "[ARCHIVER]: {0} scene objects skipped due to lack of permissions",
                    numObjectsSkippedPermissions);
            }

            // Make sure that we also request terrain texture assets
            RegionSettings regionSettings = scene.RegionInfo.RegionSettings;

            if (regionSettings.TerrainTexture1 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_1)
            {
                assetUuids[regionSettings.TerrainTexture1] = (sbyte)AssetType.Texture;
            }

            if (regionSettings.TerrainTexture2 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_2)
            {
                assetUuids[regionSettings.TerrainTexture2] = (sbyte)AssetType.Texture;
            }

            if (regionSettings.TerrainTexture3 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_3)
            {
                assetUuids[regionSettings.TerrainTexture3] = (sbyte)AssetType.Texture;
            }

            if (regionSettings.TerrainTexture4 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_4)
            {
                assetUuids[regionSettings.TerrainTexture4] = (sbyte)AssetType.Texture;
            }

            if (scene.RegionEnvironment != null)
            {
                scene.RegionEnvironment.GatherAssets(assetUuids);
            }

            List <ILandObject> landObjects = scene.LandChannel.AllParcels();

            foreach (ILandObject lo in landObjects)
            {
                if (lo.LandData != null && lo.LandData.Environment != null)
                {
                    lo.LandData.Environment.GatherAssets(assetUuids);
                }
            }

            Save(scene, sceneObjects, regionDir);
            GC.Collect();
        }
        private void ArchiveOneRegion(Scene scene, string regionDir, Dictionary <UUID, AssetType> assetUuids)
        {
            m_log.InfoFormat("[ARCHIVER]: Writing region {0}", scene.RegionInfo.RegionName);

            EntityBase[]            entities     = scene.GetEntities();
            List <SceneObjectGroup> sceneObjects = new List <SceneObjectGroup>();

            int numObjectsSkippedPermissions = 0;

            // Filter entities so that we only have scene objects.
            // FIXME: Would be nicer to have this as a proper list in SceneGraph, since lots of methods
            // end up having to do this
            IPermissionsModule permissionsModule = scene.RequestModuleInterface <IPermissionsModule>();

            foreach (EntityBase entity in entities)
            {
                if (entity is SceneObjectGroup)
                {
                    SceneObjectGroup sceneObject = (SceneObjectGroup)entity;

                    if (!sceneObject.IsDeleted && !sceneObject.IsAttachment)
                    {
                        if (!CanUserArchiveObject(scene.RegionInfo.EstateSettings.EstateOwner, sceneObject, CheckPermissions, permissionsModule))
                        {
                            // The user isn't allowed to copy/transfer this object, so it will not be included in the OAR.
                            ++numObjectsSkippedPermissions;
                        }
                        else
                        {
                            sceneObjects.Add(sceneObject);
                        }
                    }
                }
            }

            if (SaveAssets)
            {
                UuidGatherer assetGatherer = new UuidGatherer(scene.AssetService);
                int          prevAssets    = assetUuids.Count;

                foreach (SceneObjectGroup sceneObject in sceneObjects)
                {
                    assetGatherer.GatherAssetUuids(sceneObject, assetUuids);
                }

                m_log.DebugFormat(
                    "[ARCHIVER]: {0} scene objects to serialize requiring save of {1} assets",
                    sceneObjects.Count, assetUuids.Count - prevAssets);
            }

            if (numObjectsSkippedPermissions > 0)
            {
                m_log.DebugFormat(
                    "[ARCHIVER]: {0} scene objects skipped due to lack of permissions",
                    numObjectsSkippedPermissions);
            }

            // Make sure that we also request terrain texture assets
            RegionSettings regionSettings = scene.RegionInfo.RegionSettings;

            if (regionSettings.TerrainTexture1 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_1)
            {
                assetUuids[regionSettings.TerrainTexture1] = AssetType.Texture;
            }

            if (regionSettings.TerrainTexture2 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_2)
            {
                assetUuids[regionSettings.TerrainTexture2] = AssetType.Texture;
            }

            if (regionSettings.TerrainTexture3 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_3)
            {
                assetUuids[regionSettings.TerrainTexture3] = AssetType.Texture;
            }

            if (regionSettings.TerrainTexture4 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_4)
            {
                assetUuids[regionSettings.TerrainTexture4] = AssetType.Texture;
            }

            Save(scene, sceneObjects, regionDir);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks whether the user has permission to export an object group to an OAR.
        /// </summary>
        /// <param name="user">The user</param>
        /// <param name="objGroup">The object group</param>
        /// <param name="filterContent">Which permissions to check: "C" = Copy, "T" = Transfer</param>
        /// <param name="permissionsModule">The scene's permissions module</param>
        /// <returns>Whether the user is allowed to export the object to an OAR</returns>
        private bool CanUserArchiveObject(UUID user, SceneObjectGroup objGroup, string filterContent, IPermissionsModule permissionsModule)
        {
            if (filterContent == null)
                return true;

            if (permissionsModule == null)
                return true;    // this shouldn't happen

            // Check whether the user is permitted to export all of the parts in the SOG. If any
            // part can't be exported then the entire SOG can't be exported.

            bool permitted = true;
            //int primNumber = 1;

            foreach (SceneObjectPart obj in objGroup.Parts)
            {
                uint perm;
                PermissionClass permissionClass = permissionsModule.GetPermissionClass(user, obj);
                switch (permissionClass)
                {
                    case PermissionClass.Owner:
                        perm = obj.BaseMask;
                        break;
                    case PermissionClass.Group:
                        perm = obj.GroupMask | obj.EveryoneMask;
                        break;
                    case PermissionClass.Everyone:
                    default:
                        perm = obj.EveryoneMask;
                        break;
                }

                bool canCopy = (perm & (uint)PermissionMask.Copy) != 0;
                bool canTransfer = (perm & (uint)PermissionMask.Transfer) != 0;

                // Special case: if Everyone can copy the object then this implies it can also be
                // Transferred.
                // However, if the user is the Owner then we don't check EveryoneMask, because it seems that the mask
                // always (incorrectly) includes the Copy bit set in this case. But that's a mistake: the viewer
                // does NOT show that the object has Everyone-Copy permissions, and doesn't allow it to be copied.
                if (permissionClass != PermissionClass.Owner)
                    canTransfer |= (obj.EveryoneMask & (uint)PermissionMask.Copy) != 0;

                bool partPermitted = true;
                if (filterContent.Contains("C") && !canCopy)
                    partPermitted = false;
                if (filterContent.Contains("T") && !canTransfer)
                    partPermitted = false;

                // If the user is the Creator of the object then it can always be included in the OAR
                bool creator = (obj.CreatorID.Guid == user.Guid);
                if (creator)
                    partPermitted = true;

                //string name = (objGroup.PrimCount == 1) ? objGroup.Name : string.Format("{0} ({1}/{2})", obj.Name, primNumber, objGroup.PrimCount);
                //m_log.DebugFormat("[ARCHIVER]: Object permissions: {0}: Base={1:X4}, Owner={2:X4}, Everyone={3:X4}, permissionClass={4}, checkPermissions={5}, canCopy={6}, canTransfer={7}, creator={8}, permitted={9}",
                //    name, obj.BaseMask, obj.OwnerMask, obj.EveryoneMask,
                //    permissionClass, checkPermissions, canCopy, canTransfer, creator, partPermitted);

                if (!partPermitted)
                {
                    permitted = false;
                    break;
                }

                //++primNumber;
            }

            return permitted;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Checks whether the user has permission to export an object group to an OAR.
        /// </summary>
        /// <param name="user">The user</param>
        /// <param name="objGroup">The object group</param>
        /// <param name="checkPermissions">Which permissions to check: "C" = Copy, "T" = Transfer</param>
        /// <returns>Whether the user is allowed to export the object to an OAR</returns>
        private bool CanUserArchiveObject(UUID user, ISceneEntity objGroup, string checkPermissions)
        {
            if (checkPermissions == null)
            {
                return(true);
            }

            IPermissionsModule module = m_scene.RequestModuleInterface <IPermissionsModule>();

            if (module == null)
            {
                return(true); // this shouldn't happen
            }
            // Check whether the user is permitted to export all of the parts in the SOG. If any
            // part can't be exported then the entire SOG can't be exported.

            bool permitted = true;

            foreach (ISceneChildEntity obj in objGroup.ChildrenEntities())
            {
                uint            perm;
                PermissionClass permissionClass = module.GetPermissionClass(user, obj);
                switch (permissionClass)
                {
                case PermissionClass.Owner:
                    perm = obj.BaseMask;
                    break;

                case PermissionClass.Group:
                    perm = obj.GroupMask | obj.EveryoneMask;
                    break;

                case PermissionClass.Everyone:
                default:
                    perm = obj.EveryoneMask;
                    break;
                }

                bool canCopy     = (perm & (uint)PermissionMask.Copy) != 0;
                bool canTransfer = (perm & (uint)PermissionMask.Transfer) != 0;

                // Special case: if Everyone can copy the object then this implies it can also be
                // Transferred.
                // However, if the user is the Owner then we don't check EveryoneMask, because it seems that the mask
                // always (incorrectly) includes the Copy bit set in this case. But that's a mistake: the viewer
                // does NOT show that the object has Everyone-Copy permissions, and doesn't allow it to be copied.
                if (permissionClass != PermissionClass.Owner)
                {
                    canTransfer |= (obj.EveryoneMask & (uint)PermissionMask.Copy) != 0;
                }


                bool partPermitted = true;
                if (checkPermissions.Contains("C") && !canCopy)
                {
                    partPermitted = false;
                }
                if (checkPermissions.Contains("T") && !canTransfer)
                {
                    partPermitted = false;
                }

                //string name = (objGroup.PrimCount == 1) ? objGroup.Name : string.Format("{0} ({1}/{2})", obj.Name, primNumber, objGroup.PrimCount);
                //MainConsole.Instance.DebugFormat("[ARCHIVER]: Object permissions: {0}: Base={1:X4}, Owner={2:X4}, Everyone={3:X4}, permissionClass={4}, checkPermissions={5}, canCopy={6}, canTransfer={7}, permitted={8}",
                //    name, obj.BaseMask, obj.OwnerMask, obj.EveryoneMask,
                //    permissionClass, checkPermissions, canCopy, canTransfer, permitted);

                if (!partPermitted)
                {
                    permitted = false;
                    break;
                }
            }

            return(permitted);
        }