PermissionsModule.cs 100 KB

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