PermissionsModule.cs 75 KB

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