PermissionsModule.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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 OpenSim 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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications.Cache;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. namespace OpenSim.Region.CoreModules.World.Permissions
  38. {
  39. public class PermissionsModule : IRegionModule
  40. {
  41. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. protected Scene m_scene;
  43. #region Constants
  44. // These are here for testing. They will be taken out
  45. //private uint PERM_ALL = (uint)2147483647;
  46. private uint PERM_COPY = (uint)32768;
  47. //private uint PERM_MODIFY = (uint)16384;
  48. private uint PERM_MOVE = (uint)524288;
  49. //private uint PERM_TRANS = (uint)8192;
  50. private uint PERM_LOCKED = (uint)540672;
  51. /// <value>
  52. /// Different user set names that come in from the configuration file.
  53. /// </value>
  54. enum UserSet
  55. {
  56. All,
  57. Administrators
  58. };
  59. #endregion
  60. #region Bypass Permissions / Debug Permissions Stuff
  61. // Bypasses the permissions engine
  62. private bool m_bypassPermissions = true;
  63. private bool m_bypassPermissionsValue = true;
  64. private bool m_propagatePermissions = false;
  65. private bool m_debugPermissions = false;
  66. private bool m_allowGridGods = false;
  67. private bool m_RegionOwnerIsGod = false;
  68. private bool m_ParcelOwnerIsGod = false;
  69. /// <value>
  70. /// The set of users that are allowed to create scripts. This is only active if permissions are not being
  71. /// bypassed. This overrides normal permissions.
  72. /// </value>
  73. private UserSet m_allowedScriptCreators = UserSet.All;
  74. /// <value>
  75. /// The set of users that are allowed to edit (save) scripts. This is only active if
  76. /// permissions are not being bypassed. This overrides normal permissions.-
  77. /// </value>
  78. private UserSet m_allowedScriptEditors = UserSet.All;
  79. #endregion
  80. #region IRegionModule Members
  81. public void Initialise(Scene scene, IConfigSource config)
  82. {
  83. m_scene = scene;
  84. IConfig myConfig = config.Configs["Startup"];
  85. string permissionModules = myConfig.GetString("permissionmodules", "DefaultPermissionsModule");
  86. List<string> modules=new List<string>(permissionModules.Split(','));
  87. if (!modules.Contains("DefaultPermissionsModule"))
  88. return;
  89. m_allowGridGods = myConfig.GetBoolean("allow_grid_gods", false);
  90. m_bypassPermissions = !myConfig.GetBoolean("serverside_object_permissions", true);
  91. m_propagatePermissions = myConfig.GetBoolean("propagate_permissions", true);
  92. m_RegionOwnerIsGod = myConfig.GetBoolean("region_owner_is_god", true);
  93. m_ParcelOwnerIsGod = myConfig.GetBoolean("parcel_owner_is_god", true);
  94. m_allowedScriptCreators
  95. = ParseUserSetConfigSetting(myConfig, "allowed_script_creators", m_allowedScriptCreators);
  96. m_allowedScriptEditors
  97. = ParseUserSetConfigSetting(myConfig, "allowed_script_editors", m_allowedScriptEditors);
  98. if (m_bypassPermissions)
  99. m_log.Info("[PERMISSIONS]: serviceside_object_permissions = false in ini file so disabling all region service permission checks");
  100. else
  101. m_log.Debug("[PERMISSIONS]: Enabling all region service permission checks");
  102. //Register functions with Scene External Checks!
  103. m_scene.Permissions.AddBypassPermissionsHandler(BypassPermissions); //FULLY IMPLEMENTED
  104. m_scene.Permissions.AddSetBypassPermissionsHandler(SetBypassPermissions); //FULLY IMPLEMENTED
  105. m_scene.Permissions.AddPropagatePermissionsHandler(PropagatePermissions); //FULLY IMPLEMENTED
  106. m_scene.Permissions.AddGenerateClientFlagsHandler(GenerateClientFlags); //NOT YET FULLY IMPLEMENTED
  107. m_scene.Permissions.AddAbandonParcelHandler(CanAbandonParcel); //FULLY IMPLEMENTED
  108. m_scene.Permissions.AddReclaimParcelHandler(CanReclaimParcel); //FULLY IMPLEMENTED
  109. m_scene.Permissions.AddIsGodHandler(IsGod); //FULLY IMPLEMENTED
  110. m_scene.Permissions.AddDuplicateObjectHandler(CanDuplicateObject); //FULLY IMPLEMENTED
  111. m_scene.Permissions.AddDeleteObjectHandler(CanDeleteObject); //MAYBE FULLY IMPLEMENTED
  112. m_scene.Permissions.AddEditObjectHandler(CanEditObject);//MAYBE FULLY IMPLEMENTED
  113. m_scene.Permissions.AddEditParcelHandler(CanEditParcel); //FULLY IMPLEMENTED
  114. m_scene.Permissions.AddInstantMessageHandler(CanInstantMessage); //FULLY IMPLEMENTED
  115. m_scene.Permissions.AddInventoryTransferHandler(CanInventoryTransfer); //NOT YET IMPLEMENTED
  116. m_scene.Permissions.AddIssueEstateCommandHandler(CanIssueEstateCommand); //FULLY IMPLEMENTED
  117. m_scene.Permissions.AddMoveObjectHandler(CanMoveObject); //HOPEFULLY FULLY IMPLEMENTED
  118. m_scene.Permissions.AddObjectEntryHandler(CanObjectEntry); //FULLY IMPLEMENTED
  119. m_scene.Permissions.AddReturnObjectHandler(CanReturnObject); //NOT YET IMPLEMENTED
  120. m_scene.Permissions.AddRezObjectHandler(CanRezObject); //HOPEFULLY FULLY IMPLEMENTED
  121. m_scene.Permissions.AddRunConsoleCommandHandler(CanRunConsoleCommand); //FULLY IMPLEMENTED
  122. m_scene.Permissions.AddRunScriptHandler(CanRunScript); //NOT YET IMPLEMENTED
  123. m_scene.Permissions.AddSellParcelHandler(CanSellParcel); //FULLY IMPLEMENTED
  124. m_scene.Permissions.AddTakeObjectHandler(CanTakeObject); //FULLY IMPLEMENTED
  125. m_scene.Permissions.AddTakeCopyObjectHandler(CanTakeCopyObject); //FULLY IMPLEMENTED
  126. m_scene.Permissions.AddTerraformLandHandler(CanTerraformLand); //FULL IMPLEMENTED (POINT ONLY!!! NOT AREA!!!)
  127. m_scene.Permissions.AddCanLinkObjectHandler(CanLinkObject); //NOT YET IMPLEMENTED
  128. m_scene.Permissions.AddCanDelinkObjectHandler(CanDelinkObject); //NOT YET IMPLEMENTED
  129. m_scene.Permissions.AddCanBuyLandHandler(CanBuyLand); //NOT YET IMPLEMENTED
  130. m_scene.Permissions.AddViewNotecardHandler(CanViewNotecard); //NOT YET IMPLEMENTED
  131. m_scene.Permissions.AddViewScriptHandler(CanViewScript); //NOT YET IMPLEMENTED
  132. m_scene.Permissions.AddEditNotecardHandler(CanEditNotecard); //NOT YET IMPLEMENTED
  133. m_scene.Permissions.AddEditScriptHandler(CanEditScript); //NOT YET IMPLEMENTED
  134. m_scene.Permissions.AddCanCreateObjectInventoryHandler(CanCreateObjectInventory); //NOT IMPLEMENTED HERE
  135. m_scene.Permissions.AddEditObjectInventoryHandler(CanEditObjectInventory);//MAYBE FULLY IMPLEMENTED
  136. m_scene.Permissions.AddCanCopyObjectInventoryHandler(CanCopyObjectInventory); //NOT YET IMPLEMENTED
  137. m_scene.Permissions.AddCanDeleteObjectInventoryHandler(CanDeleteObjectInventory); //NOT YET IMPLEMENTED
  138. m_scene.Permissions.AddResetScriptHandler(CanResetScript);
  139. m_scene.Permissions.AddCanCreateUserInventoryHandler(CanCreateUserInventory); //NOT YET IMPLEMENTED
  140. m_scene.Permissions.AddCanCopyUserInventoryHandler(CanCopyUserInventory); //NOT YET IMPLEMENTED
  141. m_scene.Permissions.AddCanEditUserInventoryHandler(CanEditUserInventory); //NOT YET IMPLEMENTED
  142. m_scene.Permissions.AddCanDeleteUserInventoryHandler(CanDeleteUserInventory); //NOT YET IMPLEMENTED
  143. m_scene.Permissions.AddCanTeleportHandler(CanTeleport); //NOT YET IMPLEMENTED
  144. m_scene.AddCommand(this, "bypass permissions",
  145. "bypass permissions <true / false>",
  146. "Bypass permission checks",
  147. HandleBypassPermissions);
  148. m_scene.AddCommand(this, "force permissions",
  149. "force permissions <true / false>",
  150. "Force permissions on or off",
  151. HandleForcePermissions);
  152. m_scene.AddCommand(this, "debug permissions",
  153. "debug permissions <true / false>",
  154. "Enable permissions debugging",
  155. HandleDebugPermissions);
  156. }
  157. public void HandleBypassPermissions(string module, string[] args)
  158. {
  159. if (m_scene.ConsoleScene() != null &&
  160. m_scene.ConsoleScene() != m_scene)
  161. {
  162. return;
  163. }
  164. if (args.Length > 2)
  165. {
  166. bool val;
  167. if (!bool.TryParse(args[2], out val))
  168. return;
  169. m_bypassPermissions = val;
  170. m_log.InfoFormat(
  171. "[PERMISSIONS]: Set permissions bypass to {0} for {1}",
  172. m_bypassPermissions, m_scene.RegionInfo.RegionName);
  173. }
  174. }
  175. public void HandleForcePermissions(string module, string[] args)
  176. {
  177. if (m_scene.ConsoleScene() != null &&
  178. m_scene.ConsoleScene() != m_scene)
  179. {
  180. return;
  181. }
  182. if (!m_bypassPermissions)
  183. {
  184. m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first");
  185. return;
  186. }
  187. if (args.Length > 2)
  188. {
  189. bool val;
  190. if (!bool.TryParse(args[2], out val))
  191. return;
  192. m_bypassPermissionsValue = val;
  193. m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName);
  194. }
  195. }
  196. public void HandleDebugPermissions(string module, string[] args)
  197. {
  198. if (m_scene.ConsoleScene() != null &&
  199. m_scene.ConsoleScene() != m_scene)
  200. {
  201. return;
  202. }
  203. if (args.Length > 2)
  204. {
  205. bool val;
  206. if (!bool.TryParse(args[2], out val))
  207. return;
  208. m_debugPermissions = val;
  209. m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName);
  210. }
  211. }
  212. public void PostInitialise()
  213. {
  214. }
  215. public void Close()
  216. {
  217. }
  218. public string Name
  219. {
  220. get { return "PermissionsModule"; }
  221. }
  222. public bool IsSharedModule
  223. {
  224. get { return false; }
  225. }
  226. #endregion
  227. #region Helper Functions
  228. protected void SendPermissionError(UUID user, string reason)
  229. {
  230. m_scene.EventManager.TriggerPermissionError(user, reason);
  231. }
  232. protected void DebugPermissionInformation(string permissionCalled)
  233. {
  234. if (m_debugPermissions)
  235. m_log.Debug("[PERMISSIONS]: " + permissionCalled + " was called from " + m_scene.RegionInfo.RegionName);
  236. }
  237. /// <summary>
  238. /// Parse a user set configuration setting
  239. /// </summary>
  240. /// <param name="config"></param>
  241. /// <param name="settingName"></param>
  242. /// <param name="defaultValue">The default value for this attribute</param>
  243. /// <returns>The parsed value</returns>
  244. private static UserSet ParseUserSetConfigSetting(IConfig config, string settingName, UserSet defaultValue)
  245. {
  246. UserSet userSet = defaultValue;
  247. string rawSetting = config.GetString(settingName, defaultValue.ToString());
  248. // Temporary measure to allow 'gods' to be specified in config for consistency's sake. In the long term
  249. // this should disappear.
  250. if ("gods" == rawSetting.ToLower())
  251. rawSetting = UserSet.Administrators.ToString();
  252. // Doing it this was so that we can do a case insensitive conversion
  253. try
  254. {
  255. userSet = (UserSet)Enum.Parse(typeof(UserSet), rawSetting, true);
  256. }
  257. catch
  258. {
  259. m_log.ErrorFormat(
  260. "[PERMISSIONS]: {0} is not a valid {1} value, setting to {2}",
  261. rawSetting, settingName, userSet);
  262. }
  263. m_log.DebugFormat("[PERMISSIONS]: {0} {1}", settingName, userSet);
  264. return userSet;
  265. }
  266. /// <summary>
  267. /// Is the given user an administrator (in other words, a god)?
  268. /// </summary>
  269. /// <param name="user"></param>
  270. /// <returns></returns>
  271. protected bool IsAdministrator(UUID user)
  272. {
  273. if (m_scene.RegionInfo.MasterAvatarAssignedUUID != UUID.Zero)
  274. {
  275. if (m_RegionOwnerIsGod && (m_scene.RegionInfo.MasterAvatarAssignedUUID == user))
  276. return true;
  277. }
  278. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  279. {
  280. if (m_scene.RegionInfo.EstateSettings.EstateOwner == user)
  281. return true;
  282. }
  283. if (m_allowGridGods)
  284. {
  285. CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(user);
  286. if (profile != null && profile.UserProfile != null)
  287. {
  288. if (profile.UserProfile.GodLevel >= 200)
  289. return true;
  290. }
  291. //else
  292. //{
  293. // m_log.ErrorFormat("[PERMISSIONS]: Could not find user {0} for administrator check", user);
  294. //}
  295. }
  296. return false;
  297. }
  298. protected bool IsEstateManager(UUID user)
  299. {
  300. return m_scene.RegionInfo.EstateSettings.IsEstateManager(user);
  301. }
  302. #endregion
  303. public bool PropagatePermissions()
  304. {
  305. if (m_bypassPermissions)
  306. return false;
  307. return m_propagatePermissions;
  308. }
  309. public bool BypassPermissions()
  310. {
  311. return m_bypassPermissions;
  312. }
  313. public void SetBypassPermissions(bool value)
  314. {
  315. m_bypassPermissions=value;
  316. }
  317. #region Object Permissions
  318. public uint GenerateClientFlags(UUID user, UUID objID)
  319. {
  320. // Here's the way this works,
  321. // ObjectFlags and Permission flags are two different enumerations
  322. // ObjectFlags, however, tells the client to change what it will allow the user to do.
  323. // So, that means that all of the permissions type ObjectFlags are /temporary/ and only
  324. // supposed to be set when customizing the objectflags for the client.
  325. // These temporary objectflags get computed and added in this function based on the
  326. // Permission mask that's appropriate!
  327. // Outside of this method, they should never be added to objectflags!
  328. // -teravus
  329. SceneObjectPart task = m_scene.GetSceneObjectPart(objID);
  330. // this shouldn't ever happen.. return no permissions/objectflags.
  331. if (task == null)
  332. return (uint)0;
  333. uint objflags = task.GetEffectiveObjectFlags();
  334. UUID objectOwner = task.OwnerID;
  335. // Remove any of the objectFlags that are temporary. These will get added back if appropriate
  336. // in the next bit of code
  337. // libomv will moan about PrimFlags.ObjectYouOfficer being
  338. // deprecated
  339. #pragma warning disable 0612
  340. objflags &= (uint)
  341. ~(PrimFlags.ObjectCopy | // Tells client you can copy the object
  342. PrimFlags.ObjectModify | // tells client you can modify the object
  343. PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
  344. PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
  345. PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
  346. PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
  347. PrimFlags.ObjectOwnerModify | // Tells client that you're the owner of the object
  348. PrimFlags.ObjectYouOfficer // Tells client that you've got group object editing permission. Used when ObjectGroupOwned is set
  349. );
  350. #pragma warning restore 0612
  351. // Creating the three ObjectFlags options for this method to choose from.
  352. // Customize the OwnerMask
  353. uint objectOwnerMask = ApplyObjectModifyMasks(task.OwnerMask, objflags);
  354. objectOwnerMask |= (uint)PrimFlags.ObjectYouOwner | (uint)PrimFlags.ObjectAnyOwner | (uint)PrimFlags.ObjectOwnerModify;
  355. // Customize the GroupMask
  356. // uint objectGroupMask = ApplyObjectModifyMasks(task.GroupMask, objflags);
  357. // Customize the EveryoneMask
  358. uint objectEveryoneMask = ApplyObjectModifyMasks(task.EveryoneMask, objflags);
  359. // Hack to allow collaboration until Groups and Group Permissions are implemented
  360. if ((objectEveryoneMask & (uint)PrimFlags.ObjectMove) != 0)
  361. objectEveryoneMask |= (uint)PrimFlags.ObjectModify;
  362. if (m_bypassPermissions)
  363. return objectOwnerMask;
  364. // Object owners should be able to edit their own content
  365. if (user == objectOwner)
  366. {
  367. return objectOwnerMask;
  368. }
  369. // Users should be able to edit what is over their land.
  370. ILandObject parcel = m_scene.LandChannel.GetLandObject(task.AbsolutePosition.X, task.AbsolutePosition.Y);
  371. if (parcel != null && parcel.landData.OwnerID == user && m_ParcelOwnerIsGod)
  372. return objectOwnerMask;
  373. // Admin objects should not be editable by the above
  374. if (IsAdministrator(objectOwner))
  375. return objectEveryoneMask;
  376. // Estate users should be able to edit anything in the sim
  377. if (IsEstateManager(user) && m_RegionOwnerIsGod)
  378. return objectOwnerMask;
  379. // Admin should be able to edit anything in the sim (including admin objects)
  380. if (IsAdministrator(user))
  381. return objectOwnerMask;
  382. return objectEveryoneMask;
  383. }
  384. private uint ApplyObjectModifyMasks(uint setPermissionMask, uint objectFlagsMask)
  385. {
  386. // We are adding the temporary objectflags to the object's objectflags based on the
  387. // permission flag given. These change the F flags on the client.
  388. if ((setPermissionMask & (uint)PermissionMask.Copy) != 0)
  389. {
  390. objectFlagsMask |= (uint)PrimFlags.ObjectCopy;
  391. }
  392. if ((setPermissionMask & (uint)PermissionMask.Move) != 0)
  393. {
  394. objectFlagsMask |= (uint)PrimFlags.ObjectMove;
  395. }
  396. if ((setPermissionMask & (uint)PermissionMask.Modify) != 0)
  397. {
  398. objectFlagsMask |= (uint)PrimFlags.ObjectModify;
  399. }
  400. if ((setPermissionMask & (uint)PermissionMask.Transfer) != 0)
  401. {
  402. objectFlagsMask |= (uint)PrimFlags.ObjectTransfer;
  403. }
  404. return objectFlagsMask;
  405. }
  406. /// <summary>
  407. /// General permissions checks for any operation involving an object. These supplement more specific checks
  408. /// implemented by callers.
  409. /// </summary>
  410. /// <param name="currentUser"></param>
  411. /// <param name="objId"></param>
  412. /// <param name="denyOnLocked"></param>
  413. /// <returns></returns>
  414. protected bool GenericObjectPermission(UUID currentUser, UUID objId, bool denyOnLocked)
  415. {
  416. // Default: deny
  417. bool permission = false;
  418. bool locked = false;
  419. if (!m_scene.Entities.ContainsKey(objId))
  420. {
  421. return false;
  422. }
  423. // If it's not an object, we cant edit it.
  424. if ((!(m_scene.Entities[objId] is SceneObjectGroup)))
  425. {
  426. return false;
  427. }
  428. SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objId];
  429. UUID objectOwner = group.OwnerID;
  430. locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
  431. // People shouldn't be able to do anything with locked objects, except the Administrator
  432. // The 'set permissions' runs through a different permission check, so when an object owner
  433. // sets an object locked, the only thing that they can do is unlock it.
  434. //
  435. // Nobody but the object owner can set permissions on an object
  436. //
  437. if (locked && (!IsAdministrator(currentUser)) && denyOnLocked)
  438. {
  439. return false;
  440. }
  441. // Object owners should be able to edit their own content
  442. if (currentUser == objectOwner)
  443. {
  444. permission = true;
  445. }
  446. else if (group.IsAttachment)
  447. {
  448. permission = false;
  449. }
  450. // Users should be able to edit what is over their land.
  451. ILandObject parcel = m_scene.LandChannel.GetLandObject(group.AbsolutePosition.X, group.AbsolutePosition.Y);
  452. if ((parcel != null) && (parcel.landData.OwnerID == currentUser))
  453. {
  454. permission = true;
  455. }
  456. // Estate users should be able to edit anything in the sim
  457. if (IsEstateManager(currentUser))
  458. {
  459. permission = true;
  460. }
  461. // Admin objects should not be editable by the above
  462. if (IsAdministrator(objectOwner))
  463. {
  464. permission = false;
  465. }
  466. // Admin should be able to edit anything in the sim (including admin objects)
  467. if (IsAdministrator(currentUser))
  468. {
  469. permission = true;
  470. }
  471. return permission;
  472. }
  473. #endregion
  474. #region Generic Permissions
  475. protected bool GenericCommunicationPermission(UUID user, UUID target)
  476. {
  477. // Setting this to true so that cool stuff can happen until we define what determines Generic Communication Permission
  478. bool permission = true;
  479. string reason = "Only registered users may communicate with another account.";
  480. // Uhh, we need to finish this before we enable it.. because it's blocking all sorts of goodies and features
  481. if (IsAdministrator(user))
  482. permission = true;
  483. if (IsEstateManager(user))
  484. permission = true;
  485. if (!permission)
  486. SendPermissionError(user, reason);
  487. return permission;
  488. }
  489. public bool GenericEstatePermission(UUID user)
  490. {
  491. // Default: deny
  492. bool permission = false;
  493. // Estate admins should be able to use estate tools
  494. if (IsEstateManager(user))
  495. permission = true;
  496. // Administrators always have permission
  497. if (IsAdministrator(user))
  498. permission = true;
  499. return permission;
  500. }
  501. protected bool GenericParcelPermission(UUID user, ILandObject parcel)
  502. {
  503. bool permission = false;
  504. if (parcel.landData.OwnerID == user)
  505. {
  506. permission = true;
  507. }
  508. if (parcel.landData.IsGroupOwned)
  509. {
  510. // TODO: Need to do some extra checks here. Requires group code.
  511. }
  512. if (IsEstateManager(user))
  513. {
  514. permission = true;
  515. }
  516. if (IsAdministrator(user))
  517. {
  518. permission = true;
  519. }
  520. return permission;
  521. }
  522. protected bool GenericParcelPermission(UUID user, Vector3 pos)
  523. {
  524. ILandObject parcel = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
  525. if (parcel == null) return false;
  526. return GenericParcelPermission(user, parcel);
  527. }
  528. #endregion
  529. #region Permission Checks
  530. private bool CanAbandonParcel(UUID user, ILandObject parcel, Scene scene)
  531. {
  532. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  533. if (m_bypassPermissions) return m_bypassPermissionsValue;
  534. return GenericParcelPermission(user, parcel);
  535. }
  536. private bool CanReclaimParcel(UUID user, ILandObject parcel, Scene scene)
  537. {
  538. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  539. if (m_bypassPermissions) return m_bypassPermissionsValue;
  540. return GenericParcelPermission(user, parcel);
  541. }
  542. private bool IsGod(UUID user, Scene scene)
  543. {
  544. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  545. if (m_bypassPermissions) return m_bypassPermissionsValue;
  546. return IsAdministrator(user);
  547. }
  548. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
  549. {
  550. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  551. if (m_bypassPermissions) return m_bypassPermissionsValue;
  552. if (!GenericObjectPermission(owner, objectID, true))
  553. {
  554. //They can't even edit the object
  555. return false;
  556. }
  557. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  558. if (part == null)
  559. return false;
  560. if ((part.OwnerMask & PERM_COPY) == 0)
  561. return false;
  562. if ((part.ParentGroup.GetEffectivePermissions() & PERM_COPY) == 0)
  563. return false;
  564. //If they can rez, they can duplicate
  565. return CanRezObject(objectCount, owner, objectPosition, scene);
  566. }
  567. private bool CanDeleteObject(UUID objectID, UUID deleter, Scene scene)
  568. {
  569. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  570. if (m_bypassPermissions) return m_bypassPermissionsValue;
  571. return GenericObjectPermission(deleter, objectID, false);
  572. }
  573. private bool CanEditObject(UUID objectID, UUID editorID, Scene scene)
  574. {
  575. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  576. if (m_bypassPermissions) return m_bypassPermissionsValue;
  577. return GenericObjectPermission(editorID, objectID, false);
  578. }
  579. private bool CanEditObjectInventory(UUID objectID, UUID editorID, Scene scene)
  580. {
  581. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  582. if (m_bypassPermissions) return m_bypassPermissionsValue;
  583. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  584. // If we selected a sub-prim to edit, the objectID won't represent the object, but only a part.
  585. // We have to check the permissions of the group, though.
  586. if (part.ParentID != 0)
  587. {
  588. objectID = part.ParentUUID;
  589. part = m_scene.GetSceneObjectPart(objectID);
  590. }
  591. // TODO: add group support!
  592. //
  593. if (part.OwnerID != editorID)
  594. return false;
  595. return GenericObjectPermission(editorID, objectID, false);
  596. }
  597. private bool CanEditParcel(UUID user, ILandObject parcel, Scene scene)
  598. {
  599. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  600. if (m_bypassPermissions) return m_bypassPermissionsValue;
  601. return GenericParcelPermission(user, parcel);
  602. }
  603. /// <summary>
  604. /// Check whether the specified user can edit the given script
  605. /// </summary>
  606. /// <param name="script"></param>
  607. /// <param name="objectID"></param>
  608. /// <param name="user"></param>
  609. /// <param name="scene"></param>
  610. /// <returns></returns>
  611. private bool CanEditScript(UUID script, UUID objectID, UUID user, Scene scene)
  612. {
  613. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  614. if (m_bypassPermissions) return m_bypassPermissionsValue;
  615. if (m_allowedScriptEditors == UserSet.Administrators && !IsAdministrator(user))
  616. return false;
  617. // Ordinarily, if you can view it, you can edit it
  618. // There is no viewing a no mod script
  619. //
  620. return CanViewScript(script, objectID, user, scene);
  621. }
  622. /// <summary>
  623. /// Check whether the specified user can edit the given notecard
  624. /// </summary>
  625. /// <param name="notecard"></param>
  626. /// <param name="objectID"></param>
  627. /// <param name="user"></param>
  628. /// <param name="scene"></param>
  629. /// <returns></returns>
  630. private bool CanEditNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  631. {
  632. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  633. if (m_bypassPermissions) return m_bypassPermissionsValue;
  634. if (objectID == UUID.Zero) // User inventory
  635. {
  636. CachedUserInfo userInfo =
  637. scene.CommsManager.UserProfileCacheService.GetUserDetails(user);
  638. if (userInfo == null)
  639. {
  640. m_log.ErrorFormat("[PERMISSIONS]: Could not find user {0} for edit notecard check", user);
  641. return false;
  642. }
  643. if (userInfo.RootFolder == null)
  644. return false;
  645. InventoryItemBase assetRequestItem = userInfo.RootFolder.FindItem(notecard);
  646. if (assetRequestItem == null) // Library item
  647. {
  648. assetRequestItem = scene.CommsManager.UserProfileCacheService.LibraryRoot.FindItem(notecard);
  649. if (assetRequestItem != null) // Implicitly readable
  650. return true;
  651. }
  652. // Notecards must be both mod and copy to be saveable
  653. // This is because of they're not copy, you can't read
  654. // them, and if they're not mod, well, then they're
  655. // not mod. Duh.
  656. //
  657. if ((assetRequestItem.CurrentPermissions &
  658. ((uint)PermissionMask.Modify |
  659. (uint)PermissionMask.Copy)) !=
  660. ((uint)PermissionMask.Modify |
  661. (uint)PermissionMask.Copy))
  662. return false;
  663. }
  664. else // Prim inventory
  665. {
  666. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  667. if (part == null)
  668. return false;
  669. if (part.OwnerID != user)
  670. return false;
  671. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  672. return false;
  673. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  674. if (ti == null)
  675. return false;
  676. if (ti.OwnerID != user)
  677. return false;
  678. // Require full perms
  679. if ((ti.CurrentPermissions &
  680. ((uint)PermissionMask.Modify |
  681. (uint)PermissionMask.Copy)) !=
  682. ((uint)PermissionMask.Modify |
  683. (uint)PermissionMask.Copy))
  684. return false;
  685. }
  686. return true;
  687. }
  688. private bool CanInstantMessage(UUID user, UUID target, Scene startScene)
  689. {
  690. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  691. if (m_bypassPermissions) return m_bypassPermissionsValue;
  692. // If the sender is an object, check owner instead
  693. //
  694. SceneObjectPart part = startScene.GetSceneObjectPart(user);
  695. if (part != null)
  696. user = part.OwnerID;
  697. return GenericCommunicationPermission(user, target);
  698. }
  699. private bool CanInventoryTransfer(UUID user, UUID target, Scene startScene)
  700. {
  701. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  702. if (m_bypassPermissions) return m_bypassPermissionsValue;
  703. return GenericCommunicationPermission(user, target);
  704. }
  705. private bool CanIssueEstateCommand(UUID user, Scene requestFromScene, bool ownerCommand)
  706. {
  707. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  708. if (m_bypassPermissions) return m_bypassPermissionsValue;
  709. if (IsAdministrator(user))
  710. return true;
  711. if (m_scene.RegionInfo.EstateSettings.IsEstateOwner(user))
  712. return true;
  713. if (ownerCommand)
  714. return false;
  715. return GenericEstatePermission(user);
  716. }
  717. private bool CanMoveObject(UUID objectID, UUID moverID, Scene scene)
  718. {
  719. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  720. if (m_bypassPermissions)
  721. {
  722. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  723. if (part.OwnerID != moverID)
  724. {
  725. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  726. {
  727. if (part.ParentGroup.IsAttachment)
  728. return false;
  729. }
  730. }
  731. return m_bypassPermissionsValue;
  732. }
  733. bool permission = GenericObjectPermission(moverID, objectID, true);
  734. if (!permission)
  735. {
  736. if (!m_scene.Entities.ContainsKey(objectID))
  737. {
  738. return false;
  739. }
  740. // The client
  741. // may request to edit linked parts, and therefore, it needs
  742. // to also check for SceneObjectPart
  743. // If it's not an object, we cant edit it.
  744. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  745. {
  746. return false;
  747. }
  748. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  749. // UUID taskOwner = null;
  750. // Added this because at this point in time it wouldn't be wise for
  751. // the administrator object permissions to take effect.
  752. // UUID objectOwner = task.OwnerID;
  753. // Anyone can move
  754. if ((task.RootPart.EveryoneMask & PERM_MOVE) != 0)
  755. permission = true;
  756. // Locked
  757. if ((task.RootPart.OwnerMask & PERM_LOCKED) == 0)
  758. permission = false;
  759. }
  760. else
  761. {
  762. bool locked = false;
  763. if (!m_scene.Entities.ContainsKey(objectID))
  764. {
  765. return false;
  766. }
  767. // If it's not an object, we cant edit it.
  768. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  769. {
  770. return false;
  771. }
  772. SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objectID];
  773. UUID objectOwner = group.OwnerID;
  774. locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
  775. // This is an exception to the generic object permission.
  776. // Administrators who lock their objects should not be able to move them,
  777. // however generic object permission should return true.
  778. // This keeps locked objects from being affected by random click + drag actions by accident
  779. // and allows the administrator to grab or delete a locked object.
  780. // Administrators and estate managers are still able to click+grab locked objects not
  781. // owned by them in the scene
  782. // This is by design.
  783. if (locked && (moverID == objectOwner))
  784. return false;
  785. }
  786. return permission;
  787. }
  788. private bool CanObjectEntry(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  789. {
  790. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  791. if (m_bypassPermissions) return m_bypassPermissionsValue;
  792. if ((newPoint.X > 257f || newPoint.X < -1f || newPoint.Y > 257f || newPoint.Y < -1f))
  793. {
  794. return true;
  795. }
  796. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  797. ILandObject land = m_scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  798. if (!enteringRegion)
  799. {
  800. ILandObject fromland = m_scene.LandChannel.GetLandObject(task.AbsolutePosition.X, task.AbsolutePosition.Y);
  801. if (fromland == land) // Not entering
  802. return true;
  803. }
  804. if (land == null)
  805. {
  806. return false;
  807. }
  808. if ((land.landData.Flags & ((int)Parcel.ParcelFlags.AllowAPrimitiveEntry)) != 0)
  809. {
  810. return true;
  811. }
  812. //TODO: check for group rights
  813. if (!m_scene.Entities.ContainsKey(objectID))
  814. {
  815. return false;
  816. }
  817. // If it's not an object, we cant edit it.
  818. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  819. {
  820. return false;
  821. }
  822. if (GenericParcelPermission(task.OwnerID, newPoint))
  823. {
  824. return true;
  825. }
  826. //Otherwise, false!
  827. return false;
  828. }
  829. private bool CanReturnObject(UUID objectID, UUID returnerID, Scene scene)
  830. {
  831. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  832. if (m_bypassPermissions) return m_bypassPermissionsValue;
  833. return GenericObjectPermission(returnerID, objectID, false);
  834. }
  835. private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
  836. {
  837. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  838. if (m_bypassPermissions) return m_bypassPermissionsValue;
  839. bool permission = false;
  840. ILandObject land = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  841. if (land == null) return false;
  842. if ((land.landData.Flags & ((int)Parcel.ParcelFlags.CreateObjects)) ==
  843. (int)Parcel.ParcelFlags.CreateObjects)
  844. permission = true;
  845. //TODO: check for group rights
  846. if (IsAdministrator(owner))
  847. {
  848. permission = true;
  849. }
  850. if (GenericParcelPermission(owner, objectPosition))
  851. {
  852. permission = true;
  853. }
  854. return permission;
  855. }
  856. private bool CanRunConsoleCommand(UUID user, Scene requestFromScene)
  857. {
  858. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  859. if (m_bypassPermissions) return m_bypassPermissionsValue;
  860. return IsAdministrator(user);
  861. }
  862. private bool CanRunScript(UUID script, UUID objectID, UUID user, Scene scene)
  863. {
  864. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  865. if (m_bypassPermissions) return m_bypassPermissionsValue;
  866. return true;
  867. }
  868. private bool CanSellParcel(UUID user, ILandObject parcel, Scene scene)
  869. {
  870. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  871. if (m_bypassPermissions) return m_bypassPermissionsValue;
  872. return GenericParcelPermission(user, parcel);
  873. }
  874. private bool CanTakeObject(UUID objectID, UUID stealer, Scene scene)
  875. {
  876. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  877. if (m_bypassPermissions) return m_bypassPermissionsValue;
  878. return GenericObjectPermission(stealer,objectID, false);
  879. }
  880. private bool CanTakeCopyObject(UUID objectID, UUID userID, Scene inScene)
  881. {
  882. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  883. if (m_bypassPermissions) return m_bypassPermissionsValue;
  884. bool permission = GenericObjectPermission(userID, objectID,false);
  885. if (!permission)
  886. {
  887. if (!m_scene.Entities.ContainsKey(objectID))
  888. {
  889. return false;
  890. }
  891. // If it's not an object, we cant edit it.
  892. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  893. {
  894. return false;
  895. }
  896. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  897. // UUID taskOwner = null;
  898. // Added this because at this point in time it wouldn't be wise for
  899. // the administrator object permissions to take effect.
  900. // UUID objectOwner = task.OwnerID;
  901. if ((task.RootPart.EveryoneMask & PERM_COPY) != 0)
  902. permission = true;
  903. if ((task.GetEffectivePermissions() & PERM_COPY) == 0)
  904. permission = false;
  905. }
  906. else
  907. {
  908. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  909. if ((task.GetEffectivePermissions() & PERM_COPY) == 0)
  910. permission = false;
  911. }
  912. return permission;
  913. }
  914. private bool CanTerraformLand(UUID user, Vector3 position, Scene requestFromScene)
  915. {
  916. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  917. if (m_bypassPermissions) return m_bypassPermissionsValue;
  918. // Estate override
  919. if (GenericEstatePermission(user))
  920. return true;
  921. float X = position.X;
  922. float Y = position.Y;
  923. if (X > 255)
  924. X = 255;
  925. if (Y > 255)
  926. Y = 255;
  927. if (X < 0)
  928. X = 0;
  929. if (Y < 0)
  930. Y = 0;
  931. ILandObject parcel = m_scene.LandChannel.GetLandObject(X, Y);
  932. if (parcel == null)
  933. return false;
  934. // Others allowed to terraform?
  935. if ((parcel.landData.Flags & ((int)Parcel.ParcelFlags.AllowTerraform)) != 0)
  936. return true;
  937. // Land owner can terraform too
  938. if (parcel != null && GenericParcelPermission(user, parcel))
  939. return true;
  940. return false;
  941. }
  942. /// <summary>
  943. /// Check whether the specified user can view the given script
  944. /// </summary>
  945. /// <param name="script"></param>
  946. /// <param name="objectID"></param>
  947. /// <param name="user"></param>
  948. /// <param name="scene"></param>
  949. /// <returns></returns>
  950. private bool CanViewScript(UUID script, UUID objectID, UUID user, Scene scene)
  951. {
  952. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  953. if (m_bypassPermissions) return m_bypassPermissionsValue;
  954. if (objectID == UUID.Zero) // User inventory
  955. {
  956. CachedUserInfo userInfo =
  957. scene.CommsManager.UserProfileCacheService.GetUserDetails(user);
  958. if (userInfo == null)
  959. {
  960. m_log.ErrorFormat("[PERMISSIONS]: Could not find user {0} for administrator check", user);
  961. return false;
  962. }
  963. if (userInfo.RootFolder == null)
  964. return false;
  965. InventoryItemBase assetRequestItem = userInfo.RootFolder.FindItem(script);
  966. if (assetRequestItem == null) // Library item
  967. {
  968. assetRequestItem = m_scene.CommsManager.UserProfileCacheService.LibraryRoot.FindItem(script);
  969. if (assetRequestItem != null) // Implicitly readable
  970. return true;
  971. }
  972. // SL is rather harebrained here. In SL, a script you
  973. // have mod/copy no trans is readable. This subverts
  974. // permissions, but is used in some products, most
  975. // notably Hippo door plugin and HippoRent 5 networked
  976. // prim counter.
  977. // To enable this broken SL-ism, remove Transfer from
  978. // the below expressions.
  979. // Trying to improve on SL perms by making a script
  980. // readable only if it's really full perms
  981. //
  982. if ((assetRequestItem.CurrentPermissions &
  983. ((uint)PermissionMask.Modify |
  984. (uint)PermissionMask.Copy |
  985. (uint)PermissionMask.Transfer)) !=
  986. ((uint)PermissionMask.Modify |
  987. (uint)PermissionMask.Copy |
  988. (uint)PermissionMask.Transfer))
  989. return false;
  990. }
  991. else // Prim inventory
  992. {
  993. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  994. if (part == null)
  995. return false;
  996. if (part.OwnerID != user)
  997. return false;
  998. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  999. return false;
  1000. TaskInventoryItem ti = part.Inventory.GetInventoryItem(script);
  1001. if (ti == null)
  1002. return false;
  1003. if (ti.OwnerID != user)
  1004. return false;
  1005. // Require full perms
  1006. if ((ti.CurrentPermissions &
  1007. ((uint)PermissionMask.Modify |
  1008. (uint)PermissionMask.Copy |
  1009. (uint)PermissionMask.Transfer)) !=
  1010. ((uint)PermissionMask.Modify |
  1011. (uint)PermissionMask.Copy |
  1012. (uint)PermissionMask.Transfer))
  1013. return false;
  1014. }
  1015. return true;
  1016. }
  1017. /// <summary>
  1018. /// Check whether the specified user can view the given notecard
  1019. /// </summary>
  1020. /// <param name="script"></param>
  1021. /// <param name="objectID"></param>
  1022. /// <param name="user"></param>
  1023. /// <param name="scene"></param>
  1024. /// <returns></returns>
  1025. private bool CanViewNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  1026. {
  1027. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1028. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1029. if (objectID == UUID.Zero) // User inventory
  1030. {
  1031. CachedUserInfo userInfo =
  1032. scene.CommsManager.UserProfileCacheService.GetUserDetails(user);
  1033. if (userInfo == null)
  1034. {
  1035. m_log.ErrorFormat("[PERMISSIONS]: Could not find user {0} for view notecard check", user);
  1036. return false;
  1037. }
  1038. if (userInfo.RootFolder == null)
  1039. return false;
  1040. InventoryItemBase assetRequestItem = userInfo.RootFolder.FindItem(notecard);
  1041. if (assetRequestItem == null) // Library item
  1042. {
  1043. assetRequestItem = m_scene.CommsManager.UserProfileCacheService.LibraryRoot.FindItem(notecard);
  1044. if (assetRequestItem != null) // Implicitly readable
  1045. return true;
  1046. }
  1047. // Notecards are always readable unless no copy
  1048. //
  1049. if ((assetRequestItem.CurrentPermissions &
  1050. (uint)PermissionMask.Copy) !=
  1051. (uint)PermissionMask.Copy)
  1052. return false;
  1053. }
  1054. else // Prim inventory
  1055. {
  1056. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  1057. if (part == null)
  1058. return false;
  1059. if (part.OwnerID != user)
  1060. return false;
  1061. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1062. return false;
  1063. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  1064. if (ti == null)
  1065. return false;
  1066. if (ti.OwnerID != user)
  1067. return false;
  1068. // Notecards are always readable unless no copy
  1069. //
  1070. if ((ti.CurrentPermissions &
  1071. (uint)PermissionMask.Copy) !=
  1072. (uint)PermissionMask.Copy)
  1073. return false;
  1074. }
  1075. return true;
  1076. }
  1077. #endregion
  1078. private bool CanLinkObject(UUID userID, UUID objectID)
  1079. {
  1080. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1081. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1082. return true;
  1083. }
  1084. private bool CanDelinkObject(UUID userID, UUID objectID)
  1085. {
  1086. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1087. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1088. return true;
  1089. }
  1090. private bool CanBuyLand(UUID userID, ILandObject parcel, Scene scene)
  1091. {
  1092. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1093. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1094. return true;
  1095. }
  1096. private bool CanCopyObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1097. {
  1098. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1099. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1100. return true;
  1101. }
  1102. private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1103. {
  1104. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1105. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1106. return true;
  1107. }
  1108. /// <summary>
  1109. /// Check whether the specified user is allowed to directly create the given inventory type in a prim's
  1110. /// inventory (e.g. the New Script button in the 1.21 Linden Lab client).
  1111. /// </summary>
  1112. /// <param name="invType"></param>
  1113. /// <param name="objectID"></param>
  1114. /// <param name="userID"></param>
  1115. /// <returns></returns>
  1116. private bool CanCreateObjectInventory(int invType, UUID objectID, UUID userID)
  1117. {
  1118. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1119. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1120. if ((int)InventoryType.LSL == invType)
  1121. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1122. return false;
  1123. return true;
  1124. }
  1125. /// <summary>
  1126. /// Check whether the specified user is allowed to create the given inventory type in their inventory.
  1127. /// </summary>
  1128. /// <param name="invType"></param>
  1129. /// <param name="userID"></param>
  1130. /// <returns></returns>
  1131. private bool CanCreateUserInventory(int invType, UUID userID)
  1132. {
  1133. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1134. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1135. if ((int)InventoryType.LSL == invType)
  1136. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1137. return false;
  1138. return true;
  1139. }
  1140. /// <summary>
  1141. /// Check whether the specified user is allowed to copy the given inventory type in their inventory.
  1142. /// </summary>
  1143. /// <param name="itemID"></param>
  1144. /// <param name="userID"></param>
  1145. /// <returns></returns>
  1146. private bool CanCopyUserInventory(UUID itemID, UUID userID)
  1147. {
  1148. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1149. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1150. return true;
  1151. }
  1152. /// <summary>
  1153. /// Check whether the specified user is allowed to edit the given inventory item within their own inventory.
  1154. /// </summary>
  1155. /// <param name="itemID"></param>
  1156. /// <param name="userID"></param>
  1157. /// <returns></returns>
  1158. private bool CanEditUserInventory(UUID itemID, UUID userID)
  1159. {
  1160. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1161. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1162. return true;
  1163. }
  1164. /// <summary>
  1165. /// Check whether the specified user is allowed to delete the given inventory item from their own inventory.
  1166. /// </summary>
  1167. /// <param name="itemID"></param>
  1168. /// <param name="userID"></param>
  1169. /// <returns></returns>
  1170. private bool CanDeleteUserInventory(UUID itemID, UUID userID)
  1171. {
  1172. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1173. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1174. return true;
  1175. }
  1176. private bool CanTeleport(UUID userID)
  1177. {
  1178. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1179. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1180. return true;
  1181. }
  1182. private bool CanResetScript(UUID prim, UUID script, UUID agentID, Scene scene)
  1183. {
  1184. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1185. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1186. SceneObjectPart part = m_scene.GetSceneObjectPart(prim);
  1187. // If we selected a sub-prim to reset, prim won't represent the object, but only a part.
  1188. // We have to check the permissions of the object, though.
  1189. if (part.ParentID != 0) prim = part.ParentUUID;
  1190. // You can reset the scripts in any object you can edit
  1191. return GenericObjectPermission(agentID, prim, false);
  1192. }
  1193. }
  1194. }