PermissionsModule.cs 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  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 = "DefaultPermissionsModule")]
  43. public class DefaultPermissionsModule : 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 "DefaultPermissionsModule"; }
  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) && !obj.ParentGroup.IsAttachment)
  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. {
  662. // Return immediately, so that the administrator can share objects with friends
  663. return true;
  664. }
  665. // Users should be able to edit what is over their land.
  666. ILandObject parcel = m_scene.LandChannel.GetLandObject(group.AbsolutePosition.X, group.AbsolutePosition.Y);
  667. if ((parcel != null) && (parcel.LandData.OwnerID == currentUser))
  668. {
  669. permission = true;
  670. }
  671. // Estate users should be able to edit anything in the sim
  672. if (IsEstateManager(currentUser))
  673. {
  674. permission = true;
  675. }
  676. // Admin objects should not be editable by the above
  677. if (IsAdministrator(objectOwner))
  678. {
  679. permission = false;
  680. }
  681. // Admin should be able to edit anything in the sim (including admin objects)
  682. if (IsAdministrator(currentUser))
  683. {
  684. permission = true;
  685. }
  686. return permission;
  687. }
  688. #endregion
  689. #region Generic Permissions
  690. protected bool GenericCommunicationPermission(UUID user, UUID target)
  691. {
  692. // Setting this to true so that cool stuff can happen until we define what determines Generic Communication Permission
  693. bool permission = true;
  694. string reason = "Only registered users may communicate with another account.";
  695. // Uhh, we need to finish this before we enable it.. because it's blocking all sorts of goodies and features
  696. if (IsAdministrator(user))
  697. permission = true;
  698. if (IsEstateManager(user))
  699. permission = true;
  700. if (!permission)
  701. SendPermissionError(user, reason);
  702. return permission;
  703. }
  704. public bool GenericEstatePermission(UUID user)
  705. {
  706. // Default: deny
  707. bool permission = false;
  708. // Estate admins should be able to use estate tools
  709. if (IsEstateManager(user))
  710. permission = true;
  711. // Administrators always have permission
  712. if (IsAdministrator(user))
  713. permission = true;
  714. return permission;
  715. }
  716. protected bool GenericParcelPermission(UUID user, ILandObject parcel, ulong groupPowers)
  717. {
  718. bool permission = false;
  719. if (parcel.LandData.OwnerID == user)
  720. {
  721. permission = true;
  722. }
  723. if ((parcel.LandData.GroupID != UUID.Zero) && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
  724. {
  725. permission = true;
  726. }
  727. if (IsEstateManager(user))
  728. {
  729. permission = true;
  730. }
  731. if (IsAdministrator(user))
  732. {
  733. permission = true;
  734. }
  735. if (m_SimpleBuildPermissions &&
  736. (parcel.LandData.Flags & (uint)ParcelFlags.UseAccessList) == 0 && parcel.IsInLandAccessList(user))
  737. permission = true;
  738. return permission;
  739. }
  740. protected bool GenericParcelOwnerPermission(UUID user, ILandObject parcel, ulong groupPowers, bool allowEstateManager)
  741. {
  742. if (parcel.LandData.OwnerID == user)
  743. {
  744. // Returning immediately so that group deeded objects on group deeded land don't trigger a NRE on
  745. // the subsequent redundant checks when using lParcelMediaCommandList()
  746. // See http://opensimulator.org/mantis/view.php?id=3999 for more details
  747. return true;
  748. }
  749. if (parcel.LandData.IsGroupOwned && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
  750. {
  751. return true;
  752. }
  753. if (allowEstateManager && IsEstateManager(user))
  754. {
  755. return true;
  756. }
  757. if (IsAdministrator(user))
  758. {
  759. return true;
  760. }
  761. return false;
  762. }
  763. protected bool GenericParcelPermission(UUID user, Vector3 pos, ulong groupPowers)
  764. {
  765. ILandObject parcel = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
  766. if (parcel == null) return false;
  767. return GenericParcelPermission(user, parcel, groupPowers);
  768. }
  769. #endregion
  770. #region Permission Checks
  771. private bool CanAbandonParcel(UUID user, ILandObject parcel, Scene scene)
  772. {
  773. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  774. if (m_bypassPermissions) return m_bypassPermissionsValue;
  775. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandRelease, false);
  776. }
  777. private bool CanReclaimParcel(UUID user, ILandObject parcel, Scene scene)
  778. {
  779. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  780. if (m_bypassPermissions) return m_bypassPermissionsValue;
  781. return GenericParcelOwnerPermission(user, parcel, 0,true);
  782. }
  783. private bool CanDeedParcel(UUID user, ILandObject parcel, Scene scene)
  784. {
  785. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  786. if (m_bypassPermissions) return m_bypassPermissionsValue;
  787. if (parcel.LandData.OwnerID != user) // Only the owner can deed!
  788. return false;
  789. ScenePresence sp = scene.GetScenePresence(user);
  790. IClientAPI client = sp.ControllingClient;
  791. if ((client.GetGroupPowers(parcel.LandData.GroupID) & (ulong)GroupPowers.LandDeed) == 0)
  792. return false;
  793. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandDeed, false);
  794. }
  795. private bool CanDeedObject(UUID user, UUID group, Scene scene)
  796. {
  797. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  798. if (m_bypassPermissions) return m_bypassPermissionsValue;
  799. ScenePresence sp = scene.GetScenePresence(user);
  800. IClientAPI client = sp.ControllingClient;
  801. if ((client.GetGroupPowers(group) & (ulong)GroupPowers.DeedObject) == 0)
  802. return false;
  803. return true;
  804. }
  805. private bool IsGod(UUID user, Scene scene)
  806. {
  807. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  808. if (m_bypassPermissions) return m_bypassPermissionsValue;
  809. return IsAdministrator(user);
  810. }
  811. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
  812. {
  813. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  814. if (m_bypassPermissions) return m_bypassPermissionsValue;
  815. if (!GenericObjectPermission(owner, objectID, true))
  816. {
  817. //They can't even edit the object
  818. return false;
  819. }
  820. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  821. if (part == null)
  822. return false;
  823. if (part.OwnerID == owner)
  824. {
  825. if ((part.OwnerMask & PERM_COPY) == 0)
  826. return false;
  827. }
  828. else if (part.GroupID != UUID.Zero)
  829. {
  830. if ((part.OwnerID == part.GroupID) && ((owner != part.LastOwnerID) || ((part.GroupMask & PERM_TRANS) == 0)))
  831. return false;
  832. if ((part.GroupMask & PERM_COPY) == 0)
  833. return false;
  834. }
  835. //If they can rez, they can duplicate
  836. return CanRezObject(objectCount, owner, objectPosition, scene);
  837. }
  838. private bool CanDeleteObject(UUID objectID, UUID deleter, Scene scene)
  839. {
  840. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  841. if (m_bypassPermissions) return m_bypassPermissionsValue;
  842. return GenericObjectPermission(deleter, objectID, false);
  843. }
  844. private bool CanEditObject(UUID objectID, UUID editorID, Scene scene)
  845. {
  846. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  847. if (m_bypassPermissions) return m_bypassPermissionsValue;
  848. return GenericObjectPermission(editorID, objectID, false);
  849. }
  850. private bool CanEditObjectInventory(UUID objectID, UUID editorID, Scene scene)
  851. {
  852. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  853. if (m_bypassPermissions) return m_bypassPermissionsValue;
  854. return GenericObjectPermission(editorID, objectID, false);
  855. }
  856. private bool CanEditParcelProperties(UUID user, ILandObject parcel, GroupPowers p, Scene scene, bool allowManager)
  857. {
  858. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  859. if (m_bypassPermissions) return m_bypassPermissionsValue;
  860. return GenericParcelOwnerPermission(user, parcel, (ulong)p, false);
  861. }
  862. /// <summary>
  863. /// Check whether the specified user can edit the given script
  864. /// </summary>
  865. /// <param name="script"></param>
  866. /// <param name="objectID"></param>
  867. /// <param name="user"></param>
  868. /// <param name="scene"></param>
  869. /// <returns></returns>
  870. private bool CanEditScript(UUID script, UUID objectID, UUID user, Scene scene)
  871. {
  872. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  873. if (m_bypassPermissions) return m_bypassPermissionsValue;
  874. if (m_allowedScriptEditors == UserSet.Administrators && !IsAdministrator(user))
  875. return false;
  876. // Ordinarily, if you can view it, you can edit it
  877. // There is no viewing a no mod script
  878. //
  879. return CanViewScript(script, objectID, user, scene);
  880. }
  881. /// <summary>
  882. /// Check whether the specified user can edit the given notecard
  883. /// </summary>
  884. /// <param name="notecard"></param>
  885. /// <param name="objectID"></param>
  886. /// <param name="user"></param>
  887. /// <param name="scene"></param>
  888. /// <returns></returns>
  889. private bool CanEditNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  890. {
  891. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  892. if (m_bypassPermissions) return m_bypassPermissionsValue;
  893. if (objectID == UUID.Zero) // User inventory
  894. {
  895. IInventoryService invService = m_scene.InventoryService;
  896. InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
  897. assetRequestItem = invService.GetItem(assetRequestItem);
  898. if (assetRequestItem == null && LibraryRootFolder != null) // Library item
  899. {
  900. assetRequestItem = LibraryRootFolder.FindItem(notecard);
  901. if (assetRequestItem != null) // Implicitly readable
  902. return true;
  903. }
  904. // Notecards must be both mod and copy to be saveable
  905. // This is because of they're not copy, you can't read
  906. // them, and if they're not mod, well, then they're
  907. // not mod. Duh.
  908. //
  909. if ((assetRequestItem.CurrentPermissions &
  910. ((uint)PermissionMask.Modify |
  911. (uint)PermissionMask.Copy)) !=
  912. ((uint)PermissionMask.Modify |
  913. (uint)PermissionMask.Copy))
  914. return false;
  915. }
  916. else // Prim inventory
  917. {
  918. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  919. if (part == null)
  920. return false;
  921. if (part.OwnerID != user)
  922. {
  923. if (part.GroupID == UUID.Zero)
  924. return false;
  925. if (!IsGroupMember(part.GroupID, user, 0))
  926. return false;
  927. if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
  928. return false;
  929. }
  930. else
  931. {
  932. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  933. return false;
  934. }
  935. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  936. if (ti == null)
  937. return false;
  938. if (ti.OwnerID != user)
  939. {
  940. if (ti.GroupID == UUID.Zero)
  941. return false;
  942. if (!IsGroupMember(ti.GroupID, user, 0))
  943. return false;
  944. }
  945. // Require full perms
  946. if ((ti.CurrentPermissions &
  947. ((uint)PermissionMask.Modify |
  948. (uint)PermissionMask.Copy)) !=
  949. ((uint)PermissionMask.Modify |
  950. (uint)PermissionMask.Copy))
  951. return false;
  952. }
  953. return true;
  954. }
  955. private bool CanInstantMessage(UUID user, UUID target, Scene startScene)
  956. {
  957. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  958. if (m_bypassPermissions) return m_bypassPermissionsValue;
  959. // If the sender is an object, check owner instead
  960. //
  961. SceneObjectPart part = startScene.GetSceneObjectPart(user);
  962. if (part != null)
  963. user = part.OwnerID;
  964. return GenericCommunicationPermission(user, target);
  965. }
  966. private bool CanInventoryTransfer(UUID user, UUID target, Scene startScene)
  967. {
  968. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  969. if (m_bypassPermissions) return m_bypassPermissionsValue;
  970. return GenericCommunicationPermission(user, target);
  971. }
  972. private bool CanIssueEstateCommand(UUID user, Scene requestFromScene, bool ownerCommand)
  973. {
  974. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  975. if (m_bypassPermissions) return m_bypassPermissionsValue;
  976. if (IsAdministrator(user))
  977. return true;
  978. if (m_scene.RegionInfo.EstateSettings.IsEstateOwner(user))
  979. return true;
  980. if (ownerCommand)
  981. return false;
  982. return GenericEstatePermission(user);
  983. }
  984. private bool CanMoveObject(UUID objectID, UUID moverID, Scene scene)
  985. {
  986. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  987. if (m_bypassPermissions)
  988. {
  989. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  990. if (part.OwnerID != moverID)
  991. {
  992. if (!part.ParentGroup.IsDeleted)
  993. {
  994. if (part.ParentGroup.IsAttachment)
  995. return false;
  996. }
  997. }
  998. return m_bypassPermissionsValue;
  999. }
  1000. bool permission = GenericObjectPermission(moverID, objectID, true);
  1001. if (!permission)
  1002. {
  1003. if (!m_scene.Entities.ContainsKey(objectID))
  1004. {
  1005. return false;
  1006. }
  1007. // The client
  1008. // may request to edit linked parts, and therefore, it needs
  1009. // to also check for SceneObjectPart
  1010. // If it's not an object, we cant edit it.
  1011. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  1012. {
  1013. return false;
  1014. }
  1015. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  1016. // UUID taskOwner = null;
  1017. // Added this because at this point in time it wouldn't be wise for
  1018. // the administrator object permissions to take effect.
  1019. // UUID objectOwner = task.OwnerID;
  1020. // Anyone can move
  1021. if ((task.RootPart.EveryoneMask & PERM_MOVE) != 0)
  1022. permission = true;
  1023. // Locked
  1024. if ((task.RootPart.OwnerMask & PERM_LOCKED) == 0)
  1025. permission = false;
  1026. }
  1027. else
  1028. {
  1029. bool locked = false;
  1030. if (!m_scene.Entities.ContainsKey(objectID))
  1031. {
  1032. return false;
  1033. }
  1034. // If it's not an object, we cant edit it.
  1035. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  1036. {
  1037. return false;
  1038. }
  1039. SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objectID];
  1040. UUID objectOwner = group.OwnerID;
  1041. locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
  1042. // This is an exception to the generic object permission.
  1043. // Administrators who lock their objects should not be able to move them,
  1044. // however generic object permission should return true.
  1045. // This keeps locked objects from being affected by random click + drag actions by accident
  1046. // and allows the administrator to grab or delete a locked object.
  1047. // Administrators and estate managers are still able to click+grab locked objects not
  1048. // owned by them in the scene
  1049. // This is by design.
  1050. if (locked && (moverID == objectOwner))
  1051. return false;
  1052. }
  1053. return permission;
  1054. }
  1055. private bool CanObjectEntry(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  1056. {
  1057. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1058. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1059. if ((newPoint.X > 257f || newPoint.X < -1f || newPoint.Y > 257f || newPoint.Y < -1f))
  1060. {
  1061. return true;
  1062. }
  1063. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  1064. ILandObject land = m_scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  1065. if (!enteringRegion)
  1066. {
  1067. ILandObject fromland = m_scene.LandChannel.GetLandObject(task.AbsolutePosition.X, task.AbsolutePosition.Y);
  1068. if (fromland == land) // Not entering
  1069. return true;
  1070. }
  1071. if (land == null)
  1072. {
  1073. return false;
  1074. }
  1075. if ((land.LandData.Flags & ((int)ParcelFlags.AllowAPrimitiveEntry)) != 0)
  1076. {
  1077. return true;
  1078. }
  1079. if (!m_scene.Entities.ContainsKey(objectID))
  1080. {
  1081. return false;
  1082. }
  1083. // If it's not an object, we cant edit it.
  1084. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  1085. {
  1086. return false;
  1087. }
  1088. if (GenericParcelPermission(task.OwnerID, newPoint, 0))
  1089. {
  1090. return true;
  1091. }
  1092. //Otherwise, false!
  1093. return false;
  1094. }
  1095. private bool CanReturnObjects(ILandObject land, UUID user, List<SceneObjectGroup> objects, Scene scene)
  1096. {
  1097. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1098. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1099. GroupPowers powers;
  1100. ILandObject l;
  1101. ScenePresence sp = scene.GetScenePresence(user);
  1102. if (sp == null)
  1103. return false;
  1104. IClientAPI client = sp.ControllingClient;
  1105. foreach (SceneObjectGroup g in new List<SceneObjectGroup>(objects))
  1106. {
  1107. // Any user can return their own objects at any time
  1108. //
  1109. if (GenericObjectPermission(user, g.UUID, false))
  1110. continue;
  1111. // This is a short cut for efficiency. If land is non-null,
  1112. // then all objects are on that parcel and we can save
  1113. // ourselves the checking for each prim. Much faster.
  1114. //
  1115. if (land != null)
  1116. {
  1117. l = land;
  1118. }
  1119. else
  1120. {
  1121. Vector3 pos = g.AbsolutePosition;
  1122. l = scene.LandChannel.GetLandObject(pos.X, pos.Y);
  1123. }
  1124. // If it's not over any land, then we can't do a thing
  1125. if (l == null)
  1126. {
  1127. objects.Remove(g);
  1128. continue;
  1129. }
  1130. // If we own the land outright, then allow
  1131. //
  1132. if (l.LandData.OwnerID == user)
  1133. continue;
  1134. // Group voodoo
  1135. //
  1136. if (l.LandData.IsGroupOwned)
  1137. {
  1138. powers = (GroupPowers)client.GetGroupPowers(l.LandData.GroupID);
  1139. // Not a group member, or no rights at all
  1140. //
  1141. if (powers == (GroupPowers)0)
  1142. {
  1143. objects.Remove(g);
  1144. continue;
  1145. }
  1146. // Group deeded object?
  1147. //
  1148. if (g.OwnerID == l.LandData.GroupID &&
  1149. (powers & GroupPowers.ReturnGroupOwned) == (GroupPowers)0)
  1150. {
  1151. objects.Remove(g);
  1152. continue;
  1153. }
  1154. // Group set object?
  1155. //
  1156. if (g.GroupID == l.LandData.GroupID &&
  1157. (powers & GroupPowers.ReturnGroupSet) == (GroupPowers)0)
  1158. {
  1159. objects.Remove(g);
  1160. continue;
  1161. }
  1162. if ((powers & GroupPowers.ReturnNonGroup) == (GroupPowers)0)
  1163. {
  1164. objects.Remove(g);
  1165. continue;
  1166. }
  1167. // So we can remove all objects from this group land.
  1168. // Fine.
  1169. //
  1170. continue;
  1171. }
  1172. // By default, we can't remove
  1173. //
  1174. objects.Remove(g);
  1175. }
  1176. if (objects.Count == 0)
  1177. return false;
  1178. return true;
  1179. }
  1180. private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
  1181. {
  1182. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1183. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1184. // m_log.DebugFormat("[PERMISSIONS MODULE]: Checking rez object at {0} in {1}", objectPosition, m_scene.Name);
  1185. ILandObject parcel = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  1186. if (parcel == null)
  1187. return false;
  1188. if ((parcel.LandData.Flags & (uint)ParcelFlags.CreateObjects) != 0)
  1189. {
  1190. return true;
  1191. }
  1192. else if ((owner == parcel.LandData.OwnerID) || IsAdministrator(owner))
  1193. {
  1194. return true;
  1195. }
  1196. else if (((parcel.LandData.Flags & (uint)ParcelFlags.CreateGroupObjects) != 0)
  1197. && (parcel.LandData.GroupID != UUID.Zero) && IsGroupMember(parcel.LandData.GroupID, owner, 0))
  1198. {
  1199. return true;
  1200. }
  1201. else if (parcel.LandData.GroupID != UUID.Zero && IsGroupMember(parcel.LandData.GroupID, owner, (ulong)GroupPowers.AllowRez))
  1202. {
  1203. return true;
  1204. }
  1205. else
  1206. {
  1207. return false;
  1208. }
  1209. }
  1210. private bool CanRunConsoleCommand(UUID user, Scene requestFromScene)
  1211. {
  1212. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1213. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1214. return IsAdministrator(user);
  1215. }
  1216. private bool CanRunScript(UUID script, UUID objectID, UUID user, Scene scene)
  1217. {
  1218. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1219. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1220. return true;
  1221. }
  1222. private bool CanSellParcel(UUID user, ILandObject parcel, Scene scene)
  1223. {
  1224. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1225. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1226. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandSetSale, false);
  1227. }
  1228. private bool CanTakeObject(UUID objectID, UUID stealer, Scene scene)
  1229. {
  1230. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1231. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1232. return GenericObjectPermission(stealer,objectID, false);
  1233. }
  1234. private bool CanTakeCopyObject(UUID objectID, UUID userID, Scene inScene)
  1235. {
  1236. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1237. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1238. bool permission = GenericObjectPermission(userID, objectID, false);
  1239. SceneObjectGroup so = (SceneObjectGroup)m_scene.Entities[objectID];
  1240. if (!permission)
  1241. {
  1242. if (!m_scene.Entities.ContainsKey(objectID))
  1243. {
  1244. return false;
  1245. }
  1246. // If it's not an object, we cant edit it.
  1247. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  1248. {
  1249. return false;
  1250. }
  1251. // UUID taskOwner = null;
  1252. // Added this because at this point in time it wouldn't be wise for
  1253. // the administrator object permissions to take effect.
  1254. // UUID objectOwner = task.OwnerID;
  1255. if ((so.RootPart.EveryoneMask & PERM_COPY) != 0)
  1256. permission = true;
  1257. }
  1258. if (so.OwnerID != userID)
  1259. {
  1260. if ((so.GetEffectivePermissions() & (PERM_COPY | PERM_TRANS)) != (PERM_COPY | PERM_TRANS))
  1261. permission = false;
  1262. }
  1263. else
  1264. {
  1265. if ((so.GetEffectivePermissions() & PERM_COPY) != PERM_COPY)
  1266. permission = false;
  1267. }
  1268. return permission;
  1269. }
  1270. private bool CanTerraformLand(UUID user, Vector3 position, Scene requestFromScene)
  1271. {
  1272. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1273. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1274. // Estate override
  1275. if (GenericEstatePermission(user))
  1276. return true;
  1277. float X = position.X;
  1278. float Y = position.Y;
  1279. if (X > ((int)m_scene.RegionInfo.RegionSizeX - 1))
  1280. X = ((int)m_scene.RegionInfo.RegionSizeX - 1);
  1281. if (Y > ((int)m_scene.RegionInfo.RegionSizeY - 1))
  1282. Y = ((int)m_scene.RegionInfo.RegionSizeY - 1);
  1283. if (X < 0)
  1284. X = 0;
  1285. if (Y < 0)
  1286. Y = 0;
  1287. ILandObject parcel = m_scene.LandChannel.GetLandObject(X, Y);
  1288. if (parcel == null)
  1289. return false;
  1290. // Others allowed to terraform?
  1291. if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowTerraform)) != 0)
  1292. return true;
  1293. // Land owner can terraform too
  1294. if (parcel != null && GenericParcelPermission(user, parcel, (ulong)GroupPowers.AllowEditLand))
  1295. return true;
  1296. return false;
  1297. }
  1298. /// <summary>
  1299. /// Check whether the specified user can view the given script
  1300. /// </summary>
  1301. /// <param name="script"></param>
  1302. /// <param name="objectID"></param>
  1303. /// <param name="user"></param>
  1304. /// <param name="scene"></param>
  1305. /// <returns></returns>
  1306. private bool CanViewScript(UUID script, UUID objectID, UUID user, Scene scene)
  1307. {
  1308. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1309. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1310. if (objectID == UUID.Zero) // User inventory
  1311. {
  1312. IInventoryService invService = m_scene.InventoryService;
  1313. InventoryItemBase assetRequestItem = new InventoryItemBase(script, user);
  1314. assetRequestItem = invService.GetItem(assetRequestItem);
  1315. if (assetRequestItem == null && LibraryRootFolder != null) // Library item
  1316. {
  1317. assetRequestItem = LibraryRootFolder.FindItem(script);
  1318. if (assetRequestItem != null) // Implicitly readable
  1319. return true;
  1320. }
  1321. // SL is rather harebrained here. In SL, a script you
  1322. // have mod/copy no trans is readable. This subverts
  1323. // permissions, but is used in some products, most
  1324. // notably Hippo door plugin and HippoRent 5 networked
  1325. // prim counter.
  1326. // To enable this broken SL-ism, remove Transfer from
  1327. // the below expressions.
  1328. // Trying to improve on SL perms by making a script
  1329. // readable only if it's really full perms
  1330. //
  1331. if ((assetRequestItem.CurrentPermissions &
  1332. ((uint)PermissionMask.Modify |
  1333. (uint)PermissionMask.Copy |
  1334. (uint)PermissionMask.Transfer)) !=
  1335. ((uint)PermissionMask.Modify |
  1336. (uint)PermissionMask.Copy |
  1337. (uint)PermissionMask.Transfer))
  1338. return false;
  1339. }
  1340. else // Prim inventory
  1341. {
  1342. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  1343. if (part == null)
  1344. return false;
  1345. if (part.OwnerID != user)
  1346. {
  1347. if (part.GroupID == UUID.Zero)
  1348. return false;
  1349. if (!IsGroupMember(part.GroupID, user, 0))
  1350. return false;
  1351. if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
  1352. return false;
  1353. }
  1354. else
  1355. {
  1356. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1357. return false;
  1358. }
  1359. TaskInventoryItem ti = part.Inventory.GetInventoryItem(script);
  1360. if (ti == null)
  1361. return false;
  1362. if (ti.OwnerID != user)
  1363. {
  1364. if (ti.GroupID == UUID.Zero)
  1365. return false;
  1366. if (!IsGroupMember(ti.GroupID, user, 0))
  1367. return false;
  1368. }
  1369. // Require full perms
  1370. if ((ti.CurrentPermissions &
  1371. ((uint)PermissionMask.Modify |
  1372. (uint)PermissionMask.Copy |
  1373. (uint)PermissionMask.Transfer)) !=
  1374. ((uint)PermissionMask.Modify |
  1375. (uint)PermissionMask.Copy |
  1376. (uint)PermissionMask.Transfer))
  1377. return false;
  1378. }
  1379. return true;
  1380. }
  1381. /// <summary>
  1382. /// Check whether the specified user can view the given notecard
  1383. /// </summary>
  1384. /// <param name="script"></param>
  1385. /// <param name="objectID"></param>
  1386. /// <param name="user"></param>
  1387. /// <param name="scene"></param>
  1388. /// <returns></returns>
  1389. private bool CanViewNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  1390. {
  1391. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1392. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1393. if (objectID == UUID.Zero) // User inventory
  1394. {
  1395. IInventoryService invService = m_scene.InventoryService;
  1396. InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
  1397. assetRequestItem = invService.GetItem(assetRequestItem);
  1398. if (assetRequestItem == null && LibraryRootFolder != null) // Library item
  1399. {
  1400. assetRequestItem = LibraryRootFolder.FindItem(notecard);
  1401. if (assetRequestItem != null) // Implicitly readable
  1402. return true;
  1403. }
  1404. // Notecards are always readable unless no copy
  1405. //
  1406. if ((assetRequestItem.CurrentPermissions &
  1407. (uint)PermissionMask.Copy) !=
  1408. (uint)PermissionMask.Copy)
  1409. return false;
  1410. }
  1411. else // Prim inventory
  1412. {
  1413. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  1414. if (part == null)
  1415. return false;
  1416. if (part.OwnerID != user)
  1417. {
  1418. if (part.GroupID == UUID.Zero)
  1419. return false;
  1420. if (!IsGroupMember(part.GroupID, user, 0))
  1421. return false;
  1422. }
  1423. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1424. return false;
  1425. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  1426. if (ti == null)
  1427. return false;
  1428. if (ti.OwnerID != user)
  1429. {
  1430. if (ti.GroupID == UUID.Zero)
  1431. return false;
  1432. if (!IsGroupMember(ti.GroupID, user, 0))
  1433. return false;
  1434. }
  1435. // Notecards are always readable unless no copy
  1436. //
  1437. if ((ti.CurrentPermissions &
  1438. (uint)PermissionMask.Copy) !=
  1439. (uint)PermissionMask.Copy)
  1440. return false;
  1441. }
  1442. return true;
  1443. }
  1444. #endregion
  1445. private bool CanLinkObject(UUID userID, UUID objectID)
  1446. {
  1447. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1448. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1449. return GenericObjectPermission(userID, objectID, false);
  1450. }
  1451. private bool CanDelinkObject(UUID userID, UUID objectID)
  1452. {
  1453. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1454. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1455. return GenericObjectPermission(userID, objectID, false);
  1456. }
  1457. private bool CanBuyLand(UUID userID, ILandObject parcel, Scene scene)
  1458. {
  1459. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1460. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1461. return true;
  1462. }
  1463. private bool CanCopyObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1464. {
  1465. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1466. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1467. return true;
  1468. }
  1469. private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1470. {
  1471. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1472. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1473. return true;
  1474. }
  1475. /// <summary>
  1476. /// Check whether the specified user is allowed to directly create the given inventory type in a prim's
  1477. /// inventory (e.g. the New Script button in the 1.21 Linden Lab client).
  1478. /// </summary>
  1479. /// <param name="invType"></param>
  1480. /// <param name="objectID"></param>
  1481. /// <param name="userID"></param>
  1482. /// <returns></returns>
  1483. private bool CanCreateObjectInventory(int invType, UUID objectID, UUID userID)
  1484. {
  1485. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1486. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1487. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  1488. ScenePresence p = m_scene.GetScenePresence(userID);
  1489. if (part == null || p == null)
  1490. return false;
  1491. if (!IsAdministrator(userID))
  1492. {
  1493. if (part.OwnerID != userID)
  1494. {
  1495. // Group permissions
  1496. if ((part.GroupID == UUID.Zero) || (p.ControllingClient.GetGroupPowers(part.GroupID) == 0) || ((part.GroupMask & (uint)PermissionMask.Modify) == 0))
  1497. return false;
  1498. } else {
  1499. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1500. return false;
  1501. }
  1502. if ((int)InventoryType.LSL == invType)
  1503. if (m_allowedScriptCreators == UserSet.Administrators)
  1504. return false;
  1505. }
  1506. return true;
  1507. }
  1508. /// <summary>
  1509. /// Check whether the specified user is allowed to create the given inventory type in their inventory.
  1510. /// </summary>
  1511. /// <param name="invType"></param>
  1512. /// <param name="userID"></param>
  1513. /// <returns></returns>
  1514. private bool CanCreateUserInventory(int invType, UUID userID)
  1515. {
  1516. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1517. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1518. if ((int)InventoryType.LSL == invType)
  1519. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1520. return false;
  1521. return true;
  1522. }
  1523. /// <summary>
  1524. /// Check whether the specified user is allowed to copy the given inventory type in their inventory.
  1525. /// </summary>
  1526. /// <param name="itemID"></param>
  1527. /// <param name="userID"></param>
  1528. /// <returns></returns>
  1529. private bool CanCopyUserInventory(UUID itemID, UUID userID)
  1530. {
  1531. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1532. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1533. return true;
  1534. }
  1535. /// <summary>
  1536. /// Check whether the specified user is allowed to edit the given inventory item within their own inventory.
  1537. /// </summary>
  1538. /// <param name="itemID"></param>
  1539. /// <param name="userID"></param>
  1540. /// <returns></returns>
  1541. private bool CanEditUserInventory(UUID itemID, UUID userID)
  1542. {
  1543. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1544. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1545. return true;
  1546. }
  1547. /// <summary>
  1548. /// Check whether the specified user is allowed to delete the given inventory item from their own inventory.
  1549. /// </summary>
  1550. /// <param name="itemID"></param>
  1551. /// <param name="userID"></param>
  1552. /// <returns></returns>
  1553. private bool CanDeleteUserInventory(UUID itemID, UUID userID)
  1554. {
  1555. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1556. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1557. return true;
  1558. }
  1559. private bool CanTeleport(UUID userID, Scene scene)
  1560. {
  1561. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1562. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1563. return true;
  1564. }
  1565. private bool CanResetScript(UUID prim, UUID script, UUID agentID, Scene scene)
  1566. {
  1567. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1568. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1569. SceneObjectPart part = m_scene.GetSceneObjectPart(prim);
  1570. // If we selected a sub-prim to reset, prim won't represent the object, but only a part.
  1571. // We have to check the permissions of the object, though.
  1572. if (part.ParentID != 0) prim = part.ParentUUID;
  1573. // You can reset the scripts in any object you can edit
  1574. return GenericObjectPermission(agentID, prim, false);
  1575. }
  1576. private bool CanCompileScript(UUID ownerUUID, int scriptType, Scene scene)
  1577. {
  1578. //m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType);
  1579. switch (scriptType) {
  1580. case 0:
  1581. if (GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString())) {
  1582. return(true);
  1583. }
  1584. break;
  1585. case 1:
  1586. if (GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString())) {
  1587. return(true);
  1588. }
  1589. break;
  1590. case 2:
  1591. if (GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString())) {
  1592. return(true);
  1593. }
  1594. break;
  1595. case 3:
  1596. if (GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString()))
  1597. {
  1598. return (true);
  1599. }
  1600. break;
  1601. case 4:
  1602. if (GrantYP.Count == 0 || GrantYP.ContainsKey(ownerUUID.ToString()))
  1603. {
  1604. return (true);
  1605. }
  1606. break;
  1607. }
  1608. return(false);
  1609. }
  1610. private bool CanControlPrimMedia(UUID agentID, UUID primID, int face)
  1611. {
  1612. // m_log.DebugFormat(
  1613. // "[PERMISSONS]: Performing CanControlPrimMedia check with agentID {0}, primID {1}, face {2}",
  1614. // agentID, primID, face);
  1615. if (null == MoapModule)
  1616. return false;
  1617. SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
  1618. if (null == part)
  1619. return false;
  1620. MediaEntry me = MoapModule.GetMediaEntry(part, face);
  1621. // If there is no existing media entry then it can be controlled (in this context, created).
  1622. if (null == me)
  1623. return true;
  1624. // m_log.DebugFormat(
  1625. // "[PERMISSIONS]: Checking CanControlPrimMedia for {0} on {1} face {2} with control permissions {3}",
  1626. // agentID, primID, face, me.ControlPermissions);
  1627. return GenericObjectPermission(agentID, part.ParentGroup.UUID, true);
  1628. }
  1629. private bool CanInteractWithPrimMedia(UUID agentID, UUID primID, int face)
  1630. {
  1631. // m_log.DebugFormat(
  1632. // "[PERMISSONS]: Performing CanInteractWithPrimMedia check with agentID {0}, primID {1}, face {2}",
  1633. // agentID, primID, face);
  1634. if (null == MoapModule)
  1635. return false;
  1636. SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
  1637. if (null == part)
  1638. return false;
  1639. MediaEntry me = MoapModule.GetMediaEntry(part, face);
  1640. // If there is no existing media entry then it can be controlled (in this context, created).
  1641. if (null == me)
  1642. return true;
  1643. // m_log.DebugFormat(
  1644. // "[PERMISSIONS]: Checking CanInteractWithPrimMedia for {0} on {1} face {2} with interact permissions {3}",
  1645. // agentID, primID, face, me.InteractPermissions);
  1646. return GenericPrimMediaPermission(part, agentID, me.InteractPermissions);
  1647. }
  1648. private bool GenericPrimMediaPermission(SceneObjectPart part, UUID agentID, MediaPermission perms)
  1649. {
  1650. // if (IsAdministrator(agentID))
  1651. // return true;
  1652. if ((perms & MediaPermission.Anyone) == MediaPermission.Anyone)
  1653. return true;
  1654. if ((perms & MediaPermission.Owner) == MediaPermission.Owner)
  1655. {
  1656. if (agentID == part.OwnerID)
  1657. return true;
  1658. }
  1659. if ((perms & MediaPermission.Group) == MediaPermission.Group)
  1660. {
  1661. if (IsGroupMember(part.GroupID, agentID, 0))
  1662. return true;
  1663. }
  1664. return false;
  1665. }
  1666. }
  1667. }