add and use CanDropInObjectInv

httptests
UbitUmarov 2017-01-25 19:39:58 +00:00
parent f722f1cf6c
commit 02fbe5a740
3 changed files with 234 additions and 165 deletions

View File

@ -49,6 +49,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected Scene m_scene;
protected ScenePermissions scenePermissions;
protected bool m_Enabled;
private InventoryFolderImpl m_libraryRootFolder;
@ -253,74 +254,74 @@ namespace OpenSim.Region.CoreModules.World.Permissions
m_scene = scene;
scene.RegisterModuleInterface<IPermissionsModule>(this);
scenePermissions = m_scene.Permissions;
//Register functions with Scene External Checks!
m_scene.Permissions.OnBypassPermissions += BypassPermissions;
m_scene.Permissions.OnSetBypassPermissions += SetBypassPermissions;
m_scene.Permissions.OnPropagatePermissions += PropagatePermissions;
scenePermissions.OnBypassPermissions += BypassPermissions;
scenePermissions.OnSetBypassPermissions += SetBypassPermissions;
scenePermissions.OnPropagatePermissions += PropagatePermissions;
m_scene.Permissions.OnIsGridGod += IsGridAdministrator;
m_scene.Permissions.OnIsAdministrator += IsAdministrator;
m_scene.Permissions.OnIsEstateManager += IsEstateManager;
scenePermissions.OnIsGridGod += IsGridAdministrator;
scenePermissions.OnIsAdministrator += IsAdministrator;
scenePermissions.OnIsEstateManager += IsEstateManager;
m_scene.Permissions.OnGenerateClientFlags += GenerateClientFlags;
scenePermissions.OnGenerateClientFlags += GenerateClientFlags;
m_scene.Permissions.OnIssueEstateCommand += CanIssueEstateCommand;
m_scene.Permissions.OnRunConsoleCommand += CanRunConsoleCommand;
scenePermissions.OnIssueEstateCommand += CanIssueEstateCommand;
scenePermissions.OnRunConsoleCommand += CanRunConsoleCommand;
m_scene.Permissions.OnTeleport += CanTeleport;
scenePermissions.OnTeleport += CanTeleport;
m_scene.Permissions.OnInstantMessage += CanInstantMessage;
scenePermissions.OnInstantMessage += CanInstantMessage;
m_scene.Permissions.OnAbandonParcel += CanAbandonParcel;
m_scene.Permissions.OnReclaimParcel += CanReclaimParcel;
m_scene.Permissions.OnDeedParcel += CanDeedParcel;
m_scene.Permissions.OnSellParcel += CanSellParcel;
m_scene.Permissions.OnEditParcelProperties += CanEditParcelProperties;
m_scene.Permissions.OnTerraformLand += CanTerraformLand;
m_scene.Permissions.OnBuyLand += CanBuyLand;
scenePermissions.OnAbandonParcel += CanAbandonParcel;
scenePermissions.OnReclaimParcel += CanReclaimParcel;
scenePermissions.OnDeedParcel += CanDeedParcel;
scenePermissions.OnSellParcel += CanSellParcel;
scenePermissions.OnEditParcelProperties += CanEditParcelProperties;
scenePermissions.OnTerraformLand += CanTerraformLand;
scenePermissions.OnBuyLand += CanBuyLand;
m_scene.Permissions.OnRezObject += CanRezObject;
m_scene.Permissions.OnObjectEntry += CanObjectEntry;
m_scene.Permissions.OnReturnObjects += CanReturnObjects;
scenePermissions.OnRezObject += CanRezObject;
scenePermissions.OnObjectEntry += CanObjectEntry;
scenePermissions.OnReturnObjects += CanReturnObjects;
m_scene.Permissions.OnDuplicateObject += CanDuplicateObject;
m_scene.Permissions.OnDeleteObjectByIDs += CanDeleteObjectByIDs;
m_scene.Permissions.OnDeleteObject += CanDeleteObject;
m_scene.Permissions.OnEditObjectByIDs += CanEditObjectByIDs;
m_scene.Permissions.OnEditObject += CanEditObject;
m_scene.Permissions.OnInventoryTransfer += CanInventoryTransfer;
m_scene.Permissions.OnMoveObject += CanMoveObject;
m_scene.Permissions.OnTakeObject += CanTakeObject;
m_scene.Permissions.OnTakeCopyObject += CanTakeCopyObject;
m_scene.Permissions.OnLinkObject += CanLinkObject;
m_scene.Permissions.OnDelinkObject += CanDelinkObject;
m_scene.Permissions.OnDeedObject += CanDeedObject;
m_scene.Permissions.OnSellGroupObject += CanSellGroupObject;
scenePermissions.OnDuplicateObject += CanDuplicateObject;
scenePermissions.OnDeleteObjectByIDs += CanDeleteObjectByIDs;
scenePermissions.OnDeleteObject += CanDeleteObject;
scenePermissions.OnEditObjectByIDs += CanEditObjectByIDs;
scenePermissions.OnEditObject += CanEditObject;
scenePermissions.OnInventoryTransfer += CanInventoryTransfer;
scenePermissions.OnMoveObject += CanMoveObject;
scenePermissions.OnTakeObject += CanTakeObject;
scenePermissions.OnTakeCopyObject += CanTakeCopyObject;
scenePermissions.OnLinkObject += CanLinkObject;
scenePermissions.OnDelinkObject += CanDelinkObject;
scenePermissions.OnDeedObject += CanDeedObject;
scenePermissions.OnSellGroupObject += CanSellGroupObject;
scenePermissions.OnCreateObjectInventory += CanCreateObjectInventory;
scenePermissions.OnEditObjectInventory += CanEditObjectInventory;
scenePermissions.OnCopyObjectInventory += CanCopyObjectInventory;
scenePermissions.OnDeleteObjectInventory += CanDeleteObjectInventory;
scenePermissions.OnDoObjectInvToObjectInv += CanDoObjectInvToObjectInv;
scenePermissions.OnDropInObjectInv += CanDropInObjectInv;
scenePermissions.OnViewNotecard += CanViewNotecard;
scenePermissions.OnViewScript += CanViewScript;
scenePermissions.OnEditNotecard += CanEditNotecard;
scenePermissions.OnEditScript += CanEditScript;
scenePermissions.OnResetScript += CanResetScript;
scenePermissions.OnRunScript += CanRunScript;
scenePermissions.OnCompileScript += CanCompileScript;
scenePermissions.OnCreateUserInventory += CanCreateUserInventory;
scenePermissions.OnCopyUserInventory += CanCopyUserInventory;
scenePermissions.OnEditUserInventory += CanEditUserInventory;
scenePermissions.OnDeleteUserInventory += CanDeleteUserInventory;
m_scene.Permissions.OnCreateObjectInventory += CanCreateObjectInventory;
m_scene.Permissions.OnEditObjectInventory += CanEditObjectInventory;
m_scene.Permissions.OnCopyObjectInventory += CanCopyObjectInventory;
m_scene.Permissions.OnDeleteObjectInventory += CanDeleteObjectInventory;
m_scene.Permissions.OnDoObjectInvToObjectInv += CanDoObjectInvToObjectInv;
m_scene.Permissions.OnViewNotecard += CanViewNotecard;
m_scene.Permissions.OnViewScript += CanViewScript;
m_scene.Permissions.OnEditNotecard += CanEditNotecard;
m_scene.Permissions.OnEditScript += CanEditScript;
m_scene.Permissions.OnResetScript += CanResetScript;
m_scene.Permissions.OnRunScript += CanRunScript;
m_scene.Permissions.OnCompileScript += CanCompileScript;
m_scene.Permissions.OnCreateUserInventory += CanCreateUserInventory;
m_scene.Permissions.OnCopyUserInventory += CanCopyUserInventory;
m_scene.Permissions.OnEditUserInventory += CanEditUserInventory;
m_scene.Permissions.OnDeleteUserInventory += CanDeleteUserInventory;
m_scene.Permissions.OnControlPrimMedia += CanControlPrimMedia;
m_scene.Permissions.OnInteractWithPrimMedia += CanInteractWithPrimMedia;
scenePermissions.OnControlPrimMedia += CanControlPrimMedia;
scenePermissions.OnInteractWithPrimMedia += CanInteractWithPrimMedia;
m_scene.AddCommand("Users", this, "bypass permissions",
"bypass permissions <true / false>",
@ -2094,11 +2095,13 @@ namespace OpenSim.Region.CoreModules.World.Permissions
private bool CanDoObjectInvToObjectInv(TaskInventoryItem item, SceneObjectPart sourcePart, SceneObjectPart destPart)
{
DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
if (m_bypassPermissions) return m_bypassPermissionsValue;
if (sourcePart == null || destPart == null || item == null)
return false;
if (m_bypassPermissions)
return m_bypassPermissionsValue;
SceneObjectGroup srcsog = sourcePart.ParentGroup;
SceneObjectGroup destsog = destPart.ParentGroup;
if (srcsog == null || destsog == null)
@ -2127,12 +2130,12 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if(item.InvType == (int)InventoryType.LSL)
return false;
if((destPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
if((destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
return false;
}
else
{
if((destPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0 &&
if((destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0 &&
(destsog.EffectiveOwnerPerms & (uint)PermissionMask.Modify) == 0)
return false;
}
@ -2140,6 +2143,54 @@ namespace OpenSim.Region.CoreModules.World.Permissions
return true;
}
private bool CanDropInObjectInv(InventoryItemBase item, ScenePresence sp, SceneObjectPart destPart)
{
DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
if (sp == null || sp.IsDeleted || destPart == null || item == null)
return false;
SceneObjectGroup destsog = destPart.ParentGroup;
if (destsog == null || destsog.IsDeleted)
return false;
if (m_bypassPermissions)
return m_bypassPermissionsValue;
if(sp.IsGod)
return true;
// dest is locked
if((destsog.EffectiveOwnerPerms & (uint)PermissionMask.Move) == 0)
return false;
UUID destOwner = destsog.OwnerID;
UUID spID = sp.UUID;
bool spNotOwner = spID != destOwner;
// scripts can't be droped
if(spNotOwner && item.InvType == (int)InventoryType.LSL)
return false;
if(spNotOwner || item.Owner != destOwner)
{
// no copy item will be moved if it has transfer
uint itperms = item.CurrentPermissions;
if((itperms & (uint)PermissionMask.Transfer) == 0)
return false;
}
// allowdrop is a root part thing and does bypass modify rights
if((destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) != 0)
return true;
uint perms = GetObjectPermissions(spID, destsog, true);
if((perms & (uint)PermissionMask.Modify) == 0)
return false;
return true;
}
private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
{
DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
@ -2153,7 +2204,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
if (sog == null)
return false;
uint perms = GetObjectPermissions(objectID, sog, true);
uint perms = GetObjectPermissions(userID, sog, true);
if((perms & (uint)PermissionMask.Modify) == 0)
return false;

View File

@ -1645,76 +1645,78 @@ namespace OpenSim.Region.Framework.Scenes
uint primLocalID)
{
UUID itemID = itemInfo.ItemID;
if (itemID == UUID.Zero)
{
m_log.ErrorFormat(
"[PRIM INVENTORY]: UpdateTaskInventory called with item ID Zero to update for {1}!",
remoteClient.Name);
return;
}
// Find the prim we're dealing with
SceneObjectPart part = GetSceneObjectPart(primLocalID);
if (part != null)
if(part == null)
{
TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
bool allowInventoryDrop = (part.GetEffectiveObjectFlags()
& (uint)PrimFlags.AllowInventoryDrop) != 0;
m_log.WarnFormat(
"[PRIM INVENTORY]: " +
"Update with item {0} requested of prim {1} for {2} but this prim does not exist",
itemID, primLocalID, remoteClient.Name);
return;
}
// Explicity allow anyone to add to the inventory if the
// AllowInventoryDrop flag has been set. Don't however let
// them update an item unless they pass the external checks
//
if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)
&& (currentItem != null || !allowInventoryDrop))
TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
if (currentItem == null)
{
InventoryItemBase item = InventoryService.GetItem(remoteClient.AgentId, itemID);
// if not found Try library
if (item == null && LibraryService != null && LibraryService.LibraryRootFolder != null)
item = LibraryService.LibraryRootFolder.FindItem(itemID);
if(item == null)
{
m_log.ErrorFormat(
"[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
itemID, remoteClient.Name);
return;
}
if (!Permissions.CanDropInObjectInv(item, remoteClient, part))
return;
if (currentItem == null)
UUID copyID = UUID.Random();
part.ParentGroup.AddInventoryItem(remoteClient.AgentId, primLocalID, item, copyID);
m_log.InfoFormat(
"[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
item.Name, primLocalID, remoteClient.Name);
part.SendPropertiesToClient(remoteClient);
if (!Permissions.BypassPermissions())
{
UUID copyID = UUID.Random();
if (itemID != UUID.Zero)
if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
{
InventoryItemBase item = InventoryService.GetItem(remoteClient.AgentId, itemID);
// Try library
if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
{
item = LibraryService.LibraryRootFolder.FindItem(itemID);
}
// If we've found the item in the user's inventory or in the library
if (item != null)
{
part.ParentGroup.AddInventoryItem(remoteClient.AgentId, primLocalID, item, copyID);
m_log.InfoFormat(
"[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
item.Name, primLocalID, remoteClient.Name);
part.SendPropertiesToClient(remoteClient);
if (!Permissions.BypassPermissions())
{
if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
{
List<UUID> uuids = new List<UUID>();
uuids.Add(itemID);
RemoveInventoryItem(remoteClient, uuids);
}
}
}
else
{
m_log.ErrorFormat(
"[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
itemID, remoteClient.Name);
}
List<UUID> uuids = new List<UUID>();
uuids.Add(itemID);
RemoveInventoryItem(remoteClient, uuids);
}
}
else // Updating existing item with new perms etc
{
}
else // Updating existing item with new perms etc
{
// m_log.DebugFormat(
// "[PRIM INVENTORY]: Updating item {0} in {1} for UpdateTaskInventory()",
// currentItem.Name, part.Name);
// Only look for an uploaded updated asset if we are passed a transaction ID. This is only the
// case for updates uploded through UDP. Updates uploaded via a capability (e.g. a script update)
// will not pass in a transaction ID in the update message.
if (transactionID != UUID.Zero && AgentTransactionsModule != null)
{
AgentTransactionsModule.HandleTaskItemUpdateFromTransaction(
remoteClient, part, transactionID, currentItem);
if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
return;
// Only look for an uploaded updated asset if we are passed a transaction ID. This is only the
// case for updates uploded through UDP. Updates uploaded via a capability (e.g. a script update)
// will not pass in a transaction ID in the update message.
if (transactionID != UUID.Zero && AgentTransactionsModule != null)
{
AgentTransactionsModule.HandleTaskItemUpdateFromTransaction(
remoteClient, part, transactionID, currentItem);
// if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
// remoteClient.SendAgentAlertMessage("Notecard saved", false);
@ -1722,49 +1724,30 @@ namespace OpenSim.Region.Framework.Scenes
// remoteClient.SendAgentAlertMessage("Script saved", false);
// else
// remoteClient.SendAgentAlertMessage("Item saved", false);
}
}
// Base ALWAYS has move
currentItem.BasePermissions |= (uint)PermissionMask.Move;
// Base ALWAYS has move
currentItem.BasePermissions |= (uint)PermissionMask.Move;
itemInfo.Flags = currentItem.Flags;
itemInfo.Flags = currentItem.Flags;
// Check if we're allowed to mess with permissions
if (!Permissions.IsGod(remoteClient.AgentId)) // Not a god
// Check if we're allowed to mess with permissions
if (!Permissions.IsGod(remoteClient.AgentId)) // Not a god
{
if (remoteClient.AgentId != part.OwnerID) // Not owner
{
if (remoteClient.AgentId != part.OwnerID) // Not owner
{
// Friends and group members can't change any perms
itemInfo.BasePermissions = currentItem.BasePermissions;
itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
itemInfo.GroupPermissions = currentItem.GroupPermissions;
itemInfo.NextPermissions = currentItem.NextPermissions;
itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
}
else
{
// Owner can't change base, and can change other
// only up to base
itemInfo.BasePermissions = currentItem.BasePermissions;
if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
if (itemInfo.NextPermissions != currentItem.NextPermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
itemInfo.EveryonePermissions &= currentItem.BasePermissions;
itemInfo.GroupPermissions &= currentItem.BasePermissions;
itemInfo.CurrentPermissions &= currentItem.BasePermissions;
itemInfo.NextPermissions &= currentItem.BasePermissions;
}
// Friends and group members can't change any perms
itemInfo.BasePermissions = currentItem.BasePermissions;
itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
itemInfo.GroupPermissions = currentItem.GroupPermissions;
itemInfo.NextPermissions = currentItem.NextPermissions;
itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
}
else
{
if (itemInfo.BasePermissions != currentItem.BasePermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteBase;
// Owner can't change base, and can change other
// only up to base
itemInfo.BasePermissions = currentItem.BasePermissions;
if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
@ -1773,23 +1756,34 @@ namespace OpenSim.Region.Framework.Scenes
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
if (itemInfo.NextPermissions != currentItem.NextPermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
itemInfo.EveryonePermissions &= currentItem.BasePermissions;
itemInfo.GroupPermissions &= currentItem.BasePermissions;
itemInfo.CurrentPermissions &= currentItem.BasePermissions;
itemInfo.NextPermissions &= currentItem.BasePermissions;
}
// Next ALWAYS has move
itemInfo.NextPermissions |= (uint)PermissionMask.Move;
if (part.Inventory.UpdateInventoryItem(itemInfo))
{
part.SendPropertiesToClient(remoteClient);
}
}
}
else
{
m_log.WarnFormat(
"[PRIM INVENTORY]: " +
"Update with item {0} requested of prim {1} for {2} but this prim does not exist",
itemID, primLocalID, remoteClient.Name);
else
{
if (itemInfo.BasePermissions != currentItem.BasePermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteBase;
if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
if (itemInfo.NextPermissions != currentItem.NextPermissions)
itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
}
// Next ALWAYS has move
itemInfo.NextPermissions |= (uint)PermissionMask.Move;
if (part.Inventory.UpdateInventoryItem(itemInfo))
{
part.SendPropertiesToClient(remoteClient);
}
}
}

View File

@ -87,6 +87,7 @@ namespace OpenSim.Region.Framework.Scenes
public delegate bool CreateObjectInventoryHandler(int invType, UUID objectID, UUID userID);
public delegate bool CopyObjectInventoryHandler(UUID itemID, UUID objectID, UUID userID);
public delegate bool DoObjectInvToObjectInv(TaskInventoryItem item, SceneObjectPart sourcePart, SceneObjectPart destPart);
public delegate bool DoDropInObjectInv(InventoryItemBase item, ScenePresence sp, SceneObjectPart destPart);
public delegate bool DeleteObjectInventoryHandler(UUID itemID, UUID objectID, UUID userID);
public delegate bool TransferObjectInventoryHandler(UUID itemID, UUID objectID, UUID userID);
public delegate bool CreateUserInventoryHandler(int invType, UUID userID);
@ -160,6 +161,7 @@ namespace OpenSim.Region.Framework.Scenes
public event CreateObjectInventoryHandler OnCreateObjectInventory;
public event CopyObjectInventoryHandler OnCopyObjectInventory;
public event DoObjectInvToObjectInv OnDoObjectInvToObjectInv;
public event DoDropInObjectInv OnDropInObjectInv;
public event DeleteObjectInventoryHandler OnDeleteObjectInventory;
public event TransferObjectInventoryHandler OnTransferObjectInventory;
public event CreateUserInventoryHandler OnCreateUserInventory;
@ -1109,6 +1111,28 @@ namespace OpenSim.Region.Framework.Scenes
return true;
}
public bool CanDropInObjectInv(InventoryItemBase item, IClientAPI client, SceneObjectPart destPart)
{
DoDropInObjectInv handler = OnDropInObjectInv;
if (handler != null)
{
if (client == null || client.SceneAgent == null|| destPart == null || item == null)
return false;
ScenePresence sp = client.SceneAgent as ScenePresence;
if(sp == null || sp.IsDeleted)
return false;
Delegate[] list = handler.GetInvocationList();
foreach (DoDropInObjectInv h in list)
{
if (h(item, sp, destPart) == false)
return false;
}
}
return true;
}
public bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
{
DeleteObjectInventoryHandler handler = OnDeleteObjectInventory;