Fix bug where an avatar that had an object they owned attached through llAttachToAvatar() or osForceAttachToAvatar() would wrongly have next permissions come into play when they detached that object and rezzed it in scene.

This is because the attachments module code was setting the 'object slam' bit by using PermissionMask.All
Solution here is to route the attachment item creation call through the existing inventory code in BasicInventoryAccessModule rather than copy/pasted code in AttachmentsModule itself.
0.7.3-extended
Justin Clark-Casey (justincc) 2012-05-23 01:58:10 +01:00
parent 80d139297a
commit 54c222be26
8 changed files with 155 additions and 169 deletions

View File

@ -49,6 +49,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
private Scene m_scene; private Scene m_scene;
private IDialogModule m_dialogModule; private IDialogModule m_dialogModule;
private IInventoryAccessModule m_invAccessModule;
/// <summary> /// <summary>
/// Are attachments enabled? /// Are attachments enabled?
@ -87,7 +88,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
m_scene.EventManager.OnNewClient -= SubscribeToClientEvents; m_scene.EventManager.OnNewClient -= SubscribeToClientEvents;
} }
public void RegionLoaded(Scene scene) {} public void RegionLoaded(Scene scene)
{
m_invAccessModule = m_scene.RequestModuleInterface<IInventoryAccessModule>();
}
public void Close() public void Close()
{ {
@ -576,90 +580,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
/// <returns>The user inventory item created that holds the attachment.</returns> /// <returns>The user inventory item created that holds the attachment.</returns>
private InventoryItemBase AddSceneObjectAsNewAttachmentInInv(IScenePresence sp, SceneObjectGroup grp) private InventoryItemBase AddSceneObjectAsNewAttachmentInInv(IScenePresence sp, SceneObjectGroup grp)
{ {
if (m_invAccessModule == null)
return null;
// m_log.DebugFormat( // m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}", // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
// grp.Name, grp.LocalId, remoteClient.Name); // grp.Name, grp.LocalId, remoteClient.Name);
Vector3 inventoryStoredPosition = new Vector3 InventoryItemBase newItem = m_invAccessModule.CopyToInventory(
(((grp.AbsolutePosition.X > (int)Constants.RegionSize) DeRezAction.TakeCopy,
? Constants.RegionSize - 6 m_scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object).ID,
: grp.AbsolutePosition.X) new List<SceneObjectGroup> { grp },
, sp.ControllingClient, true)[0];
(grp.AbsolutePosition.Y > (int)Constants.RegionSize)
? Constants.RegionSize - 6
: grp.AbsolutePosition.Y,
grp.AbsolutePosition.Z);
Vector3 originalPosition = grp.AbsolutePosition;
grp.AbsolutePosition = inventoryStoredPosition;
// If we're being called from a script, then trying to serialize that same script's state will not complete
// in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
// the client/server crashes rather than logging out normally, the attachment's scripts will resume
// without state on relog. Arguably, this is what we want anyway.
string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false);
grp.AbsolutePosition = originalPosition;
AssetBase asset = m_scene.CreateAsset(
grp.GetPartName(grp.LocalId),
grp.GetPartDescription(grp.LocalId),
(sbyte)AssetType.Object,
Utils.StringToBytes(sceneObjectXml),
sp.UUID);
m_scene.AssetService.Store(asset);
InventoryItemBase item = new InventoryItemBase();
item.CreatorId = grp.RootPart.CreatorID.ToString();
item.CreatorData = grp.RootPart.CreatorData;
item.Owner = sp.UUID;
item.ID = UUID.Random();
item.AssetID = asset.FullID;
item.Description = asset.Description;
item.Name = asset.Name;
item.AssetType = asset.Type;
item.InvType = (int)InventoryType.Object;
InventoryFolderBase folder = m_scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object);
if (folder != null)
item.Folder = folder.ID;
else // oopsies
item.Folder = UUID.Zero;
if ((sp.UUID != grp.RootPart.OwnerID) && m_scene.Permissions.PropagatePermissions())
{
item.BasePermissions = grp.RootPart.NextOwnerMask;
item.CurrentPermissions = grp.RootPart.NextOwnerMask;
item.NextPermissions = grp.RootPart.NextOwnerMask;
item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
}
else
{
item.BasePermissions = grp.RootPart.BaseMask;
item.CurrentPermissions = grp.RootPart.OwnerMask;
item.NextPermissions = grp.RootPart.NextOwnerMask;
item.EveryOnePermissions = grp.RootPart.EveryoneMask;
item.GroupPermissions = grp.RootPart.GroupMask;
}
item.CreationDate = Util.UnixTimeSinceEpoch();
// sets itemID so client can show item as 'attached' in inventory // sets itemID so client can show item as 'attached' in inventory
grp.FromItemID = item.ID; grp.FromItemID = newItem.ID;
if (m_scene.AddInventoryItem(item)) return newItem;
{
sp.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
}
else
{
if (m_dialogModule != null)
m_dialogModule.SendAlertToUser(sp.ControllingClient, "Operation failed");
}
return item;
} }
// What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards. // What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards.
@ -707,19 +644,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
private SceneObjectGroup RezSingleAttachmentFromInventoryInternal( private SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt) IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt)
{ {
IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>(); if (m_invAccessModule == null)
if (invAccess != null) return null;
{
lock (sp.AttachmentsSyncLock) lock (sp.AttachmentsSyncLock)
{ {
SceneObjectGroup objatt; SceneObjectGroup objatt;
if (itemID != UUID.Zero) if (itemID != UUID.Zero)
objatt = invAccess.RezObject(sp.ControllingClient, objatt = m_invAccessModule.RezObject(sp.ControllingClient,
itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true, itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
false, false, sp.UUID, true); false, false, sp.UUID, true);
else else
objatt = invAccess.RezObject(sp.ControllingClient, objatt = m_invAccessModule.RezObject(sp.ControllingClient,
null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true, null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
false, false, sp.UUID, true); false, false, sp.UUID, true);
@ -772,7 +709,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
itemID, sp.Name, attachmentPt); itemID, sp.Name, attachmentPt);
} }
} }
}
return null; return null;
} }

