PermissionsModule.cs 76 KB

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