diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 69b5f43ba0..dd0f787016 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -1883,8 +1883,11 @@ namespace OpenSim.Region.Framework.Scenes /// Rez a script into a prim's inventory from another prim /// /// - /// - /// + /// + /// + /// + /// + /// public void RezScriptFromPrim(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param) { TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId); @@ -1904,12 +1907,11 @@ namespace OpenSim.Region.Framework.Scenes if (destPart == null) { m_log.ErrorFormat( - "[PRIM INVENTORY]: " + - "Could not find script for ID {0}", - destId); + "[PRIM INVENTORY]: Could not find part {0} to insert script item {1} from {2} {3} in {4}", + destId, srcId, srcPart.Name, srcPart.UUID, Name); return; } - + // Must own the object, and have modify rights if (srcPart.OwnerID != destPart.OwnerID) { @@ -1917,12 +1919,14 @@ namespace OpenSim.Region.Framework.Scenes if ((destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) || ((destPart.GroupMask & (uint)PermissionMask.Modify) == 0)) return; - } else { + } + else + { if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0) return; } - if (destPart.ScriptAccessPin != pin) + if (destPart.ScriptAccessPin == 0 || destPart.ScriptAccessPin != pin) { m_log.WarnFormat( "[PRIM INVENTORY]: " + diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs index 6dd6c170b7..02a9361394 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs @@ -167,5 +167,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); } } + + [Test] + public void TestLlRemoteLoadScriptPin() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + UUID user1Id = TestHelpers.ParseTail(0x1); + UUID user2Id = TestHelpers.ParseTail(0x2); + + SceneObjectGroup sourceSo = SceneHelpers.AddSceneObject(m_scene, "sourceSo", user1Id); + m_scene.AddSceneObject(sourceSo); + LSL_Api api = new LSL_Api(); + api.Initialize(m_engine, sourceSo.RootPart, null, null); + TaskInventoryHelpers.AddScript(m_scene, sourceSo.RootPart, "script", "Hello World"); + + SceneObjectGroup targetSo = SceneHelpers.AddSceneObject(m_scene, "targetSo", user1Id); + SceneObjectGroup otherOwnedTargetSo = SceneHelpers.AddSceneObject(m_scene, "otherOwnedTargetSo", user2Id); + + // Test that we cannot load a script when the target pin has never been set (i.e. it is zero) + api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 0, 0, 0); + Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script")); + + // Test that we cannot load a script when the given pin does not match the target + targetSo.RootPart.ScriptAccessPin = 5; + api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0); + Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script")); + + // Test that we cannot load into a prim with a different owner + otherOwnedTargetSo.RootPart.ScriptAccessPin = 3; + api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0); + Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script")); + + // Test that we can load a script when given pin and dest pin match. + targetSo.RootPart.ScriptAccessPin = 3; + api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0); + TaskInventoryItem insertedItem = targetSo.RootPart.Inventory.GetInventoryItem("script"); + Assert.IsNotNull(insertedItem); + + // Test that we can no longer load if access pin is unset + targetSo.RootPart.Inventory.RemoveInventoryItem(insertedItem.ItemID); + Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script")); + + targetSo.RootPart.ScriptAccessPin = 0; + api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0); + Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script")); + } } } \ No newline at end of file