From 462ad336dcd59dfc4325aed9e6d635aa866cd094 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 2 Nov 2012 00:02:10 +0000
Subject: Move check to allow only deletion of maptiles up to
AssetServerDeleteHandler from AssetService.
This allows us to use a common check for both AssetService and XAssetService.
It also allows future console commands to delete an asset.
As before, deletion of maptile assets is not allowed remotely unless this is explicitly configured.
---
.../Server/Handlers/Asset/AssetServerDeleteHandler.cs | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs')
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
index 0cfe5b1..9a8aee6 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
@@ -44,7 +44,7 @@ namespace OpenSim.Server.Handlers.Asset
{
public class AssetServerDeleteHandler : BaseStreamHandler
{
- // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IAssetService m_AssetService;
protected bool m_allowDelete;
@@ -65,11 +65,22 @@ namespace OpenSim.Server.Handlers.Asset
if (p.Length > 0 && m_allowDelete)
{
- result = m_AssetService.Delete(p[0]);
+ string assetID = p[0];
+
+ AssetBase asset = m_AssetService.Get(assetID);
+ if (asset != null && (int)(asset.Flags & AssetFlags.Maptile) != 0)
+ {
+ result = m_AssetService.Delete(assetID);
+ }
+ else
+ {
+ m_log.DebugFormat(
+ "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but flags are not Maptile", assetID);
+ }
}
XmlSerializer xs = new XmlSerializer(typeof(bool));
return ServerUtils.SerializeResult(xs, result);
}
}
-}
+}
\ No newline at end of file
--
cgit v1.1
From ce7beb6f20cb09e19e0f695f445cfa860b9e9c78 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 2 Nov 2012 01:41:38 +0000
Subject: Add [AssetService] AllowRemoteDeleteAllTypes (default false).
This allows a closed grid to delete asset types other than maptile remotely.
Only operational if AllowRemoteDelete = true also.
Defaults to false - do not enable if anybody other than you can make asset service requests.
---
.../Handlers/Asset/AssetServerDeleteHandler.cs | 50 ++++++++++++++++------
1 file changed, 36 insertions(+), 14 deletions(-)
(limited to 'OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs')
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
index 9a8aee6..986394b 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
@@ -42,18 +42,32 @@ using OpenSim.Framework.Servers.HttpServer;
namespace OpenSim.Server.Handlers.Asset
{
+ ///
+ /// Remote deletes allowed.
+ ///
+ public enum AllowedRemoteDeleteTypes
+ {
+ None,
+ MapTile,
+ All
+ }
+
public class AssetServerDeleteHandler : BaseStreamHandler
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IAssetService m_AssetService;
- protected bool m_allowDelete;
- public AssetServerDeleteHandler(IAssetService service, bool allowDelete) :
+ ///
+ /// Asset types that can be deleted remotely.
+ ///
+ private AllowedRemoteDeleteTypes m_allowedTypes;
+
+ public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes) :
base("DELETE", "/assets")
{
m_AssetService = service;
- m_allowDelete = allowDelete;
+ m_allowedTypes = allowedTypes;
}
public override byte[] Handle(string path, Stream request,
@@ -63,19 +77,27 @@ namespace OpenSim.Server.Handlers.Asset
string[] p = SplitParams(path);
- if (p.Length > 0 && m_allowDelete)
+ if (p.Length > 0)
{
- string assetID = p[0];
-
- AssetBase asset = m_AssetService.Get(assetID);
- if (asset != null && (int)(asset.Flags & AssetFlags.Maptile) != 0)
- {
- result = m_AssetService.Delete(assetID);
- }
- else
+ if (m_allowedTypes != AllowedRemoteDeleteTypes.None)
{
- m_log.DebugFormat(
- "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but flags are not Maptile", assetID);
+ string assetID = p[0];
+
+ AssetBase asset = m_AssetService.Get(assetID);
+ if (asset != null)
+ {
+ if (m_allowedTypes == AllowedRemoteDeleteTypes.All
+ || (int)(asset.Flags & AssetFlags.Maptile) != 0)
+ {
+ result = m_AssetService.Delete(assetID);
+ }
+ else
+ {
+ m_log.DebugFormat(
+ "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but type is {1} and allowed remote delete types are {2}",
+ assetID, (AssetFlags)asset.Flags, m_allowedTypes);
+ }
+ }
}
}
--
cgit v1.1