PermissionsModule.cs 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using log4net;
  32. using Nini.Config;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Services.Interfaces;
  38. using Mono.Addins;
  39. using PermissionMask = OpenSim.Framework.PermissionMask;
  40. namespace OpenSim.Region.CoreModules.World.Permissions
  41. {
  42. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DefaultPermissionsModule")]
  43. public class DefaultPermissionsModule : INonSharedRegionModule, IPermissionsModule
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. protected Scene m_scene;
  47. protected ScenePermissions scenePermissions;
  48. protected bool m_Enabled;
  49. private InventoryFolderImpl m_libraryRootFolder;
  50. protected InventoryFolderImpl LibraryRootFolder
  51. {
  52. get
  53. {
  54. if (m_libraryRootFolder is null)
  55. {
  56. ILibraryService lib = m_scene.RequestModuleInterface<ILibraryService>();
  57. if (lib is not null)
  58. {
  59. m_libraryRootFolder = lib.LibraryRootFolder;
  60. }
  61. }
  62. return m_libraryRootFolder;
  63. }
  64. }
  65. #region Constants
  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_allowGridAdmins = false;
  82. private bool m_RegionOwnerIsAdmin = false;
  83. private bool m_RegionManagerIsAdmin = false;
  84. private bool m_forceGridAdminsOnly;
  85. private bool m_forceAdminModeAlwaysOn;
  86. private bool m_allowAdminActionsWithoutGodMode;
  87. /// <value>
  88. /// The set of users that are allowed to create scripts. This is only active if permissions are not being
  89. /// bypassed. This overrides normal permissions.
  90. /// </value>
  91. private UserSet m_allowedScriptCreators = UserSet.All;
  92. /// <value>
  93. /// The set of users that are allowed to edit (save) scripts. This is only active if
  94. /// permissions are not being bypassed. This overrides normal permissions.-
  95. /// </value>
  96. private UserSet m_allowedScriptEditors = UserSet.All;
  97. private readonly Dictionary<string, bool> GrantLSL = new();
  98. private readonly Dictionary<string, bool> GrantCS = new();
  99. private readonly Dictionary<string, bool> GrantVB = new();
  100. private readonly Dictionary<string, bool> GrantJS = new();
  101. private readonly Dictionary<string, bool> GrantYP = new();
  102. private IFriendsModule m_friendsModule;
  103. private IFriendsModule FriendsModule
  104. {
  105. get
  106. {
  107. m_friendsModule ??= m_scene.RequestModuleInterface<IFriendsModule>();
  108. return m_friendsModule;
  109. }
  110. }
  111. private IGroupsModule m_groupsModule;
  112. private IGroupsModule GroupsModule
  113. {
  114. get
  115. {
  116. m_groupsModule ??= m_scene.RequestModuleInterface<IGroupsModule>();
  117. return m_groupsModule;
  118. }
  119. }
  120. private IMoapModule m_moapModule;
  121. private IMoapModule MoapModule
  122. {
  123. get
  124. {
  125. m_moapModule ??= m_scene.RequestModuleInterface<IMoapModule>();
  126. return m_moapModule;
  127. }
  128. }
  129. #endregion
  130. #region INonSharedRegionModule Members
  131. public void Initialise(IConfigSource config)
  132. {
  133. string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules",
  134. new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
  135. List<string> modules = new(permissionModules.Split(',').Select(m => m.Trim()));
  136. if (!modules.Contains("DefaultPermissionsModule"))
  137. return;
  138. m_Enabled = true;
  139. string[] sections = new string[] { "Startup", "Permissions" };
  140. m_allowGridAdmins = Util.GetConfigVarFromSections<bool>(config, "allow_grid_gods", sections, false);
  141. m_bypassPermissions = !Util.GetConfigVarFromSections<bool>(config, "serverside_object_permissions", sections, true);
  142. m_propagatePermissions = Util.GetConfigVarFromSections<bool>(config, "propagate_permissions", sections, true);
  143. m_forceGridAdminsOnly = Util.GetConfigVarFromSections<bool>(config, "force_grid_gods_only", sections, false);
  144. if(!m_forceGridAdminsOnly)
  145. {
  146. m_RegionOwnerIsAdmin = Util.GetConfigVarFromSections<bool>(config, "region_owner_is_god",sections, true);
  147. m_RegionManagerIsAdmin = Util.GetConfigVarFromSections<bool>(config, "region_manager_is_god",sections, false);
  148. }
  149. else
  150. m_allowGridAdmins = true;
  151. m_forceAdminModeAlwaysOn = Util.GetConfigVarFromSections<bool>(config, "automatic_gods", sections, false);
  152. m_allowAdminActionsWithoutGodMode = Util.GetConfigVarFromSections<bool>(config, "implicit_gods", sections, false);
  153. if(m_allowAdminActionsWithoutGodMode)
  154. m_forceAdminModeAlwaysOn = false;
  155. m_allowedScriptCreators
  156. = ParseUserSetConfigSetting(config, "allowed_script_creators", m_allowedScriptCreators);
  157. m_allowedScriptEditors
  158. = ParseUserSetConfigSetting(config, "allowed_script_editors", m_allowedScriptEditors);
  159. if (m_bypassPermissions)
  160. m_log.Info("[PERMISSIONS]: serverside_object_permissions = false in ini file so disabling all region service permission checks");
  161. else
  162. m_log.Debug("[PERMISSIONS]: Enabling all region service permission checks");
  163. string grant = Util.GetConfigVarFromSections<string>(config, "GrantLSL",
  164. new string[] { "Startup", "Permissions" }, string.Empty);
  165. if (grant.Length > 0)
  166. {
  167. foreach (string uuidl in grant.Split(','))
  168. {
  169. string uuid = uuidl.Trim(" \t".ToCharArray());
  170. GrantLSL.Add(uuid, true);
  171. }
  172. }
  173. grant = Util.GetConfigVarFromSections<string>(config, "GrantCS",
  174. new string[] { "Startup", "Permissions" }, string.Empty);
  175. if (grant.Length > 0)
  176. {
  177. foreach (string uuidl in grant.Split(','))
  178. {
  179. string uuid = uuidl.Trim(" \t".ToCharArray());
  180. GrantCS.Add(uuid, true);
  181. }
  182. }
  183. grant = Util.GetConfigVarFromSections<string>(config, "GrantVB",
  184. new string[] { "Startup", "Permissions" }, string.Empty);
  185. if (grant.Length > 0)
  186. {
  187. foreach (string uuidl in grant.Split(','))
  188. {
  189. string uuid = uuidl.Trim(" \t".ToCharArray());
  190. GrantVB.Add(uuid, true);
  191. }
  192. }
  193. grant = Util.GetConfigVarFromSections<string>(config, "GrantJS",
  194. new string[] { "Startup", "Permissions" }, string.Empty);
  195. if (grant.Length > 0)
  196. {
  197. foreach (string uuidl in grant.Split(','))
  198. {
  199. string uuid = uuidl.Trim(" \t".ToCharArray());
  200. GrantJS.Add(uuid, true);
  201. }
  202. }
  203. grant = Util.GetConfigVarFromSections<string>(config, "GrantYP",
  204. new string[] { "Startup", "Permissions" }, string.Empty);
  205. if (grant.Length > 0)
  206. {
  207. foreach (string uuidl in grant.Split(','))
  208. {
  209. string uuid = uuidl.Trim(" \t".ToCharArray());
  210. GrantYP.Add(uuid, true);
  211. }
  212. }
  213. }
  214. public void AddRegion(Scene scene)
  215. {
  216. if (!m_Enabled)
  217. return;
  218. m_scene = scene;
  219. scene.RegisterModuleInterface<IPermissionsModule>(this);
  220. scenePermissions = m_scene.Permissions;
  221. //Register functions with Scene External Checks!
  222. scenePermissions.OnBypassPermissions += BypassPermissions;
  223. scenePermissions.OnSetBypassPermissions += SetBypassPermissions;
  224. scenePermissions.OnPropagatePermissions += PropagatePermissions;
  225. scenePermissions.OnIsGridGod += IsGridAdministrator;
  226. scenePermissions.OnIsAdministrator += IsAdministrator;
  227. scenePermissions.OnIsEstateManager += IsEstateManager;
  228. scenePermissions.OnGenerateClientFlags += GenerateClientFlags;
  229. scenePermissions.OnIssueEstateCommand += CanIssueEstateCommand;
  230. scenePermissions.OnRunConsoleCommand += CanRunConsoleCommand;
  231. scenePermissions.OnTeleport += CanTeleport;
  232. scenePermissions.OnInstantMessage += CanInstantMessage;
  233. scenePermissions.OnAbandonParcel += CanAbandonParcel;
  234. scenePermissions.OnReclaimParcel += CanReclaimParcel;
  235. scenePermissions.OnDeedParcel += CanDeedParcel;
  236. scenePermissions.OnSellParcel += CanSellParcel;
  237. scenePermissions.OnEditParcelProperties += CanEditParcelProperties;
  238. scenePermissions.OnTerraformLand += CanTerraformLand;
  239. scenePermissions.OnBuyLand += CanBuyLand;
  240. scenePermissions.OnReturnObjects += CanReturnObjects;
  241. scenePermissions.OnRezObject += CanRezObject;
  242. scenePermissions.OnObjectEntry += CanObjectEntry;
  243. scenePermissions.OnObjectEnterWithScripts += OnObjectEnterWithScripts;
  244. scenePermissions.OnDuplicateObject += CanDuplicateObject;
  245. scenePermissions.OnDeleteObjectByIDs += CanDeleteObjectByIDs;
  246. scenePermissions.OnDeleteObject += CanDeleteObject;
  247. scenePermissions.OnEditObjectByIDs += CanEditObjectByIDs;
  248. scenePermissions.OnEditObject += CanEditObject;
  249. scenePermissions.OnEditObjectPerms += CanEditObjectPerms;
  250. scenePermissions.OnInventoryTransfer += CanInventoryTransfer;
  251. scenePermissions.OnMoveObject += CanMoveObject;
  252. scenePermissions.OnTakeObject += CanTakeObject;
  253. scenePermissions.OnTakeCopyObject += CanTakeCopyObject;
  254. scenePermissions.OnLinkObject += CanLinkObject;
  255. scenePermissions.OnDelinkObject += CanDelinkObject;
  256. scenePermissions.OnDeedObject += CanDeedObject;
  257. scenePermissions.OnSellGroupObject += CanSellGroupObject;
  258. scenePermissions.OnSellObjectByUserID += CanSellObjectByUserID;
  259. scenePermissions.OnSellObject += CanSellObject;
  260. scenePermissions.OnCreateObjectInventory += CanCreateObjectInventory;
  261. scenePermissions.OnEditObjectInventory += CanEditObjectInventory;
  262. scenePermissions.OnCopyObjectInventory += CanCopyObjectInventory;
  263. scenePermissions.OnDeleteObjectInventory += CanDeleteObjectInventory;
  264. scenePermissions.OnDoObjectInvToObjectInv += CanDoObjectInvToObjectInv;
  265. scenePermissions.OnDropInObjectInv += CanDropInObjectInv;
  266. scenePermissions.OnViewNotecard += CanViewNotecard;
  267. scenePermissions.OnViewScript += CanViewScript;
  268. scenePermissions.OnEditNotecard += CanEditNotecard;
  269. scenePermissions.OnEditScript += CanEditScript;
  270. scenePermissions.OnResetScript += CanResetScript;
  271. scenePermissions.OnRunScript += CanRunScript;
  272. scenePermissions.OnCompileScript += CanCompileScript;
  273. scenePermissions.OnCreateUserInventory += CanCreateUserInventory;
  274. scenePermissions.OnCopyUserInventory += CanCopyUserInventory;
  275. scenePermissions.OnEditUserInventory += CanEditUserInventory;
  276. scenePermissions.OnDeleteUserInventory += CanDeleteUserInventory;
  277. scenePermissions.OnControlPrimMedia += CanControlPrimMedia;
  278. scenePermissions.OnInteractWithPrimMedia += CanInteractWithPrimMedia;
  279. m_scene.AddCommand("Users", this, "bypass permissions",
  280. "bypass permissions <true / false>",
  281. "Bypass permission checks",
  282. HandleBypassPermissions);
  283. m_scene.AddCommand("Users", this, "force permissions",
  284. "force permissions <true / false>",
  285. "Force permissions on or off",
  286. HandleForcePermissions);
  287. m_scene.AddCommand("Debug", this, "debug permissions",
  288. "debug permissions <true / false>",
  289. "Turn on permissions debugging",
  290. HandleDebugPermissions);
  291. }
  292. public void RegionLoaded(Scene scene)
  293. {
  294. }
  295. public void RemoveRegion(Scene scene)
  296. {
  297. if (!m_Enabled)
  298. return;
  299. m_scene.UnregisterModuleInterface<IPermissionsModule>(this);
  300. scenePermissions.OnBypassPermissions -= BypassPermissions;
  301. scenePermissions.OnSetBypassPermissions -= SetBypassPermissions;
  302. scenePermissions.OnPropagatePermissions -= PropagatePermissions;
  303. scenePermissions.OnIsGridGod -= IsGridAdministrator;
  304. scenePermissions.OnIsAdministrator -= IsAdministrator;
  305. scenePermissions.OnIsEstateManager -= IsEstateManager;
  306. scenePermissions.OnGenerateClientFlags -= GenerateClientFlags;
  307. scenePermissions.OnIssueEstateCommand -= CanIssueEstateCommand;
  308. scenePermissions.OnRunConsoleCommand -= CanRunConsoleCommand;
  309. scenePermissions.OnTeleport -= CanTeleport;
  310. scenePermissions.OnInstantMessage -= CanInstantMessage;
  311. scenePermissions.OnAbandonParcel -= CanAbandonParcel;
  312. scenePermissions.OnReclaimParcel -= CanReclaimParcel;
  313. scenePermissions.OnDeedParcel -= CanDeedParcel;
  314. scenePermissions.OnSellParcel -= CanSellParcel;
  315. scenePermissions.OnEditParcelProperties -= CanEditParcelProperties;
  316. scenePermissions.OnTerraformLand -= CanTerraformLand;
  317. scenePermissions.OnBuyLand -= CanBuyLand;
  318. scenePermissions.OnRezObject -= CanRezObject;
  319. scenePermissions.OnObjectEntry -= CanObjectEntry;
  320. scenePermissions.OnObjectEnterWithScripts -= OnObjectEnterWithScripts;
  321. scenePermissions.OnReturnObjects -= CanReturnObjects;
  322. scenePermissions.OnDuplicateObject -= CanDuplicateObject;
  323. scenePermissions.OnDeleteObjectByIDs -= CanDeleteObjectByIDs;
  324. scenePermissions.OnDeleteObject -= CanDeleteObject;
  325. scenePermissions.OnEditObjectByIDs -= CanEditObjectByIDs;
  326. scenePermissions.OnEditObject -= CanEditObject;
  327. scenePermissions.OnEditObjectPerms -= CanEditObjectPerms;
  328. scenePermissions.OnInventoryTransfer -= CanInventoryTransfer;
  329. scenePermissions.OnMoveObject -= CanMoveObject;
  330. scenePermissions.OnTakeObject -= CanTakeObject;
  331. scenePermissions.OnTakeCopyObject -= CanTakeCopyObject;
  332. scenePermissions.OnLinkObject -= CanLinkObject;
  333. scenePermissions.OnDelinkObject -= CanDelinkObject;
  334. scenePermissions.OnDeedObject -= CanDeedObject;
  335. scenePermissions.OnSellGroupObject -= CanSellGroupObject;
  336. scenePermissions.OnSellObjectByUserID -= CanSellObjectByUserID;
  337. scenePermissions.OnSellObject -= CanSellObject;
  338. scenePermissions.OnCreateObjectInventory -= CanCreateObjectInventory;
  339. scenePermissions.OnEditObjectInventory -= CanEditObjectInventory;
  340. scenePermissions.OnCopyObjectInventory -= CanCopyObjectInventory;
  341. scenePermissions.OnDeleteObjectInventory -= CanDeleteObjectInventory;
  342. scenePermissions.OnDoObjectInvToObjectInv -= CanDoObjectInvToObjectInv;
  343. scenePermissions.OnDropInObjectInv -= CanDropInObjectInv;
  344. scenePermissions.OnViewNotecard -= CanViewNotecard;
  345. scenePermissions.OnViewScript -= CanViewScript;
  346. scenePermissions.OnEditNotecard -= CanEditNotecard;
  347. scenePermissions.OnEditScript -= CanEditScript;
  348. scenePermissions.OnResetScript -= CanResetScript;
  349. scenePermissions.OnRunScript -= CanRunScript;
  350. scenePermissions.OnCompileScript -= CanCompileScript;
  351. scenePermissions.OnCreateUserInventory -= CanCreateUserInventory;
  352. scenePermissions.OnCopyUserInventory -= CanCopyUserInventory;
  353. scenePermissions.OnEditUserInventory -= CanEditUserInventory;
  354. scenePermissions.OnDeleteUserInventory -= CanDeleteUserInventory;
  355. scenePermissions.OnControlPrimMedia -= CanControlPrimMedia;
  356. scenePermissions.OnInteractWithPrimMedia -= CanInteractWithPrimMedia;
  357. }
  358. public void Close()
  359. {
  360. }
  361. public string Name
  362. {
  363. get { return "DefaultPermissionsModule"; }
  364. }
  365. public Type ReplaceableInterface
  366. {
  367. get { return null; }
  368. }
  369. #endregion
  370. #region Console command handlers
  371. public void HandleBypassPermissions(string module, string[] args)
  372. {
  373. if (m_scene.ConsoleScene() is not null &&
  374. m_scene.ConsoleScene() != m_scene)
  375. {
  376. return;
  377. }
  378. if (args.Length > 2)
  379. {
  380. if (!bool.TryParse(args[2], out bool val))
  381. return;
  382. m_bypassPermissions = val;
  383. m_log.InfoFormat(
  384. "[PERMISSIONS]: Set permissions bypass to {0} for {1}",
  385. m_bypassPermissions, m_scene.RegionInfo.RegionName);
  386. }
  387. }
  388. public void HandleForcePermissions(string module, string[] args)
  389. {
  390. if (m_scene.ConsoleScene() is not null &&
  391. m_scene.ConsoleScene() != m_scene)
  392. {
  393. return;
  394. }
  395. if (!m_bypassPermissions)
  396. {
  397. m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first");
  398. return;
  399. }
  400. if (args.Length > 2)
  401. {
  402. if (!bool.TryParse(args[2], out bool val))
  403. return;
  404. m_bypassPermissionsValue = val;
  405. m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName);
  406. }
  407. }
  408. public void HandleDebugPermissions(string module, string[] args)
  409. {
  410. if (m_scene.ConsoleScene() is not null &&
  411. m_scene.ConsoleScene() != m_scene)
  412. {
  413. return;
  414. }
  415. if (args.Length > 2)
  416. {
  417. if (!bool.TryParse(args[2], out bool val))
  418. return;
  419. m_debugPermissions = val;
  420. m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName);
  421. }
  422. }
  423. #endregion
  424. #region Helper Functions
  425. protected void SendPermissionError(UUID user, string reason)
  426. {
  427. m_scene.EventManager.TriggerPermissionError(user, reason);
  428. }
  429. protected void DebugPermissionInformation(string permissionCalled)
  430. {
  431. if (m_debugPermissions)
  432. m_log.Debug("[PERMISSIONS]: " + permissionCalled + " was called from " + m_scene.RegionInfo.RegionName);
  433. }
  434. /// <summary>
  435. /// Checks if the given group is active and if the user is a group member
  436. /// with the powers requested (powers = 0 for no powers check)
  437. /// </summary>
  438. /// <param name="groupID"></param>
  439. /// <param name="userID"></param>
  440. /// <param name="powers"></param>
  441. /// <returns></returns>
  442. protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers)
  443. {
  444. if (GroupsModule is null)
  445. return false;
  446. GroupMembershipData gmd = GroupsModule.GetMembershipData(groupID, userID);
  447. if (gmd is not null)
  448. {
  449. if (((gmd.GroupPowers != 0) && powers == 0) || (gmd.GroupPowers & powers) == powers)
  450. return true;
  451. }
  452. return false;
  453. }
  454. protected bool GroupMemberPowers(UUID groupID, UUID userID, ref ulong powers)
  455. {
  456. powers = 0;
  457. if (GroupsModule is null)
  458. return false;
  459. GroupMembershipData gmd = GroupsModule.GetMembershipData(groupID, userID);
  460. if (gmd is not null)
  461. {
  462. powers = gmd.GroupPowers;
  463. return true;
  464. }
  465. return false;
  466. }
  467. protected bool GroupMemberPowers(UUID groupID, ScenePresence sp, ref ulong powers)
  468. {
  469. powers = 0;
  470. IClientAPI client = sp.ControllingClient;
  471. if (client is null)
  472. return false;
  473. if(!client.IsGroupMember(groupID))
  474. return false;
  475. powers = client.GetGroupPowers(groupID);
  476. return true;
  477. }
  478. /// <summary>
  479. /// Parse a user set configuration setting
  480. /// </summary>
  481. /// <param name="config"></param>
  482. /// <param name="settingName"></param>
  483. /// <param name="defaultValue">The default value for this attribute</param>
  484. /// <returns>The parsed value</returns>
  485. private static UserSet ParseUserSetConfigSetting(IConfigSource config, string settingName, UserSet defaultValue)
  486. {
  487. UserSet userSet = defaultValue;
  488. string rawSetting = Util.GetConfigVarFromSections<string>(config, settingName,
  489. new string[] {"Startup", "Permissions"}, defaultValue.ToString());
  490. // Temporary measure to allow 'gods' to be specified in config for consistency's sake. In the long term
  491. // this should disappear.
  492. if ("gods" == rawSetting.ToLower())
  493. rawSetting = UserSet.Administrators.ToString();
  494. // Doing it this was so that we can do a case insensitive conversion
  495. try
  496. {
  497. userSet = (UserSet)Enum.Parse(typeof(UserSet), rawSetting, true);
  498. }
  499. catch
  500. {
  501. m_log.ErrorFormat(
  502. "[PERMISSIONS]: {0} is not a valid {1} value, setting to {2}",
  503. rawSetting, settingName, userSet);
  504. }
  505. m_log.DebugFormat("[PERMISSIONS]: {0} {1}", settingName, userSet);
  506. return userSet;
  507. }
  508. /// <summary>
  509. /// Is the user regarded as an administrator?
  510. /// </summary>
  511. /// <param name="user"></param>
  512. /// <returns></returns>
  513. protected bool IsAdministrator(UUID user)
  514. {
  515. if (user.IsZero())
  516. return false;
  517. if (m_RegionOwnerIsAdmin && m_scene.RegionInfo.EstateSettings.EstateOwner.Equals(user))
  518. return true;
  519. if (m_RegionManagerIsAdmin && IsEstateManager(user))
  520. return true;
  521. if (IsGridAdministrator(user))
  522. return true;
  523. return false;
  524. }
  525. /// <summary>
  526. /// Is the given user a God throughout the grid (not just in the current scene)?
  527. /// </summary>
  528. /// <param name="user">The user</param>
  529. /// <param name="scene">Unused, can be null</param>
  530. /// <returns></returns>
  531. protected bool IsGridAdministrator(UUID user)
  532. {
  533. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  534. if (m_bypassPermissions) return m_bypassPermissionsValue;
  535. if (user.IsZero())
  536. return false;
  537. if (m_allowGridAdmins)
  538. {
  539. ScenePresence sp = m_scene.GetScenePresence(user);
  540. if (sp is not null)
  541. return (sp.GodController.UserLevel >= 200);
  542. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, user);
  543. if (account is not null)
  544. return (account.UserLevel >= 200);
  545. }
  546. return false;
  547. }
  548. protected bool IsFriendWithPerms(UUID user, UUID objectOwner)
  549. {
  550. if (FriendsModule is null)
  551. return false;
  552. if (user.IsZero())
  553. return false;
  554. int friendPerms = FriendsModule.GetRightsGrantedByFriend(user, objectOwner);
  555. return (friendPerms & (int)FriendRights.CanModifyObjects) != 0;
  556. }
  557. protected bool IsEstateManager(UUID user)
  558. {
  559. if (user.IsZero())
  560. return false;
  561. return m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(user);
  562. }
  563. #endregion
  564. public bool PropagatePermissions()
  565. {
  566. if (m_bypassPermissions)
  567. return false;
  568. return m_propagatePermissions;
  569. }
  570. public bool BypassPermissions()
  571. {
  572. return m_bypassPermissions;
  573. }
  574. public void SetBypassPermissions(bool value)
  575. {
  576. m_bypassPermissions=value;
  577. }
  578. #region Object Permissions
  579. const uint DEFAULT_FLAGS = (uint)(
  580. PrimFlags.ObjectCopy | // Tells client you can copy the object
  581. PrimFlags.ObjectModify | // tells client you can modify the object
  582. PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
  583. PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
  584. PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
  585. PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
  586. PrimFlags.ObjectOwnerModify // Tells client that you're the owner of the object
  587. );
  588. const uint NOT_DEFAULT_FLAGS = (uint)~(
  589. PrimFlags.ObjectCopy | // Tells client you can copy the object
  590. PrimFlags.ObjectModify | // tells client you can modify the object
  591. PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
  592. PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
  593. PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
  594. PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
  595. PrimFlags.ObjectOwnerModify // Tells client that you're the owner of the object
  596. );
  597. const uint EXTRAOWNERMASK = (uint)(
  598. PrimFlags.ObjectYouOwner |
  599. PrimFlags.ObjectAnyOwner
  600. );
  601. const uint EXTRAGODMASK = (uint)(
  602. PrimFlags.ObjectYouOwner |
  603. PrimFlags.ObjectAnyOwner |
  604. PrimFlags.ObjectOwnerModify |
  605. PrimFlags.ObjectModify |
  606. PrimFlags.ObjectMove
  607. );
  608. const uint GOD_FLAGS = (uint)(
  609. PrimFlags.ObjectCopy | // Tells client you can copy the object
  610. PrimFlags.ObjectModify | // tells client you can modify the object
  611. PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
  612. PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
  613. PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
  614. PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
  615. PrimFlags.ObjectOwnerModify // Tells client that you're the owner of the object
  616. );
  617. const uint LOCKED_GOD_FLAGS = (uint)(
  618. PrimFlags.ObjectCopy | // Tells client you can copy the object
  619. PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
  620. PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
  621. PrimFlags.ObjectAnyOwner // Tells client that someone owns the object
  622. );
  623. const uint SHAREDMASK = (uint)(
  624. PermissionMask.Move |
  625. PermissionMask.Modify |
  626. PermissionMask.Copy
  627. );
  628. public uint GenerateClientFlags(SceneObjectPart task, ScenePresence sp, uint curEffectivePerms)
  629. {
  630. if(sp is null || task is null || curEffectivePerms == 0)
  631. return 0;
  632. // Remove any of the objectFlags that are temporary. These will get added back if appropriate
  633. uint objflags = curEffectivePerms & NOT_DEFAULT_FLAGS ;
  634. uint returnMask;
  635. SceneObjectGroup grp = task.ParentGroup;
  636. if(grp is null)
  637. return 0;
  638. bool unlocked = (grp.RootPart.OwnerMask & (uint)PermissionMask.Move) != 0;
  639. if(sp.IsGod)
  640. {
  641. // do locked on objects owned by admin
  642. if(!unlocked && sp.UUID.Equals(task.OwnerID))
  643. return objflags | LOCKED_GOD_FLAGS;
  644. else
  645. return objflags | GOD_FLAGS;
  646. }
  647. //bypass option == owner rights
  648. if (m_bypassPermissions)
  649. {
  650. returnMask = ApplyObjectModifyMasks(task.OwnerMask, objflags, true); //??
  651. returnMask |= EXTRAOWNERMASK;
  652. if((returnMask & (uint)PrimFlags.ObjectModify) != 0)
  653. returnMask |= (uint)PrimFlags.ObjectOwnerModify;
  654. return returnMask;
  655. }
  656. uint grpEffectiveOwnerPerms = grp.EffectiveOwnerPerms;
  657. // owner
  658. if (sp.UUID.Equals(task.OwnerID))
  659. {
  660. returnMask = ApplyObjectModifyMasks(grpEffectiveOwnerPerms, objflags, unlocked);
  661. returnMask |= EXTRAOWNERMASK;
  662. if((returnMask & (uint)PrimFlags.ObjectModify) != 0)
  663. returnMask |= (uint)PrimFlags.ObjectOwnerModify;
  664. return returnMask;
  665. }
  666. // if not god or owner, do attachments as everyone
  667. if (task.ParentGroup.IsAttachment)
  668. {
  669. returnMask = ApplyObjectModifyMasks(grp.EffectiveEveryOnePerms, objflags, unlocked);
  670. if (!task.OwnerID.IsZero())
  671. returnMask |= (uint)PrimFlags.ObjectAnyOwner;
  672. return returnMask;
  673. }
  674. bool notGroupdOwned = task.OwnerID.NotEqual(task.GroupID);
  675. if ((grpEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
  676. grpEffectiveOwnerPerms &= ~(uint)PermissionMask.Copy;
  677. // if friends with rights then owner
  678. if (notGroupdOwned && IsFriendWithPerms(sp.UUID, task.OwnerID))
  679. {
  680. returnMask = ApplyObjectModifyMasks(grpEffectiveOwnerPerms, objflags, unlocked);
  681. returnMask |= EXTRAOWNERMASK;
  682. if((returnMask & (uint)PrimFlags.ObjectModify) != 0)
  683. returnMask |= (uint)PrimFlags.ObjectOwnerModify;
  684. return returnMask;
  685. }
  686. // group owned or shared ?
  687. ulong powers = 0;
  688. if(task.GroupID.IsNotZero() && GroupMemberPowers(task.GroupID, sp, ref powers))
  689. {
  690. if(notGroupdOwned)
  691. {
  692. // group sharing or everyone
  693. returnMask = ApplyObjectModifyMasks(grp.EffectiveGroupOrEveryOnePerms, objflags, unlocked);
  694. if (task.OwnerID.IsNotZero())
  695. returnMask |= (uint)PrimFlags.ObjectAnyOwner;
  696. return returnMask;
  697. }
  698. // object is owned by group, check role powers
  699. if((powers & (ulong)GroupPowers.ObjectManipulate) == 0)
  700. {
  701. // group sharing or everyone
  702. returnMask = ApplyObjectModifyMasks(grp.EffectiveGroupOrEveryOnePerms, objflags, unlocked);
  703. returnMask |=
  704. (uint)PrimFlags.ObjectGroupOwned |
  705. (uint)PrimFlags.ObjectAnyOwner;
  706. return returnMask;
  707. }
  708. returnMask = ApplyObjectModifyMasks(grpEffectiveOwnerPerms, objflags, unlocked);
  709. returnMask |=
  710. (uint)PrimFlags.ObjectGroupOwned |
  711. (uint)PrimFlags.ObjectYouOwner |
  712. (uint)PrimFlags.ObjectAnyOwner;
  713. if ((returnMask & (uint)PrimFlags.ObjectModify) != 0)
  714. returnMask |= (uint)PrimFlags.ObjectOwnerModify;
  715. return returnMask;
  716. }
  717. // fallback is everyone rights
  718. returnMask = ApplyObjectModifyMasks(grp.EffectiveEveryOnePerms, objflags, unlocked);
  719. if (task.OwnerID.IsNotZero())
  720. returnMask |= (uint)PrimFlags.ObjectAnyOwner;
  721. return returnMask;
  722. }
  723. private uint ApplyObjectModifyMasks(uint setPermissionMask, uint objectFlagsMask, bool unlocked)
  724. {
  725. // We are adding the temporary objectflags to the object's objectflags based on the
  726. // permission flag given. These change the F flags on the client.
  727. if ((setPermissionMask & (uint)PermissionMask.Copy) != 0)
  728. {
  729. objectFlagsMask |= (uint)PrimFlags.ObjectCopy;
  730. }
  731. if (unlocked)
  732. {
  733. if ((setPermissionMask & (uint)PermissionMask.Move) != 0)
  734. {
  735. objectFlagsMask |= (uint)PrimFlags.ObjectMove;
  736. }
  737. if ((setPermissionMask & (uint)PermissionMask.Modify) != 0)
  738. {
  739. objectFlagsMask |= (uint)PrimFlags.ObjectModify;
  740. }
  741. }
  742. if ((setPermissionMask & (uint)PermissionMask.Transfer) != 0)
  743. {
  744. objectFlagsMask |= (uint)PrimFlags.ObjectTransfer;
  745. }
  746. return objectFlagsMask;
  747. }
  748. // OARs still need this method that handles offline users
  749. public PermissionClass GetPermissionClass(UUID user, SceneObjectPart obj)
  750. {
  751. if (obj is null)
  752. return PermissionClass.Everyone;
  753. if (m_bypassPermissions)
  754. return PermissionClass.Owner;
  755. // Object owners should be able to edit their own content
  756. if (user.Equals(obj.OwnerID))
  757. return PermissionClass.Owner;
  758. // Admin should be able to edit anything in the sim (including admin objects)
  759. if (IsAdministrator(user))
  760. return PermissionClass.Owner;
  761. if(!obj.ParentGroup.IsAttachment)
  762. {
  763. if (IsFriendWithPerms(user, obj.OwnerID) )
  764. return PermissionClass.Owner;
  765. // Group permissions
  766. if (obj.GroupID.IsNotZero() && IsGroupMember(obj.GroupID, user, 0))
  767. return PermissionClass.Group;
  768. }
  769. return PermissionClass.Everyone;
  770. }
  771. // get effective object permissions using user UUID. User rights will be fixed
  772. protected uint GetObjectPermissions(UUID currentUser, SceneObjectGroup group, bool denyOnLocked)
  773. {
  774. if (group is null)
  775. return 0;
  776. SceneObjectPart root = group.RootPart;
  777. if (root is null)
  778. return 0;
  779. bool locked = denyOnLocked && ((root.OwnerMask & (uint)PermissionMask.Move) == 0);
  780. if (IsAdministrator(currentUser))
  781. {
  782. // do lock on admin owned objects
  783. if(locked && currentUser.Equals(group.OwnerID))
  784. return (uint)(PermissionMask.AllEffective & ~(PermissionMask.Modify | PermissionMask.Move));
  785. return (uint)PermissionMask.AllEffective;
  786. }
  787. uint lockmask = (uint)PermissionMask.AllEffective;
  788. if(locked)
  789. lockmask &= ~(uint)(PermissionMask.Modify | PermissionMask.Move);
  790. uint grpEffectiveOwnerPerms = group.EffectiveOwnerPerms & lockmask;
  791. if (currentUser.Equals(group.OwnerID))
  792. return grpEffectiveOwnerPerms & lockmask;
  793. if (group.IsAttachment)
  794. return 0;
  795. if ((grpEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
  796. grpEffectiveOwnerPerms &= ~(uint)PermissionMask.Copy;
  797. bool notgroudOwned = group.GroupID.NotEqual(group.OwnerID);
  798. if (notgroudOwned && IsFriendWithPerms(currentUser, group.OwnerID))
  799. return grpEffectiveOwnerPerms & lockmask;
  800. ulong powers = 0;
  801. if (group.GroupID.IsNotZero() && GroupMemberPowers(group.GroupID, currentUser, ref powers))
  802. {
  803. if(notgroudOwned)
  804. return group.EffectiveGroupOrEveryOnePerms & lockmask;
  805. if((powers & (ulong)GroupPowers.ObjectManipulate) == 0)
  806. return group.EffectiveGroupOrEveryOnePerms & lockmask;
  807. return grpEffectiveOwnerPerms & lockmask;
  808. }
  809. return group.EffectiveEveryOnePerms & lockmask;
  810. }
  811. // get effective object permissions using present presence. So some may depend on requested rights (ie God)
  812. protected uint GetObjectPermissions(ScenePresence sp, SceneObjectGroup group, bool denyOnLocked)
  813. {
  814. if (sp is null || sp.IsDeleted || group is null || group.IsDeleted)
  815. return 0;
  816. SceneObjectPart root = group.RootPart;
  817. if (root is null)
  818. return 0;
  819. bool locked = denyOnLocked && ((root.OwnerMask & (uint)PermissionMask.Move) == 0);
  820. if (sp.IsGod)
  821. {
  822. if(locked && sp.UUID.Equals(group.OwnerID))
  823. return (uint)(PermissionMask.AllEffective & ~(PermissionMask.Modify | PermissionMask.Move));
  824. return (uint)PermissionMask.AllEffective;
  825. }
  826. uint lockmask = (uint)PermissionMask.AllEffective;
  827. if(locked)
  828. lockmask &= ~(uint)(PermissionMask.Modify | PermissionMask.Move);
  829. uint ownerperms = group.EffectiveOwnerPerms;
  830. if (sp.UUID.Equals(group.OwnerID))
  831. return ownerperms & lockmask;
  832. if (group.IsAttachment)
  833. return 0;
  834. if ((ownerperms & (uint)PermissionMask.Transfer) == 0)
  835. ownerperms &= ~(uint)PermissionMask.Copy;
  836. bool notgroudOwned = group.GroupID.NotEqual(group.OwnerID);
  837. if (notgroudOwned && IsFriendWithPerms(sp.UUID, group.OwnerID))
  838. {
  839. return ownerperms & lockmask;
  840. }
  841. ulong powers = 0;
  842. if (group.GroupID.IsNotZero() && GroupMemberPowers(group.GroupID, sp, ref powers))
  843. {
  844. if(notgroudOwned)
  845. return group.EffectiveGroupOrEveryOnePerms & lockmask;
  846. if((powers & (ulong)GroupPowers.ObjectManipulate) == 0)
  847. return group.EffectiveGroupOrEveryOnePerms & lockmask;
  848. return ownerperms & lockmask;
  849. }
  850. return group.EffectiveEveryOnePerms & lockmask;
  851. }
  852. private uint GetObjectItemPermissions(UUID userID, TaskInventoryItem ti)
  853. {
  854. if(ti.OwnerID.Equals(userID))
  855. return ti.CurrentPermissions;
  856. if(IsAdministrator(userID))
  857. return (uint)PermissionMask.AllEffective;
  858. // ??
  859. if (IsFriendWithPerms(userID, ti.OwnerID))
  860. return ti.CurrentPermissions;
  861. if(ti.GroupID.IsNotZero())
  862. {
  863. ulong powers = 0;
  864. if(GroupMemberPowers(ti.GroupID, userID, ref powers))
  865. {
  866. if(ti.GroupID.Equals(ti.OwnerID))
  867. {
  868. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  869. return ti.CurrentPermissions;
  870. }
  871. return ti.GroupPermissions;
  872. }
  873. }
  874. return 0;
  875. }
  876. private uint GetObjectItemPermissions(ScenePresence sp, TaskInventoryItem ti, bool notEveryone)
  877. {
  878. if(ti.OwnerID.Equals(sp.UUID))
  879. return ti.CurrentPermissions;
  880. // ??
  881. if (IsFriendWithPerms(sp.UUID, ti.OwnerID))
  882. return ti.CurrentPermissions;
  883. if(ti.GroupID.IsNotZero())
  884. {
  885. ulong powers = 0;
  886. if(GroupMemberPowers(ti.GroupID, sp.UUID, ref powers))
  887. {
  888. if(ti.GroupID.Equals(ti.OwnerID))
  889. {
  890. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  891. return ti.CurrentPermissions;
  892. }
  893. uint p = ti.GroupPermissions;
  894. if(!notEveryone)
  895. p |= ti.EveryonePermissions;
  896. return p;
  897. }
  898. }
  899. if(notEveryone)
  900. return 0;
  901. return ti.EveryonePermissions;
  902. }
  903. #endregion
  904. #region Generic Permissions
  905. /* this still does nothing but waste time
  906. protected bool GenericCommunicationPermission(UUID user, UUID target)
  907. {
  908. // Setting this to true so that cool stuff can happen until we define what determines Generic Communication Permission
  909. bool permission = true;
  910. string reason = "Only registered users may communicate with another account.";
  911. // Uhh, we need to finish this before we enable it.. because it's blocking all sorts of goodies and features
  912. if (IsAdministrator(user))
  913. permission = true;
  914. if (IsEstateManager(user))
  915. permission = true;
  916. if (!permission)
  917. SendPermissionError(user, reason);
  918. return permission;
  919. }
  920. */
  921. public bool GenericEstatePermission(UUID user)
  922. {
  923. // Estate admins should be able to use estate tools
  924. if (IsEstateManager(user))
  925. return true;
  926. // Administrators always have permission
  927. if (IsAdministrator(user))
  928. return true;
  929. return false;
  930. }
  931. protected bool GenericParcelOwnerPermission(UUID user, ILandObject parcel, ulong groupPowers, bool allowEstateManager)
  932. {
  933. if (parcel.LandData.OwnerID.Equals(user))
  934. return true;
  935. if (parcel.LandData.IsGroupOwned && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
  936. return true;
  937. if (allowEstateManager && IsEstateManager(user))
  938. return true;
  939. if (IsAdministrator(user))
  940. return true;
  941. return false;
  942. }
  943. #endregion
  944. #region Permission Checks
  945. private bool CanAbandonParcel(UUID user, ILandObject parcel)
  946. {
  947. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  948. if (m_bypassPermissions) return m_bypassPermissionsValue;
  949. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandRelease, false);
  950. }
  951. private bool CanReclaimParcel(UUID user, ILandObject parcel)
  952. {
  953. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  954. if (m_bypassPermissions) return m_bypassPermissionsValue;
  955. return GenericParcelOwnerPermission(user, parcel, 0,true);
  956. }
  957. private bool CanDeedParcel(UUID user, ILandObject parcel)
  958. {
  959. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  960. if (m_bypassPermissions) return m_bypassPermissionsValue;
  961. if(parcel.LandData.GroupID.IsZero())
  962. return false;
  963. if (IsAdministrator(user))
  964. return true;
  965. if (parcel.LandData.OwnerID.NotEqual(user)) // Only the owner can deed!
  966. return false;
  967. ScenePresence sp = m_scene.GetScenePresence(user);
  968. if(sp is null)
  969. return false;
  970. IClientAPI client = sp.ControllingClient;
  971. if ((client.GetGroupPowers(parcel.LandData.GroupID) & (ulong)GroupPowers.LandDeed) == 0)
  972. return false;
  973. return true;
  974. }
  975. private bool CanDeedObject(ScenePresence sp, SceneObjectGroup sog, UUID targetGroupID)
  976. {
  977. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  978. if (m_bypassPermissions) return m_bypassPermissionsValue;
  979. if(sog is null || sog.IsDeleted || sp is null || sp.IsDeleted || targetGroupID.IsZero())
  980. return false;
  981. // object has group already?
  982. if(sog.GroupID.NotEqual(targetGroupID))
  983. return false;
  984. // is effectivelly shared?
  985. if(sog.EffectiveGroupPerms == 0)
  986. return false;
  987. if(sp.IsGod)
  988. return true;
  989. // owned by requester?
  990. if(sog.OwnerID.NotEqual(sp.UUID))
  991. return false;
  992. // owner can transfer?
  993. if((sog.EffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
  994. return false;
  995. // group member ?
  996. ulong powers = 0;
  997. if(!GroupMemberPowers(targetGroupID, sp, ref powers))
  998. return false;
  999. // has group rights?
  1000. if ((powers & (ulong)GroupPowers.DeedObject) == 0)
  1001. return false;
  1002. return true;
  1003. }
  1004. private bool CanDuplicateObject(SceneObjectGroup sog, ScenePresence sp)
  1005. {
  1006. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1007. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1008. if (sog is null || sog.IsDeleted || sp is null || sp.IsDeleted)
  1009. return false;
  1010. uint perms = GetObjectPermissions(sp, sog, false);
  1011. if((perms & (uint)PermissionMask.Copy) == 0)
  1012. return false;
  1013. if(sog.OwnerID.NotEqual(sp.UUID) && (perms & (uint)PermissionMask.Transfer) == 0)
  1014. return false;
  1015. //If they can rez, they can duplicate
  1016. return CanRezObject(0, sp.UUID, sog.AbsolutePosition);
  1017. }
  1018. private bool CanDeleteObject(SceneObjectGroup sog, ScenePresence sp)
  1019. {
  1020. // ignoring locked. viewers should warn and ask for confirmation
  1021. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1022. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1023. if (sog is null || sog.IsDeleted || sp is null || sp.IsDeleted)
  1024. return false;
  1025. if(sog.IsAttachment)
  1026. return false;
  1027. if(sog.OwnerID.Equals(sp.UUID))
  1028. return true;
  1029. if (sp.IsGod)
  1030. return true;
  1031. if (IsFriendWithPerms(sog.UUID, sog.OwnerID))
  1032. return true;
  1033. if (sog.GroupID.IsNotZero())
  1034. {
  1035. ulong powers = 0;
  1036. if(GroupMemberPowers(sog.GroupID, sp, ref powers))
  1037. {
  1038. if(sog.GroupID.Equals(sog.OwnerID))
  1039. {
  1040. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1041. return true;
  1042. }
  1043. return (sog.EffectiveGroupPerms & (uint)PermissionMask.Modify) != 0;
  1044. }
  1045. }
  1046. return false;
  1047. }
  1048. private bool CanDeleteObjectByIDs(UUID objectID, UUID userID)
  1049. {
  1050. // ignoring locked. viewers should warn and ask for confirmation
  1051. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1052. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1053. SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
  1054. if (sog is null)
  1055. return false;
  1056. if(sog.IsAttachment)
  1057. return false;
  1058. if(sog.OwnerID.Equals(userID))
  1059. return true;
  1060. if (IsAdministrator(userID))
  1061. return true;
  1062. if (IsFriendWithPerms(objectID, sog.OwnerID))
  1063. return true;
  1064. if (sog.GroupID.IsNotZero())
  1065. {
  1066. ulong powers = 0;
  1067. if(GroupMemberPowers(sog.GroupID, userID, ref powers))
  1068. {
  1069. if(sog.GroupID.Equals(sog.OwnerID))
  1070. {
  1071. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1072. return true;
  1073. }
  1074. return (sog.EffectiveGroupPerms & (uint)PermissionMask.Modify) != 0;
  1075. }
  1076. }
  1077. return false;
  1078. }
  1079. private bool CanEditObjectByIDs(UUID objectID, UUID userID)
  1080. {
  1081. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1082. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1083. SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
  1084. if (sog is null)
  1085. return false;
  1086. uint perms = GetObjectPermissions(userID, sog, true);
  1087. if((perms & (uint)PermissionMask.Modify) == 0)
  1088. return false;
  1089. return true;
  1090. }
  1091. private bool CanEditObject(SceneObjectGroup sog, ScenePresence sp)
  1092. {
  1093. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1094. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1095. if(sog is null || sog.IsDeleted || sp is null || sp.IsDeleted)
  1096. return false;
  1097. uint perms = GetObjectPermissions(sp, sog, true);
  1098. if((perms & (uint)PermissionMask.Modify) == 0)
  1099. return false;
  1100. return true;
  1101. }
  1102. private bool CanEditObjectPerms(SceneObjectGroup sog, UUID userID)
  1103. {
  1104. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1105. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1106. if (sog is null)
  1107. return false;
  1108. if(sog.OwnerID.Equals(userID) || IsAdministrator(userID))
  1109. return true;
  1110. if(sog.GroupID.IsZero() || sog.GroupID.NotEqual(sog.OwnerID))
  1111. return false;
  1112. uint perms = sog.EffectiveOwnerPerms;
  1113. if((perms & (uint)PermissionMask.Modify) == 0)
  1114. return false;
  1115. ulong powers = 0;
  1116. if(GroupMemberPowers(sog.GroupID, userID, ref powers))
  1117. {
  1118. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1119. return true;
  1120. }
  1121. return false;
  1122. }
  1123. private bool CanEditObjectInventory(UUID objectID, UUID userID)
  1124. {
  1125. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1126. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1127. SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
  1128. if (sog is null)
  1129. return false;
  1130. uint perms = GetObjectPermissions(userID, sog, true);
  1131. if((perms & (uint)PermissionMask.Modify) == 0)
  1132. return false;
  1133. return true;
  1134. }
  1135. private bool CanEditParcelProperties(UUID userID, ILandObject parcel, GroupPowers p, bool allowManager)
  1136. {
  1137. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1138. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1139. return GenericParcelOwnerPermission(userID, parcel, (ulong)p, false);
  1140. }
  1141. /// <summary>
  1142. /// Check whether the specified user can edit the given script
  1143. /// </summary>
  1144. /// <param name="script"></param>
  1145. /// <param name="objectID"></param>
  1146. /// <param name="user"></param>
  1147. /// <param name="scene"></param>
  1148. /// <returns></returns>
  1149. private bool CanEditScript(UUID script, UUID objectID, UUID userID)
  1150. {
  1151. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1152. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1153. if (m_allowedScriptEditors == UserSet.Administrators && !IsAdministrator(userID))
  1154. return false;
  1155. // Ordinarily, if you can view it, you can edit it
  1156. // There is no viewing a no mod script
  1157. //
  1158. return CanViewScript(script, objectID, userID);
  1159. }
  1160. /// <summary>
  1161. /// Check whether the specified user can edit the given notecard
  1162. /// </summary>
  1163. /// <param name="notecard"></param>
  1164. /// <param name="objectID"></param>
  1165. /// <param name="user"></param>
  1166. /// <param name="scene"></param>
  1167. /// <returns></returns>
  1168. private bool CanEditNotecard(UUID notecard, UUID objectID, UUID user)
  1169. {
  1170. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1171. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1172. if (objectID.IsZero()) // User inventory
  1173. {
  1174. IInventoryService invService = m_scene.InventoryService;
  1175. InventoryItemBase assetRequestItem = invService.GetItem(user, notecard);
  1176. if (assetRequestItem is null && LibraryRootFolder is not null) // Library item
  1177. {
  1178. assetRequestItem = LibraryRootFolder.FindItem(notecard);
  1179. if (assetRequestItem is not null) // Implicitly readable
  1180. return true;
  1181. }
  1182. // Notecards must be both mod and copy to be saveable
  1183. // This is because of they're not copy, you can't read
  1184. // them, and if they're not mod, well, then they're
  1185. // not mod. Duh.
  1186. //
  1187. if ((assetRequestItem.CurrentPermissions &
  1188. ((uint)PermissionMask.Modify |
  1189. (uint)PermissionMask.Copy)) !=
  1190. ((uint)PermissionMask.Modify |
  1191. (uint)PermissionMask.Copy))
  1192. return false;
  1193. }
  1194. else // Prim inventory
  1195. {
  1196. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  1197. if (part is null)
  1198. return false;
  1199. SceneObjectGroup sog = part.ParentGroup;
  1200. if (sog is null)
  1201. return false;
  1202. // check object mod right
  1203. uint perms = GetObjectPermissions(user, sog, true);
  1204. if((perms & (uint)PermissionMask.Modify) == 0)
  1205. return false;
  1206. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  1207. if (ti is null)
  1208. return false;
  1209. if (ti.OwnerID.NotEqual(user))
  1210. {
  1211. if (ti.GroupID.IsZero())
  1212. return false;
  1213. ulong powers = 0;
  1214. if(!GroupMemberPowers(ti.GroupID, user, ref powers))
  1215. return false;
  1216. if(ti.GroupID.Equals(ti.OwnerID) && (powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1217. {
  1218. if ((ti.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy)) ==
  1219. ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy))
  1220. return true;
  1221. }
  1222. if ((ti.GroupPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy)) ==
  1223. ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy))
  1224. return true;
  1225. return false;
  1226. }
  1227. // Require full perms
  1228. if ((ti.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy)) !=
  1229. ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy))
  1230. return false;
  1231. }
  1232. return true;
  1233. }
  1234. private bool CanInstantMessage(UUID user, UUID target)
  1235. {
  1236. return true; // we still did not define this
  1237. /*
  1238. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1239. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1240. // If the sender is an object, check owner instead
  1241. //
  1242. SceneObjectPart part = m_scene.GetSceneObjectPart(user);
  1243. if (part != null)
  1244. user = part.OwnerID;
  1245. return GenericCommunicationPermission(user, target);
  1246. */
  1247. }
  1248. private bool CanInventoryTransfer(UUID user, UUID target)
  1249. {
  1250. return true; // we still did not define this
  1251. /*
  1252. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1253. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1254. return GenericCommunicationPermission(user, target);
  1255. */
  1256. }
  1257. private bool CanIssueEstateCommand(UUID user, bool ownerCommand)
  1258. {
  1259. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1260. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1261. if (IsAdministrator(user))
  1262. return true;
  1263. if (ownerCommand)
  1264. return m_scene.RegionInfo.EstateSettings.IsEstateOwner(user);
  1265. return IsEstateManager(user);
  1266. }
  1267. private bool CanMoveObject(SceneObjectGroup sog, ScenePresence sp)
  1268. {
  1269. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1270. if(sog is null || sog.IsDeleted || sp is null || sp.IsDeleted)
  1271. return false;
  1272. if (m_bypassPermissions)
  1273. {
  1274. if (sog.OwnerID.NotEqual(sp.UUID) && sog.IsAttachment)
  1275. return false;
  1276. return m_bypassPermissionsValue;
  1277. }
  1278. uint perms = GetObjectPermissions(sp, sog, true);
  1279. if((perms & (uint)PermissionMask.Move) == 0)
  1280. return false;
  1281. return true;
  1282. }
  1283. private bool CanObjectEntry(SceneObjectGroup sog, bool enteringRegion, Vector3 newPoint)
  1284. {
  1285. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1286. float newX = newPoint.X;
  1287. float newY = newPoint.Y;
  1288. // allow outside region this is needed for crossings
  1289. if (newX < -1f || newX > (m_scene.RegionInfo.RegionSizeX + 1.0f) ||
  1290. newY < -1f || newY > (m_scene.RegionInfo.RegionSizeY + 1.0f) )
  1291. return true;
  1292. if(sog is null || sog.IsDeleted)
  1293. return false;
  1294. if (m_bypassPermissions)
  1295. return m_bypassPermissionsValue;
  1296. ILandObject parcel = m_scene.LandChannel.GetLandObject(newX, newY);
  1297. if (parcel is null)
  1298. return false;
  1299. if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowAPrimitiveEntry)) != 0)
  1300. return true;
  1301. if (!enteringRegion)
  1302. {
  1303. Vector3 oldPoint = sog.AbsolutePosition;
  1304. ILandObject fromparcel = m_scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
  1305. if (fromparcel is not null && fromparcel.Equals(parcel)) // it already entered parcel ????
  1306. return true;
  1307. }
  1308. UUID userID = sog.OwnerID;
  1309. LandData landdata = parcel.LandData;
  1310. if (landdata.OwnerID.Equals(userID))
  1311. return true;
  1312. if (IsAdministrator(userID))
  1313. return true;
  1314. if (landdata.GroupID.IsNotZero())
  1315. {
  1316. if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowGroupObjectEntry)) != 0)
  1317. return IsGroupMember(landdata.GroupID, userID, 0);
  1318. if (landdata.IsGroupOwned && IsGroupMember(landdata.GroupID, userID, (ulong)GroupPowers.AllowRez))
  1319. return true;
  1320. }
  1321. //Otherwise, false!
  1322. return false;
  1323. }
  1324. private bool OnObjectEnterWithScripts(SceneObjectGroup sog, ILandObject parcel)
  1325. {
  1326. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1327. if(sog is null || sog.IsDeleted)
  1328. return false;
  1329. if (m_bypassPermissions)
  1330. return m_bypassPermissionsValue;
  1331. if (parcel is null)
  1332. return true;
  1333. int checkflags = ((int)ParcelFlags.AllowAPrimitiveEntry);
  1334. bool scripts = (sog.ScriptCount() > 0);
  1335. if(scripts)
  1336. checkflags |= ((int)ParcelFlags.AllowOtherScripts);
  1337. if ((parcel.LandData.Flags & checkflags) == checkflags)
  1338. return true;
  1339. UUID userID = sog.OwnerID;
  1340. LandData landdata = parcel.LandData;
  1341. if (landdata.OwnerID.Equals(userID))
  1342. return true;
  1343. if (IsAdministrator(userID))
  1344. return true;
  1345. if (landdata.GroupID.IsNotZero())
  1346. {
  1347. checkflags = (int)ParcelFlags.AllowGroupObjectEntry;
  1348. if(scripts)
  1349. checkflags |= ((int)ParcelFlags.AllowGroupScripts);
  1350. if ((parcel.LandData.Flags & checkflags) == checkflags)
  1351. return IsGroupMember(landdata.GroupID, userID, 0);
  1352. if (landdata.IsGroupOwned && IsGroupMember(landdata.GroupID, userID, (ulong)GroupPowers.AllowRez))
  1353. return true;
  1354. }
  1355. //Otherwise, false!
  1356. return false;
  1357. }
  1358. private bool CanReturnObjects(ILandObject land, ScenePresence sp, List<SceneObjectGroup> objects)
  1359. {
  1360. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1361. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1362. if(sp is null)
  1363. return true; // assuming that in this case rights are as owner
  1364. bool isPrivUser = sp.IsGod || IsEstateManager(sp.UUID);
  1365. IClientAPI client = sp.ControllingClient;
  1366. ulong powers;
  1367. ILandObject l;
  1368. foreach (SceneObjectGroup g in new List<SceneObjectGroup>(objects))
  1369. {
  1370. if(g.IsAttachment)
  1371. {
  1372. objects.Remove(g);
  1373. continue;
  1374. }
  1375. if (isPrivUser || g.OwnerID.Equals(sp.UUID))
  1376. continue;
  1377. // This is a short cut for efficiency. If land is non-null,
  1378. // then all objects are on that parcel and we can save
  1379. // ourselves the checking for each prim. Much faster.
  1380. //
  1381. if (land is not null)
  1382. {
  1383. l = land;
  1384. }
  1385. else
  1386. {
  1387. Vector3 pos = g.AbsolutePosition;
  1388. l = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
  1389. }
  1390. // If it's not over any land, then we can't do a thing
  1391. if (l is null || l.LandData is null)
  1392. {
  1393. objects.Remove(g);
  1394. continue;
  1395. }
  1396. LandData ldata = l.LandData;
  1397. // If we own the land outright, then allow
  1398. //
  1399. if (ldata.OwnerID.Equals(sp.UUID))
  1400. continue;
  1401. // Group voodoo
  1402. //
  1403. if (ldata.IsGroupOwned)
  1404. {
  1405. // Not a group member, or no rights at all
  1406. //
  1407. powers = client.GetGroupPowers(ldata.GroupID);
  1408. if(powers == 0)
  1409. {
  1410. objects.Remove(g);
  1411. continue;
  1412. }
  1413. // Group deeded object?
  1414. //
  1415. if (g.OwnerID.Equals(ldata.GroupID) && (powers & (ulong)GroupPowers.ReturnGroupOwned) == 0)
  1416. {
  1417. objects.Remove(g);
  1418. continue;
  1419. }
  1420. // Group set object?
  1421. //
  1422. if (g.GroupID.Equals(ldata.GroupID) && (powers & (ulong)GroupPowers.ReturnGroupSet) == 0)
  1423. {
  1424. objects.Remove(g);
  1425. continue;
  1426. }
  1427. if ((powers & (ulong)GroupPowers.ReturnNonGroup) == 0)
  1428. {
  1429. objects.Remove(g);
  1430. continue;
  1431. }
  1432. // So we can remove all objects from this group land.
  1433. // Fine.
  1434. //
  1435. continue;
  1436. }
  1437. // By default, we can't remove
  1438. //
  1439. objects.Remove(g);
  1440. }
  1441. if (objects.Count == 0)
  1442. return false;
  1443. return true;
  1444. }
  1445. private bool CanRezObject(int objectCount, UUID userID, Vector3 objectPosition)
  1446. {
  1447. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1448. if (m_bypassPermissions)
  1449. return m_bypassPermissionsValue;
  1450. // m_log.DebugFormat("[PERMISSIONS MODULE]: Checking rez object at {0} in {1}", objectPosition, m_scene.Name);
  1451. ILandObject parcel = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  1452. if (parcel is null || parcel.LandData is null)
  1453. return false;
  1454. LandData landdata = parcel.LandData;
  1455. if (userID.Equals(landdata.OwnerID))
  1456. return true;
  1457. if ((landdata.Flags & (uint)ParcelFlags.CreateObjects) != 0)
  1458. return true;
  1459. if(IsAdministrator(userID))
  1460. return true;
  1461. if(landdata.GroupID.IsNotZero())
  1462. {
  1463. if ((landdata.Flags & (uint)ParcelFlags.CreateGroupObjects) != 0)
  1464. return IsGroupMember(landdata.GroupID, userID, 0);
  1465. if (landdata.IsGroupOwned && IsGroupMember(landdata.GroupID, userID, (ulong)GroupPowers.AllowRez))
  1466. return true;
  1467. }
  1468. return false;
  1469. }
  1470. private bool CanRunConsoleCommand(UUID user)
  1471. {
  1472. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1473. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1474. return IsAdministrator(user);
  1475. }
  1476. private bool CanRunScript(TaskInventoryItem scriptitem, SceneObjectPart part)
  1477. {
  1478. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1479. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1480. if(scriptitem is null || part is null)
  1481. return false;
  1482. SceneObjectGroup sog = part.ParentGroup;
  1483. if(sog is null)
  1484. return false;
  1485. Vector3 pos = sog.AbsolutePosition;
  1486. ILandObject parcel = m_scene.LandChannel.GetLandObjectClippedXY(pos.X, pos.Y);
  1487. if (parcel is null)
  1488. return false;
  1489. LandData ldata = parcel.LandData;
  1490. if(ldata is null)
  1491. return false;
  1492. uint lflags = ldata.Flags;
  1493. if ((lflags & (uint)ParcelFlags.AllowOtherScripts) != 0)
  1494. return true;
  1495. if ((part.OwnerID == ldata.OwnerID))
  1496. return true;
  1497. if (((lflags & (uint)ParcelFlags.AllowGroupScripts) != 0)
  1498. && ldata.GroupID.IsNotZero() && ldata.GroupID.Equals(part.GroupID))
  1499. return true;
  1500. return GenericEstatePermission(part.OwnerID);
  1501. }
  1502. private bool CanSellParcel(UUID user, ILandObject parcel)
  1503. {
  1504. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1505. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1506. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandSetSale, true);
  1507. }
  1508. private bool CanSellGroupObject(UUID userID, UUID groupID)
  1509. {
  1510. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1511. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1512. return IsGroupMember(groupID, userID, (ulong)GroupPowers.ObjectSetForSale);
  1513. }
  1514. private bool CanSellObjectByUserID(SceneObjectGroup sog, UUID userID, byte saleType)
  1515. {
  1516. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1517. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1518. if (sog is null || sog.IsDeleted || userID.IsZero())
  1519. return false;
  1520. // sell is not a attachment op
  1521. if(sog.IsAttachment)
  1522. return false;
  1523. if(IsAdministrator(userID))
  1524. return true;
  1525. uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms;
  1526. if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
  1527. return false;
  1528. if(saleType == (byte)SaleType.Copy &&
  1529. (sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0)
  1530. return false;
  1531. if(sog.OwnerID.Equals(userID))
  1532. return true;
  1533. // else only group owned can be sold by members with powers
  1534. if(sog.GroupID.IsZero() || sog.OwnerID.NotEqual(sog.GroupID))
  1535. return false;
  1536. return IsGroupMember(sog.GroupID, userID, (ulong)GroupPowers.ObjectSetForSale);
  1537. }
  1538. private bool CanSellObject(SceneObjectGroup sog, ScenePresence sp, byte saleType)
  1539. {
  1540. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1541. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1542. if (sog is null || sog.IsDeleted || sp is null || sp.IsDeleted)
  1543. return false;
  1544. // sell is not a attachment op
  1545. if(sog.IsAttachment)
  1546. return false;
  1547. if(sp.IsGod)
  1548. return true;
  1549. uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms;
  1550. if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
  1551. return false;
  1552. if(saleType == (byte)SaleType.Copy &&
  1553. (sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0)
  1554. return false;
  1555. if(sog.OwnerID.Equals(sp.UUID))
  1556. return true;
  1557. // else only group owned can be sold by members with powers
  1558. if(sog.GroupID.IsZero() || sog.OwnerID.NotEqual(sog.GroupID))
  1559. return false;
  1560. ulong powers = 0;
  1561. if(!GroupMemberPowers(sog.GroupID, sp, ref powers))
  1562. return false;
  1563. if((powers & (ulong)GroupPowers.ObjectSetForSale) == 0)
  1564. return false;
  1565. return true;
  1566. }
  1567. private bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp)
  1568. {
  1569. // ignore locked, viewers shell ask for confirmation
  1570. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1571. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1572. if (sog is null || sog.IsDeleted || sp is null || sp.IsDeleted)
  1573. return false;
  1574. // take is not a attachment op
  1575. if(sog.IsAttachment)
  1576. return false;
  1577. if(sog.OwnerID.Equals(sp.UUID))
  1578. return true;
  1579. if (sp.IsGod)
  1580. return true;
  1581. if((sog.EffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
  1582. return false;
  1583. if (IsFriendWithPerms(sog.UUID, sog.OwnerID))
  1584. return true;
  1585. if (sog.GroupID.IsNotZero())
  1586. {
  1587. ulong powers = 0;
  1588. if(GroupMemberPowers(sog.GroupID, sp, ref powers))
  1589. {
  1590. if(sog.GroupID.Equals(sog.OwnerID))
  1591. {
  1592. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1593. return true;
  1594. }
  1595. return (sog.EffectiveGroupPerms & (uint)PermissionMask.Modify) != 0;
  1596. }
  1597. }
  1598. return false;
  1599. }
  1600. private bool CanTakeCopyObject(SceneObjectGroup sog, ScenePresence sp)
  1601. {
  1602. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1603. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1604. if (sog is null || sog.IsDeleted || sp is null || sp.IsDeleted)
  1605. return false;
  1606. // refuse on attachments
  1607. if(sog.IsAttachment && !sp.IsGod)
  1608. return false;
  1609. uint perms = GetObjectPermissions(sp, sog, true);
  1610. if((perms & (uint)PermissionMask.Copy) == 0)
  1611. {
  1612. //sp.ControllingClient.SendAgentAlertMessage("Copying this item has been denied by the permissions system", false);
  1613. return false;
  1614. }
  1615. if(sog.OwnerID.NotEqual(sp.UUID) && (perms & (uint)PermissionMask.Transfer) == 0)
  1616. return false;
  1617. return true;
  1618. }
  1619. private bool CanTerraformLand(UUID userID, Vector3 position)
  1620. {
  1621. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1622. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1623. // Estate override
  1624. if (GenericEstatePermission(userID))
  1625. return true;
  1626. float X = position.X;
  1627. float Y = position.Y;
  1628. int id = (int)position.Z;
  1629. ILandObject parcel;
  1630. if(id >= 0 && X < 0 && Y < 0)
  1631. parcel = m_scene.LandChannel.GetLandObject(id);
  1632. else
  1633. {
  1634. parcel = m_scene.LandChannel.GetLandObjectClippedXY(X, Y);
  1635. }
  1636. if (parcel is null)
  1637. return false;
  1638. LandData landdata = parcel.LandData;
  1639. if (landdata is null)
  1640. return false;
  1641. if ((landdata.Flags & ((int)ParcelFlags.AllowTerraform)) != 0)
  1642. return true;
  1643. if(landdata.OwnerID.Equals(userID))
  1644. return true;
  1645. if (landdata.IsGroupOwned && parcel.LandData.GroupID.IsNotZero() &&
  1646. IsGroupMember(landdata.GroupID, userID, (ulong)GroupPowers.AllowEditLand))
  1647. return true;
  1648. return false;
  1649. }
  1650. /// <summary>
  1651. /// Check whether the specified user can view the given script
  1652. /// </summary>
  1653. /// <param name="script"></param>
  1654. /// <param name="objectID"></param>
  1655. /// <param name="user"></param>
  1656. /// <param name="scene"></param>
  1657. /// <returns></returns>
  1658. private bool CanViewScript(UUID script, UUID objectID, UUID userID)
  1659. {
  1660. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1661. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1662. // A god is a god is a god
  1663. if (IsAdministrator(userID))
  1664. return true;
  1665. if (objectID.IsZero()) // User inventory
  1666. {
  1667. IInventoryService invService = m_scene.InventoryService;
  1668. InventoryItemBase assetRequestItem = invService.GetItem(userID, script);
  1669. if (assetRequestItem == null && LibraryRootFolder != null) // Library item
  1670. {
  1671. assetRequestItem = LibraryRootFolder.FindItem(script);
  1672. if (assetRequestItem is not null) // Implicitly readable
  1673. return true;
  1674. }
  1675. // SL is rather harebrained here. In SL, a script you
  1676. // have mod/copy no trans is readable. This subverts
  1677. // permissions, but is used in some products, most
  1678. // notably Hippo door plugin and HippoRent 5 networked
  1679. // prim counter.
  1680. // To enable this broken SL-ism, remove Transfer from
  1681. // the below expressions.
  1682. // Trying to improve on SL perms by making a script
  1683. // readable only if it's really full perms
  1684. //
  1685. if ((assetRequestItem.CurrentPermissions &
  1686. /*
  1687. ((uint)PermissionMask.Modify |
  1688. (uint)PermissionMask.Copy |
  1689. (uint)PermissionMask.Transfer)) !=
  1690. ((uint)PermissionMask.Modify |
  1691. (uint)PermissionMask.Copy |
  1692. (uint)PermissionMask.Transfer))
  1693. */
  1694. (uint)(PermissionMask.Modify | PermissionMask.Copy)) !=
  1695. (uint)(PermissionMask.Modify | PermissionMask.Copy))
  1696. return false;
  1697. }
  1698. else // Prim inventory
  1699. {
  1700. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  1701. if (part is null)
  1702. return false;
  1703. SceneObjectGroup sog = part.ParentGroup;
  1704. if (sog is null)
  1705. return false;
  1706. uint perms = GetObjectPermissions(userID, sog, true);
  1707. if((perms & (uint)PermissionMask.Modify) == 0)
  1708. return false;
  1709. TaskInventoryItem ti = part.Inventory.GetInventoryItem(script);
  1710. if (ti is null) // legacy may not have type
  1711. return false;
  1712. uint itperms = GetObjectItemPermissions(userID, ti);
  1713. // Require full perms
  1714. if ((itperms &
  1715. /*
  1716. ((uint)(PermissionMask.Modify |
  1717. (uint)PermissionMask.Copy |
  1718. (uint)PermissionMask.Transfer)) !=
  1719. ((uint)PermissionMask.Modify |
  1720. (uint)PermissionMask.Copy |
  1721. (uint)PermissionMask.Transfer))
  1722. */
  1723. (uint)(PermissionMask.Modify | PermissionMask.Copy)) !=
  1724. (uint)(PermissionMask.Modify | PermissionMask.Copy))
  1725. return false;
  1726. }
  1727. return true;
  1728. }
  1729. /// <summary>
  1730. /// Check whether the specified user can view the given notecard
  1731. /// </summary>
  1732. /// <param name="script"></param>
  1733. /// <param name="objectID"></param>
  1734. /// <param name="user"></param>
  1735. /// <param name="scene"></param>
  1736. /// <returns></returns>
  1737. private bool CanViewNotecard(UUID notecard, UUID objectID, UUID userID)
  1738. {
  1739. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1740. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1741. // A god is a god is a god
  1742. if (IsAdministrator(userID))
  1743. return true;
  1744. if (objectID.IsZero()) // User inventory
  1745. {
  1746. IInventoryService invService = m_scene.InventoryService;
  1747. InventoryItemBase assetRequestItem = invService.GetItem(userID, notecard);
  1748. if (assetRequestItem is null && LibraryRootFolder is not null) // Library item
  1749. {
  1750. assetRequestItem = LibraryRootFolder.FindItem(notecard);
  1751. if (assetRequestItem is not null) // Implicitly readable
  1752. return true;
  1753. }
  1754. // Notecards are always readable unless no copy
  1755. //
  1756. if ((assetRequestItem.CurrentPermissions &
  1757. (uint)PermissionMask.Copy) !=
  1758. (uint)PermissionMask.Copy)
  1759. return false;
  1760. }
  1761. else // Prim inventory
  1762. {
  1763. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  1764. if (part is null)
  1765. return false;
  1766. SceneObjectGroup sog = part.ParentGroup;
  1767. if (sog is null)
  1768. return false;
  1769. uint perms = GetObjectPermissions(userID, sog, true);
  1770. if((perms & (uint)PermissionMask.Modify) == 0)
  1771. return false;
  1772. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  1773. if (ti is null)
  1774. return false;
  1775. uint itperms = GetObjectItemPermissions(userID, ti);
  1776. // Notecards are always readable unless no copy
  1777. //
  1778. if ((itperms &
  1779. (uint)PermissionMask.Copy) !=
  1780. (uint)PermissionMask.Copy)
  1781. return false;
  1782. }
  1783. return true;
  1784. }
  1785. #endregion
  1786. private bool CanLinkObject(UUID userID, UUID objectID)
  1787. {
  1788. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1789. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1790. SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
  1791. if (sog is null)
  1792. return false;
  1793. uint perms = GetObjectPermissions(userID, sog, true);
  1794. if((perms & (uint)PermissionMask.Modify) == 0)
  1795. return false;
  1796. return true;
  1797. }
  1798. private bool CanDelinkObject(UUID userID, UUID objectID)
  1799. {
  1800. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1801. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1802. SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
  1803. if (sog is null)
  1804. return false;
  1805. uint perms = GetObjectPermissions(userID, sog, true);
  1806. if((perms & (uint)PermissionMask.Modify) == 0)
  1807. return false;
  1808. return true;
  1809. }
  1810. private bool CanBuyLand(UUID userID, ILandObject parcel)
  1811. {
  1812. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1813. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1814. return true;
  1815. }
  1816. private bool CanCopyObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1817. {
  1818. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1819. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1820. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  1821. if (part is null)
  1822. return false;
  1823. SceneObjectGroup sog = part.ParentGroup;
  1824. if (sog is null)
  1825. return false;
  1826. if(sog.OwnerID.Equals(userID) || IsAdministrator(userID))
  1827. return true;
  1828. if(sog.IsAttachment)
  1829. return false;
  1830. if(sog.GroupID.IsZero() || sog.GroupID.NotEqual(sog.OwnerID))
  1831. return false;
  1832. TaskInventoryItem ti = part.Inventory.GetInventoryItem(itemID);
  1833. if(ti is null)
  1834. return false;
  1835. ulong powers = 0;
  1836. if(GroupMemberPowers(sog.GroupID, userID, ref powers))
  1837. {
  1838. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1839. return true;
  1840. if((ti.EveryonePermissions & (uint)PermissionMask.Copy) != 0)
  1841. return true;
  1842. }
  1843. return false;
  1844. }
  1845. // object inventory to object inventory item drag and drop
  1846. private bool CanDoObjectInvToObjectInv(TaskInventoryItem item, SceneObjectPart sourcePart, SceneObjectPart destPart)
  1847. {
  1848. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1849. if (sourcePart is null || destPart is null || item is null)
  1850. return false;
  1851. if (m_bypassPermissions)
  1852. return true;
  1853. SceneObjectGroup srcsog = sourcePart.ParentGroup;
  1854. SceneObjectGroup destsog = destPart.ParentGroup;
  1855. if (srcsog is null || destsog is null)
  1856. return false;
  1857. uint destsogEffectiveOwnerPerms = destsog.EffectiveOwnerPerms;
  1858. // dest is locked
  1859. if ((destsogEffectiveOwnerPerms & (uint)PermissionMask.Move) == 0)
  1860. return false;
  1861. uint itperms = item.CurrentPermissions;
  1862. uint srcsogEffectiveOwnerPerms = srcsog.EffectiveOwnerPerms;
  1863. // if item is no copy the source is modifed
  1864. if ((itperms & (uint)PermissionMask.Copy) == 0)
  1865. {
  1866. if(srcsog.IsAttachment || destsog.IsAttachment)
  1867. return false;
  1868. if((srcsogEffectiveOwnerPerms & (uint)PermissionMask.Modify) == 0)
  1869. return false;
  1870. }
  1871. if(srcsog.OwnerID.NotEqual(destsog.OwnerID))
  1872. {
  1873. if((itperms & (uint)PermissionMask.Transfer) == 0)
  1874. return false;
  1875. if(destsog.IsAttachment && (destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
  1876. return false;
  1877. if((destsogEffectiveOwnerPerms & (uint)PermissionMask.Modify) == 0)
  1878. return false;
  1879. }
  1880. else
  1881. {
  1882. if((destsogEffectiveOwnerPerms & (uint)PermissionMask.Modify) == 0 &&
  1883. (destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
  1884. return false;
  1885. }
  1886. return true;
  1887. }
  1888. private bool CanDropInObjectInv(InventoryItemBase item, ScenePresence sp, SceneObjectPart destPart)
  1889. {
  1890. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1891. if (sp is null || sp.IsDeleted || destPart is null || item == null)
  1892. return false;
  1893. SceneObjectGroup destsog = destPart.ParentGroup;
  1894. if (destsog is null || destsog.IsDeleted)
  1895. return false;
  1896. if (m_bypassPermissions)
  1897. return true;
  1898. if(sp.IsGod)
  1899. return true;
  1900. // dest is locked
  1901. if((destsog.EffectiveOwnerPerms & (uint)PermissionMask.Move) == 0)
  1902. return false;
  1903. bool spNotOwner = sp.UUID.NotEqual(destsog.OwnerID);
  1904. // scripts can't be droped
  1905. if(spNotOwner && item.InvType == (int)InventoryType.LSL)
  1906. return false;
  1907. if(spNotOwner || item.Owner.NotEqual(destsog.OwnerID))
  1908. {
  1909. // no copy item will be moved if it has transfer
  1910. uint itperms = item.CurrentPermissions;
  1911. if((itperms & (uint)PermissionMask.Transfer) == 0)
  1912. return false;
  1913. }
  1914. // allowdrop is a root part thing and does bypass modify rights
  1915. if((destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) != 0)
  1916. return true;
  1917. uint perms = GetObjectPermissions(sp.UUID, destsog, true);
  1918. if((perms & (uint)PermissionMask.Modify) == 0)
  1919. return false;
  1920. return true;
  1921. }
  1922. private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1923. {
  1924. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1925. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1926. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  1927. if (part is null)
  1928. return false;
  1929. SceneObjectGroup sog = part.ParentGroup;
  1930. if (sog is null)
  1931. return false;
  1932. uint perms = GetObjectPermissions(userID, sog, true);
  1933. if((perms & (uint)PermissionMask.Modify) == 0)
  1934. return false;
  1935. TaskInventoryItem ti = part.Inventory.GetInventoryItem(itemID);
  1936. if(ti is null)
  1937. return false;
  1938. //TODO item perm ?
  1939. return true;
  1940. }
  1941. /// <summary>
  1942. /// Check whether the specified user is allowed to directly create the given inventory type in a prim's
  1943. /// inventory (e.g. the New Script button in the 1.21 Linden Lab client).
  1944. /// </summary>
  1945. /// <param name="invType"></param>
  1946. /// <param name="objectID"></param>
  1947. /// <param name="userID"></param>
  1948. /// <returns></returns>
  1949. private bool CanCreateObjectInventory(int invType, UUID objectID, UUID userID)
  1950. {
  1951. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1952. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1953. ScenePresence p = m_scene.GetScenePresence(userID);
  1954. if (p is null)
  1955. return false;
  1956. SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
  1957. if (sog is null)
  1958. return false;
  1959. uint perms = GetObjectPermissions(userID, sog, true);
  1960. if((perms & (uint)PermissionMask.Modify) == 0)
  1961. return false;
  1962. if ((int)InventoryType.LSL == invType)
  1963. {
  1964. if (m_allowedScriptCreators == UserSet.Administrators)
  1965. return false;
  1966. }
  1967. return true;
  1968. }
  1969. /// <summary>
  1970. /// Check whether the specified user is allowed to create the given inventory type in their inventory.
  1971. /// </summary>
  1972. /// <param name="invType"></param>
  1973. /// <param name="userID"></param>
  1974. /// <returns></returns>
  1975. private bool CanCreateUserInventory(int invType, UUID userID)
  1976. {
  1977. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1978. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1979. if ((int)InventoryType.LSL == invType)
  1980. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1981. return false;
  1982. return true;
  1983. }
  1984. /// <summary>
  1985. /// Check whether the specified user is allowed to copy the given inventory type in their inventory.
  1986. /// </summary>
  1987. /// <param name="itemID"></param>
  1988. /// <param name="userID"></param>
  1989. /// <returns></returns>
  1990. private bool CanCopyUserInventory(UUID itemID, UUID userID)
  1991. {
  1992. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1993. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1994. return true;
  1995. }
  1996. /// <summary>
  1997. /// Check whether the specified user is allowed to edit the given inventory item within their own inventory.
  1998. /// </summary>
  1999. /// <param name="itemID"></param>
  2000. /// <param name="userID"></param>
  2001. /// <returns></returns>
  2002. private bool CanEditUserInventory(UUID itemID, UUID userID)
  2003. {
  2004. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  2005. if (m_bypassPermissions) return m_bypassPermissionsValue;
  2006. return true;
  2007. }
  2008. /// <summary>
  2009. /// Check whether the specified user is allowed to delete the given inventory item from their own inventory.
  2010. /// </summary>
  2011. /// <param name="itemID"></param>
  2012. /// <param name="userID"></param>
  2013. /// <returns></returns>
  2014. private bool CanDeleteUserInventory(UUID itemID, UUID userID)
  2015. {
  2016. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  2017. if (m_bypassPermissions) return m_bypassPermissionsValue;
  2018. return true;
  2019. }
  2020. private bool CanTeleport(UUID userID, Scene scene)
  2021. {
  2022. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  2023. if (m_bypassPermissions) return m_bypassPermissionsValue;
  2024. return true;
  2025. }
  2026. private bool CanResetScript(UUID primID, UUID script, UUID agentID)
  2027. {
  2028. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  2029. if (m_bypassPermissions) return m_bypassPermissionsValue;
  2030. SceneObjectGroup sog = m_scene.GetGroupByPrim(primID);
  2031. if (sog is null)
  2032. return false;
  2033. uint perms = GetObjectPermissions(agentID, sog, false);
  2034. if((perms & (uint)PermissionMask.Modify) == 0) // ??
  2035. return false;
  2036. return true;
  2037. }
  2038. private bool CanCompileScript(UUID ownerUUID, int scriptType)
  2039. {
  2040. //m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType);
  2041. return scriptType switch
  2042. {
  2043. 0 => GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString()),
  2044. 1 => GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString()),
  2045. 2 => GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString()),
  2046. 3 => GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString()),
  2047. 4 => GrantYP.Count == 0 || GrantYP.ContainsKey(ownerUUID.ToString()),
  2048. _ => (false),
  2049. };
  2050. }
  2051. private bool CanControlPrimMedia(UUID agentID, UUID primID, int face)
  2052. {
  2053. //m_log.DebugFormat(
  2054. // "[PERMISSONS]: Performing CanControlPrimMedia check with agentID {0}, primID {1}, face {2}",
  2055. // agentID, primID, face);
  2056. if (MoapModule is null)
  2057. return false;
  2058. SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
  2059. if (part is null)
  2060. return false;
  2061. MediaEntry me = MoapModule.GetMediaEntry(part, face);
  2062. // If there is no existing media entry then it can be controlled (in this context, created).
  2063. if (me is null)
  2064. return true;
  2065. //m_log.DebugFormat(
  2066. // "[PERMISSIONS]: Checking CanControlPrimMedia for {0} on {1} face {2} with control permissions {3}",
  2067. // agentID, primID, face, me.ControlPermissions);
  2068. SceneObjectGroup sog = part.ParentGroup;
  2069. if (sog is null)
  2070. return false;
  2071. uint perms = GetObjectPermissions(agentID, sog, false);
  2072. if((perms & (uint)PermissionMask.Modify) == 0)
  2073. return false;
  2074. return true;
  2075. }
  2076. private bool CanInteractWithPrimMedia(UUID agentID, UUID primID, int face)
  2077. {
  2078. //m_log.DebugFormat(
  2079. // "[PERMISSONS]: Performing CanInteractWithPrimMedia check with agentID {0}, primID {1}, face {2}",
  2080. // agentID, primID, face);
  2081. if (MoapModule is null)
  2082. return false;
  2083. SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
  2084. if (part is null)
  2085. return false;
  2086. MediaEntry me = MoapModule.GetMediaEntry(part, face);
  2087. // If there is no existing media entry then it can be controlled (in this context, created).
  2088. if (me is null)
  2089. return true;
  2090. //m_log.DebugFormat(
  2091. // "[PERMISSIONS]: Checking CanInteractWithPrimMedia for {0} on {1} face {2} with interact permissions {3}",
  2092. // agentID, primID, face, me.InteractPermissions);
  2093. return GenericPrimMediaPermission(part, agentID, me.InteractPermissions);
  2094. }
  2095. private bool GenericPrimMediaPermission(SceneObjectPart part, UUID agentID, MediaPermission perms)
  2096. {
  2097. //if (IsAdministrator(agentID))
  2098. // return true;
  2099. if ((perms & MediaPermission.Anyone) == MediaPermission.Anyone)
  2100. return true;
  2101. if ((perms & MediaPermission.Owner) == MediaPermission.Owner)
  2102. {
  2103. if (agentID.Equals(part.OwnerID))
  2104. return true;
  2105. }
  2106. if ((perms & MediaPermission.Group) == MediaPermission.Group)
  2107. {
  2108. if (IsGroupMember(part.GroupID, agentID, 0))
  2109. return true;
  2110. }
  2111. return false;
  2112. }
  2113. }
  2114. }