From 186f0b73cd9c3005fc75a9925bc65902d26d497b Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 21 Jan 2017 10:22:00 +0000 Subject: [PATCH] add/fix CanRunScript --- .../World/Permissions/PermissionsModule.cs | 32 +++++++++++++++++-- .../Framework/Scenes/Scene.Permissions.cs | 26 +++++++++++++-- .../Scenes/SceneObjectPartInventory.cs | 2 +- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index 59da1c287f..b012f5fb51 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -1612,12 +1612,40 @@ namespace OpenSim.Region.CoreModules.World.Permissions return IsAdministrator(user); } - private bool CanRunScript(UUID script, UUID objectID, UUID user, Scene scene) + private bool CanRunScript(TaskInventoryItem scriptitem, SceneObjectPart part) { DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name); if (m_bypassPermissions) return m_bypassPermissionsValue; - return true; + if(scriptitem == null || part == null) + return false; + + SceneObjectGroup sog = part.ParentGroup; + if(sog == null) + return false; + + Vector3 pos = sog.AbsolutePosition; + ILandObject parcel = m_scene.LandChannel.GetLandObject(pos.X, pos.Y); + if (parcel == null) + return false; + + LandData ldata = parcel.LandData; + if(ldata == null) + return false; + + uint lflags = ldata.Flags; + + if ((lflags & (uint)ParcelFlags.AllowOtherScripts) != 0) + return true; + + if ((part.OwnerID == ldata.OwnerID)) + return true; + + if (((lflags & (uint)ParcelFlags.AllowGroupScripts) != 0) + && (ldata.GroupID != UUID.Zero) && (ldata.GroupID == part.GroupID)) + return true; + + return GenericEstatePermission(part.OwnerID); } private bool CanSellParcel(UUID user, ILandObject parcel, Scene scene) diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs index 6925b6c622..e941210d77 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs @@ -60,7 +60,8 @@ namespace OpenSim.Region.Framework.Scenes public delegate bool ViewNotecardHandler(UUID script, UUID objectID, UUID user, Scene scene); public delegate bool EditScriptHandler(UUID script, UUID objectID, UUID user, Scene scene); public delegate bool EditNotecardHandler(UUID notecard, UUID objectID, UUID user, Scene scene); - public delegate bool RunScriptHandler(UUID script, UUID objectID, UUID user, Scene scene); + public delegate bool RunScriptHandlerByIDs(UUID script, UUID objectID, UUID user, Scene scene); + public delegate bool RunScriptHandler(TaskInventoryItem item, SceneObjectPart part); public delegate bool CompileScriptHandler(UUID ownerUUID, int scriptType, Scene scene); public delegate bool StartScriptHandler(UUID script, UUID user, Scene scene); public delegate bool StopScriptHandler(UUID script, UUID user, Scene scene); @@ -131,6 +132,7 @@ namespace OpenSim.Region.Framework.Scenes public event ViewNotecardHandler OnViewNotecard; public event EditScriptHandler OnEditScript; public event EditNotecardHandler OnEditNotecard; + public event RunScriptHandlerByIDs OnRunScriptByIDs; public event RunScriptHandler OnRunScript; public event CompileScriptHandler OnCompileScript; public event StartScriptHandler OnStartScript; @@ -654,11 +656,11 @@ namespace OpenSim.Region.Framework.Scenes #region RUN SCRIPT (When Script Placed in Object) public bool CanRunScript(UUID script, UUID objectID, UUID user) { - RunScriptHandler handler = OnRunScript; + RunScriptHandlerByIDs handler = OnRunScriptByIDs; if (handler != null) { Delegate[] list = handler.GetInvocationList(); - foreach (RunScriptHandler h in list) + foreach (RunScriptHandlerByIDs h in list) { if (h(script, objectID, user, m_scene) == false) return false; @@ -667,6 +669,24 @@ namespace OpenSim.Region.Framework.Scenes return true; } + public bool CanRunScript(TaskInventoryItem item, SceneObjectPart part) + { + RunScriptHandler handler = OnRunScript; + if (handler != null) + { + if(item == null || part == null) + return false; + Delegate[] list = handler.GetInvocationList(); + foreach (RunScriptHandler h in list) + { + if (h(item, part) == false) + return false; + } + } + return true; + } + + #endregion #region COMPILE SCRIPT (When Script needs to get (re)compiled) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 545d44b4d7..b53c355333 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -360,7 +360,7 @@ namespace OpenSim.Region.Framework.Scenes // m_log.DebugFormat("[PRIM INVENTORY]: Starting script {0} {1} in prim {2} {3} in {4}", // item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName); - if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) + if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item, m_part)) { StoreScriptError(item.ItemID, "no permission"); return false;