PermissionsModule.cs 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  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. 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. using OpenSim.Services.Interfaces;
  38. // Temporary fix of wrong GroupPowers constants in OpenMetaverse library
  39. enum GroupPowers : long
  40. {
  41. None = 0,
  42. LandEjectAndFreeze = 1,
  43. Invite = 2,
  44. ReturnGroupSet = 2,
  45. Eject = 4,
  46. ReturnNonGroup = 4,
  47. ChangeOptions = 8,
  48. LandGardening = 8,
  49. CreateRole = 16,
  50. DeedObject = 16,
  51. ModerateChat = 32,
  52. DeleteRole = 32,
  53. RoleProperties = 64,
  54. ObjectManipulate = 64,
  55. ObjectSetForSale = 128,
  56. AssignMemberLimited = 128,
  57. AssignMember = 256,
  58. Accountable = 256,
  59. RemoveMember = 512,
  60. SendNotices = 1024,
  61. ChangeActions = 1024,
  62. ChangeIdentity = 2048,
  63. ReceiveNotices = 2048,
  64. StartProposal = 4096,
  65. LandDeed = 4096,
  66. VoteOnProposal = 8192,
  67. LandRelease = 8192,
  68. LandSetSale = 16384,
  69. LandDivideJoin = 32768,
  70. ReturnGroupOwned = 65536,
  71. JoinChat = 65536,
  72. FindPlaces = 131072,
  73. LandChangeIdentity = 262144,
  74. SetLandingPoint = 524288,
  75. ChangeMedia = 1048576,
  76. LandEdit = 2097152,
  77. LandOptions = 4194304,
  78. AllowEditLand = 8388608,
  79. AllowFly = 16777216,
  80. AllowRez = 33554432,
  81. AllowLandmark = 67108864,
  82. AllowVoiceChat = 134217728,
  83. AllowSetHome = 268435456,
  84. LandManageAllowed = 536870912,
  85. LandManageBanned = 1073741824
  86. }
  87. namespace OpenSim.Region.CoreModules.World.Permissions
  88. {
  89. public class PermissionsModule : IRegionModule
  90. {
  91. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  92. protected Scene m_scene;
  93. #region Constants
  94. // These are here for testing. They will be taken out
  95. //private uint PERM_ALL = (uint)2147483647;
  96. private uint PERM_COPY = (uint)32768;
  97. //private uint PERM_MODIFY = (uint)16384;
  98. private uint PERM_MOVE = (uint)524288;
  99. private uint PERM_TRANS = (uint)8192;
  100. private uint PERM_LOCKED = (uint)540672;
  101. /// <value>
  102. /// Different user set names that come in from the configuration file.
  103. /// </value>
  104. enum UserSet
  105. {
  106. All,
  107. Administrators
  108. };
  109. #endregion
  110. #region Bypass Permissions / Debug Permissions Stuff
  111. // Bypasses the permissions engine
  112. private bool m_bypassPermissions = true;
  113. private bool m_bypassPermissionsValue = true;
  114. private bool m_propagatePermissions = false;
  115. private bool m_debugPermissions = false;
  116. private bool m_allowGridGods = false;
  117. private bool m_RegionOwnerIsGod = false;
  118. private bool m_ParcelOwnerIsGod = false;
  119. /// <value>
  120. /// The set of users that are allowed to create scripts. This is only active if permissions are not being
  121. /// bypassed. This overrides normal permissions.
  122. /// </value>
  123. private UserSet m_allowedScriptCreators = UserSet.All;
  124. /// <value>
  125. /// The set of users that are allowed to edit (save) scripts. This is only active if
  126. /// permissions are not being bypassed. This overrides normal permissions.-
  127. /// </value>
  128. private UserSet m_allowedScriptEditors = UserSet.All;
  129. private Dictionary<string, bool> GrantLSL = new Dictionary<string, bool>();
  130. private Dictionary<string, bool> GrantCS = new Dictionary<string, bool>();
  131. private Dictionary<string, bool> GrantVB = new Dictionary<string, bool>();
  132. private Dictionary<string, bool> GrantJS = new Dictionary<string, bool>();
  133. private Dictionary<string, bool> GrantYP = new Dictionary<string, bool>();
  134. #endregion
  135. #region IRegionModule Members
  136. public void Initialise(Scene scene, IConfigSource config)
  137. {
  138. m_scene = scene;
  139. IConfig myConfig = config.Configs["Startup"];
  140. string permissionModules = myConfig.GetString("permissionmodules", "DefaultPermissionsModule");
  141. List<string> modules=new List<string>(permissionModules.Split(','));
  142. if (!modules.Contains("DefaultPermissionsModule"))
  143. return;
  144. m_allowGridGods = myConfig.GetBoolean("allow_grid_gods", false);
  145. m_bypassPermissions = !myConfig.GetBoolean("serverside_object_permissions", false);
  146. m_propagatePermissions = myConfig.GetBoolean("propagate_permissions", true);
  147. m_RegionOwnerIsGod = myConfig.GetBoolean("region_owner_is_god", true);
  148. m_ParcelOwnerIsGod = myConfig.GetBoolean("parcel_owner_is_god", true);
  149. m_allowedScriptCreators
  150. = ParseUserSetConfigSetting(myConfig, "allowed_script_creators", m_allowedScriptCreators);
  151. m_allowedScriptEditors
  152. = ParseUserSetConfigSetting(myConfig, "allowed_script_editors", m_allowedScriptEditors);
  153. if (m_bypassPermissions)
  154. m_log.Info("[PERMISSIONS]: serviceside_object_permissions = false in ini file so disabling all region service permission checks");
  155. else
  156. m_log.Debug("[PERMISSIONS]: Enabling all region service permission checks");
  157. //Register functions with Scene External Checks!
  158. m_scene.Permissions.OnBypassPermissions += BypassPermissions;
  159. m_scene.Permissions.OnSetBypassPermissions += SetBypassPermissions;
  160. m_scene.Permissions.OnPropagatePermissions += PropagatePermissions;
  161. m_scene.Permissions.OnGenerateClientFlags += GenerateClientFlags;
  162. m_scene.Permissions.OnAbandonParcel += CanAbandonParcel;
  163. m_scene.Permissions.OnReclaimParcel += CanReclaimParcel;
  164. m_scene.Permissions.OnDeedParcel += CanDeedParcel;
  165. m_scene.Permissions.OnDeedObject += CanDeedObject;
  166. m_scene.Permissions.OnIsGod += IsGod;
  167. m_scene.Permissions.OnDuplicateObject += CanDuplicateObject;
  168. m_scene.Permissions.OnDeleteObject += CanDeleteObject; //MAYBE FULLY IMPLEMENTED
  169. m_scene.Permissions.OnEditObject += CanEditObject; //MAYBE FULLY IMPLEMENTED
  170. m_scene.Permissions.OnEditParcel += CanEditParcel; //MAYBE FULLY IMPLEMENTED
  171. m_scene.Permissions.OnInstantMessage += CanInstantMessage;
  172. m_scene.Permissions.OnInventoryTransfer += CanInventoryTransfer; //NOT YET IMPLEMENTED
  173. m_scene.Permissions.OnIssueEstateCommand += CanIssueEstateCommand; //FULLY IMPLEMENTED
  174. m_scene.Permissions.OnMoveObject += CanMoveObject; //MAYBE FULLY IMPLEMENTED
  175. m_scene.Permissions.OnObjectEntry += CanObjectEntry;
  176. m_scene.Permissions.OnReturnObject += CanReturnObject; //NOT YET IMPLEMENTED
  177. m_scene.Permissions.OnRezObject += CanRezObject; //MAYBE FULLY IMPLEMENTED
  178. m_scene.Permissions.OnRunConsoleCommand += CanRunConsoleCommand;
  179. m_scene.Permissions.OnRunScript += CanRunScript; //NOT YET IMPLEMENTED
  180. m_scene.Permissions.OnCompileScript += CanCompileScript;
  181. m_scene.Permissions.OnSellParcel += CanSellParcel;
  182. m_scene.Permissions.OnTakeObject += CanTakeObject;
  183. m_scene.Permissions.OnTakeCopyObject += CanTakeCopyObject;
  184. m_scene.Permissions.OnTerraformLand += CanTerraformLand;
  185. m_scene.Permissions.OnLinkObject += CanLinkObject; //NOT YET IMPLEMENTED
  186. m_scene.Permissions.OnDelinkObject += CanDelinkObject; //NOT YET IMPLEMENTED
  187. m_scene.Permissions.OnBuyLand += CanBuyLand; //NOT YET IMPLEMENTED
  188. m_scene.Permissions.OnViewNotecard += CanViewNotecard; //NOT YET IMPLEMENTED
  189. m_scene.Permissions.OnViewScript += CanViewScript; //NOT YET IMPLEMENTED
  190. m_scene.Permissions.OnEditNotecard += CanEditNotecard; //NOT YET IMPLEMENTED
  191. m_scene.Permissions.OnEditScript += CanEditScript; //NOT YET IMPLEMENTED
  192. m_scene.Permissions.OnCreateObjectInventory += CanCreateObjectInventory; //NOT IMPLEMENTED HERE
  193. m_scene.Permissions.OnEditObjectInventory += CanEditObjectInventory;//MAYBE FULLY IMPLEMENTED
  194. m_scene.Permissions.OnCopyObjectInventory += CanCopyObjectInventory; //NOT YET IMPLEMENTED
  195. m_scene.Permissions.OnDeleteObjectInventory += CanDeleteObjectInventory; //NOT YET IMPLEMENTED
  196. m_scene.Permissions.OnResetScript += CanResetScript;
  197. m_scene.Permissions.OnCreateUserInventory += CanCreateUserInventory; //NOT YET IMPLEMENTED
  198. m_scene.Permissions.OnCopyUserInventory += CanCopyUserInventory; //NOT YET IMPLEMENTED
  199. m_scene.Permissions.OnEditUserInventory += CanEditUserInventory; //NOT YET IMPLEMENTED
  200. m_scene.Permissions.OnDeleteUserInventory += CanDeleteUserInventory; //NOT YET IMPLEMENTED
  201. m_scene.Permissions.OnTeleport += CanTeleport; //NOT YET IMPLEMENTED
  202. m_scene.Permissions.OnUseObjectReturn += CanUseObjectReturn; //NOT YET IMPLEMENTED
  203. m_scene.AddCommand(this, "bypass permissions",
  204. "bypass permissions <true / false>",
  205. "Bypass permission checks",
  206. HandleBypassPermissions);
  207. m_scene.AddCommand(this, "force permissions",
  208. "force permissions <true / false>",
  209. "Force permissions on or off",
  210. HandleForcePermissions);
  211. m_scene.AddCommand(this, "debug permissions",
  212. "debug permissions <true / false>",
  213. "Enable permissions debugging",
  214. HandleDebugPermissions);
  215. string grant = myConfig.GetString("GrantLSL","");
  216. if (grant.Length > 0) {
  217. foreach (string uuidl in grant.Split(',')) {
  218. string uuid = uuidl.Trim(" \t".ToCharArray());
  219. GrantLSL.Add(uuid, true);
  220. }
  221. }
  222. grant = myConfig.GetString("GrantCS","");
  223. if (grant.Length > 0) {
  224. foreach (string uuidl in grant.Split(',')) {
  225. string uuid = uuidl.Trim(" \t".ToCharArray());
  226. GrantCS.Add(uuid, true);
  227. }
  228. }
  229. grant = myConfig.GetString("GrantVB","");
  230. if (grant.Length > 0) {
  231. foreach (string uuidl in grant.Split(',')) {
  232. string uuid = uuidl.Trim(" \t".ToCharArray());
  233. GrantVB.Add(uuid, true);
  234. }
  235. }
  236. grant = myConfig.GetString("GrantJS", "");
  237. if (grant.Length > 0)
  238. {
  239. foreach (string uuidl in grant.Split(','))
  240. {
  241. string uuid = uuidl.Trim(" \t".ToCharArray());
  242. GrantJS.Add(uuid, true);
  243. }
  244. }
  245. grant = myConfig.GetString("GrantYP", "");
  246. if (grant.Length > 0)
  247. {
  248. foreach (string uuidl in grant.Split(','))
  249. {
  250. string uuid = uuidl.Trim(" \t".ToCharArray());
  251. GrantYP.Add(uuid, true);
  252. }
  253. }
  254. }
  255. public void HandleBypassPermissions(string module, string[] args)
  256. {
  257. if (m_scene.ConsoleScene() != null &&
  258. m_scene.ConsoleScene() != m_scene)
  259. {
  260. return;
  261. }
  262. if (args.Length > 2)
  263. {
  264. bool val;
  265. if (!bool.TryParse(args[2], out val))
  266. return;
  267. m_bypassPermissions = val;
  268. m_log.InfoFormat(
  269. "[PERMISSIONS]: Set permissions bypass to {0} for {1}",
  270. m_bypassPermissions, m_scene.RegionInfo.RegionName);
  271. }
  272. }
  273. public void HandleForcePermissions(string module, string[] args)
  274. {
  275. if (m_scene.ConsoleScene() != null &&
  276. m_scene.ConsoleScene() != m_scene)
  277. {
  278. return;
  279. }
  280. if (!m_bypassPermissions)
  281. {
  282. m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first");
  283. return;
  284. }
  285. if (args.Length > 2)
  286. {
  287. bool val;
  288. if (!bool.TryParse(args[2], out val))
  289. return;
  290. m_bypassPermissionsValue = val;
  291. m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName);
  292. }
  293. }
  294. public void HandleDebugPermissions(string module, string[] args)
  295. {
  296. if (m_scene.ConsoleScene() != null &&
  297. m_scene.ConsoleScene() != m_scene)
  298. {
  299. return;
  300. }
  301. if (args.Length > 2)
  302. {
  303. bool val;
  304. if (!bool.TryParse(args[2], out val))
  305. return;
  306. m_debugPermissions = val;
  307. m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName);
  308. }
  309. }
  310. public void PostInitialise()
  311. {
  312. }
  313. public void Close()
  314. {
  315. }
  316. public string Name
  317. {
  318. get { return "PermissionsModule"; }
  319. }
  320. public bool IsSharedModule
  321. {
  322. get { return false; }
  323. }
  324. #endregion
  325. #region Helper Functions
  326. protected void SendPermissionError(UUID user, string reason)
  327. {
  328. m_scene.EventManager.TriggerPermissionError(user, reason);
  329. }
  330. protected void DebugPermissionInformation(string permissionCalled)
  331. {
  332. if (m_debugPermissions)
  333. m_log.Debug("[PERMISSIONS]: " + permissionCalled + " was called from " + m_scene.RegionInfo.RegionName);
  334. }
  335. // Checks if the given group is active and if the user is a group member
  336. // with the powers requested (powers = 0 for no powers check)
  337. protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers)
  338. {
  339. ScenePresence sp = m_scene.GetScenePresence(userID);
  340. if (sp != null)
  341. {
  342. IClientAPI client = sp.ControllingClient;
  343. return ((groupID == client.ActiveGroupId) && (client.ActiveGroupPowers != 0) &&
  344. ((powers == 0) || ((client.ActiveGroupPowers & powers) == powers)));
  345. }
  346. return false;
  347. }
  348. /// <summary>
  349. /// Parse a user set configuration setting
  350. /// </summary>
  351. /// <param name="config"></param>
  352. /// <param name="settingName"></param>
  353. /// <param name="defaultValue">The default value for this attribute</param>
  354. /// <returns>The parsed value</returns>
  355. private static UserSet ParseUserSetConfigSetting(IConfig config, string settingName, UserSet defaultValue)
  356. {
  357. UserSet userSet = defaultValue;
  358. string rawSetting = config.GetString(settingName, defaultValue.ToString());
  359. // Temporary measure to allow 'gods' to be specified in config for consistency's sake. In the long term
  360. // this should disappear.
  361. if ("gods" == rawSetting.ToLower())
  362. rawSetting = UserSet.Administrators.ToString();
  363. // Doing it this was so that we can do a case insensitive conversion
  364. try
  365. {
  366. userSet = (UserSet)Enum.Parse(typeof(UserSet), rawSetting, true);
  367. }
  368. catch
  369. {
  370. m_log.ErrorFormat(
  371. "[PERMISSIONS]: {0} is not a valid {1} value, setting to {2}",
  372. rawSetting, settingName, userSet);
  373. }
  374. m_log.DebugFormat("[PERMISSIONS]: {0} {1}", settingName, userSet);
  375. return userSet;
  376. }
  377. /// <summary>
  378. /// Is the given user an administrator (in other words, a god)?
  379. /// </summary>
  380. /// <param name="user"></param>
  381. /// <returns></returns>
  382. protected bool IsAdministrator(UUID user)
  383. {
  384. if (user == UUID.Zero) return false;
  385. if (m_scene.RegionInfo.MasterAvatarAssignedUUID != UUID.Zero)
  386. {
  387. if (m_RegionOwnerIsGod && (m_scene.RegionInfo.MasterAvatarAssignedUUID == user))
  388. return true;
  389. }
  390. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  391. {
  392. if (m_scene.RegionInfo.EstateSettings.EstateOwner == user)
  393. return true;
  394. }
  395. if (m_allowGridGods)
  396. {
  397. CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(user);
  398. if (profile != null && profile.UserProfile != null)
  399. {
  400. if (profile.UserProfile.GodLevel >= 200)
  401. return true;
  402. }
  403. }
  404. return false;
  405. }
  406. protected bool IsEstateManager(UUID user)
  407. {
  408. if (user == UUID.Zero) return false;
  409. return m_scene.RegionInfo.EstateSettings.IsEstateManager(user);
  410. }
  411. #endregion
  412. public bool PropagatePermissions()
  413. {
  414. if (m_bypassPermissions)
  415. return false;
  416. return m_propagatePermissions;
  417. }
  418. public bool BypassPermissions()
  419. {
  420. return m_bypassPermissions;
  421. }
  422. public void SetBypassPermissions(bool value)
  423. {
  424. m_bypassPermissions=value;
  425. }
  426. #region Object Permissions
  427. public uint GenerateClientFlags(UUID user, UUID objID)
  428. {
  429. // Here's the way this works,
  430. // ObjectFlags and Permission flags are two different enumerations
  431. // ObjectFlags, however, tells the client to change what it will allow the user to do.
  432. // So, that means that all of the permissions type ObjectFlags are /temporary/ and only
  433. // supposed to be set when customizing the objectflags for the client.
  434. // These temporary objectflags get computed and added in this function based on the
  435. // Permission mask that's appropriate!
  436. // Outside of this method, they should never be added to objectflags!
  437. // -teravus
  438. SceneObjectPart task = m_scene.GetSceneObjectPart(objID);
  439. // this shouldn't ever happen.. return no permissions/objectflags.
  440. if (task == null)
  441. return (uint)0;
  442. uint objflags = task.GetEffectiveObjectFlags();
  443. UUID objectOwner = task.OwnerID;
  444. // Remove any of the objectFlags that are temporary. These will get added back if appropriate
  445. // in the next bit of code
  446. // libomv will moan about PrimFlags.ObjectYouOfficer being
  447. // deprecated
  448. #pragma warning disable 0612
  449. objflags &= (uint)
  450. ~(PrimFlags.ObjectCopy | // Tells client you can copy the object
  451. PrimFlags.ObjectModify | // tells client you can modify the object
  452. PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
  453. PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
  454. PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
  455. PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
  456. PrimFlags.ObjectOwnerModify | // Tells client that you're the owner of the object
  457. PrimFlags.ObjectYouOfficer // Tells client that you've got group object editing permission. Used when ObjectGroupOwned is set
  458. );
  459. #pragma warning restore 0612
  460. // Creating the three ObjectFlags options for this method to choose from.
  461. // Customize the OwnerMask
  462. uint objectOwnerMask = ApplyObjectModifyMasks(task.OwnerMask, objflags);
  463. objectOwnerMask |= (uint)PrimFlags.ObjectYouOwner | (uint)PrimFlags.ObjectAnyOwner | (uint)PrimFlags.ObjectOwnerModify;
  464. // Customize the GroupMask
  465. uint objectGroupMask = ApplyObjectModifyMasks(task.GroupMask, objflags);
  466. // Customize the EveryoneMask
  467. uint objectEveryoneMask = ApplyObjectModifyMasks(task.EveryoneMask, objflags);
  468. if (objectOwner != UUID.Zero)
  469. objectEveryoneMask |= (uint)PrimFlags.ObjectAnyOwner;
  470. if (m_bypassPermissions)
  471. return objectOwnerMask;
  472. // Object owners should be able to edit their own content
  473. if (user == objectOwner)
  474. return objectOwnerMask;
  475. // Estate users should be able to edit anything in the sim
  476. if (IsEstateManager(user) && m_RegionOwnerIsGod && !IsAdministrator(objectOwner))
  477. return objectOwnerMask;
  478. // Admin should be able to edit anything in the sim (including admin objects)
  479. if (IsAdministrator(user))
  480. return objectOwnerMask;
  481. // Users should be able to edit what is over their land.
  482. ILandObject parcel = m_scene.LandChannel.GetLandObject(task.AbsolutePosition.X, task.AbsolutePosition.Y);
  483. if (parcel != null && parcel.LandData.OwnerID == user && m_ParcelOwnerIsGod)
  484. {
  485. // Admin objects should not be editable by the above
  486. if (!IsAdministrator(objectOwner))
  487. return objectOwnerMask;
  488. }
  489. // Group permissions
  490. if ((task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0))
  491. return objectGroupMask | objectEveryoneMask;
  492. return objectEveryoneMask;
  493. }
  494. private uint ApplyObjectModifyMasks(uint setPermissionMask, uint objectFlagsMask)
  495. {
  496. // We are adding the temporary objectflags to the object's objectflags based on the
  497. // permission flag given. These change the F flags on the client.
  498. if ((setPermissionMask & (uint)PermissionMask.Copy) != 0)
  499. {
  500. objectFlagsMask |= (uint)PrimFlags.ObjectCopy;
  501. }
  502. if ((setPermissionMask & (uint)PermissionMask.Move) != 0)
  503. {
  504. objectFlagsMask |= (uint)PrimFlags.ObjectMove;
  505. }
  506. if ((setPermissionMask & (uint)PermissionMask.Modify) != 0)
  507. {
  508. objectFlagsMask |= (uint)PrimFlags.ObjectModify;
  509. }
  510. if ((setPermissionMask & (uint)PermissionMask.Transfer) != 0)
  511. {
  512. objectFlagsMask |= (uint)PrimFlags.ObjectTransfer;
  513. }
  514. return objectFlagsMask;
  515. }
  516. /// <summary>
  517. /// General permissions checks for any operation involving an object. These supplement more specific checks
  518. /// implemented by callers.
  519. /// </summary>
  520. /// <param name="currentUser"></param>
  521. /// <param name="objId"></param>
  522. /// <param name="denyOnLocked"></param>
  523. /// <returns></returns>
  524. protected bool GenericObjectPermission(UUID currentUser, UUID objId, bool denyOnLocked)
  525. {
  526. // Default: deny
  527. bool permission = false;
  528. bool locked = false;
  529. if (!m_scene.Entities.ContainsKey(objId))
  530. {
  531. return false;
  532. }
  533. // If it's not an object, we cant edit it.
  534. if ((!(m_scene.Entities[objId] is SceneObjectGroup)))
  535. {
  536. return false;
  537. }
  538. SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objId];
  539. UUID objectOwner = group.OwnerID;
  540. locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
  541. // People shouldn't be able to do anything with locked objects, except the Administrator
  542. // The 'set permissions' runs through a different permission check, so when an object owner
  543. // sets an object locked, the only thing that they can do is unlock it.
  544. //
  545. // Nobody but the object owner can set permissions on an object
  546. //
  547. if (locked && (!IsAdministrator(currentUser)) && denyOnLocked)
  548. {
  549. return false;
  550. }
  551. // Object owners should be able to edit their own content
  552. if (currentUser == objectOwner)
  553. {
  554. permission = true;
  555. }
  556. else if (group.IsAttachment)
  557. {
  558. permission = false;
  559. }
  560. // Group members should be able to edit group objects
  561. if ((group.GroupID != UUID.Zero) && ((m_scene.GetSceneObjectPart(objId).GroupMask & (uint)PermissionMask.Modify) != 0) && IsGroupMember(group.GroupID, currentUser, 0))
  562. {
  563. // Return immediately, so that the administrator can shares group objects
  564. return true;
  565. }
  566. // Users should be able to edit what is over their land.
  567. ILandObject parcel = m_scene.LandChannel.GetLandObject(group.AbsolutePosition.X, group.AbsolutePosition.Y);
  568. if ((parcel != null) && (parcel.LandData.OwnerID == currentUser))
  569. {
  570. permission = true;
  571. }
  572. // Estate users should be able to edit anything in the sim
  573. if (IsEstateManager(currentUser))
  574. {
  575. permission = true;
  576. }
  577. // Admin objects should not be editable by the above
  578. if (IsAdministrator(objectOwner))
  579. {
  580. permission = false;
  581. }
  582. // Admin should be able to edit anything in the sim (including admin objects)
  583. if (IsAdministrator(currentUser))
  584. {
  585. permission = true;
  586. }
  587. return permission;
  588. }
  589. #endregion
  590. #region Generic Permissions
  591. protected bool GenericCommunicationPermission(UUID user, UUID target)
  592. {
  593. // Setting this to true so that cool stuff can happen until we define what determines Generic Communication Permission
  594. bool permission = true;
  595. string reason = "Only registered users may communicate with another account.";
  596. // Uhh, we need to finish this before we enable it.. because it's blocking all sorts of goodies and features
  597. if (IsAdministrator(user))
  598. permission = true;
  599. if (IsEstateManager(user))
  600. permission = true;
  601. if (!permission)
  602. SendPermissionError(user, reason);
  603. return permission;
  604. }
  605. public bool GenericEstatePermission(UUID user)
  606. {
  607. // Default: deny
  608. bool permission = false;
  609. // Estate admins should be able to use estate tools
  610. if (IsEstateManager(user))
  611. permission = true;
  612. // Administrators always have permission
  613. if (IsAdministrator(user))
  614. permission = true;
  615. return permission;
  616. }
  617. protected bool GenericParcelPermission(UUID user, ILandObject parcel, ulong groupPowers)
  618. {
  619. bool permission = false;
  620. if (parcel.LandData.OwnerID == user)
  621. {
  622. permission = true;
  623. }
  624. if ((parcel.LandData.GroupID != UUID.Zero) && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
  625. {
  626. permission = true;
  627. }
  628. if (IsEstateManager(user))
  629. {
  630. permission = true;
  631. }
  632. if (IsAdministrator(user))
  633. {
  634. permission = true;
  635. }
  636. return permission;
  637. }
  638. protected bool GenericParcelOwnerPermission(UUID user, ILandObject parcel, ulong groupPowers)
  639. {
  640. bool permission = false;
  641. if (parcel.LandData.OwnerID == user)
  642. {
  643. permission = true;
  644. }
  645. if (parcel.LandData.IsGroupOwned && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
  646. {
  647. permission = true;
  648. }
  649. if (IsEstateManager(user))
  650. {
  651. permission = true;
  652. }
  653. if (IsAdministrator(user))
  654. {
  655. permission = true;
  656. }
  657. return permission;
  658. }
  659. protected bool GenericParcelPermission(UUID user, Vector3 pos, ulong groupPowers)
  660. {
  661. ILandObject parcel = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
  662. if (parcel == null) return false;
  663. return GenericParcelPermission(user, parcel, groupPowers);
  664. }
  665. #endregion
  666. #region Permission Checks
  667. private bool CanAbandonParcel(UUID user, ILandObject parcel, Scene scene)
  668. {
  669. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  670. if (m_bypassPermissions) return m_bypassPermissionsValue;
  671. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandRelease);
  672. }
  673. private bool CanReclaimParcel(UUID user, ILandObject parcel, Scene scene)
  674. {
  675. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  676. if (m_bypassPermissions) return m_bypassPermissionsValue;
  677. return GenericParcelOwnerPermission(user, parcel, 0);
  678. }
  679. private bool CanDeedParcel(UUID user, ILandObject parcel, Scene scene)
  680. {
  681. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  682. if (m_bypassPermissions) return m_bypassPermissionsValue;
  683. if (parcel.LandData.OwnerID != user) // Only the owner can deed!
  684. return false;
  685. ScenePresence sp = scene.GetScenePresence(user);
  686. IClientAPI client = sp.ControllingClient;
  687. if ((client.GetGroupPowers(parcel.LandData.GroupID) & (ulong)GroupPowers.LandDeed) == 0)
  688. return false;
  689. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandDeed);
  690. }
  691. private bool CanDeedObject(UUID user, UUID group, Scene scene)
  692. {
  693. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  694. if (m_bypassPermissions) return m_bypassPermissionsValue;
  695. ScenePresence sp = scene.GetScenePresence(user);
  696. IClientAPI client = sp.ControllingClient;
  697. if ((client.GetGroupPowers(group) & (ulong)GroupPowers.DeedObject) == 0)
  698. return false;
  699. return true;
  700. }
  701. private bool IsGod(UUID user, Scene scene)
  702. {
  703. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  704. if (m_bypassPermissions) return m_bypassPermissionsValue;
  705. return IsAdministrator(user);
  706. }
  707. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
  708. {
  709. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  710. if (m_bypassPermissions) return m_bypassPermissionsValue;
  711. if (!GenericObjectPermission(owner, objectID, true))
  712. {
  713. //They can't even edit the object
  714. return false;
  715. }
  716. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  717. if (part == null)
  718. return false;
  719. if (part.OwnerID == owner)
  720. return ((part.OwnerMask & PERM_COPY) != 0);
  721. if (part.GroupID != UUID.Zero)
  722. {
  723. if ((part.OwnerID == part.GroupID) && ((owner != part.LastOwnerID) || ((part.GroupMask & PERM_TRANS) == 0)))
  724. return false;
  725. if ((part.GroupMask & PERM_COPY) == 0)
  726. return false;
  727. }
  728. //If they can rez, they can duplicate
  729. return CanRezObject(objectCount, owner, objectPosition, scene);
  730. }
  731. private bool CanDeleteObject(UUID objectID, UUID deleter, Scene scene)
  732. {
  733. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  734. if (m_bypassPermissions) return m_bypassPermissionsValue;
  735. return GenericObjectPermission(deleter, objectID, false);
  736. }
  737. private bool CanEditObject(UUID objectID, UUID editorID, Scene scene)
  738. {
  739. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  740. if (m_bypassPermissions) return m_bypassPermissionsValue;
  741. return GenericObjectPermission(editorID, objectID, false);
  742. }
  743. private bool CanEditObjectInventory(UUID objectID, UUID editorID, Scene scene)
  744. {
  745. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  746. if (m_bypassPermissions) return m_bypassPermissionsValue;
  747. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  748. // If we selected a sub-prim to edit, the objectID won't represent the object, but only a part.
  749. // We have to check the permissions of the group, though.
  750. if (part.ParentID != 0)
  751. {
  752. objectID = part.ParentUUID;
  753. part = m_scene.GetSceneObjectPart(objectID);
  754. }
  755. return GenericObjectPermission(editorID, objectID, false);
  756. }
  757. private bool CanEditParcel(UUID user, ILandObject parcel, Scene scene)
  758. {
  759. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  760. if (m_bypassPermissions) return m_bypassPermissionsValue;
  761. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandDivideJoin);
  762. }
  763. /// <summary>
  764. /// Check whether the specified user can edit the given script
  765. /// </summary>
  766. /// <param name="script"></param>
  767. /// <param name="objectID"></param>
  768. /// <param name="user"></param>
  769. /// <param name="scene"></param>
  770. /// <returns></returns>
  771. private bool CanEditScript(UUID script, UUID objectID, UUID user, Scene scene)
  772. {
  773. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  774. if (m_bypassPermissions) return m_bypassPermissionsValue;
  775. if (m_allowedScriptEditors == UserSet.Administrators && !IsAdministrator(user))
  776. return false;
  777. // Ordinarily, if you can view it, you can edit it
  778. // There is no viewing a no mod script
  779. //
  780. return CanViewScript(script, objectID, user, scene);
  781. }
  782. /// <summary>
  783. /// Check whether the specified user can edit the given notecard
  784. /// </summary>
  785. /// <param name="notecard"></param>
  786. /// <param name="objectID"></param>
  787. /// <param name="user"></param>
  788. /// <param name="scene"></param>
  789. /// <returns></returns>
  790. private bool CanEditNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  791. {
  792. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  793. if (m_bypassPermissions) return m_bypassPermissionsValue;
  794. if (objectID == UUID.Zero) // User inventory
  795. {
  796. IInventoryService invService = m_scene.InventoryService;
  797. InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
  798. assetRequestItem = invService.GetItem(assetRequestItem);
  799. if (assetRequestItem == null) // Library item
  800. {
  801. assetRequestItem = scene.CommsManager.UserProfileCacheService.LibraryRoot.FindItem(notecard);
  802. if (assetRequestItem != null) // Implicitly readable
  803. return true;
  804. }
  805. // Notecards must be both mod and copy to be saveable
  806. // This is because of they're not copy, you can't read
  807. // them, and if they're not mod, well, then they're
  808. // not mod. Duh.
  809. //
  810. if ((assetRequestItem.CurrentPermissions &
  811. ((uint)PermissionMask.Modify |
  812. (uint)PermissionMask.Copy)) !=
  813. ((uint)PermissionMask.Modify |
  814. (uint)PermissionMask.Copy))
  815. return false;
  816. }
  817. else // Prim inventory
  818. {
  819. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  820. if (part == null)
  821. return false;
  822. if (part.OwnerID != user)
  823. {
  824. if (part.GroupID == UUID.Zero)
  825. return false;
  826. if (!IsGroupMember(part.GroupID, user, 0))
  827. return false;
  828. if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
  829. return false;
  830. } else {
  831. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  832. return false;
  833. }
  834. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  835. if (ti == null)
  836. return false;
  837. if (ti.OwnerID != user)
  838. {
  839. if (ti.GroupID == UUID.Zero)
  840. return false;
  841. if (!IsGroupMember(ti.GroupID, user, 0))
  842. return false;
  843. }
  844. // Require full perms
  845. if ((ti.CurrentPermissions &
  846. ((uint)PermissionMask.Modify |
  847. (uint)PermissionMask.Copy)) !=
  848. ((uint)PermissionMask.Modify |
  849. (uint)PermissionMask.Copy))
  850. return false;
  851. }
  852. return true;
  853. }
  854. private bool CanInstantMessage(UUID user, UUID target, Scene startScene)
  855. {
  856. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  857. if (m_bypassPermissions) return m_bypassPermissionsValue;
  858. // If the sender is an object, check owner instead
  859. //
  860. SceneObjectPart part = startScene.GetSceneObjectPart(user);
  861. if (part != null)
  862. user = part.OwnerID;
  863. return GenericCommunicationPermission(user, target);
  864. }
  865. private bool CanInventoryTransfer(UUID user, UUID target, Scene startScene)
  866. {
  867. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  868. if (m_bypassPermissions) return m_bypassPermissionsValue;
  869. return GenericCommunicationPermission(user, target);
  870. }
  871. private bool CanIssueEstateCommand(UUID user, Scene requestFromScene, bool ownerCommand)
  872. {
  873. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  874. if (m_bypassPermissions) return m_bypassPermissionsValue;
  875. if (IsAdministrator(user))
  876. return true;
  877. if (m_scene.RegionInfo.EstateSettings.IsEstateOwner(user))
  878. return true;
  879. if (ownerCommand)
  880. return false;
  881. return GenericEstatePermission(user);
  882. }
  883. private bool CanMoveObject(UUID objectID, UUID moverID, Scene scene)
  884. {
  885. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  886. if (m_bypassPermissions)
  887. {
  888. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  889. if (part.OwnerID != moverID)
  890. {
  891. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  892. {
  893. if (part.ParentGroup.IsAttachment)
  894. return false;
  895. }
  896. }
  897. return m_bypassPermissionsValue;
  898. }
  899. bool permission = GenericObjectPermission(moverID, objectID, true);
  900. if (!permission)
  901. {
  902. if (!m_scene.Entities.ContainsKey(objectID))
  903. {
  904. return false;
  905. }
  906. // The client
  907. // may request to edit linked parts, and therefore, it needs
  908. // to also check for SceneObjectPart
  909. // If it's not an object, we cant edit it.
  910. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  911. {
  912. return false;
  913. }
  914. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  915. // UUID taskOwner = null;
  916. // Added this because at this point in time it wouldn't be wise for
  917. // the administrator object permissions to take effect.
  918. // UUID objectOwner = task.OwnerID;
  919. // Anyone can move
  920. if ((task.RootPart.EveryoneMask & PERM_MOVE) != 0)
  921. permission = true;
  922. // Locked
  923. if ((task.RootPart.OwnerMask & PERM_LOCKED) == 0)
  924. permission = false;
  925. }
  926. else
  927. {
  928. bool locked = false;
  929. if (!m_scene.Entities.ContainsKey(objectID))
  930. {
  931. return false;
  932. }
  933. // If it's not an object, we cant edit it.
  934. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  935. {
  936. return false;
  937. }
  938. SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objectID];
  939. UUID objectOwner = group.OwnerID;
  940. locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
  941. // This is an exception to the generic object permission.
  942. // Administrators who lock their objects should not be able to move them,
  943. // however generic object permission should return true.
  944. // This keeps locked objects from being affected by random click + drag actions by accident
  945. // and allows the administrator to grab or delete a locked object.
  946. // Administrators and estate managers are still able to click+grab locked objects not
  947. // owned by them in the scene
  948. // This is by design.
  949. if (locked && (moverID == objectOwner))
  950. return false;
  951. }
  952. return permission;
  953. }
  954. private bool CanObjectEntry(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  955. {
  956. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  957. if (m_bypassPermissions) return m_bypassPermissionsValue;
  958. if ((newPoint.X > 257f || newPoint.X < -1f || newPoint.Y > 257f || newPoint.Y < -1f))
  959. {
  960. return true;
  961. }
  962. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  963. ILandObject land = m_scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  964. if (!enteringRegion)
  965. {
  966. ILandObject fromland = m_scene.LandChannel.GetLandObject(task.AbsolutePosition.X, task.AbsolutePosition.Y);
  967. if (fromland == land) // Not entering
  968. return true;
  969. }
  970. if (land == null)
  971. {
  972. return false;
  973. }
  974. if ((land.LandData.Flags & ((int)ParcelFlags.AllowAPrimitiveEntry)) != 0)
  975. {
  976. return true;
  977. }
  978. if (!m_scene.Entities.ContainsKey(objectID))
  979. {
  980. return false;
  981. }
  982. // If it's not an object, we cant edit it.
  983. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  984. {
  985. return false;
  986. }
  987. if (GenericParcelPermission(task.OwnerID, newPoint, 0))
  988. {
  989. return true;
  990. }
  991. //Otherwise, false!
  992. return false;
  993. }
  994. private bool CanReturnObject(UUID objectID, UUID returnerID, Scene scene)
  995. {
  996. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  997. if (m_bypassPermissions) return m_bypassPermissionsValue;
  998. return GenericObjectPermission(returnerID, objectID, false);
  999. }
  1000. private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
  1001. {
  1002. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1003. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1004. bool permission = false;
  1005. ILandObject land = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  1006. if (land == null) return false;
  1007. if ((land.LandData.Flags & ((int)ParcelFlags.CreateObjects)) ==
  1008. (int)ParcelFlags.CreateObjects)
  1009. permission = true;
  1010. if (IsAdministrator(owner))
  1011. {
  1012. permission = true;
  1013. }
  1014. // Powers are zero, because GroupPowers.AllowRez is not a precondition for rezzing objects
  1015. if (GenericParcelPermission(owner, objectPosition, 0))
  1016. {
  1017. permission = true;
  1018. }
  1019. return permission;
  1020. }
  1021. private bool CanRunConsoleCommand(UUID user, Scene requestFromScene)
  1022. {
  1023. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1024. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1025. return IsAdministrator(user);
  1026. }
  1027. private bool CanRunScript(UUID script, UUID objectID, UUID user, Scene scene)
  1028. {
  1029. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1030. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1031. return true;
  1032. }
  1033. private bool CanSellParcel(UUID user, ILandObject parcel, Scene scene)
  1034. {
  1035. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1036. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1037. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandSetSale);
  1038. }
  1039. private bool CanTakeObject(UUID objectID, UUID stealer, Scene scene)
  1040. {
  1041. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1042. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1043. return GenericObjectPermission(stealer,objectID, false);
  1044. }
  1045. private bool CanTakeCopyObject(UUID objectID, UUID userID, Scene inScene)
  1046. {
  1047. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1048. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1049. bool permission = GenericObjectPermission(userID, objectID, false);
  1050. if (!permission)
  1051. {
  1052. if (!m_scene.Entities.ContainsKey(objectID))
  1053. {
  1054. return false;
  1055. }
  1056. // If it's not an object, we cant edit it.
  1057. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  1058. {
  1059. return false;
  1060. }
  1061. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  1062. // UUID taskOwner = null;
  1063. // Added this because at this point in time it wouldn't be wise for
  1064. // the administrator object permissions to take effect.
  1065. // UUID objectOwner = task.OwnerID;
  1066. if ((task.RootPart.EveryoneMask & PERM_COPY) != 0)
  1067. permission = true;
  1068. if (task.OwnerID != userID)
  1069. {
  1070. if ((task.GetEffectivePermissions() & (PERM_COPY | PERM_TRANS)) != (PERM_COPY | PERM_TRANS))
  1071. permission = false;
  1072. }
  1073. else
  1074. {
  1075. if ((task.GetEffectivePermissions() & PERM_COPY) != PERM_COPY)
  1076. permission = false;
  1077. }
  1078. }
  1079. else
  1080. {
  1081. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  1082. if ((task.GetEffectivePermissions() & (PERM_COPY | PERM_TRANS)) != (PERM_COPY | PERM_TRANS))
  1083. permission = false;
  1084. }
  1085. return permission;
  1086. }
  1087. private bool CanTerraformLand(UUID user, Vector3 position, Scene requestFromScene)
  1088. {
  1089. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1090. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1091. // Estate override
  1092. if (GenericEstatePermission(user))
  1093. return true;
  1094. float X = position.X;
  1095. float Y = position.Y;
  1096. if (X > ((int)Constants.RegionSize - 1))
  1097. X = ((int)Constants.RegionSize - 1);
  1098. if (Y > ((int)Constants.RegionSize - 1))
  1099. Y = ((int)Constants.RegionSize - 1);
  1100. if (X < 0)
  1101. X = 0;
  1102. if (Y < 0)
  1103. Y = 0;
  1104. ILandObject parcel = m_scene.LandChannel.GetLandObject(X, Y);
  1105. if (parcel == null)
  1106. return false;
  1107. // Others allowed to terraform?
  1108. if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowTerraform)) != 0)
  1109. return true;
  1110. // Land owner can terraform too
  1111. if (parcel != null && GenericParcelPermission(user, parcel, (ulong)GroupPowers.AllowEditLand))
  1112. return true;
  1113. return false;
  1114. }
  1115. /// <summary>
  1116. /// Check whether the specified user can view the given script
  1117. /// </summary>
  1118. /// <param name="script"></param>
  1119. /// <param name="objectID"></param>
  1120. /// <param name="user"></param>
  1121. /// <param name="scene"></param>
  1122. /// <returns></returns>
  1123. private bool CanViewScript(UUID script, UUID objectID, UUID user, Scene scene)
  1124. {
  1125. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1126. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1127. if (objectID == UUID.Zero) // User inventory
  1128. {
  1129. IInventoryService invService = m_scene.InventoryService;
  1130. InventoryItemBase assetRequestItem = new InventoryItemBase(script, user);
  1131. assetRequestItem = invService.GetItem(assetRequestItem);
  1132. if (assetRequestItem == null) // Library item
  1133. {
  1134. assetRequestItem = m_scene.CommsManager.UserProfileCacheService.LibraryRoot.FindItem(script);
  1135. if (assetRequestItem != null) // Implicitly readable
  1136. return true;
  1137. }
  1138. // SL is rather harebrained here. In SL, a script you
  1139. // have mod/copy no trans is readable. This subverts
  1140. // permissions, but is used in some products, most
  1141. // notably Hippo door plugin and HippoRent 5 networked
  1142. // prim counter.
  1143. // To enable this broken SL-ism, remove Transfer from
  1144. // the below expressions.
  1145. // Trying to improve on SL perms by making a script
  1146. // readable only if it's really full perms
  1147. //
  1148. if ((assetRequestItem.CurrentPermissions &
  1149. ((uint)PermissionMask.Modify |
  1150. (uint)PermissionMask.Copy |
  1151. (uint)PermissionMask.Transfer)) !=
  1152. ((uint)PermissionMask.Modify |
  1153. (uint)PermissionMask.Copy |
  1154. (uint)PermissionMask.Transfer))
  1155. return false;
  1156. }
  1157. else // Prim inventory
  1158. {
  1159. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  1160. if (part == null)
  1161. return false;
  1162. if (part.OwnerID != user)
  1163. {
  1164. if (part.GroupID == UUID.Zero)
  1165. return false;
  1166. if (!IsGroupMember(part.GroupID, user, 0))
  1167. return false;
  1168. if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
  1169. return false;
  1170. } else {
  1171. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1172. return false;
  1173. }
  1174. TaskInventoryItem ti = part.Inventory.GetInventoryItem(script);
  1175. if (ti == null)
  1176. return false;
  1177. if (ti.OwnerID != user)
  1178. {
  1179. if (ti.GroupID == UUID.Zero)
  1180. return false;
  1181. if (!IsGroupMember(ti.GroupID, user, 0))
  1182. return false;
  1183. }
  1184. // Require full perms
  1185. if ((ti.CurrentPermissions &
  1186. ((uint)PermissionMask.Modify |
  1187. (uint)PermissionMask.Copy |
  1188. (uint)PermissionMask.Transfer)) !=
  1189. ((uint)PermissionMask.Modify |
  1190. (uint)PermissionMask.Copy |
  1191. (uint)PermissionMask.Transfer))
  1192. return false;
  1193. }
  1194. return true;
  1195. }
  1196. /// <summary>
  1197. /// Check whether the specified user can view the given notecard
  1198. /// </summary>
  1199. /// <param name="script"></param>
  1200. /// <param name="objectID"></param>
  1201. /// <param name="user"></param>
  1202. /// <param name="scene"></param>
  1203. /// <returns></returns>
  1204. private bool CanViewNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  1205. {
  1206. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1207. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1208. if (objectID == UUID.Zero) // User inventory
  1209. {
  1210. IInventoryService invService = m_scene.InventoryService;
  1211. InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
  1212. assetRequestItem = invService.GetItem(assetRequestItem);
  1213. if (assetRequestItem == null) // Library item
  1214. {
  1215. assetRequestItem = m_scene.CommsManager.UserProfileCacheService.LibraryRoot.FindItem(notecard);
  1216. if (assetRequestItem != null) // Implicitly readable
  1217. return true;
  1218. }
  1219. // Notecards are always readable unless no copy
  1220. //
  1221. if ((assetRequestItem.CurrentPermissions &
  1222. (uint)PermissionMask.Copy) !=
  1223. (uint)PermissionMask.Copy)
  1224. return false;
  1225. }
  1226. else // Prim inventory
  1227. {
  1228. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  1229. if (part == null)
  1230. return false;
  1231. if (part.OwnerID != user)
  1232. {
  1233. if (part.GroupID == UUID.Zero)
  1234. return false;
  1235. if (!IsGroupMember(part.GroupID, user, 0))
  1236. return false;
  1237. }
  1238. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1239. return false;
  1240. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  1241. if (ti == null)
  1242. return false;
  1243. if (ti.OwnerID != user)
  1244. {
  1245. if (ti.GroupID == UUID.Zero)
  1246. return false;
  1247. if (!IsGroupMember(ti.GroupID, user, 0))
  1248. return false;
  1249. }
  1250. // Notecards are always readable unless no copy
  1251. //
  1252. if ((ti.CurrentPermissions &
  1253. (uint)PermissionMask.Copy) !=
  1254. (uint)PermissionMask.Copy)
  1255. return false;
  1256. }
  1257. return true;
  1258. }
  1259. #endregion
  1260. private bool CanLinkObject(UUID userID, UUID objectID)
  1261. {
  1262. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1263. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1264. return true;
  1265. }
  1266. private bool CanDelinkObject(UUID userID, UUID objectID)
  1267. {
  1268. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1269. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1270. return true;
  1271. }
  1272. private bool CanBuyLand(UUID userID, ILandObject parcel, Scene scene)
  1273. {
  1274. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1275. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1276. return true;
  1277. }
  1278. private bool CanCopyObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1279. {
  1280. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1281. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1282. return true;
  1283. }
  1284. private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1285. {
  1286. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1287. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1288. return true;
  1289. }
  1290. /// <summary>
  1291. /// Check whether the specified user is allowed to directly create the given inventory type in a prim's
  1292. /// inventory (e.g. the New Script button in the 1.21 Linden Lab client).
  1293. /// </summary>
  1294. /// <param name="invType"></param>
  1295. /// <param name="objectID"></param>
  1296. /// <param name="userID"></param>
  1297. /// <returns></returns>
  1298. private bool CanCreateObjectInventory(int invType, UUID objectID, UUID userID)
  1299. {
  1300. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1301. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1302. if ((int)InventoryType.LSL == invType)
  1303. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1304. return false;
  1305. return true;
  1306. }
  1307. /// <summary>
  1308. /// Check whether the specified user is allowed to create the given inventory type in their inventory.
  1309. /// </summary>
  1310. /// <param name="invType"></param>
  1311. /// <param name="userID"></param>
  1312. /// <returns></returns>
  1313. private bool CanCreateUserInventory(int invType, UUID userID)
  1314. {
  1315. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1316. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1317. if ((int)InventoryType.LSL == invType)
  1318. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1319. return false;
  1320. return true;
  1321. }
  1322. /// <summary>
  1323. /// Check whether the specified user is allowed to copy the given inventory type in their inventory.
  1324. /// </summary>
  1325. /// <param name="itemID"></param>
  1326. /// <param name="userID"></param>
  1327. /// <returns></returns>
  1328. private bool CanCopyUserInventory(UUID itemID, UUID userID)
  1329. {
  1330. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1331. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1332. return true;
  1333. }
  1334. /// <summary>
  1335. /// Check whether the specified user is allowed to edit the given inventory item within their own inventory.
  1336. /// </summary>
  1337. /// <param name="itemID"></param>
  1338. /// <param name="userID"></param>
  1339. /// <returns></returns>
  1340. private bool CanEditUserInventory(UUID itemID, UUID userID)
  1341. {
  1342. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1343. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1344. return true;
  1345. }
  1346. /// <summary>
  1347. /// Check whether the specified user is allowed to delete the given inventory item from their own inventory.
  1348. /// </summary>
  1349. /// <param name="itemID"></param>
  1350. /// <param name="userID"></param>
  1351. /// <returns></returns>
  1352. private bool CanDeleteUserInventory(UUID itemID, UUID userID)
  1353. {
  1354. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1355. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1356. return true;
  1357. }
  1358. private bool CanTeleport(UUID userID, Scene scene)
  1359. {
  1360. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1361. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1362. return true;
  1363. }
  1364. private bool CanResetScript(UUID prim, UUID script, UUID agentID, Scene scene)
  1365. {
  1366. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1367. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1368. SceneObjectPart part = m_scene.GetSceneObjectPart(prim);
  1369. // If we selected a sub-prim to reset, prim won't represent the object, but only a part.
  1370. // We have to check the permissions of the object, though.
  1371. if (part.ParentID != 0) prim = part.ParentUUID;
  1372. // You can reset the scripts in any object you can edit
  1373. return GenericObjectPermission(agentID, prim, false);
  1374. }
  1375. private bool CanUseObjectReturn(ILandObject parcel, uint type, IClientAPI client, List<SceneObjectGroup> retlist, Scene scene)
  1376. {
  1377. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1378. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1379. long powers = 0;
  1380. if (parcel.LandData.GroupID != UUID.Zero)
  1381. client.GetGroupPowers(parcel.LandData.GroupID);
  1382. switch (type)
  1383. {
  1384. case (uint)ObjectReturnType.Owner:
  1385. // Don't let group members return owner's objects, ever
  1386. //
  1387. if (parcel.LandData.IsGroupOwned)
  1388. {
  1389. if ((powers & (long)GroupPowers.ReturnGroupOwned) != 0)
  1390. return true;
  1391. }
  1392. else
  1393. {
  1394. if (parcel.LandData.OwnerID != client.AgentId)
  1395. return false;
  1396. }
  1397. return GenericParcelOwnerPermission(client.AgentId, parcel, (ulong)GroupPowers.ReturnGroupOwned);
  1398. case (uint)ObjectReturnType.Group:
  1399. if (parcel.LandData.OwnerID != client.AgentId)
  1400. {
  1401. // If permissionis granted through a group...
  1402. //
  1403. if ((powers & (long)GroupPowers.ReturnGroupSet) != 0)
  1404. {
  1405. foreach (SceneObjectGroup g in new List<SceneObjectGroup>(retlist))
  1406. {
  1407. // check for and remove group owned objects unless
  1408. // the user also has permissions to return those
  1409. //
  1410. if (g.OwnerID == g.GroupID &&
  1411. ((powers & (long)GroupPowers.ReturnGroupOwned) == 0))
  1412. {
  1413. retlist.Remove(g);
  1414. }
  1415. }
  1416. // And allow the operation
  1417. //
  1418. return true;
  1419. }
  1420. }
  1421. return GenericParcelOwnerPermission(client.AgentId, parcel, (ulong)GroupPowers.ReturnGroupSet);
  1422. case (uint)ObjectReturnType.Other:
  1423. if ((powers & (long)GroupPowers.ReturnNonGroup) != 0)
  1424. return true;
  1425. return GenericParcelOwnerPermission(client.AgentId, parcel, (ulong)GroupPowers.ReturnNonGroup);
  1426. case (uint)ObjectReturnType.List:
  1427. break;
  1428. }
  1429. return GenericParcelOwnerPermission(client.AgentId, parcel, 0);
  1430. // Is it correct to be less restrictive for lists of objects to be returned?
  1431. }
  1432. private bool CanCompileScript(UUID ownerUUID, int scriptType, Scene scene) {
  1433. //m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType);
  1434. switch (scriptType) {
  1435. case 0:
  1436. if (GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString())) {
  1437. return(true);
  1438. }
  1439. break;
  1440. case 1:
  1441. if (GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString())) {
  1442. return(true);
  1443. }
  1444. break;
  1445. case 2:
  1446. if (GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString())) {
  1447. return(true);
  1448. }
  1449. break;
  1450. case 3:
  1451. if (GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString()))
  1452. {
  1453. return (true);
  1454. }
  1455. break;
  1456. case 4:
  1457. if (GrantYP.Count == 0 || GrantYP.ContainsKey(ownerUUID.ToString()))
  1458. {
  1459. return (true);
  1460. }
  1461. break;
  1462. }
  1463. return(false);
  1464. }
  1465. }
  1466. }