PermissionsModule.cs 74 KB

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