From ce7694c108e8abf2e52a0b0167eab3d550f364ab Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Wed, 1 Aug 2012 10:28:58 +0100 Subject: added perms checking, duplicated functionality to methods that do not require perms and have higher threat level --- .../Shared/Api/Implementation/OSSL_Api.cs | 70 ++++++++++++++++++++-- .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 12 ++++ .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 10 ++++ 3 files changed, 86 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 02b97e8..d0db15f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -3538,7 +3538,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return new LSL_Key(m_host.ParentGroup.FromPartID.ToString()); } - + /// /// Sets the response type for an HTTP request/response /// @@ -3549,11 +3549,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_UrlModule != null) m_UrlModule.HttpContentType(new UUID(id),type); } - - public void osDropAttachment() + /// Shout an error if the object owner did not grant the script the specified permissions. + /// + /// + /// boolean indicating whether an error was shouted. + protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix) { CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment"); m_host.AddScriptLPS(1); + bool fail = false; + if (m_item.PermsGranter != m_host.OwnerID) + { + fail = true; + OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix)); + } + else if ((m_item.PermsMask & perms) == 0) + { + fail = true; + OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix)); + } + + return fail; + } + + protected void DropAttachment(bool checkPerms) + { + if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment")) + { + return; + } IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID); @@ -3564,10 +3588,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } - public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) + protected void DropAttachemntAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot) { - CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt"); - m_host.AddScriptLPS(1); + if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment")) + { + return; + } IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID); @@ -3579,5 +3605,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, omvPos, omvRot); } } + + public void osDropAttachment() + { + CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment"); + m_host.AddScriptLPS(1); + + DropAttachment(true); + } + + public void osForceDropAttachment() + { + CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment"); + m_host.AddScriptLPS(1); + + DropAttachment(false); + } + + public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) + { + CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt"); + m_host.AddScriptLPS(1); + + DropAttachemntAt(true, pos, rot); + } + + public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot) + { + CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt"); + m_host.AddScriptLPS(1); + + DropAttachemntAt(false, pos, rot); + } } } \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index e28473d..93188c9 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -401,10 +401,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces void osDropAttachment(); /// + /// Attempts to drop an attachment to the ground while bypassing the script permissions + /// + void osForceDropAttachment(); + + /// /// Attempts to drop an attachment at the specified coordinates. /// /// /// void osDropAttachmentAt(vector pos, rotation rot); + + /// + /// Attempts to drop an attachment at the specified coordinates while bypassing the script permissions + /// + /// + /// + void osForceDropAttachmentAt(vector pos, rotation rot); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index bae5594..dee1b28 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -978,9 +978,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase m_OSSL_Functions.osDropAttachment(); } + public void osForceDropAttachment() + { + m_OSSL_Functions.osForceDropAttachment(); + } + public void osDropAttachmentAt(vector pos, rotation rot) { m_OSSL_Functions.osDropAttachmentAt(pos, rot); } + + public void osForceDropAttachmentAt(vector pos, rotation rot) + { + m_OSSL_Functions.osForceDropAttachmentAt(pos, rot); + } } } -- cgit v1.1