PermissionsModule.cs 69 KB

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