diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent')
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs | 127 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs | 11 |
2 files changed, 134 insertions, 4 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs index ec4dfd0..4cedfe6 100644 --- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs +++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Collections.Generic; | ||
31 | using log4net; | 32 | using log4net; |
32 | using OpenMetaverse; | 33 | using OpenMetaverse; |
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
@@ -38,6 +39,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
38 | { | 39 | { |
39 | public class AssetXferUploader | 40 | public class AssetXferUploader |
40 | { | 41 | { |
42 | // Viewer's notion of the default texture | ||
43 | private List<UUID> defaultIDs = new List<UUID> { | ||
44 | new UUID("5748decc-f629-461c-9a36-a35a221fe21f"), | ||
45 | new UUID("7ca39b4c-bd19-4699-aff7-f93fd03d3e7b"), | ||
46 | new UUID("6522e74d-1660-4e7f-b601-6f48c1659a77"), | ||
47 | new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97") | ||
48 | }; | ||
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | 50 | ||
43 | /// <summary> | 51 | /// <summary> |
@@ -65,6 +73,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
65 | private UUID TransactionID = UUID.Zero; | 73 | private UUID TransactionID = UUID.Zero; |
66 | private sbyte type = 0; | 74 | private sbyte type = 0; |
67 | private byte wearableType = 0; | 75 | private byte wearableType = 0; |
76 | private byte[] m_oldData = null; | ||
68 | public ulong XferID; | 77 | public ulong XferID; |
69 | private Scene m_Scene; | 78 | private Scene m_Scene; |
70 | 79 | ||
@@ -302,6 +311,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
302 | 311 | ||
303 | private void DoCreateItem(uint callbackID) | 312 | private void DoCreateItem(uint callbackID) |
304 | { | 313 | { |
314 | ValidateAssets(); | ||
305 | m_Scene.AssetService.Store(m_asset); | 315 | m_Scene.AssetService.Store(m_asset); |
306 | 316 | ||
307 | InventoryItemBase item = new InventoryItemBase(); | 317 | InventoryItemBase item = new InventoryItemBase(); |
@@ -322,12 +332,84 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
322 | item.Flags = (uint) wearableType; | 332 | item.Flags = (uint) wearableType; |
323 | item.CreationDate = Util.UnixTimeSinceEpoch(); | 333 | item.CreationDate = Util.UnixTimeSinceEpoch(); |
324 | 334 | ||
335 | m_log.DebugFormat("[XFER]: Created item {0} with asset {1}", | ||
336 | item.ID, item.AssetID); | ||
337 | |||
325 | if (m_Scene.AddInventoryItem(item)) | 338 | if (m_Scene.AddInventoryItem(item)) |
326 | ourClient.SendInventoryItemCreateUpdate(item, callbackID); | 339 | ourClient.SendInventoryItemCreateUpdate(item, callbackID); |
327 | else | 340 | else |
328 | ourClient.SendAlertMessage("Unable to create inventory item"); | 341 | ourClient.SendAlertMessage("Unable to create inventory item"); |
329 | } | 342 | } |
330 | 343 | ||
344 | private void ValidateAssets() | ||
345 | { | ||
346 | if (m_asset.Type == (sbyte)AssetType.Clothing || | ||
347 | m_asset.Type == (sbyte)AssetType.Bodypart) | ||
348 | { | ||
349 | string content = System.Text.Encoding.ASCII.GetString(m_asset.Data); | ||
350 | string[] lines = content.Split(new char[] {'\n'}); | ||
351 | |||
352 | List<string> validated = new List<string>(); | ||
353 | |||
354 | Dictionary<int, UUID> allowed = ExtractTexturesFromOldData(); | ||
355 | |||
356 | int textures = 0; | ||
357 | |||
358 | foreach (string line in lines) | ||
359 | { | ||
360 | try | ||
361 | { | ||
362 | if (line.StartsWith("textures ")) | ||
363 | { | ||
364 | textures = Convert.ToInt32(line.Substring(9)); | ||
365 | validated.Add(line); | ||
366 | } | ||
367 | else if (textures > 0) | ||
368 | { | ||
369 | string[] parts = line.Split(new char[] {' '}); | ||
370 | |||
371 | UUID tx = new UUID(parts[1]); | ||
372 | int id = Convert.ToInt32(parts[0]); | ||
373 | |||
374 | if (defaultIDs.Contains(tx) || tx == UUID.Zero || | ||
375 | (allowed.ContainsKey(id) && allowed[id] == tx)) | ||
376 | { | ||
377 | validated.Add(parts[0] + " " + tx.ToString()); | ||
378 | } | ||
379 | else | ||
380 | { | ||
381 | int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, tx); | ||
382 | int full = (int)(PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Copy); | ||
383 | |||
384 | if ((perms & full) != full) | ||
385 | { | ||
386 | m_log.ErrorFormat("[ASSET UPLOADER]: REJECTED update with texture {0} from {1} because they do not own the texture", tx, ourClient.AgentId); | ||
387 | validated.Add(parts[0] + " " + UUID.Zero.ToString()); | ||
388 | } | ||
389 | else | ||
390 | { | ||
391 | validated.Add(line); | ||
392 | } | ||
393 | } | ||
394 | textures--; | ||
395 | } | ||
396 | else | ||
397 | { | ||
398 | validated.Add(line); | ||
399 | } | ||
400 | } | ||
401 | catch | ||
402 | { | ||
403 | // If it's malformed, skip it | ||
404 | } | ||
405 | } | ||
406 | |||
407 | string final = String.Join("\n", validated.ToArray()); | ||
408 | |||
409 | m_asset.Data = System.Text.Encoding.ASCII.GetBytes(final); | ||
410 | } | ||
411 | } | ||
412 | |||
331 | /// <summary> | 413 | /// <summary> |
332 | /// Get the asset data uploaded in this transfer. | 414 | /// Get the asset data uploaded in this transfer. |
333 | /// </summary> | 415 | /// </summary> |
@@ -336,10 +418,55 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
336 | { | 418 | { |
337 | if (m_finished) | 419 | if (m_finished) |
338 | { | 420 | { |
421 | ValidateAssets(); | ||
339 | return m_asset; | 422 | return m_asset; |
340 | } | 423 | } |
341 | 424 | ||
342 | return null; | 425 | return null; |
343 | } | 426 | } |
427 | |||
428 | public void SetOldData(byte[] d) | ||
429 | { | ||
430 | m_oldData = d; | ||
431 | } | ||
432 | |||
433 | private Dictionary<int,UUID> ExtractTexturesFromOldData() | ||
434 | { | ||
435 | Dictionary<int,UUID> result = new Dictionary<int,UUID>(); | ||
436 | if (m_oldData == null) | ||
437 | return result; | ||
438 | |||
439 | string content = System.Text.Encoding.ASCII.GetString(m_oldData); | ||
440 | string[] lines = content.Split(new char[] {'\n'}); | ||
441 | |||
442 | int textures = 0; | ||
443 | |||
444 | foreach (string line in lines) | ||
445 | { | ||
446 | try | ||
447 | { | ||
448 | if (line.StartsWith("textures ")) | ||
449 | { | ||
450 | textures = Convert.ToInt32(line.Substring(9)); | ||
451 | } | ||
452 | else if (textures > 0) | ||
453 | { | ||
454 | string[] parts = line.Split(new char[] {' '}); | ||
455 | |||
456 | UUID tx = new UUID(parts[1]); | ||
457 | int id = Convert.ToInt32(parts[0]); | ||
458 | result[id] = tx; | ||
459 | textures--; | ||
460 | } | ||
461 | } | ||
462 | catch | ||
463 | { | ||
464 | // If it's malformed, skip it | ||
465 | } | ||
466 | } | ||
467 | |||
468 | return result; | ||
469 | } | ||
344 | } | 470 | } |
345 | } | 471 | } |
472 | |||
diff --git a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs index b8e2820..78d597d 100644 --- a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs +++ b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs | |||
@@ -145,6 +145,8 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer | |||
145 | { | 145 | { |
146 | byte[] fileData = NewFiles[fileName].Data; | 146 | byte[] fileData = NewFiles[fileName].Data; |
147 | XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient); | 147 | XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient); |
148 | if (fileName.StartsWith("inventory_")) | ||
149 | transaction.isTaskInventory = true; | ||
148 | 150 | ||
149 | Transfers.Add(xferID, transaction); | 151 | Transfers.Add(xferID, transaction); |
150 | 152 | ||
@@ -228,6 +230,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer | |||
228 | public uint Packet = 0; | 230 | public uint Packet = 0; |
229 | public uint Serial = 1; | 231 | public uint Serial = 1; |
230 | public ulong XferID = 0; | 232 | public ulong XferID = 0; |
233 | public bool isTaskInventory = false; | ||
231 | 234 | ||
232 | public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client) | 235 | public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client) |
233 | { | 236 | { |
@@ -253,7 +256,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer | |||
253 | byte[] transferData = new byte[Data.Length + 4]; | 256 | byte[] transferData = new byte[Data.Length + 4]; |
254 | Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); | 257 | Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); |
255 | Array.Copy(Data, 0, transferData, 4, Data.Length); | 258 | Array.Copy(Data, 0, transferData, 4, Data.Length); |
256 | Client.SendXferPacket(XferID, 0 + 0x80000000, transferData); | 259 | Client.SendXferPacket(XferID, 0 + 0x80000000, transferData, isTaskInventory); |
257 | complete = true; | 260 | complete = true; |
258 | } | 261 | } |
259 | else | 262 | else |
@@ -261,7 +264,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer | |||
261 | byte[] transferData = new byte[1000 + 4]; | 264 | byte[] transferData = new byte[1000 + 4]; |
262 | Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); | 265 | Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); |
263 | Array.Copy(Data, 0, transferData, 4, 1000); | 266 | Array.Copy(Data, 0, transferData, 4, 1000); |
264 | Client.SendXferPacket(XferID, 0, transferData); | 267 | Client.SendXferPacket(XferID, 0, transferData, isTaskInventory); |
265 | Packet++; | 268 | Packet++; |
266 | DataPointer = 1000; | 269 | DataPointer = 1000; |
267 | } | 270 | } |
@@ -282,7 +285,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer | |||
282 | { | 285 | { |
283 | byte[] transferData = new byte[1000]; | 286 | byte[] transferData = new byte[1000]; |
284 | Array.Copy(Data, DataPointer, transferData, 0, 1000); | 287 | Array.Copy(Data, DataPointer, transferData, 0, 1000); |
285 | Client.SendXferPacket(XferID, Packet, transferData); | 288 | Client.SendXferPacket(XferID, Packet, transferData, isTaskInventory); |
286 | Packet++; | 289 | Packet++; |
287 | DataPointer += 1000; | 290 | DataPointer += 1000; |
288 | } | 291 | } |
@@ -291,7 +294,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer | |||
291 | byte[] transferData = new byte[Data.Length - DataPointer]; | 294 | byte[] transferData = new byte[Data.Length - DataPointer]; |
292 | Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer); | 295 | Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer); |
293 | uint endPacket = Packet |= (uint) 0x80000000; | 296 | uint endPacket = Packet |= (uint) 0x80000000; |
294 | Client.SendXferPacket(XferID, endPacket, transferData); | 297 | Client.SendXferPacket(XferID, endPacket, transferData, isTaskInventory); |
295 | Packet++; | 298 | Packet++; |
296 | DataPointer += (Data.Length - DataPointer); | 299 | DataPointer += (Data.Length - DataPointer); |
297 | 300 | ||