aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-07-13 23:19:45 +0100
committerJustin Clark-Casey (justincc)2010-07-13 23:19:45 +0100
commit6f644f5322ee0c5ffe6c654387981f1c13f7112d (patch)
tree818903820f1af3a1760e89ec470d4bf36388f918 /OpenSim/Region
parentdiscard an object media update message if it tries to set more media textures... (diff)
downloadopensim-SC_OLD-6f644f5322ee0c5ffe6c654387981f1c13f7112d.zip
opensim-SC_OLD-6f644f5322ee0c5ffe6c654387981f1c13f7112d.tar.gz
opensim-SC_OLD-6f644f5322ee0c5ffe6c654387981f1c13f7112d.tar.bz2
opensim-SC_OLD-6f644f5322ee0c5ffe6c654387981f1c13f7112d.tar.xz
implement prim media control permissions serverside in order to stop bad clients
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs87
-rw-r--r--OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs43
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Permissions.cs21
3 files changed, 127 insertions, 24 deletions
diff --git a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
index 378ff4a..d7aede9 100644
--- a/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
+++ b/OpenSim/Region/CoreModules/World/Media/Moap/MoapModule.cs
@@ -58,8 +58,21 @@ namespace OpenSim.Region.CoreModules.Media.Moap
58 public string Name { get { return "MoapModule"; } } 58 public string Name { get { return "MoapModule"; } }
59 public Type ReplaceableInterface { get { return null; } } 59 public Type ReplaceableInterface { get { return null; } }
60 60
61 /// <summary>
62 /// The scene to which this module is attached
63 /// </summary>
61 protected Scene m_scene; 64 protected Scene m_scene;
62 65
66 /// <summary>
67 /// Track the ObjectMedia capabilities given to users
68 /// </summary>
69 protected Dictionary<string, UUID> m_omCapUsers = new Dictionary<string, UUID>();
70
71 /// <summary>
72 /// Track the ObjectMediaUpdate capabilities given to users
73 /// </summary>
74 protected Dictionary<string, UUID> m_omuCapUsers = new Dictionary<string, UUID>();
75
63 public void Initialise(IConfigSource config) 76 public void Initialise(IConfigSource config)
64 { 77 {
65 // TODO: Add config switches to enable/disable this module 78 // TODO: Add config switches to enable/disable this module
@@ -87,16 +100,27 @@ namespace OpenSim.Region.CoreModules.Media.Moap
87 m_log.DebugFormat( 100 m_log.DebugFormat(
88 "[MOAP]: Registering ObjectMedia and ObjectMediaNavigate capabilities for agent {0}", agentID); 101 "[MOAP]: Registering ObjectMedia and ObjectMediaNavigate capabilities for agent {0}", agentID);
89 102
90 // We do receive a post to ObjectMedia when a new avatar enters the region - though admittedly this is the 103 string omCapUrl = "/CAPS/" + UUID.Random();
91 // avatar that set the texture in the first place. 104
92 // Even though we're registering for POST we're going to get GETS and UPDATES too 105 lock (m_omCapUsers)
93 caps.RegisterHandler( 106 {
94 "ObjectMedia", new RestStreamHandler("POST", "/CAPS/" + UUID.Random(), HandleObjectMediaMessage)); 107 m_omCapUsers[omCapUrl] = agentID;
108
109 // Even though we're registering for POST we're going to get GETS and UPDATES too
110 caps.RegisterHandler(
111 "ObjectMedia", new RestStreamHandler("POST", omCapUrl, HandleObjectMediaMessage));
112 }
113
114 string omuCapUrl = "/CAPS/" + UUID.Random();
95 115
96 // We do get these posts when the url has been changed. 116 lock (m_omuCapUsers)
97 // Even though we're registering for POST we're going to get GETS and UPDATES too 117 {
98 caps.RegisterHandler( 118 m_omuCapUsers[omuCapUrl] = agentID;
99 "ObjectMediaNavigate", new RestStreamHandler("POST", "/CAPS/" + UUID.Random(), HandleObjectMediaNavigateMessage)); 119
120 // Even though we're registering for POST we're going to get GETS and UPDATES too
121 caps.RegisterHandler(
122 "ObjectMediaNavigate", new RestStreamHandler("POST", omuCapUrl, HandleObjectMediaNavigateMessage));
123 }
100 } 124 }
101 125
102 public MediaEntry GetMediaEntry(SceneObjectPart part, int face) 126 public MediaEntry GetMediaEntry(SceneObjectPart part, int face)
@@ -147,7 +171,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
147 protected string HandleObjectMediaMessage( 171 protected string HandleObjectMediaMessage(
148 string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse) 172 string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
149 { 173 {
150 m_log.DebugFormat("[MOAP]: Got ObjectMedia raw request [{0}]", request); 174 m_log.DebugFormat("[MOAP]: Got ObjectMedia path [{0}], raw request [{1}]", path, request);
151 175
152 OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(request); 176 OSDMap osd = (OSDMap)OSDParser.DeserializeLLSDXml(request);
153 ObjectMediaMessage omm = new ObjectMediaMessage(); 177 ObjectMediaMessage omm = new ObjectMediaMessage();
@@ -156,7 +180,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
156 if (omm.Request is ObjectMediaRequest) 180 if (omm.Request is ObjectMediaRequest)
157 return HandleObjectMediaRequest(omm.Request as ObjectMediaRequest); 181 return HandleObjectMediaRequest(omm.Request as ObjectMediaRequest);
158 else if (omm.Request is ObjectMediaUpdate) 182 else if (omm.Request is ObjectMediaUpdate)
159 return HandleObjectMediaUpdate(omm.Request as ObjectMediaUpdate); 183 return HandleObjectMediaUpdate(path, omm.Request as ObjectMediaUpdate);
160 184
161 throw new Exception( 185 throw new Exception(
162 string.Format( 186 string.Format(
@@ -165,7 +189,7 @@ namespace OpenSim.Region.CoreModules.Media.Moap
165 } 189 }
166 190
167 /// <summary> 191 /// <summary>
168 /// Handle a request for media textures 192 /// Handle a fetch request for media textures
169 /// </summary> 193 /// </summary>
170 /// <param name="omr"></param> 194 /// <param name="omr"></param>
171 /// <returns></returns> 195 /// <returns></returns>
@@ -202,9 +226,10 @@ namespace OpenSim.Region.CoreModules.Media.Moap
202 /// <summary> 226 /// <summary>
203 /// Handle an update of media textures. 227 /// Handle an update of media textures.
204 /// </summary> 228 /// </summary>
229 /// <param name="path">Path on which this request was made</param>
205 /// <param name="omu">/param> 230 /// <param name="omu">/param>
206 /// <returns></returns> 231 /// <returns></returns>
207 protected string HandleObjectMediaUpdate(ObjectMediaUpdate omu) 232 protected string HandleObjectMediaUpdate(string path, ObjectMediaUpdate omu)
208 { 233 {
209 UUID primId = omu.PrimID; 234 UUID primId = omu.PrimID;
210 235
@@ -216,16 +241,16 @@ namespace OpenSim.Region.CoreModules.Media.Moap
216 "[MOAP]: Received an UPDATE ObjectMediaRequest for prim {0} but this doesn't exist in region {1}", 241 "[MOAP]: Received an UPDATE ObjectMediaRequest for prim {0} but this doesn't exist in region {1}",
217 primId, m_scene.RegionInfo.RegionName); 242 primId, m_scene.RegionInfo.RegionName);
218 return string.Empty; 243 return string.Empty;
219 } 244 }
220 245
221 m_log.DebugFormat("[MOAP]: Received {0} media entries for prim {1}", omu.FaceMedia.Length, primId); 246 m_log.DebugFormat("[MOAP]: Received {0} media entries for prim {1}", omu.FaceMedia.Length, primId);
222 247
223// for (int i = 0; i < omu.FaceMedia.Length; i++) 248 for (int i = 0; i < omu.FaceMedia.Length; i++)
224// { 249 {
225// MediaEntry me = omu.FaceMedia[i]; 250 MediaEntry me = omu.FaceMedia[i];
226// string v = (null == me ? "null": OSDParser.SerializeLLSDXmlString(me.GetOSD())); 251 string v = (null == me ? "null": OSDParser.SerializeLLSDXmlString(me.GetOSD()));
227// m_log.DebugFormat("[MOAP]: Face {0} [{1}]", i, v); 252 m_log.DebugFormat("[MOAP]: Face {0} [{1}]", i, v);
228// } 253 }
229 254
230 if (omu.FaceMedia.Length > part.GetNumberOfSides()) 255 if (omu.FaceMedia.Length > part.GetNumberOfSides())
231 { 256 {
@@ -235,7 +260,27 @@ namespace OpenSim.Region.CoreModules.Media.Moap
235 return string.Empty; 260 return string.Empty;
236 } 261 }
237 262
238 part.Shape.Media = new List<MediaEntry>(omu.FaceMedia); 263 List<MediaEntry> media = part.Shape.Media;
264
265 if (null == media)
266 {
267 part.Shape.Media = new List<MediaEntry>(omu.FaceMedia);
268 }
269 else
270 {
271 // We need to go through the media textures one at a time to make sure that we have permission
272 // to change them
273 UUID agentId = default(UUID);
274
275 lock (m_omCapUsers)
276 agentId = m_omCapUsers[path];
277
278 for (int i = 0; i < media.Count; i++)
279 {
280 if (m_scene.Permissions.CanControlPrimMedia(agentId, part.UUID, i))
281 media[i] = omu.FaceMedia[i];
282 }
283 }
239 284
240 UpdateMediaUrl(part); 285 UpdateMediaUrl(part);
241 286
diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
index 69b247c..358ea59 100644
--- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
@@ -164,6 +164,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
164 private Dictionary<string, bool> GrantYP = new Dictionary<string, bool>(); 164 private Dictionary<string, bool> GrantYP = new Dictionary<string, bool>();
165 private IFriendsModule m_friendsModule; 165 private IFriendsModule m_friendsModule;
166 private IGroupsModule m_groupsModule; 166 private IGroupsModule m_groupsModule;
167 private IMoapModule m_moapModule;
167 168
168 #endregion 169 #endregion
169 170
@@ -248,6 +249,8 @@ namespace OpenSim.Region.CoreModules.World.Permissions
248 m_scene.Permissions.OnDeleteUserInventory += CanDeleteUserInventory; //NOT YET IMPLEMENTED 249 m_scene.Permissions.OnDeleteUserInventory += CanDeleteUserInventory; //NOT YET IMPLEMENTED
249 250
250 m_scene.Permissions.OnTeleport += CanTeleport; //NOT YET IMPLEMENTED 251 m_scene.Permissions.OnTeleport += CanTeleport; //NOT YET IMPLEMENTED
252
253 m_scene.Permissions.OnControlPrimMedia += CanControlPrimMedia;
251 254
252 m_scene.AddCommand(this, "bypass permissions", 255 m_scene.AddCommand(this, "bypass permissions",
253 "bypass permissions <true / false>", 256 "bypass permissions <true / false>",
@@ -393,6 +396,8 @@ namespace OpenSim.Region.CoreModules.World.Permissions
393 396
394 if (m_groupsModule == null) 397 if (m_groupsModule == null)
395 m_log.Warn("[PERMISSIONS]: Groups module not found, group permissions will not work"); 398 m_log.Warn("[PERMISSIONS]: Groups module not found, group permissions will not work");
399
400 m_moapModule = m_scene.RequestModuleInterface<IMoapModule>();
396 } 401 }
397 402
398 public void Close() 403 public void Close()
@@ -1893,5 +1898,41 @@ namespace OpenSim.Region.CoreModules.World.Permissions
1893 } 1898 }
1894 return(false); 1899 return(false);
1895 } 1900 }
1901
1902 private bool CanControlPrimMedia(UUID agentID, UUID primID, int face)
1903 {
1904 if (null == m_moapModule)
1905 return false;
1906
1907 SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
1908 if (null == part)
1909 return false;
1910
1911 MediaEntry me = m_moapModule.GetMediaEntry(part, face);
1912
1913 // If there is no existing media entry then it can be controlled (in this context, created).
1914 if (null == me)
1915 return true;
1916
1917 if (IsAdministrator(agentID))
1918 return true;
1919
1920 if ((me.ControlPermissions & MediaPermission.Anyone) == MediaPermission.Anyone)
1921 return true;
1922
1923 if ((me.ControlPermissions & MediaPermission.Owner) == MediaPermission.Owner)
1924 {
1925 if (agentID == part.OwnerID)
1926 return true;
1927 }
1928
1929 if ((me.ControlPermissions & MediaPermission.Group) == MediaPermission.Group)
1930 {
1931 if (IsGroupMember(part.GroupID, agentID, 0))
1932 return true;
1933 }
1934
1935 return false;
1936 }
1896 } 1937 }
1897} 1938} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
index 7dab04f..70af978 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -81,6 +81,7 @@ namespace OpenSim.Region.Framework.Scenes
81 public delegate bool CopyUserInventoryHandler(UUID itemID, UUID userID); 81 public delegate bool CopyUserInventoryHandler(UUID itemID, UUID userID);
82 public delegate bool DeleteUserInventoryHandler(UUID itemID, UUID userID); 82 public delegate bool DeleteUserInventoryHandler(UUID itemID, UUID userID);
83 public delegate bool TeleportHandler(UUID userID, Scene scene); 83 public delegate bool TeleportHandler(UUID userID, Scene scene);
84 public delegate bool ControlPrimMediaHandler(UUID userID, UUID primID, int face);
84 #endregion 85 #endregion
85 86
86 public class ScenePermissions 87 public class ScenePermissions
@@ -139,6 +140,7 @@ namespace OpenSim.Region.Framework.Scenes
139 public event CopyUserInventoryHandler OnCopyUserInventory; 140 public event CopyUserInventoryHandler OnCopyUserInventory;
140 public event DeleteUserInventoryHandler OnDeleteUserInventory; 141 public event DeleteUserInventoryHandler OnDeleteUserInventory;
141 public event TeleportHandler OnTeleport; 142 public event TeleportHandler OnTeleport;
143 public event ControlPrimMediaHandler OnControlPrimMedia;
142 #endregion 144 #endregion
143 145
144 #region Object Permission Checks 146 #region Object Permission Checks
@@ -947,5 +949,20 @@ namespace OpenSim.Region.Framework.Scenes
947 } 949 }
948 return true; 950 return true;
949 } 951 }
952
953 public bool CanControlPrimMedia(UUID userID, UUID primID, int face)
954 {
955 ControlPrimMediaHandler handler = OnControlPrimMedia;
956 if (handler != null)
957 {
958 Delegate[] list = handler.GetInvocationList();
959 foreach (ControlPrimMediaHandler h in list)
960 {
961 if (h(userID, primID, face) == false)
962 return false;
963 }
964 }
965 return true;
966 }
950 } 967 }
951} 968} \ No newline at end of file