PermissionsModule.cs 99 KB

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