From b47c0d7e51bdb4d4bfa34f0952593f94c657d19c Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 12 Jan 2012 18:14:19 +0000 Subject: refactor: Move existing npc owner checks to NPCModule.CheckPermissions() methods and expose on interface for external calls. --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 49 ++++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index e874417..8f9b513 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -56,6 +56,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC } } + public void PostInitialise() + { + } + + public void Close() + { + } + + public string Name + { + get { return "NPCModule"; } + } + + public bool IsSharedModule + { + get { return true; } + } + public bool IsNPC(UUID agentId, Scene scene) { // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect @@ -255,7 +273,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC NPCAvatar av; if (m_avatars.TryGetValue(agentID, out av)) { - if (av.OwnerID != UUID.Zero && callerID != UUID.Zero && av.OwnerID != callerID) + if (!CheckPermissions(av, callerID)); return false; scene.RemoveClient(agentID, false); @@ -268,22 +286,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC return false; } - public void PostInitialise() - { - } - - public void Close() - { - } - - public string Name + public bool CheckPermissions(UUID npcID, UUID callerID) { - get { return "NPCModule"; } + lock (m_avatars) + { + NPCAvatar av; + if (m_avatars.TryGetValue(npcID, out av)) + return CheckPermissions(av, callerID); + else + return false; + } } - public bool IsSharedModule + /// + /// Check if the caller has permission to manipulate the given NPC. + /// + /// + /// + /// true if they do, false if they don't. + private bool CheckPermissions(NPCAvatar av, UUID callerID) { - get { return true; } + return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID; } } } -- cgit v1.1 From ba3491c76e2d7cc7187a025dccd782790929f0b7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 12 Jan 2012 19:06:46 +0000 Subject: Add permissions checks for owned avatars to all other osNpc* functions. This is being done outside the npc module since the check is meaningless for region module callers, who can fake any id that they like. --- OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 8f9b513..d90309f 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -266,16 +266,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC return UUID.Zero; } - public bool DeleteNPC(UUID agentID, UUID callerID, Scene scene) + public bool DeleteNPC(UUID agentID, Scene scene) { lock (m_avatars) { NPCAvatar av; if (m_avatars.TryGetValue(agentID, out av)) { - if (!CheckPermissions(av, callerID)); - return false; - scene.RemoveClient(agentID, false); m_avatars.Remove(agentID); -- cgit v1.1 From 1ac5aa68087910dbb3cdfc141d77a95eb89177fa Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 12 Jan 2012 20:47:19 +0000 Subject: Add remove test for unowned avatars --- .../World/NPC/Tests/NPCModuleTests.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 571d33d..d21d601 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -119,6 +119,26 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests } [Test] + public void TestRemove() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); +// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); + + Vector3 startPos = new Vector3(128, 128, 30); + INPCModule npcModule = scene.RequestModuleInterface(); + UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); + + npcModule.DeleteNPC(npcId, scene); + + ScenePresence deletedNpc = scene.GetScenePresence(npcId); + + Assert.That(deletedNpc, Is.Null); + } + + [Test] public void TestAttachments() { TestHelpers.InMethod(); -- cgit v1.1