PermissionsModule.cs 68 KB

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