PermissionsModule.cs 100 KB

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