PermissionsModule.cs 100 KB

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