PermissionsModule.cs 73 KB

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