PermissionsModule.cs 100 KB

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