OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
PermissionsModule.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections.Generic;
30 using System.Linq;
31 using System.Reflection;
32 using log4net;
33 using Nini.Config;
34 using OpenMetaverse;
35 using OpenSim.Framework;
36 
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
40 
41 using Mono.Addins;
43 
44 namespace OpenSim.Region.CoreModules.World.Permissions
45 {
46  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DefaultPermissionsModule")]
48  {
49  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 
51  protected Scene m_scene;
52  protected bool m_Enabled;
53 
54  private InventoryFolderImpl m_libraryRootFolder;
55  protected InventoryFolderImpl LibraryRootFolder
56  {
57  get
58  {
59  if (m_libraryRootFolder != null)
60  return m_libraryRootFolder;
61 
62  ILibraryService lib = m_scene.RequestModuleInterface<ILibraryService>();
63  if (lib != null)
64  {
65  m_libraryRootFolder = lib.LibraryRootFolder;
66  }
67  return m_libraryRootFolder;
68  }
69  }
70 
71  #region Constants
72  // These are here for testing. They will be taken out
73 
74  //private uint PERM_ALL = (uint)2147483647;
75  private uint PERM_COPY = (uint)32768;
76  //private uint PERM_MODIFY = (uint)16384;
77  private uint PERM_MOVE = (uint)524288;
78  private uint PERM_TRANS = (uint)8192;
79  private uint PERM_LOCKED = (uint)540672;
80 
84  enum UserSet
85  {
86  All,
87  Administrators
88  };
89 
90  #endregion
91 
92  #region Bypass Permissions / Debug Permissions Stuff
93 
94  // Bypasses the permissions engine
95  private bool m_bypassPermissions = true;
96  private bool m_bypassPermissionsValue = true;
97  private bool m_propagatePermissions = false;
98  private bool m_debugPermissions = false;
99  private bool m_allowGridGods = false;
100  private bool m_RegionOwnerIsGod = false;
101  private bool m_RegionManagerIsGod = false;
102  private bool m_ParcelOwnerIsGod = false;
103 
104  private bool m_SimpleBuildPermissions = false;
105 
110  private UserSet m_allowedScriptCreators = UserSet.All;
111 
116  private UserSet m_allowedScriptEditors = UserSet.All;
117 
118  private Dictionary<string, bool> GrantLSL = new Dictionary<string, bool>();
119  private Dictionary<string, bool> GrantCS = new Dictionary<string, bool>();
120  private Dictionary<string, bool> GrantVB = new Dictionary<string, bool>();
121  private Dictionary<string, bool> GrantJS = new Dictionary<string, bool>();
122  private Dictionary<string, bool> GrantYP = new Dictionary<string, bool>();
123 
124  private IFriendsModule m_friendsModule;
125  private IFriendsModule FriendsModule
126  {
127  get
128  {
129  if (m_friendsModule == null)
130  m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
131  return m_friendsModule;
132  }
133  }
134  private IGroupsModule m_groupsModule;
135  private IGroupsModule GroupsModule
136  {
137  get
138  {
139  if (m_groupsModule == null)
140  m_groupsModule = m_scene.RequestModuleInterface<IGroupsModule>();
141  return m_groupsModule;
142  }
143  }
144 
145  private IMoapModule m_moapModule;
146  private IMoapModule MoapModule
147  {
148  get
149  {
150  if (m_moapModule == null)
151  m_moapModule = m_scene.RequestModuleInterface<IMoapModule>();
152  return m_moapModule;
153  }
154  }
155  #endregion
156 
157  #region INonSharedRegionModule Members
158 
159  public void Initialise(IConfigSource config)
160  {
161  string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules",
162  new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
163 
164  List<string> modules = new List<string>(permissionModules.Split(',').Select(m => m.Trim()));
165 
166  if (!modules.Contains("DefaultPermissionsModule"))
167  return;
168 
169  m_Enabled = true;
170 
171  m_allowGridGods = Util.GetConfigVarFromSections<bool>(config, "allow_grid_gods",
172  new string[] { "Startup", "Permissions" }, false);
173  m_bypassPermissions = !Util.GetConfigVarFromSections<bool>(config, "serverside_object_permissions",
174  new string[] { "Startup", "Permissions" }, true);
175  m_propagatePermissions = Util.GetConfigVarFromSections<bool>(config, "propagate_permissions",
176  new string[] { "Startup", "Permissions" }, true);
177  m_RegionOwnerIsGod = Util.GetConfigVarFromSections<bool>(config, "region_owner_is_god",
178  new string[] { "Startup", "Permissions" }, true);
179  m_RegionManagerIsGod = Util.GetConfigVarFromSections<bool>(config, "region_manager_is_god",
180  new string[] { "Startup", "Permissions" }, false);
181  m_ParcelOwnerIsGod = Util.GetConfigVarFromSections<bool>(config, "parcel_owner_is_god",
182  new string[] { "Startup", "Permissions" }, false);
183 
184  m_SimpleBuildPermissions = Util.GetConfigVarFromSections<bool>(config, "simple_build_permissions",
185  new string[] { "Startup", "Permissions" }, false);
186 
187  m_allowedScriptCreators
188  = ParseUserSetConfigSetting(config, "allowed_script_creators", m_allowedScriptCreators);
189  m_allowedScriptEditors
190  = ParseUserSetConfigSetting(config, "allowed_script_editors", m_allowedScriptEditors);
191 
192  if (m_bypassPermissions)
193  m_log.Info("[PERMISSIONS]: serverside_object_permissions = false in ini file so disabling all region service permission checks");
194  else
195  m_log.Debug("[PERMISSIONS]: Enabling all region service permission checks");
196 
197  string grant = Util.GetConfigVarFromSections<string>(config, "GrantLSL",
198  new string[] { "Startup", "Permissions" }, string.Empty);
199  if (grant.Length > 0)
200  {
201  foreach (string uuidl in grant.Split(','))
202  {
203  string uuid = uuidl.Trim(" \t".ToCharArray());
204  GrantLSL.Add(uuid, true);
205  }
206  }
207 
208  grant = Util.GetConfigVarFromSections<string>(config, "GrantCS",
209  new string[] { "Startup", "Permissions" }, string.Empty);
210  if (grant.Length > 0)
211  {
212  foreach (string uuidl in grant.Split(','))
213  {
214  string uuid = uuidl.Trim(" \t".ToCharArray());
215  GrantCS.Add(uuid, true);
216  }
217  }
218 
219  grant = Util.GetConfigVarFromSections<string>(config, "GrantVB",
220  new string[] { "Startup", "Permissions" }, string.Empty);
221  if (grant.Length > 0)
222  {
223  foreach (string uuidl in grant.Split(','))
224  {
225  string uuid = uuidl.Trim(" \t".ToCharArray());
226  GrantVB.Add(uuid, true);
227  }
228  }
229 
230  grant = Util.GetConfigVarFromSections<string>(config, "GrantJS",
231  new string[] { "Startup", "Permissions" }, string.Empty);
232  if (grant.Length > 0)
233  {
234  foreach (string uuidl in grant.Split(','))
235  {
236  string uuid = uuidl.Trim(" \t".ToCharArray());
237  GrantJS.Add(uuid, true);
238  }
239  }
240 
241  grant = Util.GetConfigVarFromSections<string>(config, "GrantYP",
242  new string[] { "Startup", "Permissions" }, string.Empty);
243  if (grant.Length > 0)
244  {
245  foreach (string uuidl in grant.Split(','))
246  {
247  string uuid = uuidl.Trim(" \t".ToCharArray());
248  GrantYP.Add(uuid, true);
249  }
250  }
251  }
252 
253  public void AddRegion(Scene scene)
254  {
255  if (!m_Enabled)
256  return;
257 
258  m_scene = scene;
259 
260  scene.RegisterModuleInterface<IPermissionsModule>(this);
261 
262  //Register functions with Scene External Checks!
263  m_scene.Permissions.OnBypassPermissions += BypassPermissions;
264  m_scene.Permissions.OnSetBypassPermissions += SetBypassPermissions;
265  m_scene.Permissions.OnPropagatePermissions += PropagatePermissions;
266  m_scene.Permissions.OnGenerateClientFlags += GenerateClientFlags;
267  m_scene.Permissions.OnAbandonParcel += CanAbandonParcel;
268  m_scene.Permissions.OnReclaimParcel += CanReclaimParcel;
269  m_scene.Permissions.OnDeedParcel += CanDeedParcel;
270  m_scene.Permissions.OnDeedObject += CanDeedObject;
271  m_scene.Permissions.OnIsGod += IsGod;
272  m_scene.Permissions.OnIsGridGod += IsGridGod;
273  m_scene.Permissions.OnIsAdministrator += IsAdministrator;
274  m_scene.Permissions.OnIsEstateManager += IsEstateManager;
275  m_scene.Permissions.OnDuplicateObject += CanDuplicateObject;
276  m_scene.Permissions.OnDeleteObject += CanDeleteObject;
277  m_scene.Permissions.OnEditObject += CanEditObject;
278  m_scene.Permissions.OnEditParcelProperties += CanEditParcelProperties;
279  m_scene.Permissions.OnInstantMessage += CanInstantMessage;
280  m_scene.Permissions.OnInventoryTransfer += CanInventoryTransfer;
281  m_scene.Permissions.OnIssueEstateCommand += CanIssueEstateCommand;
282  m_scene.Permissions.OnMoveObject += CanMoveObject;
283  m_scene.Permissions.OnObjectEntry += CanObjectEntry;
284  m_scene.Permissions.OnReturnObjects += CanReturnObjects;
285  m_scene.Permissions.OnRezObject += CanRezObject;
286  m_scene.Permissions.OnRunConsoleCommand += CanRunConsoleCommand;
287  m_scene.Permissions.OnRunScript += CanRunScript;
288  m_scene.Permissions.OnCompileScript += CanCompileScript;
289  m_scene.Permissions.OnSellParcel += CanSellParcel;
290  m_scene.Permissions.OnTakeObject += CanTakeObject;
291  m_scene.Permissions.OnTakeCopyObject += CanTakeCopyObject;
292  m_scene.Permissions.OnTerraformLand += CanTerraformLand;
293  m_scene.Permissions.OnLinkObject += CanLinkObject;
294  m_scene.Permissions.OnDelinkObject += CanDelinkObject;
295  m_scene.Permissions.OnBuyLand += CanBuyLand;
296 
297  m_scene.Permissions.OnViewNotecard += CanViewNotecard;
298  m_scene.Permissions.OnViewScript += CanViewScript;
299  m_scene.Permissions.OnEditNotecard += CanEditNotecard;
300  m_scene.Permissions.OnEditScript += CanEditScript;
301 
302  m_scene.Permissions.OnCreateObjectInventory += CanCreateObjectInventory;
303  m_scene.Permissions.OnEditObjectInventory += CanEditObjectInventory;
304  m_scene.Permissions.OnCopyObjectInventory += CanCopyObjectInventory;
305  m_scene.Permissions.OnDeleteObjectInventory += CanDeleteObjectInventory;
306  m_scene.Permissions.OnResetScript += CanResetScript;
307 
308  m_scene.Permissions.OnCreateUserInventory += CanCreateUserInventory;
309  m_scene.Permissions.OnCopyUserInventory += CanCopyUserInventory;
310  m_scene.Permissions.OnEditUserInventory += CanEditUserInventory;
311  m_scene.Permissions.OnDeleteUserInventory += CanDeleteUserInventory;
312 
313  m_scene.Permissions.OnTeleport += CanTeleport;
314 
315  m_scene.Permissions.OnControlPrimMedia += CanControlPrimMedia;
316  m_scene.Permissions.OnInteractWithPrimMedia += CanInteractWithPrimMedia;
317 
318  m_scene.AddCommand("Users", this, "bypass permissions",
319  "bypass permissions <true / false>",
320  "Bypass permission checks",
321  HandleBypassPermissions);
322 
323  m_scene.AddCommand("Users", this, "force permissions",
324  "force permissions <true / false>",
325  "Force permissions on or off",
326  HandleForcePermissions);
327 
328  m_scene.AddCommand("Debug", this, "debug permissions",
329  "debug permissions <true / false>",
330  "Turn on permissions debugging",
331  HandleDebugPermissions);
332 
333  }
334 
335  public void RegionLoaded(Scene scene)
336  {
337  }
338 
339  public void RemoveRegion(Scene scene)
340  {
341  if (!m_Enabled)
342  return;
343 
344  m_scene.UnregisterModuleInterface<IPermissionsModule>(this);
345  }
346 
347  public void Close()
348  {
349  }
350 
351  public string Name
352  {
353  get { return "DefaultPermissionsModule"; }
354  }
355 
356  public Type ReplaceableInterface
357  {
358  get { return null; }
359  }
360 
361  #endregion
362 
363  #region Console command handlers
364 
365  public void HandleBypassPermissions(string module, string[] args)
366  {
367  if (m_scene.ConsoleScene() != null &&
368  m_scene.ConsoleScene() != m_scene)
369  {
370  return;
371  }
372 
373  if (args.Length > 2)
374  {
375  bool val;
376 
377  if (!bool.TryParse(args[2], out val))
378  return;
379 
380  m_bypassPermissions = val;
381 
382  m_log.InfoFormat(
383  "[PERMISSIONS]: Set permissions bypass to {0} for {1}",
384  m_bypassPermissions, m_scene.RegionInfo.RegionName);
385  }
386  }
387 
388  public void HandleForcePermissions(string module, string[] args)
389  {
390  if (m_scene.ConsoleScene() != null &&
391  m_scene.ConsoleScene() != m_scene)
392  {
393  return;
394  }
395 
396  if (!m_bypassPermissions)
397  {
398  m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first");
399  return;
400  }
401 
402  if (args.Length > 2)
403  {
404  bool val;
405 
406  if (!bool.TryParse(args[2], out val))
407  return;
408 
409  m_bypassPermissionsValue = val;
410 
411  m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName);
412  }
413  }
414 
415  public void HandleDebugPermissions(string module, string[] args)
416  {
417  if (m_scene.ConsoleScene() != null &&
418  m_scene.ConsoleScene() != m_scene)
419  {
420  return;
421  }
422 
423  if (args.Length > 2)
424  {
425  bool val;
426 
427  if (!bool.TryParse(args[2], out val))
428  return;
429 
430  m_debugPermissions = val;
431 
432  m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName);
433  }
434  }
435 
436  #endregion
437 
438  #region Helper Functions
439  protected void SendPermissionError(UUID user, string reason)
440  {
441  m_scene.EventManager.TriggerPermissionError(user, reason);
442  }
443 
444  protected void DebugPermissionInformation(string permissionCalled)
445  {
446  if (m_debugPermissions)
447  m_log.Debug("[PERMISSIONS]: " + permissionCalled + " was called from " + m_scene.RegionInfo.RegionName);
448  }
449 
458  protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers)
459  {
460  if (null == GroupsModule)
461  return false;
462 
463  GroupMembershipData gmd = GroupsModule.GetMembershipData(groupID, userID);
464 
465  if (gmd != null)
466  {
467  if (((gmd.GroupPowers != 0) && powers == 0) || (gmd.GroupPowers & powers) == powers)
468  return true;
469  }
470 
471  return false;
472  }
473 
481  private static UserSet ParseUserSetConfigSetting(IConfigSource config, string settingName, UserSet defaultValue)
482  {
483  UserSet userSet = defaultValue;
484 
485  string rawSetting = Util.GetConfigVarFromSections<string>(config, settingName,
486  new string[] {"Startup", "Permissions"}, defaultValue.ToString());
487 
488  // Temporary measure to allow 'gods' to be specified in config for consistency's sake. In the long term
489  // this should disappear.
490  if ("gods" == rawSetting.ToLower())
491  rawSetting = UserSet.Administrators.ToString();
492 
493  // Doing it this was so that we can do a case insensitive conversion
494  try
495  {
496  userSet = (UserSet)Enum.Parse(typeof(UserSet), rawSetting, true);
497  }
498  catch
499  {
500  m_log.ErrorFormat(
501  "[PERMISSIONS]: {0} is not a valid {1} value, setting to {2}",
502  rawSetting, settingName, userSet);
503  }
504 
505  m_log.DebugFormat("[PERMISSIONS]: {0} {1}", settingName, userSet);
506 
507  return userSet;
508  }
509 
515  protected bool IsAdministrator(UUID user)
516  {
517  if (user == UUID.Zero)
518  return false;
519 
520  if (m_scene.RegionInfo.EstateSettings.EstateOwner == user && m_RegionOwnerIsGod)
521  return true;
522 
523  if (IsEstateManager(user) && m_RegionManagerIsGod)
524  return true;
525 
526  if (IsGridGod(user, null))
527  return true;
528 
529  return false;
530  }
531 
538  protected bool IsGridGod(UUID user, Scene scene)
539  {
540  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
541  if (m_bypassPermissions) return m_bypassPermissionsValue;
542 
543  if (user == UUID.Zero) return false;
544 
545  if (m_allowGridGods)
546  {
547  ScenePresence sp = m_scene.GetScenePresence(user);
548  if (sp != null)
549  return (sp.UserLevel >= 200);
550 
551  UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, user);
552  if (account != null)
553  return (account.UserLevel >= 200);
554  }
555 
556  return false;
557  }
558 
559  protected bool IsFriendWithPerms(UUID user, UUID objectOwner)
560  {
561  if (user == UUID.Zero)
562  return false;
563 
564  if (FriendsModule == null)
565  return false;
566 
567  int friendPerms = FriendsModule.GetRightsGrantedByFriend(user, objectOwner);
568  return (friendPerms & (int)FriendRights.CanModifyObjects) != 0;
569  }
570 
571  protected bool IsEstateManager(UUID user)
572  {
573  if (user == UUID.Zero) return false;
574 
575  return m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(user);
576  }
577 
578 #endregion
579 
580  public bool PropagatePermissions()
581  {
582  if (m_bypassPermissions)
583  return false;
584 
585  return m_propagatePermissions;
586  }
587 
588  public bool BypassPermissions()
589  {
590  return m_bypassPermissions;
591  }
592 
593  public void SetBypassPermissions(bool value)
594  {
595  m_bypassPermissions=value;
596  }
597 
598  #region Object Permissions
599 
600  public uint GenerateClientFlags(UUID user, UUID objID)
601  {
602  // Here's the way this works,
603  // ObjectFlags and Permission flags are two different enumerations
604  // ObjectFlags, however, tells the client to change what it will allow the user to do.
605  // So, that means that all of the permissions type ObjectFlags are /temporary/ and only
606  // supposed to be set when customizing the objectflags for the client.
607 
608  // These temporary objectflags get computed and added in this function based on the
609  // Permission mask that's appropriate!
610  // Outside of this method, they should never be added to objectflags!
611  // -teravus
612 
613  SceneObjectPart task = m_scene.GetSceneObjectPart(objID);
614 
615  // this shouldn't ever happen.. return no permissions/objectflags.
616  if (task == null)
617  return (uint)0;
618 
619  uint objflags = task.GetEffectiveObjectFlags();
620  UUID objectOwner = task.OwnerID;
621 
622 
623  // Remove any of the objectFlags that are temporary. These will get added back if appropriate
624  // in the next bit of code
625 
626  // libomv will moan about PrimFlags.ObjectYouOfficer being
627  // deprecated
628 #pragma warning disable 0612
629  objflags &= (uint)
630  ~(PrimFlags.ObjectCopy | // Tells client you can copy the object
631  PrimFlags.ObjectModify | // tells client you can modify the object
632  PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
633  PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
634  PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
635  PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
636  PrimFlags.ObjectOwnerModify | // Tells client that you're the owner of the object
637  PrimFlags.ObjectYouOfficer // Tells client that you've got group object editing permission. Used when ObjectGroupOwned is set
638  );
639 #pragma warning restore 0612
640 
641  // Creating the three ObjectFlags options for this method to choose from.
642  // Customize the OwnerMask
643  uint objectOwnerMask = ApplyObjectModifyMasks(task.OwnerMask, objflags);
644  objectOwnerMask |= (uint)PrimFlags.ObjectYouOwner | (uint)PrimFlags.ObjectAnyOwner | (uint)PrimFlags.ObjectOwnerModify;
645 
646  // Customize the GroupMask
647  uint objectGroupMask = ApplyObjectModifyMasks(task.GroupMask, objflags);
648 
649  // Customize the EveryoneMask
650  uint objectEveryoneMask = ApplyObjectModifyMasks(task.EveryoneMask, objflags);
651  if (objectOwner != UUID.Zero)
652  objectEveryoneMask |= (uint)PrimFlags.ObjectAnyOwner;
653 
654  PermissionClass permissionClass = GetPermissionClass(user, task);
655 
656  switch (permissionClass)
657  {
658  case PermissionClass.Owner:
659  return objectOwnerMask;
660  case PermissionClass.Group:
661  return objectGroupMask | objectEveryoneMask;
662  case PermissionClass.Everyone:
663  default:
664  return objectEveryoneMask;
665  }
666  }
667 
668  private uint ApplyObjectModifyMasks(uint setPermissionMask, uint objectFlagsMask)
669  {
670  // We are adding the temporary objectflags to the object's objectflags based on the
671  // permission flag given. These change the F flags on the client.
672 
673  if ((setPermissionMask & (uint)PermissionMask.Copy) != 0)
674  {
675  objectFlagsMask |= (uint)PrimFlags.ObjectCopy;
676  }
677 
678  if ((setPermissionMask & (uint)PermissionMask.Move) != 0)
679  {
680  objectFlagsMask |= (uint)PrimFlags.ObjectMove;
681  }
682 
683  if ((setPermissionMask & (uint)PermissionMask.Modify) != 0)
684  {
685  objectFlagsMask |= (uint)PrimFlags.ObjectModify;
686  }
687 
688  if ((setPermissionMask & (uint)PermissionMask.Transfer) != 0)
689  {
690  objectFlagsMask |= (uint)PrimFlags.ObjectTransfer;
691  }
692 
693  return objectFlagsMask;
694  }
695 
697  {
698  if (obj == null)
699  return PermissionClass.Everyone;
700 
701  if (m_bypassPermissions)
702  return PermissionClass.Owner;
703 
704  // Object owners should be able to edit their own content
705  UUID objectOwner = obj.OwnerID;
706  if (user == objectOwner)
707  return PermissionClass.Owner;
708 
709  if (IsFriendWithPerms(user, objectOwner) && !obj.ParentGroup.IsAttachment)
710  return PermissionClass.Owner;
711 
712  // Estate users should be able to edit anything in the sim if RegionOwnerIsGod is set
713  if (m_RegionOwnerIsGod && IsEstateManager(user) && !IsAdministrator(objectOwner))
714  return PermissionClass.Owner;
715 
716  // Admin should be able to edit anything in the sim (including admin objects)
717  if (IsAdministrator(user))
718  return PermissionClass.Owner;
719 
720  // Users should be able to edit what is over their land.
721  Vector3 taskPos = obj.AbsolutePosition;
722  ILandObject parcel = m_scene.LandChannel.GetLandObject(taskPos.X, taskPos.Y);
723  if (parcel != null && parcel.LandData.OwnerID == user && m_ParcelOwnerIsGod)
724  {
725  // Admin objects should not be editable by the above
726  if (!IsAdministrator(objectOwner))
727  return PermissionClass.Owner;
728  }
729 
730  // Group permissions
731  if ((obj.GroupID != UUID.Zero) && IsGroupMember(obj.GroupID, user, 0))
732  return PermissionClass.Group;
733 
734  return PermissionClass.Everyone;
735  }
736 
745  protected bool GenericObjectPermission(UUID currentUser, UUID objId, bool denyOnLocked)
746  {
747  // Default: deny
748  bool permission = false;
749  bool locked = false;
750 
751  SceneObjectPart part = m_scene.GetSceneObjectPart(objId);
752 
753  if (part == null)
754  return false;
755 
756  SceneObjectGroup group = part.ParentGroup;
757 
758  UUID objectOwner = group.OwnerID;
759  locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
760 
761  // People shouldn't be able to do anything with locked objects, except the Administrator
762  // The 'set permissions' runs through a different permission check, so when an object owner
763  // sets an object locked, the only thing that they can do is unlock it.
764  //
765  // Nobody but the object owner can set permissions on an object
766  //
767  if (locked && (!IsAdministrator(currentUser)) && denyOnLocked)
768  {
769  return false;
770  }
771 
772  // Object owners should be able to edit their own content
773  if (currentUser == objectOwner)
774  {
775  // there is no way that later code can change this back to false
776  // so just return true immediately and short circuit the more
777  // expensive group checks
778  return true;
779 
780  //permission = true;
781  }
782  else if (group.IsAttachment)
783  {
784  permission = false;
785  }
786 
787 // m_log.DebugFormat(
788 // "[PERMISSIONS]: group.GroupID = {0}, part.GroupMask = {1}, isGroupMember = {2} for {3}",
789 // group.GroupID,
790 // m_scene.GetSceneObjectPart(objId).GroupMask,
791 // IsGroupMember(group.GroupID, currentUser, 0),
792 // currentUser);
793 
794  // Group members should be able to edit group objects
795  if ((group.GroupID != UUID.Zero)
796  && ((m_scene.GetSceneObjectPart(objId).GroupMask & (uint)PermissionMask.Modify) != 0)
797  && IsGroupMember(group.GroupID, currentUser, 0))
798  {
799  // Return immediately, so that the administrator can shares group objects
800  return true;
801  }
802 
803  // Friends with benefits should be able to edit the objects too
804  if (IsFriendWithPerms(currentUser, objectOwner))
805  {
806  // Return immediately, so that the administrator can share objects with friends
807  return true;
808  }
809 
810  // Users should be able to edit what is over their land.
811  ILandObject parcel = m_scene.LandChannel.GetLandObject(group.AbsolutePosition.X, group.AbsolutePosition.Y);
812  if ((parcel != null) && (parcel.LandData.OwnerID == currentUser))
813  {
814  permission = true;
815  }
816 
817  // Estate users should be able to edit anything in the sim
818  if (IsEstateManager(currentUser))
819  {
820  permission = true;
821  }
822 
823  // Admin objects should not be editable by the above
824  if (IsAdministrator(objectOwner))
825  {
826  permission = false;
827  }
828 
829  // Admin should be able to edit anything in the sim (including admin objects)
830  if (IsAdministrator(currentUser))
831  {
832  permission = true;
833  }
834 
835  return permission;
836  }
837 
838  #endregion
839 
840  #region Generic Permissions
841  protected bool GenericCommunicationPermission(UUID user, UUID target)
842  {
843  // Setting this to true so that cool stuff can happen until we define what determines Generic Communication Permission
844  bool permission = true;
845  string reason = "Only registered users may communicate with another account.";
846 
847  // Uhh, we need to finish this before we enable it.. because it's blocking all sorts of goodies and features
848  if (IsAdministrator(user))
849  permission = true;
850 
851  if (IsEstateManager(user))
852  permission = true;
853 
854  if (!permission)
855  SendPermissionError(user, reason);
856 
857  return permission;
858  }
859 
860  public bool GenericEstatePermission(UUID user)
861  {
862  // Default: deny
863  bool permission = false;
864 
865  // Estate admins should be able to use estate tools
866  if (IsEstateManager(user))
867  permission = true;
868 
869  // Administrators always have permission
870  if (IsAdministrator(user))
871  permission = true;
872 
873  return permission;
874  }
875 
876  protected bool GenericParcelPermission(UUID user, ILandObject parcel, ulong groupPowers)
877  {
878  bool permission = false;
879 
880  if (parcel.LandData.OwnerID == user)
881  {
882  permission = true;
883  }
884 
885  if ((parcel.LandData.GroupID != UUID.Zero) && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
886  {
887  permission = true;
888  }
889 
890  if (IsEstateManager(user))
891  {
892  permission = true;
893  }
894 
895  if (IsAdministrator(user))
896  {
897  permission = true;
898  }
899 
900  if (m_SimpleBuildPermissions &&
901  (parcel.LandData.Flags & (uint)ParcelFlags.UseAccessList) == 0 && parcel.IsInLandAccessList(user))
902  permission = true;
903 
904  return permission;
905  }
906 
907  protected bool GenericParcelOwnerPermission(UUID user, ILandObject parcel, ulong groupPowers, bool allowEstateManager)
908  {
909  if (parcel.LandData.OwnerID == user)
910  {
911  // Returning immediately so that group deeded objects on group deeded land don't trigger a NRE on
912  // the subsequent redundant checks when using lParcelMediaCommandList()
913  // See http://opensimulator.org/mantis/view.php?id=3999 for more details
914  return true;
915  }
916 
917  if (parcel.LandData.IsGroupOwned && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
918  {
919  return true;
920  }
921 
922  if (allowEstateManager && IsEstateManager(user))
923  {
924  return true;
925  }
926 
927  if (IsAdministrator(user))
928  {
929  return true;
930  }
931 
932  return false;
933  }
934 
935  protected bool GenericParcelPermission(UUID user, Vector3 pos, ulong groupPowers)
936  {
937  ILandObject parcel = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
938  if (parcel == null) return false;
939  return GenericParcelPermission(user, parcel, groupPowers);
940  }
941 #endregion
942 
943  #region Permission Checks
944  private bool CanAbandonParcel(UUID user, ILandObject parcel, Scene scene)
945  {
946  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
947  if (m_bypassPermissions) return m_bypassPermissionsValue;
948 
949  return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandRelease, false);
950  }
951 
952  private bool CanReclaimParcel(UUID user, ILandObject parcel, Scene scene)
953  {
954  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
955  if (m_bypassPermissions) return m_bypassPermissionsValue;
956 
957  return GenericParcelOwnerPermission(user, parcel, 0,true);
958  }
959 
960  private bool CanDeedParcel(UUID user, ILandObject parcel, Scene scene)
961  {
962  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
963  if (m_bypassPermissions) return m_bypassPermissionsValue;
964 
965  if (parcel.LandData.OwnerID != user) // Only the owner can deed!
966  return false;
967 
968  ScenePresence sp = scene.GetScenePresence(user);
969  IClientAPI client = sp.ControllingClient;
970 
971  if ((client.GetGroupPowers(parcel.LandData.GroupID) & (ulong)GroupPowers.LandDeed) == 0)
972  return false;
973 
974  return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandDeed, false);
975  }
976 
977  private bool CanDeedObject(UUID user, UUID group, Scene scene)
978  {
979  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
980  if (m_bypassPermissions) return m_bypassPermissionsValue;
981 
982  ScenePresence sp = scene.GetScenePresence(user);
983  IClientAPI client = sp.ControllingClient;
984 
985  if ((client.GetGroupPowers(group) & (ulong)GroupPowers.DeedObject) == 0)
986  return false;
987 
988  return true;
989  }
990 
991  private bool IsGod(UUID user, Scene scene)
992  {
993  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
994  if (m_bypassPermissions) return m_bypassPermissionsValue;
995 
996  return IsAdministrator(user);
997  }
998 
999  private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
1000  {
1001  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1002  if (m_bypassPermissions) return m_bypassPermissionsValue;
1003 
1004  if (!GenericObjectPermission(owner, objectID, true))
1005  {
1006  //They can't even edit the object
1007  return false;
1008  }
1009 
1010  SceneObjectPart part = scene.GetSceneObjectPart(objectID);
1011  if (part == null)
1012  return false;
1013 
1014  if (part.OwnerID == owner)
1015  {
1016  if ((part.OwnerMask & PERM_COPY) == 0)
1017  return false;
1018  }
1019  else if (part.GroupID != UUID.Zero)
1020  {
1021  if ((part.OwnerID == part.GroupID) && ((owner != part.LastOwnerID) || ((part.GroupMask & PERM_TRANS) == 0)))
1022  return false;
1023 
1024  if ((part.GroupMask & PERM_COPY) == 0)
1025  return false;
1026  }
1027 
1028  //If they can rez, they can duplicate
1029  return CanRezObject(objectCount, owner, objectPosition, scene);
1030  }
1031 
1032  private bool CanDeleteObject(UUID objectID, UUID deleter, Scene scene)
1033  {
1034  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1035  if (m_bypassPermissions) return m_bypassPermissionsValue;
1036 
1037  return GenericObjectPermission(deleter, objectID, false);
1038  }
1039 
1040  private bool CanEditObject(UUID objectID, UUID editorID, Scene scene)
1041  {
1042  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1043  if (m_bypassPermissions) return m_bypassPermissionsValue;
1044 
1045  return GenericObjectPermission(editorID, objectID, false);
1046  }
1047 
1048  private bool CanEditObjectInventory(UUID objectID, UUID editorID, Scene scene)
1049  {
1050  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1051  if (m_bypassPermissions) return m_bypassPermissionsValue;
1052 
1053  return GenericObjectPermission(editorID, objectID, false);
1054  }
1055 
1056  private bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers p, Scene scene, bool allowManager)
1057  {
1058  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1059  if (m_bypassPermissions) return m_bypassPermissionsValue;
1060 
1061  return GenericParcelOwnerPermission(user, parcel, (ulong)p, false);
1062  }
1063 
1072  private bool CanEditScript(UUID script, UUID objectID, UUID user, Scene scene)
1073  {
1074  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1075  if (m_bypassPermissions) return m_bypassPermissionsValue;
1076 
1077  if (m_allowedScriptEditors == UserSet.Administrators && !IsAdministrator(user))
1078  return false;
1079 
1080  // Ordinarily, if you can view it, you can edit it
1081  // There is no viewing a no mod script
1082  //
1083  return CanViewScript(script, objectID, user, scene);
1084  }
1085 
1094  private bool CanEditNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
1095  {
1096  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1097  if (m_bypassPermissions) return m_bypassPermissionsValue;
1098 
1099  if (objectID == UUID.Zero) // User inventory
1100  {
1101  IInventoryService invService = m_scene.InventoryService;
1102  InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
1103  assetRequestItem = invService.GetItem(assetRequestItem);
1104  if (assetRequestItem == null && LibraryRootFolder != null) // Library item
1105  {
1106  assetRequestItem = LibraryRootFolder.FindItem(notecard);
1107 
1108  if (assetRequestItem != null) // Implicitly readable
1109  return true;
1110  }
1111 
1112  // Notecards must be both mod and copy to be saveable
1113  // This is because of they're not copy, you can't read
1114  // them, and if they're not mod, well, then they're
1115  // not mod. Duh.
1116  //
1117  if ((assetRequestItem.CurrentPermissions &
1118  ((uint)PermissionMask.Modify |
1119  (uint)PermissionMask.Copy)) !=
1120  ((uint)PermissionMask.Modify |
1121  (uint)PermissionMask.Copy))
1122  return false;
1123  }
1124  else // Prim inventory
1125  {
1126  SceneObjectPart part = scene.GetSceneObjectPart(objectID);
1127 
1128  if (part == null)
1129  return false;
1130 
1131  if (part.OwnerID != user)
1132  {
1133  if (part.GroupID == UUID.Zero)
1134  return false;
1135 
1136  if (!IsGroupMember(part.GroupID, user, 0))
1137  return false;
1138 
1139  if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
1140  return false;
1141  }
1142  else
1143  {
1144  if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
1145  return false;
1146  }
1147 
1148  TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
1149 
1150  if (ti == null)
1151  return false;
1152 
1153  if (ti.OwnerID != user)
1154  {
1155  if (ti.GroupID == UUID.Zero)
1156  return false;
1157 
1158  if (!IsGroupMember(ti.GroupID, user, 0))
1159  return false;
1160  }
1161 
1162  // Require full perms
1163  if ((ti.CurrentPermissions &
1164  ((uint)PermissionMask.Modify |
1165  (uint)PermissionMask.Copy)) !=
1166  ((uint)PermissionMask.Modify |
1167  (uint)PermissionMask.Copy))
1168  return false;
1169  }
1170 
1171  return true;
1172  }
1173 
1174  private bool CanInstantMessage(UUID user, UUID target, Scene startScene)
1175  {
1176  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1177  if (m_bypassPermissions) return m_bypassPermissionsValue;
1178 
1179  // If the sender is an object, check owner instead
1180  //
1181  SceneObjectPart part = startScene.GetSceneObjectPart(user);
1182  if (part != null)
1183  user = part.OwnerID;
1184 
1185  return GenericCommunicationPermission(user, target);
1186  }
1187 
1188  private bool CanInventoryTransfer(UUID user, UUID target, Scene startScene)
1189  {
1190  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1191  if (m_bypassPermissions) return m_bypassPermissionsValue;
1192 
1193  return GenericCommunicationPermission(user, target);
1194  }
1195 
1196  private bool CanIssueEstateCommand(UUID user, Scene requestFromScene, bool ownerCommand)
1197  {
1198  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1199  if (m_bypassPermissions) return m_bypassPermissionsValue;
1200 
1201  if (IsAdministrator(user))
1202  return true;
1203 
1204  if (m_scene.RegionInfo.EstateSettings.IsEstateOwner(user))
1205  return true;
1206 
1207  if (ownerCommand)
1208  return false;
1209 
1210  return GenericEstatePermission(user);
1211  }
1212 
1213  private bool CanMoveObject(UUID objectID, UUID moverID, Scene scene)
1214  {
1215  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1216  if (m_bypassPermissions)
1217  {
1218  SceneObjectPart part = scene.GetSceneObjectPart(objectID);
1219  if (part.OwnerID != moverID)
1220  {
1221  if (!part.ParentGroup.IsDeleted)
1222  {
1223  if (part.ParentGroup.IsAttachment)
1224  return false;
1225  }
1226  }
1227  return m_bypassPermissionsValue;
1228  }
1229 
1230  bool permission = GenericObjectPermission(moverID, objectID, true);
1231  if (!permission)
1232  {
1233  if (!m_scene.Entities.ContainsKey(objectID))
1234  {
1235  return false;
1236  }
1237 
1238  // The client
1239  // may request to edit linked parts, and therefore, it needs
1240  // to also check for SceneObjectPart
1241 
1242  // If it's not an object, we cant edit it.
1243  if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
1244  {
1245  return false;
1246  }
1247 
1248 
1249  SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
1250 
1251 
1252  // UUID taskOwner = null;
1253  // Added this because at this point in time it wouldn't be wise for
1254  // the administrator object permissions to take effect.
1255  // UUID objectOwner = task.OwnerID;
1256 
1257  // Anyone can move
1258  if ((task.RootPart.EveryoneMask & PERM_MOVE) != 0)
1259  permission = true;
1260 
1261  // Locked
1262  if ((task.RootPart.OwnerMask & PERM_LOCKED) == 0)
1263  permission = false;
1264  }
1265  else
1266  {
1267  bool locked = false;
1268  if (!m_scene.Entities.ContainsKey(objectID))
1269  {
1270  return false;
1271  }
1272 
1273  // If it's not an object, we cant edit it.
1274  if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
1275  {
1276  return false;
1277  }
1278 
1279  SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objectID];
1280 
1281  UUID objectOwner = group.OwnerID;
1282  locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
1283 
1284  // This is an exception to the generic object permission.
1285  // Administrators who lock their objects should not be able to move them,
1286  // however generic object permission should return true.
1287  // This keeps locked objects from being affected by random click + drag actions by accident
1288  // and allows the administrator to grab or delete a locked object.
1289 
1290  // Administrators and estate managers are still able to click+grab locked objects not
1291  // owned by them in the scene
1292  // This is by design.
1293 
1294  if (locked && (moverID == objectOwner))
1295  return false;
1296  }
1297  return permission;
1298  }
1299 
1300  private bool CanObjectEntry(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
1301  {
1302  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1303  if (m_bypassPermissions) return m_bypassPermissionsValue;
1304 
1305  if ((newPoint.X > 257f || newPoint.X < -1f || newPoint.Y > 257f || newPoint.Y < -1f))
1306  {
1307  return true;
1308  }
1309 
1310  SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
1311 
1312  ILandObject land = m_scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
1313 
1314  if (!enteringRegion)
1315  {
1316  ILandObject fromland = m_scene.LandChannel.GetLandObject(task.AbsolutePosition.X, task.AbsolutePosition.Y);
1317 
1318  if (fromland == land) // Not entering
1319  return true;
1320  }
1321 
1322  if (land == null)
1323  {
1324  return false;
1325  }
1326 
1327  if ((land.LandData.Flags & ((int)ParcelFlags.AllowAPrimitiveEntry)) != 0)
1328  {
1329  return true;
1330  }
1331 
1332  if (!m_scene.Entities.ContainsKey(objectID))
1333  {
1334  return false;
1335  }
1336 
1337  // If it's not an object, we cant edit it.
1338  if (!(m_scene.Entities[objectID] is SceneObjectGroup))
1339  {
1340  return false;
1341  }
1342 
1343 
1344  if (GenericParcelPermission(task.OwnerID, newPoint, 0))
1345  {
1346  return true;
1347  }
1348 
1349  //Otherwise, false!
1350  return false;
1351  }
1352 
1353  private bool CanReturnObjects(ILandObject land, UUID user, List<SceneObjectGroup> objects, Scene scene)
1354  {
1355  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1356  if (m_bypassPermissions) return m_bypassPermissionsValue;
1357 
1358  GroupPowers powers;
1359  ILandObject l;
1360 
1361  ScenePresence sp = scene.GetScenePresence(user);
1362  if (sp == null)
1363  return false;
1364 
1365  IClientAPI client = sp.ControllingClient;
1366 
1367  foreach (SceneObjectGroup g in new List<SceneObjectGroup>(objects))
1368  {
1369  // Any user can return their own objects at any time
1370  //
1371  if (GenericObjectPermission(user, g.UUID, false))
1372  continue;
1373 
1374  // This is a short cut for efficiency. If land is non-null,
1375  // then all objects are on that parcel and we can save
1376  // ourselves the checking for each prim. Much faster.
1377  //
1378  if (land != null)
1379  {
1380  l = land;
1381  }
1382  else
1383  {
1384  Vector3 pos = g.AbsolutePosition;
1385 
1386  l = scene.LandChannel.GetLandObject(pos.X, pos.Y);
1387  }
1388 
1389  // If it's not over any land, then we can't do a thing
1390  if (l == null)
1391  {
1392  objects.Remove(g);
1393  continue;
1394  }
1395 
1396  // If we own the land outright, then allow
1397  //
1398  if (l.LandData.OwnerID == user)
1399  continue;
1400 
1401  // Group voodoo
1402  //
1403  if (l.LandData.IsGroupOwned)
1404  {
1405  powers = (GroupPowers)client.GetGroupPowers(l.LandData.GroupID);
1406  // Not a group member, or no rights at all
1407  //
1408  if (powers == (GroupPowers)0)
1409  {
1410  objects.Remove(g);
1411  continue;
1412  }
1413 
1414  // Group deeded object?
1415  //
1416  if (g.OwnerID == l.LandData.GroupID &&
1417  (powers & GroupPowers.ReturnGroupOwned) == (GroupPowers)0)
1418  {
1419  objects.Remove(g);
1420  continue;
1421  }
1422 
1423  // Group set object?
1424  //
1425  if (g.GroupID == l.LandData.GroupID &&
1426  (powers & GroupPowers.ReturnGroupSet) == (GroupPowers)0)
1427  {
1428  objects.Remove(g);
1429  continue;
1430  }
1431 
1432  if ((powers & GroupPowers.ReturnNonGroup) == (GroupPowers)0)
1433  {
1434  objects.Remove(g);
1435  continue;
1436  }
1437 
1438  // So we can remove all objects from this group land.
1439  // Fine.
1440  //
1441  continue;
1442  }
1443 
1444  // By default, we can't remove
1445  //
1446  objects.Remove(g);
1447  }
1448 
1449  if (objects.Count == 0)
1450  return false;
1451 
1452  return true;
1453  }
1454 
1455  private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
1456  {
1457  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1458  if (m_bypassPermissions) return m_bypassPermissionsValue;
1459 
1460 // m_log.DebugFormat("[PERMISSIONS MODULE]: Checking rez object at {0} in {1}", objectPosition, m_scene.Name);
1461 
1462  ILandObject parcel = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
1463  if (parcel == null)
1464  return false;
1465 
1466  if ((parcel.LandData.Flags & (uint)ParcelFlags.CreateObjects) != 0)
1467  {
1468  return true;
1469  }
1470  else if ((owner == parcel.LandData.OwnerID) || IsAdministrator(owner))
1471  {
1472  return true;
1473  }
1474  else if (((parcel.LandData.Flags & (uint)ParcelFlags.CreateGroupObjects) != 0)
1475  && (parcel.LandData.GroupID != UUID.Zero) && IsGroupMember(parcel.LandData.GroupID, owner, 0))
1476  {
1477  return true;
1478  }
1479  else if (parcel.LandData.GroupID != UUID.Zero && IsGroupMember(parcel.LandData.GroupID, owner, (ulong)GroupPowers.AllowRez))
1480  {
1481  return true;
1482  }
1483  else
1484  {
1485  return false;
1486  }
1487  }
1488 
1489  private bool CanRunConsoleCommand(UUID user, Scene requestFromScene)
1490  {
1491  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1492  if (m_bypassPermissions) return m_bypassPermissionsValue;
1493 
1494 
1495  return IsAdministrator(user);
1496  }
1497 
1498  private bool CanRunScript(UUID script, UUID objectID, UUID user, Scene scene)
1499  {
1500  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1501  if (m_bypassPermissions) return m_bypassPermissionsValue;
1502 
1503  return true;
1504  }
1505 
1506  private bool CanSellParcel(UUID user, ILandObject parcel, Scene scene)
1507  {
1508  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1509  if (m_bypassPermissions) return m_bypassPermissionsValue;
1510 
1511  return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandSetSale, false);
1512  }
1513 
1514  private bool CanTakeObject(UUID objectID, UUID stealer, Scene scene)
1515  {
1516  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1517  if (m_bypassPermissions) return m_bypassPermissionsValue;
1518 
1519  return GenericObjectPermission(stealer,objectID, false);
1520  }
1521 
1522  private bool CanTakeCopyObject(UUID objectID, UUID userID, Scene inScene)
1523  {
1524  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1525  if (m_bypassPermissions) return m_bypassPermissionsValue;
1526 
1527  bool permission = GenericObjectPermission(userID, objectID, false);
1528 
1529  SceneObjectGroup so = (SceneObjectGroup)m_scene.Entities[objectID];
1530 
1531  if (!permission)
1532  {
1533  if (!m_scene.Entities.ContainsKey(objectID))
1534  {
1535  return false;
1536  }
1537 
1538  // If it's not an object, we cant edit it.
1539  if (!(m_scene.Entities[objectID] is SceneObjectGroup))
1540  {
1541  return false;
1542  }
1543 
1544  // UUID taskOwner = null;
1545  // Added this because at this point in time it wouldn't be wise for
1546  // the administrator object permissions to take effect.
1547  // UUID objectOwner = task.OwnerID;
1548 
1549  if ((so.RootPart.EveryoneMask & PERM_COPY) != 0)
1550  permission = true;
1551  }
1552 
1553  if (so.OwnerID != userID)
1554  {
1555  if ((so.GetEffectivePermissions() & (PERM_COPY | PERM_TRANS)) != (PERM_COPY | PERM_TRANS))
1556  permission = false;
1557  }
1558  else
1559  {
1560  if ((so.GetEffectivePermissions() & PERM_COPY) != PERM_COPY)
1561  permission = false;
1562  }
1563 
1564  return permission;
1565  }
1566 
1567  private bool CanTerraformLand(UUID user, Vector3 position, Scene requestFromScene)
1568  {
1569  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1570  if (m_bypassPermissions) return m_bypassPermissionsValue;
1571 
1572  // Estate override
1573  if (GenericEstatePermission(user))
1574  return true;
1575 
1576  float X = position.X;
1577  float Y = position.Y;
1578 
1579  if (X > ((int)m_scene.RegionInfo.RegionSizeX - 1))
1580  X = ((int)m_scene.RegionInfo.RegionSizeX - 1);
1581  if (Y > ((int)m_scene.RegionInfo.RegionSizeY - 1))
1582  Y = ((int)m_scene.RegionInfo.RegionSizeY - 1);
1583  if (X < 0)
1584  X = 0;
1585  if (Y < 0)
1586  Y = 0;
1587 
1588  ILandObject parcel = m_scene.LandChannel.GetLandObject(X, Y);
1589  if (parcel == null)
1590  return false;
1591 
1592  // Others allowed to terraform?
1593  if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowTerraform)) != 0)
1594  return true;
1595 
1596  // Land owner can terraform too
1597  if (parcel != null && GenericParcelPermission(user, parcel, (ulong)GroupPowers.AllowEditLand))
1598  return true;
1599 
1600  return false;
1601  }
1602 
1611  private bool CanViewScript(UUID script, UUID objectID, UUID user, Scene scene)
1612  {
1613  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1614  if (m_bypassPermissions) return m_bypassPermissionsValue;
1615 
1616  if (objectID == UUID.Zero) // User inventory
1617  {
1618  IInventoryService invService = m_scene.InventoryService;
1619  InventoryItemBase assetRequestItem = new InventoryItemBase(script, user);
1620  assetRequestItem = invService.GetItem(assetRequestItem);
1621  if (assetRequestItem == null && LibraryRootFolder != null) // Library item
1622  {
1623  assetRequestItem = LibraryRootFolder.FindItem(script);
1624 
1625  if (assetRequestItem != null) // Implicitly readable
1626  return true;
1627  }
1628 
1629  // SL is rather harebrained here. In SL, a script you
1630  // have mod/copy no trans is readable. This subverts
1631  // permissions, but is used in some products, most
1632  // notably Hippo door plugin and HippoRent 5 networked
1633  // prim counter.
1634  // To enable this broken SL-ism, remove Transfer from
1635  // the below expressions.
1636  // Trying to improve on SL perms by making a script
1637  // readable only if it's really full perms
1638  //
1639  if ((assetRequestItem.CurrentPermissions &
1640  ((uint)PermissionMask.Modify |
1641  (uint)PermissionMask.Copy |
1642  (uint)PermissionMask.Transfer)) !=
1643  ((uint)PermissionMask.Modify |
1644  (uint)PermissionMask.Copy |
1645  (uint)PermissionMask.Transfer))
1646  return false;
1647  }
1648  else // Prim inventory
1649  {
1650  SceneObjectPart part = scene.GetSceneObjectPart(objectID);
1651 
1652  if (part == null)
1653  return false;
1654 
1655  if (part.OwnerID != user)
1656  {
1657  if (part.GroupID == UUID.Zero)
1658  return false;
1659 
1660  if (!IsGroupMember(part.GroupID, user, 0))
1661  return false;
1662 
1663  if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
1664  return false;
1665  }
1666  else
1667  {
1668  if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
1669  return false;
1670  }
1671 
1672  TaskInventoryItem ti = part.Inventory.GetInventoryItem(script);
1673 
1674  if (ti == null)
1675  return false;
1676 
1677  if (ti.OwnerID != user)
1678  {
1679  if (ti.GroupID == UUID.Zero)
1680  return false;
1681 
1682  if (!IsGroupMember(ti.GroupID, user, 0))
1683  return false;
1684  }
1685 
1686  // Require full perms
1687  if ((ti.CurrentPermissions &
1688  ((uint)PermissionMask.Modify |
1689  (uint)PermissionMask.Copy |
1690  (uint)PermissionMask.Transfer)) !=
1691  ((uint)PermissionMask.Modify |
1692  (uint)PermissionMask.Copy |
1693  (uint)PermissionMask.Transfer))
1694  return false;
1695  }
1696 
1697  return true;
1698  }
1699 
1708  private bool CanViewNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
1709  {
1710  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1711  if (m_bypassPermissions) return m_bypassPermissionsValue;
1712 
1713  if (objectID == UUID.Zero) // User inventory
1714  {
1715  IInventoryService invService = m_scene.InventoryService;
1716  InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
1717  assetRequestItem = invService.GetItem(assetRequestItem);
1718  if (assetRequestItem == null && LibraryRootFolder != null) // Library item
1719  {
1720  assetRequestItem = LibraryRootFolder.FindItem(notecard);
1721 
1722  if (assetRequestItem != null) // Implicitly readable
1723  return true;
1724  }
1725 
1726  // Notecards are always readable unless no copy
1727  //
1728  if ((assetRequestItem.CurrentPermissions &
1729  (uint)PermissionMask.Copy) !=
1730  (uint)PermissionMask.Copy)
1731  return false;
1732  }
1733  else // Prim inventory
1734  {
1735  SceneObjectPart part = scene.GetSceneObjectPart(objectID);
1736 
1737  if (part == null)
1738  return false;
1739 
1740  if (part.OwnerID != user)
1741  {
1742  if (part.GroupID == UUID.Zero)
1743  return false;
1744 
1745  if (!IsGroupMember(part.GroupID, user, 0))
1746  return false;
1747  }
1748 
1749  if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
1750  return false;
1751 
1752  TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
1753 
1754  if (ti == null)
1755  return false;
1756 
1757  if (ti.OwnerID != user)
1758  {
1759  if (ti.GroupID == UUID.Zero)
1760  return false;
1761 
1762  if (!IsGroupMember(ti.GroupID, user, 0))
1763  return false;
1764  }
1765 
1766  // Notecards are always readable unless no copy
1767  //
1768  if ((ti.CurrentPermissions &
1769  (uint)PermissionMask.Copy) !=
1770  (uint)PermissionMask.Copy)
1771  return false;
1772  }
1773 
1774  return true;
1775  }
1776 
1777  #endregion
1778 
1779  private bool CanLinkObject(UUID userID, UUID objectID)
1780  {
1781  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1782  if (m_bypassPermissions) return m_bypassPermissionsValue;
1783 
1784  return GenericObjectPermission(userID, objectID, false);
1785  }
1786 
1787  private bool CanDelinkObject(UUID userID, UUID objectID)
1788  {
1789  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1790  if (m_bypassPermissions) return m_bypassPermissionsValue;
1791 
1792  return GenericObjectPermission(userID, objectID, false);
1793  }
1794 
1795  private bool CanBuyLand(UUID userID, ILandObject parcel, Scene scene)
1796  {
1797  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1798  if (m_bypassPermissions) return m_bypassPermissionsValue;
1799 
1800  return true;
1801  }
1802 
1803  private bool CanCopyObjectInventory(UUID itemID, UUID objectID, UUID userID)
1804  {
1805  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1806  if (m_bypassPermissions) return m_bypassPermissionsValue;
1807 
1808  return true;
1809  }
1810 
1811  private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
1812  {
1813  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1814  if (m_bypassPermissions) return m_bypassPermissionsValue;
1815 
1816  return true;
1817  }
1818 
1827  private bool CanCreateObjectInventory(int invType, UUID objectID, UUID userID)
1828  {
1829  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1830  if (m_bypassPermissions) return m_bypassPermissionsValue;
1831 
1832  SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
1833  ScenePresence p = m_scene.GetScenePresence(userID);
1834 
1835  if (part == null || p == null)
1836  return false;
1837 
1838  if (!IsAdministrator(userID))
1839  {
1840  if (part.OwnerID != userID)
1841  {
1842  // Group permissions
1843  if ((part.GroupID == UUID.Zero) || (p.ControllingClient.GetGroupPowers(part.GroupID) == 0) || ((part.GroupMask & (uint)PermissionMask.Modify) == 0))
1844  return false;
1845  } else {
1846  if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
1847  return false;
1848  }
1849  if ((int)InventoryType.LSL == invType)
1850  if (m_allowedScriptCreators == UserSet.Administrators)
1851  return false;
1852  }
1853 
1854  return true;
1855  }
1856 
1863  private bool CanCreateUserInventory(int invType, UUID userID)
1864  {
1865  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1866  if (m_bypassPermissions) return m_bypassPermissionsValue;
1867 
1868  if ((int)InventoryType.LSL == invType)
1869  if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
1870  return false;
1871 
1872  return true;
1873  }
1874 
1881  private bool CanCopyUserInventory(UUID itemID, UUID userID)
1882  {
1883  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1884  if (m_bypassPermissions) return m_bypassPermissionsValue;
1885 
1886  return true;
1887  }
1888 
1895  private bool CanEditUserInventory(UUID itemID, UUID userID)
1896  {
1897  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1898  if (m_bypassPermissions) return m_bypassPermissionsValue;
1899 
1900  return true;
1901  }
1902 
1909  private bool CanDeleteUserInventory(UUID itemID, UUID userID)
1910  {
1911  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1912  if (m_bypassPermissions) return m_bypassPermissionsValue;
1913 
1914  return true;
1915  }
1916 
1917  private bool CanTeleport(UUID userID, Scene scene)
1918  {
1919  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1920  if (m_bypassPermissions) return m_bypassPermissionsValue;
1921 
1922  return true;
1923  }
1924 
1925  private bool CanResetScript(UUID prim, UUID script, UUID agentID, Scene scene)
1926  {
1927  DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
1928  if (m_bypassPermissions) return m_bypassPermissionsValue;
1929 
1930  SceneObjectPart part = m_scene.GetSceneObjectPart(prim);
1931 
1932  // If we selected a sub-prim to reset, prim won't represent the object, but only a part.
1933  // We have to check the permissions of the object, though.
1934  if (part.ParentID != 0) prim = part.ParentUUID;
1935 
1936  // You can reset the scripts in any object you can edit
1937  return GenericObjectPermission(agentID, prim, false);
1938  }
1939 
1940  private bool CanCompileScript(UUID ownerUUID, int scriptType, Scene scene)
1941  {
1942  //m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType);
1943  switch (scriptType) {
1944  case 0:
1945  if (GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString())) {
1946  return(true);
1947  }
1948  break;
1949  case 1:
1950  if (GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString())) {
1951  return(true);
1952  }
1953  break;
1954  case 2:
1955  if (GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString())) {
1956  return(true);
1957  }
1958  break;
1959  case 3:
1960  if (GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString()))
1961  {
1962  return (true);
1963  }
1964  break;
1965  case 4:
1966  if (GrantYP.Count == 0 || GrantYP.ContainsKey(ownerUUID.ToString()))
1967  {
1968  return (true);
1969  }
1970  break;
1971  }
1972  return(false);
1973  }
1974 
1975  private bool CanControlPrimMedia(UUID agentID, UUID primID, int face)
1976  {
1977 // m_log.DebugFormat(
1978 // "[PERMISSONS]: Performing CanControlPrimMedia check with agentID {0}, primID {1}, face {2}",
1979 // agentID, primID, face);
1980 
1981  if (null == MoapModule)
1982  return false;
1983 
1984  SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
1985  if (null == part)
1986  return false;
1987 
1988  MediaEntry me = MoapModule.GetMediaEntry(part, face);
1989 
1990  // If there is no existing media entry then it can be controlled (in this context, created).
1991  if (null == me)
1992  return true;
1993 
1994 // m_log.DebugFormat(
1995 // "[PERMISSIONS]: Checking CanControlPrimMedia for {0} on {1} face {2} with control permissions {3}",
1996 // agentID, primID, face, me.ControlPermissions);
1997 
1998  return GenericObjectPermission(agentID, part.ParentGroup.UUID, true);
1999  }
2000 
2001  private bool CanInteractWithPrimMedia(UUID agentID, UUID primID, int face)
2002  {
2003 // m_log.DebugFormat(
2004 // "[PERMISSONS]: Performing CanInteractWithPrimMedia check with agentID {0}, primID {1}, face {2}",
2005 // agentID, primID, face);
2006 
2007  if (null == MoapModule)
2008  return false;
2009 
2010  SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
2011  if (null == part)
2012  return false;
2013 
2014  MediaEntry me = MoapModule.GetMediaEntry(part, face);
2015 
2016  // If there is no existing media entry then it can be controlled (in this context, created).
2017  if (null == me)
2018  return true;
2019 
2020 // m_log.DebugFormat(
2021 // "[PERMISSIONS]: Checking CanInteractWithPrimMedia for {0} on {1} face {2} with interact permissions {3}",
2022 // agentID, primID, face, me.InteractPermissions);
2023 
2024  return GenericPrimMediaPermission(part, agentID, me.InteractPermissions);
2025  }
2026 
2027  private bool GenericPrimMediaPermission(SceneObjectPart part, UUID agentID, MediaPermission perms)
2028  {
2029 // if (IsAdministrator(agentID))
2030 // return true;
2031 
2032  if ((perms & MediaPermission.Anyone) == MediaPermission.Anyone)
2033  return true;
2034 
2035  if ((perms & MediaPermission.Owner) == MediaPermission.Owner)
2036  {
2037  if (agentID == part.OwnerID)
2038  return true;
2039  }
2040 
2041  if ((perms & MediaPermission.Group) == MediaPermission.Group)
2042  {
2043  if (IsGroupMember(part.GroupID, agentID, 0))
2044  return true;
2045  }
2046 
2047  return false;
2048  }
2049  }
2050 }
bool GenericObjectPermission(UUID currentUser, UUID objId, bool denyOnLocked)
General permissions checks for any operation involving an object. These supplement more specific chec...
ulong GetGroupPowers(UUID groupID)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
bool IsGridGod(UUID user, Scene scene)
Is the given user a God throughout the grid (not just in the current scene)?
bool GenericParcelPermission(UUID user, ILandObject parcel, ulong groupPowers)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
bool IsGroupMember(UUID groupID, UUID userID, ulong powers)
Checks if the given group is active and if the user is a group member with the powers requested (powe...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
bool IsDeleted
Signals whether this entity was in a scene but has since been removed from it.
Definition: EntityBase.cs:73
UUID GroupID
Unique ID of the Group that owns
Definition: LandData.cs:342
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
PermissionClass GetPermissionClass(UUID user, SceneObjectPart obj)
Returns the type of permissions that the user has over an object.
Inventory Item - contains all the properties associated with an individual inventory piece...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
OpenSim.Framework.PermissionMask PermissionMask
Interactive OpenSim region server
Definition: OpenSim.cs:55
bool IsAdministrator(UUID user)
Is the user regarded as an administrator?
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
uint ParentID
The parent ID of this part.
bool IsGroupOwned
Returns true if the Land Parcel is owned by a group
Definition: LandData.cs:357
bool GenericParcelPermission(UUID user, Vector3 pos, ulong groupPowers)
uint Flags
Parcel settings. Access flags, Fly, NoPush, Voice, Scripts allowed, etc. ParcelFlags ...
Definition: LandData.cs:402
bool IsInLandAccessList(UUID avatar)
Provides methods from manipulating media-on-a-prim
Definition: IMoapModule.cs:37
bool GenericParcelOwnerPermission(UUID user, ILandObject parcel, ulong groupPowers, bool allowEstateManager)
bool IsAttachment
Is this scene object acting as an attachment?
UUID OwnerID
Owner Avatar or Group of the parcel. Naturally, all land masses must be owned by someone ...
Definition: LandData.cs:551