View File

@ -99,12 +99,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
public void TestAddAttachmentFromGround() public void TestAddAttachmentFromGround()
{ {
TestHelpers.InMethod(); TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure(); // TestHelpers.EnableLogging();
AddPresence(); AddPresence();
string attName = "att"; string attName = "att";
SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, m_presence.UUID).ParentGroup;
m_attMod.AttachObject(m_presence, so, (uint)AttachmentPoint.Chest, false); m_attMod.AttachObject(m_presence, so, (uint)AttachmentPoint.Chest, false);
@ -123,6 +123,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
Assert.That( Assert.That(
m_presence.Appearance.GetAttachpoint(attSo.FromItemID), m_presence.Appearance.GetAttachpoint(attSo.FromItemID),
Is.EqualTo((int)AttachmentPoint.Chest)); Is.EqualTo((int)AttachmentPoint.Chest));
InventoryItemBase attachmentItem = scene.InventoryService.GetItem(new InventoryItemBase(attSo.FromItemID));
Assert.That(attachmentItem, Is.Not.Null);
Assert.That(attachmentItem.Name, Is.EqualTo(attName));
InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(m_presence.UUID, AssetType.Object);
Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
// TestHelpers.DisableLogging();
} }
[Test] [Test]

View File

@ -295,9 +295,12 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
return UUID.Zero; return UUID.Zero;
} }
public virtual UUID CopyToInventory(DeRezAction action, UUID folderID, public virtual List<InventoryItemBase> CopyToInventory(
List<SceneObjectGroup> objectGroups, IClientAPI remoteClient) DeRezAction action, UUID folderID,
List<SceneObjectGroup> objectGroups, IClientAPI remoteClient, bool asAttachment)
{ {
List<InventoryItemBase> copiedItems = new List<InventoryItemBase>();
Dictionary<UUID, List<SceneObjectGroup>> bundlesToCopy = new Dictionary<UUID, List<SceneObjectGroup>>(); Dictionary<UUID, List<SceneObjectGroup>> bundlesToCopy = new Dictionary<UUID, List<SceneObjectGroup>>();
if (CoalesceMultipleObjectsToInventory) if (CoalesceMultipleObjectsToInventory)
@ -324,16 +327,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
} }
} }
// This is method scoped and will be returned. It will be the // m_log.DebugFormat(
// last created asset id // "[INVENTORY ACCESS MODULE]: Copying {0} object bundles to folder {1} action {2} for {3}",
UUID assetID = UUID.Zero; // bundlesToCopy.Count, folderID, action, remoteClient.Name);
// Each iteration is really a separate asset being created, // Each iteration is really a separate asset being created,
// with distinct destinations as well. // with distinct destinations as well.
foreach (List<SceneObjectGroup> bundle in bundlesToCopy.Values) foreach (List<SceneObjectGroup> bundle in bundlesToCopy.Values)
assetID = CopyBundleToInventory(action, folderID, bundle, remoteClient); copiedItems.Add(CopyBundleToInventory(action, folderID, bundle, remoteClient, asAttachment));
return assetID; return copiedItems;
} }
/// <summary> /// <summary>
@ -344,12 +347,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
/// <param name="folderID"></param> /// <param name="folderID"></param>
/// <param name="objlist"></param> /// <param name="objlist"></param>
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
/// <returns></returns> /// <param name="asAttachment">Should be true if the bundle is being copied as an attachment. This prevents
protected UUID CopyBundleToInventory( /// attempted serialization of any script state which would abort any operating scripts.</param>
DeRezAction action, UUID folderID, List<SceneObjectGroup> objlist, IClientAPI remoteClient) /// <returns>The inventory item created by the copy</returns>
protected InventoryItemBase CopyBundleToInventory(
DeRezAction action, UUID folderID, List<SceneObjectGroup> objlist, IClientAPI remoteClient,
bool asAttachment)
{ {
UUID assetID = UUID.Zero;
CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero);
Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>(); Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>();
@ -385,18 +389,27 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
string itemXml; string itemXml;
// If we're being called from a script, then trying to serialize that same script's state will not complete
// in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
// the client/server crashes rather than logging out normally, the attachment's scripts will resume
// without state on relog. Arguably, this is what we want anyway.
if (objlist.Count > 1) if (objlist.Count > 1)
itemXml = CoalescedSceneObjectsSerializer.ToXml(coa); itemXml = CoalescedSceneObjectsSerializer.ToXml(coa, !asAttachment);
else else
itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0]); itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0], !asAttachment);
// Restore the position of each group now that it has been stored to inventory. // Restore the position of each group now that it has been stored to inventory.
foreach (SceneObjectGroup objectGroup in objlist) foreach (SceneObjectGroup objectGroup in objlist)
objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID];
InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID);
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Created item is {0}",
// item != null ? item.ID.ToString() : "NULL");
if (item == null) if (item == null)
return UUID.Zero; return null;
// Can't know creator is the same, so null it in inventory // Can't know creator is the same, so null it in inventory
if (objlist.Count > 1) if (objlist.Count > 1)
@ -407,6 +420,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
else else
{ {
item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); item.CreatorId = objlist[0].RootPart.CreatorID.ToString();
item.CreatorData = objlist[0].RootPart.CreatorData;
item.SaleType = objlist[0].RootPart.ObjectSaleType; item.SaleType = objlist[0].RootPart.ObjectSaleType;
item.SalePrice = objlist[0].RootPart.SalePrice; item.SalePrice = objlist[0].RootPart.SalePrice;
} }
@ -420,7 +434,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
m_Scene.AssetService.Store(asset); m_Scene.AssetService.Store(asset);
item.AssetID = asset.FullID; item.AssetID = asset.FullID;
assetID = asset.FullID;
if (DeRezAction.SaveToExistingUserInventoryItem == action) if (DeRezAction.SaveToExistingUserInventoryItem == action)
{ {
@ -453,9 +466,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
// This is a hook to do some per-asset post-processing for subclasses that need that // This is a hook to do some per-asset post-processing for subclasses that need that
if (remoteClient != null) if (remoteClient != null)
ExportAsset(remoteClient.AgentId, assetID); ExportAsset(remoteClient.AgentId, asset.FullID);
return assetID; return item;
} }
protected virtual void ExportAsset(UUID agentID, UUID assetID) protected virtual void ExportAsset(UUID agentID, UUID assetID)
@ -643,7 +656,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
{ {
// Catch all. Use lost & found // Catch all. Use lost & found
// //
folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
} }
} }
@ -959,7 +971,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
so.FromFolderID = item.Folder; so.FromFolderID = item.Folder;
// Console.WriteLine("rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}", // m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}",
// rootPart.OwnerID, item.Owner, item.CurrentPermissions); // rootPart.OwnerID, item.Owner, item.CurrentPermissions);
if ((rootPart.OwnerID != item.Owner) || if ((rootPart.OwnerID != item.Owner) ||

View File

@ -49,11 +49,15 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="folderID"></param> /// <param name="folderID"></param>
/// <param name="objectGroups"></param> /// <param name="objectGroups"></param>
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
/// <param name="asAttachment">
/// Should be true if the object(s) are begin taken as attachments. False otherwise.
/// </param>
/// <returns> /// <returns>
/// Returns the UUID of the newly created item asset (not the item itself). /// A list of the items created. If there was more than one object and objects are not being coaleseced in
/// FIXME: This is not very useful. It would be far more useful to return a list of items instead. /// inventory, then the order of items is in the same order as the input objects.
/// </returns> /// </returns>
UUID CopyToInventory(DeRezAction action, UUID folderID, List<SceneObjectGroup> objectGroups, IClientAPI remoteClient); List<InventoryItemBase> CopyToInventory(
DeRezAction action, UUID folderID, List<SceneObjectGroup> objectGroups, IClientAPI remoteClient, bool asAttachment);
/// <summary> /// <summary>
/// Rez an object into the scene from the user's inventory /// Rez an object into the scene from the user's inventory

View File

@ -155,7 +155,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>(); IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
if (invAccess != null) if (invAccess != null)
invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient); invAccess.CopyToInventory(x.action, x.folderID, x.objectGroups, x.remoteClient, false);
if (x.permissionToDelete) if (x.permissionToDelete)
{ {

View File

@ -1027,10 +1027,16 @@ namespace OpenSim.Region.Framework.Scenes
public void ApplyNextOwnerPermissions() public void ApplyNextOwnerPermissions()
{ {
Util.PrintCallStack();
lock (m_items) lock (m_items)
{ {
foreach (TaskInventoryItem item in m_items.Values) foreach (TaskInventoryItem item in m_items.Values)
{ {
// m_log.DebugFormat (
// "[SCENE OBJECT PART INVENTORY]: Applying next permissions {0} to {1} in {2} with current {3}, base {4}, everyone {5}",
// item.NextPermissions, item.Name, m_part.Name, item.CurrentPermissions, item.BasePermissions, item.EveryonePermissions);
if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
{ {
if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
@ -1040,6 +1046,7 @@ namespace OpenSim.Region.Framework.Scenes
if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
item.CurrentPermissions &= ~(uint)PermissionMask.Modify; item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
} }
item.CurrentPermissions &= item.NextPermissions; item.CurrentPermissions &= item.NextPermissions;
item.BasePermissions &= item.NextPermissions; item.BasePermissions &= item.NextPermissions;
item.EveryonePermissions &= item.NextPermissions; item.EveryonePermissions &= item.NextPermissions;

View File

@ -53,8 +53,24 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
/// Serialize coalesced objects to Xml /// Serialize coalesced objects to Xml
/// </summary> /// </summary>
/// <param name="coa"></param> /// <param name="coa"></param>
/// <param name="doScriptStates">
/// If true then serialize script states. This will halt any running scripts
/// </param>
/// <returns></returns> /// <returns></returns>
public static string ToXml(CoalescedSceneObjects coa) public static string ToXml(CoalescedSceneObjects coa)
{
return ToXml(coa, true);
}
/// <summary>
/// Serialize coalesced objects to Xml
/// </summary>
/// <param name="coa"></param>
/// <param name="doScriptStates">
/// If true then serialize script states. This will halt any running scripts
/// </param>
/// <returns></returns>
public static string ToXml(CoalescedSceneObjects coa, bool doScriptStates)
{ {
using (StringWriter sw = new StringWriter()) using (StringWriter sw = new StringWriter())
{ {
@ -91,7 +107,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
writer.WriteAttributeString("offsety", offsets[i].Y.ToString()); writer.WriteAttributeString("offsety", offsets[i].Y.ToString());
writer.WriteAttributeString("offsetz", offsets[i].Z.ToString()); writer.WriteAttributeString("offsetz", offsets[i].Z.ToString());
SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, true); SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, doScriptStates);
writer.WriteEndElement(); // SceneObjectGroup writer.WriteEndElement(); // SceneObjectGroup
} }

View File

@ -566,7 +566,7 @@ namespace OpenSim.Tests.Common
/// <returns></returns> /// <returns></returns>
public static SceneObjectPart AddSceneObject(Scene scene) public static SceneObjectPart AddSceneObject(Scene scene)
{ {
return AddSceneObject(scene, "Test Object"); return AddSceneObject(scene, "Test Object", UUID.Zero);
} }
/// <summary> /// <summary>
@ -574,10 +574,11 @@ namespace OpenSim.Tests.Common
/// </summary> /// </summary>
/// <param name="scene"></param> /// <param name="scene"></param>
/// <param name="name"></param> /// <param name="name"></param>
/// <param name="ownerId"></param>
/// <returns></returns> /// <returns></returns>
public static SceneObjectPart AddSceneObject(Scene scene, string name) public static SceneObjectPart AddSceneObject(Scene scene, string name, UUID ownerId)
{ {
SceneObjectPart part = CreateSceneObjectPart(name, UUID.Random(), UUID.Zero); SceneObjectPart part = CreateSceneObjectPart(name, UUID.Random(), ownerId);
//part.UpdatePrimFlags(false, false, true); //part.UpdatePrimFlags(false, false, true);
//part.ObjectFlags |= (uint)PrimFlags.Phantom; //part.ObjectFlags |= (uint)PrimFlags.Phantom;