PermissionsModule.cs 75 KB

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