123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using log4net;
- using Nini.Config;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Region.Framework.Scenes;
- using OpenSim.Services.Interfaces;
- using Mono.Addins;
- using PermissionMask = OpenSim.Framework.PermissionMask;
- namespace OpenSim.Region.CoreModules.World.Permissions
- {
- [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DefaultPermissionsModule")]
- public class DefaultPermissionsModule : INonSharedRegionModule, IPermissionsModule
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- protected Scene m_scene;
- protected ScenePermissions scenePermissions;
- protected bool m_Enabled;
- private InventoryFolderImpl m_libraryRootFolder;
- protected InventoryFolderImpl LibraryRootFolder
- {
- get
- {
- if (m_libraryRootFolder != null)
- return m_libraryRootFolder;
- ILibraryService lib = m_scene.RequestModuleInterface<ILibraryService>();
- if (lib != null)
- {
- m_libraryRootFolder = lib.LibraryRootFolder;
- }
- return m_libraryRootFolder;
- }
- }
- #region Constants
- /// <value>
- /// Different user set names that come in from the configuration file.
- /// </value>
- enum UserSet
- {
- All,
- Administrators
- };
- #endregion
- #region Bypass Permissions / Debug Permissions Stuff
- // Bypasses the permissions engine
- private bool m_bypassPermissions = true;
- private bool m_bypassPermissionsValue = true;
- private bool m_propagatePermissions = false;
- private bool m_debugPermissions = false;
- private bool m_allowGridAdmins = false;
- private bool m_RegionOwnerIsAdmin = false;
- private bool m_RegionManagerIsAdmin = false;
- private bool m_forceGridAdminsOnly;
- private bool m_forceAdminModeAlwaysOn;
- private bool m_allowAdminActionsWithoutGodMode;
- /// <value>
- /// The set of users that are allowed to create scripts. This is only active if permissions are not being
- /// bypassed. This overrides normal permissions.
- /// </value>
- private UserSet m_allowedScriptCreators = UserSet.All;
- /// <value>
- /// The set of users that are allowed to edit (save) scripts. This is only active if
- /// permissions are not being bypassed. This overrides normal permissions.-
- /// </value>
- private UserSet m_allowedScriptEditors = UserSet.All;
- private Dictionary<string, bool> GrantLSL = new Dictionary<string, bool>();
- private Dictionary<string, bool> GrantCS = new Dictionary<string, bool>();
- private Dictionary<string, bool> GrantVB = new Dictionary<string, bool>();
- private Dictionary<string, bool> GrantJS = new Dictionary<string, bool>();
- private Dictionary<string, bool> GrantYP = new Dictionary<string, bool>();
- private IFriendsModule m_friendsModule;
- private IFriendsModule FriendsModule
- {
- get
- {
- if (m_friendsModule == null)
- m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
- return m_friendsModule;
- }
- }
- private IGroupsModule m_groupsModule;
- private IGroupsModule GroupsModule
- {
- get
- {
- if (m_groupsModule == null)
- m_groupsModule = m_scene.RequestModuleInterface<IGroupsModule>();
- return m_groupsModule;
- }
- }
- private IMoapModule m_moapModule;
- private IMoapModule MoapModule
- {
- get
- {
- if (m_moapModule == null)
- m_moapModule = m_scene.RequestModuleInterface<IMoapModule>();
- return m_moapModule;
- }
- }
- #endregion
- #region INonSharedRegionModule Members
- public void Initialise(IConfigSource config)
- {
- string permissionModules = Util.GetConfigVarFromSections<string>(config, "permissionmodules",
- new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
- List<string> modules = new List<string>(permissionModules.Split(',').Select(m => m.Trim()));
- if (!modules.Contains("DefaultPermissionsModule"))
- return;
- m_Enabled = true;
- string[] sections = new string[] { "Startup", "Permissions" };
- m_allowGridAdmins = Util.GetConfigVarFromSections<bool>(config, "allow_grid_gods", sections, false);
- m_bypassPermissions = !Util.GetConfigVarFromSections<bool>(config, "serverside_object_permissions", sections, true);
- m_propagatePermissions = Util.GetConfigVarFromSections<bool>(config, "propagate_permissions", sections, true);
- m_forceGridAdminsOnly = Util.GetConfigVarFromSections<bool>(config, "force_grid_gods_only", sections, false);
- if(!m_forceGridAdminsOnly)
- {
- m_RegionOwnerIsAdmin = Util.GetConfigVarFromSections<bool>(config, "region_owner_is_god",sections, true);
- m_RegionManagerIsAdmin = Util.GetConfigVarFromSections<bool>(config, "region_manager_is_god",sections, false);
- }
- else
- m_allowGridAdmins = true;
- m_forceAdminModeAlwaysOn = Util.GetConfigVarFromSections<bool>(config, "automatic_gods", sections, false);
- m_allowAdminActionsWithoutGodMode = Util.GetConfigVarFromSections<bool>(config, "implicit_gods", sections, false);
- if(m_allowAdminActionsWithoutGodMode)
- m_forceAdminModeAlwaysOn = false;
- m_allowedScriptCreators
- = ParseUserSetConfigSetting(config, "allowed_script_creators", m_allowedScriptCreators);
- m_allowedScriptEditors
- = ParseUserSetConfigSetting(config, "allowed_script_editors", m_allowedScriptEditors);
- if (m_bypassPermissions)
- m_log.Info("[PERMISSIONS]: serverside_object_permissions = false in ini file so disabling all region service permission checks");
- else
- m_log.Debug("[PERMISSIONS]: Enabling all region service permission checks");
- string grant = Util.GetConfigVarFromSections<string>(config, "GrantLSL",
- new string[] { "Startup", "Permissions" }, string.Empty);
- if (grant.Length > 0)
- {
- foreach (string uuidl in grant.Split(','))
- {
- string uuid = uuidl.Trim(" \t".ToCharArray());
- GrantLSL.Add(uuid, true);
- }
- }
- grant = Util.GetConfigVarFromSections<string>(config, "GrantCS",
- new string[] { "Startup", "Permissions" }, string.Empty);
- if (grant.Length > 0)
- {
- foreach (string uuidl in grant.Split(','))
- {
- string uuid = uuidl.Trim(" \t".ToCharArray());
- GrantCS.Add(uuid, true);
- }
- }
- grant = Util.GetConfigVarFromSections<string>(config, "GrantVB",
- new string[] { "Startup", "Permissions" }, string.Empty);
- if (grant.Length > 0)
- {
- foreach (string uuidl in grant.Split(','))
- {
- string uuid = uuidl.Trim(" \t".ToCharArray());
- GrantVB.Add(uuid, true);
- }
- }
- grant = Util.GetConfigVarFromSections<string>(config, "GrantJS",
- new string[] { "Startup", "Permissions" }, string.Empty);
- if (grant.Length > 0)
- {
- foreach (string uuidl in grant.Split(','))
- {
- string uuid = uuidl.Trim(" \t".ToCharArray());
- GrantJS.Add(uuid, true);
- }
- }
- grant = Util.GetConfigVarFromSections<string>(config, "GrantYP",
- new string[] { "Startup", "Permissions" }, string.Empty);
- if (grant.Length > 0)
- {
- foreach (string uuidl in grant.Split(','))
- {
- string uuid = uuidl.Trim(" \t".ToCharArray());
- GrantYP.Add(uuid, true);
- }
- }
- }
- public void AddRegion(Scene scene)
- {
- if (!m_Enabled)
- return;
- m_scene = scene;
- scene.RegisterModuleInterface<IPermissionsModule>(this);
- scenePermissions = m_scene.Permissions;
- //Register functions with Scene External Checks!
- scenePermissions.OnBypassPermissions += BypassPermissions;
- scenePermissions.OnSetBypassPermissions += SetBypassPermissions;
- scenePermissions.OnPropagatePermissions += PropagatePermissions;
- scenePermissions.OnIsGridGod += IsGridAdministrator;
- scenePermissions.OnIsAdministrator += IsAdministrator;
- scenePermissions.OnIsEstateManager += IsEstateManager;
- scenePermissions.OnGenerateClientFlags += GenerateClientFlags;
- scenePermissions.OnIssueEstateCommand += CanIssueEstateCommand;
- scenePermissions.OnRunConsoleCommand += CanRunConsoleCommand;
- scenePermissions.OnTeleport += CanTeleport;
- scenePermissions.OnInstantMessage += CanInstantMessage;
- scenePermissions.OnAbandonParcel += CanAbandonParcel;
- scenePermissions.OnReclaimParcel += CanReclaimParcel;
- scenePermissions.OnDeedParcel += CanDeedParcel;
- scenePermissions.OnSellParcel += CanSellParcel;
- scenePermissions.OnEditParcelProperties += CanEditParcelProperties;
- scenePermissions.OnTerraformLand += CanTerraformLand;
- scenePermissions.OnBuyLand += CanBuyLand;
- scenePermissions.OnReturnObjects += CanReturnObjects;
- scenePermissions.OnRezObject += CanRezObject;
- scenePermissions.OnObjectEntry += CanObjectEntry;
- scenePermissions.OnObjectEnterWithScripts += OnObjectEnterWithScripts;
- scenePermissions.OnDuplicateObject += CanDuplicateObject;
- scenePermissions.OnDeleteObjectByIDs += CanDeleteObjectByIDs;
- scenePermissions.OnDeleteObject += CanDeleteObject;
- scenePermissions.OnEditObjectByIDs += CanEditObjectByIDs;
- scenePermissions.OnEditObject += CanEditObject;
- scenePermissions.OnEditObjectPerms += CanEditObjectPerms;
- scenePermissions.OnInventoryTransfer += CanInventoryTransfer;
- scenePermissions.OnMoveObject += CanMoveObject;
- scenePermissions.OnTakeObject += CanTakeObject;
- scenePermissions.OnTakeCopyObject += CanTakeCopyObject;
- scenePermissions.OnLinkObject += CanLinkObject;
- scenePermissions.OnDelinkObject += CanDelinkObject;
- scenePermissions.OnDeedObject += CanDeedObject;
- scenePermissions.OnSellGroupObject += CanSellGroupObject;
- scenePermissions.OnSellObjectByUserID += CanSellObjectByUserID;
- scenePermissions.OnSellObject += CanSellObject;
-
- scenePermissions.OnCreateObjectInventory += CanCreateObjectInventory;
- scenePermissions.OnEditObjectInventory += CanEditObjectInventory;
- scenePermissions.OnCopyObjectInventory += CanCopyObjectInventory;
- scenePermissions.OnDeleteObjectInventory += CanDeleteObjectInventory;
- scenePermissions.OnDoObjectInvToObjectInv += CanDoObjectInvToObjectInv;
- scenePermissions.OnDropInObjectInv += CanDropInObjectInv;
- scenePermissions.OnViewNotecard += CanViewNotecard;
- scenePermissions.OnViewScript += CanViewScript;
- scenePermissions.OnEditNotecard += CanEditNotecard;
- scenePermissions.OnEditScript += CanEditScript;
- scenePermissions.OnResetScript += CanResetScript;
- scenePermissions.OnRunScript += CanRunScript;
- scenePermissions.OnCompileScript += CanCompileScript;
-
- scenePermissions.OnCreateUserInventory += CanCreateUserInventory;
- scenePermissions.OnCopyUserInventory += CanCopyUserInventory;
- scenePermissions.OnEditUserInventory += CanEditUserInventory;
- scenePermissions.OnDeleteUserInventory += CanDeleteUserInventory;
- scenePermissions.OnControlPrimMedia += CanControlPrimMedia;
- scenePermissions.OnInteractWithPrimMedia += CanInteractWithPrimMedia;
- m_scene.AddCommand("Users", this, "bypass permissions",
- "bypass permissions <true / false>",
- "Bypass permission checks",
- HandleBypassPermissions);
- m_scene.AddCommand("Users", this, "force permissions",
- "force permissions <true / false>",
- "Force permissions on or off",
- HandleForcePermissions);
- m_scene.AddCommand("Debug", this, "debug permissions",
- "debug permissions <true / false>",
- "Turn on permissions debugging",
- HandleDebugPermissions);
- }
- public void RegionLoaded(Scene scene)
- {
- }
- public void RemoveRegion(Scene scene)
- {
- if (!m_Enabled)
- return;
- m_scene.UnregisterModuleInterface<IPermissionsModule>(this);
- scenePermissions.OnBypassPermissions -= BypassPermissions;
- scenePermissions.OnSetBypassPermissions -= SetBypassPermissions;
- scenePermissions.OnPropagatePermissions -= PropagatePermissions;
- scenePermissions.OnIsGridGod -= IsGridAdministrator;
- scenePermissions.OnIsAdministrator -= IsAdministrator;
- scenePermissions.OnIsEstateManager -= IsEstateManager;
- scenePermissions.OnGenerateClientFlags -= GenerateClientFlags;
- scenePermissions.OnIssueEstateCommand -= CanIssueEstateCommand;
- scenePermissions.OnRunConsoleCommand -= CanRunConsoleCommand;
- scenePermissions.OnTeleport -= CanTeleport;
- scenePermissions.OnInstantMessage -= CanInstantMessage;
- scenePermissions.OnAbandonParcel -= CanAbandonParcel;
- scenePermissions.OnReclaimParcel -= CanReclaimParcel;
- scenePermissions.OnDeedParcel -= CanDeedParcel;
- scenePermissions.OnSellParcel -= CanSellParcel;
- scenePermissions.OnEditParcelProperties -= CanEditParcelProperties;
- scenePermissions.OnTerraformLand -= CanTerraformLand;
- scenePermissions.OnBuyLand -= CanBuyLand;
- scenePermissions.OnRezObject -= CanRezObject;
- scenePermissions.OnObjectEntry -= CanObjectEntry;
- scenePermissions.OnObjectEnterWithScripts -= OnObjectEnterWithScripts;
- scenePermissions.OnReturnObjects -= CanReturnObjects;
- scenePermissions.OnDuplicateObject -= CanDuplicateObject;
- scenePermissions.OnDeleteObjectByIDs -= CanDeleteObjectByIDs;
- scenePermissions.OnDeleteObject -= CanDeleteObject;
- scenePermissions.OnEditObjectByIDs -= CanEditObjectByIDs;
- scenePermissions.OnEditObject -= CanEditObject;
- scenePermissions.OnEditObjectPerms -= CanEditObjectPerms;
- scenePermissions.OnInventoryTransfer -= CanInventoryTransfer;
- scenePermissions.OnMoveObject -= CanMoveObject;
- scenePermissions.OnTakeObject -= CanTakeObject;
- scenePermissions.OnTakeCopyObject -= CanTakeCopyObject;
- scenePermissions.OnLinkObject -= CanLinkObject;
- scenePermissions.OnDelinkObject -= CanDelinkObject;
- scenePermissions.OnDeedObject -= CanDeedObject;
- scenePermissions.OnSellGroupObject -= CanSellGroupObject;
- scenePermissions.OnSellObjectByUserID -= CanSellObjectByUserID;
- scenePermissions.OnSellObject -= CanSellObject;
-
- scenePermissions.OnCreateObjectInventory -= CanCreateObjectInventory;
- scenePermissions.OnEditObjectInventory -= CanEditObjectInventory;
- scenePermissions.OnCopyObjectInventory -= CanCopyObjectInventory;
- scenePermissions.OnDeleteObjectInventory -= CanDeleteObjectInventory;
- scenePermissions.OnDoObjectInvToObjectInv -= CanDoObjectInvToObjectInv;
- scenePermissions.OnDropInObjectInv -= CanDropInObjectInv;
- scenePermissions.OnViewNotecard -= CanViewNotecard;
- scenePermissions.OnViewScript -= CanViewScript;
- scenePermissions.OnEditNotecard -= CanEditNotecard;
- scenePermissions.OnEditScript -= CanEditScript;
- scenePermissions.OnResetScript -= CanResetScript;
- scenePermissions.OnRunScript -= CanRunScript;
- scenePermissions.OnCompileScript -= CanCompileScript;
-
- scenePermissions.OnCreateUserInventory -= CanCreateUserInventory;
- scenePermissions.OnCopyUserInventory -= CanCopyUserInventory;
- scenePermissions.OnEditUserInventory -= CanEditUserInventory;
- scenePermissions.OnDeleteUserInventory -= CanDeleteUserInventory;
- scenePermissions.OnControlPrimMedia -= CanControlPrimMedia;
- scenePermissions.OnInteractWithPrimMedia -= CanInteractWithPrimMedia;
- }
- public void Close()
- {
- }
- public string Name
- {
- get { return "DefaultPermissionsModule"; }
- }
- public Type ReplaceableInterface
- {
- get { return null; }
- }
- #endregion
- #region Console command handlers
- public void HandleBypassPermissions(string module, string[] args)
- {
- if (m_scene.ConsoleScene() != null &&
- m_scene.ConsoleScene() != m_scene)
- {
- return;
- }
- if (args.Length > 2)
- {
- if (!bool.TryParse(args[2], out bool val))
- return;
- m_bypassPermissions = val;
- m_log.InfoFormat(
- "[PERMISSIONS]: Set permissions bypass to {0} for {1}",
- m_bypassPermissions, m_scene.RegionInfo.RegionName);
- }
- }
- public void HandleForcePermissions(string module, string[] args)
- {
- if (m_scene.ConsoleScene() != null &&
- m_scene.ConsoleScene() != m_scene)
- {
- return;
- }
- if (!m_bypassPermissions)
- {
- m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first");
- return;
- }
- if (args.Length > 2)
- {
- if (!bool.TryParse(args[2], out bool val))
- return;
- m_bypassPermissionsValue = val;
- m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName);
- }
- }
- public void HandleDebugPermissions(string module, string[] args)
- {
- if (m_scene.ConsoleScene() != null &&
- m_scene.ConsoleScene() != m_scene)
- {
- return;
- }
- if (args.Length > 2)
- {
- if (!bool.TryParse(args[2], out bool val))
- return;
- m_debugPermissions = val;
- m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName);
- }
- }
- #endregion
- #region Helper Functions
- protected void SendPermissionError(UUID user, string reason)
- {
- m_scene.EventManager.TriggerPermissionError(user, reason);
- }
- protected void DebugPermissionInformation(string permissionCalled)
- {
- if (m_debugPermissions)
- m_log.Debug("[PERMISSIONS]: " + permissionCalled + " was called from " + m_scene.RegionInfo.RegionName);
- }
- /// <summary>
- /// Checks if the given group is active and if the user is a group member
- /// with the powers requested (powers = 0 for no powers check)
- /// </summary>
- /// <param name="groupID"></param>
- /// <param name="userID"></param>
- /// <param name="powers"></param>
- /// <returns></returns>
- protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers)
- {
- if (null == GroupsModule)
- return false;
- GroupMembershipData gmd = GroupsModule.GetMembershipData(groupID, userID);
- if (gmd != null)
- {
- if (((gmd.GroupPowers != 0) && powers == 0) || (gmd.GroupPowers & powers) == powers)
- return true;
- }
- return false;
- }
- protected bool GroupMemberPowers(UUID groupID, UUID userID, ref ulong powers)
- {
- powers = 0;
- if (null == GroupsModule)
- return false;
- GroupMembershipData gmd = GroupsModule.GetMembershipData(groupID, userID);
-
- if (gmd != null)
- {
- powers = gmd.GroupPowers;
- return true;
- }
- return false;
- }
- protected bool GroupMemberPowers(UUID groupID, ScenePresence sp, ref ulong powers)
- {
- powers = 0;
- IClientAPI client = sp.ControllingClient;
- if (client == null)
- return false;
- if(!client.IsGroupMember(groupID))
- return false;
-
- powers = client.GetGroupPowers(groupID);
- return true;
- }
- /// <summary>
- /// Parse a user set configuration setting
- /// </summary>
- /// <param name="config"></param>
- /// <param name="settingName"></param>
- /// <param name="defaultValue">The default value for this attribute</param>
- /// <returns>The parsed value</returns>
- private static UserSet ParseUserSetConfigSetting(IConfigSource config, string settingName, UserSet defaultValue)
- {
- UserSet userSet = defaultValue;
- string rawSetting = Util.GetConfigVarFromSections<string>(config, settingName,
- new string[] {"Startup", "Permissions"}, defaultValue.ToString());
- // Temporary measure to allow 'gods' to be specified in config for consistency's sake. In the long term
- // this should disappear.
- if ("gods" == rawSetting.ToLower())
- rawSetting = UserSet.Administrators.ToString();
- // Doing it this was so that we can do a case insensitive conversion
- try
- {
- userSet = (UserSet)Enum.Parse(typeof(UserSet), rawSetting, true);
- }
- catch
- {
- m_log.ErrorFormat(
- "[PERMISSIONS]: {0} is not a valid {1} value, setting to {2}",
- rawSetting, settingName, userSet);
- }
- m_log.DebugFormat("[PERMISSIONS]: {0} {1}", settingName, userSet);
- return userSet;
- }
- /// <summary>
- /// Is the user regarded as an administrator?
- /// </summary>
- /// <param name="user"></param>
- /// <returns></returns>
- protected bool IsAdministrator(UUID user)
- {
- if (user == UUID.Zero)
- return false;
- if (m_RegionOwnerIsAdmin && m_scene.RegionInfo.EstateSettings.EstateOwner == user)
- return true;
- if (m_RegionManagerIsAdmin && IsEstateManager(user))
- return true;
- if (IsGridAdministrator(user))
- return true;
- return false;
- }
- /// <summary>
- /// Is the given user a God throughout the grid (not just in the current scene)?
- /// </summary>
- /// <param name="user">The user</param>
- /// <param name="scene">Unused, can be null</param>
- /// <returns></returns>
- protected bool IsGridAdministrator(UUID user)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (user == UUID.Zero)
- return false;
- if (m_allowGridAdmins)
- {
- ScenePresence sp = m_scene.GetScenePresence(user);
- if (sp != null)
- return (sp.GodController.UserLevel >= 200);
- UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, user);
- if (account != null)
- return (account.UserLevel >= 200);
- }
- return false;
- }
- protected bool IsFriendWithPerms(UUID user, UUID objectOwner)
- {
- if (FriendsModule == null)
- return false;
- if (user == UUID.Zero)
- return false;
- int friendPerms = FriendsModule.GetRightsGrantedByFriend(user, objectOwner);
- return (friendPerms & (int)FriendRights.CanModifyObjects) != 0;
- }
- protected bool IsEstateManager(UUID user)
- {
- if (user == UUID.Zero) return false;
- return m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(user);
- }
- #endregion
- public bool PropagatePermissions()
- {
- if (m_bypassPermissions)
- return false;
- return m_propagatePermissions;
- }
- public bool BypassPermissions()
- {
- return m_bypassPermissions;
- }
- public void SetBypassPermissions(bool value)
- {
- m_bypassPermissions=value;
- }
- #region Object Permissions
- const uint DEFAULT_FLAGS = (uint)(
- PrimFlags.ObjectCopy | // Tells client you can copy the object
- PrimFlags.ObjectModify | // tells client you can modify the object
- PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
- PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
- PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
- PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
- PrimFlags.ObjectOwnerModify // Tells client that you're the owner of the object
- );
- const uint NOT_DEFAULT_FLAGS = (uint)~(
- PrimFlags.ObjectCopy | // Tells client you can copy the object
- PrimFlags.ObjectModify | // tells client you can modify the object
- PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
- PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
- PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
- PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
- PrimFlags.ObjectOwnerModify // Tells client that you're the owner of the object
- );
- const uint EXTRAOWNERMASK = (uint)(
- PrimFlags.ObjectYouOwner |
- PrimFlags.ObjectAnyOwner
- );
- const uint EXTRAGODMASK = (uint)(
- PrimFlags.ObjectYouOwner |
- PrimFlags.ObjectAnyOwner |
- PrimFlags.ObjectOwnerModify |
- PrimFlags.ObjectModify |
- PrimFlags.ObjectMove
- );
- const uint GOD_FLAGS = (uint)(
- PrimFlags.ObjectCopy | // Tells client you can copy the object
- PrimFlags.ObjectModify | // tells client you can modify the object
- PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
- PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
- PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
- PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
- PrimFlags.ObjectOwnerModify // Tells client that you're the owner of the object
- );
- const uint LOCKED_GOD_FLAGS = (uint)(
- PrimFlags.ObjectCopy | // Tells client you can copy the object
- PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
- PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
- PrimFlags.ObjectAnyOwner // Tells client that someone owns the object
- );
- const uint SHAREDMASK = (uint)(
- PermissionMask.Move |
- PermissionMask.Modify |
- PermissionMask.Copy
- );
- public uint GenerateClientFlags(SceneObjectPart task, ScenePresence sp, uint curEffectivePerms)
- {
- if(sp == null || task == null || curEffectivePerms == 0)
- return 0;
- // Remove any of the objectFlags that are temporary. These will get added back if appropriate
- uint objflags = curEffectivePerms & NOT_DEFAULT_FLAGS ;
- uint returnMask;
- SceneObjectGroup grp = task.ParentGroup;
- if(grp == null)
- return 0;
- UUID taskOwnerID = task.OwnerID;
- UUID spID = sp.UUID;
- bool unlocked = (grp.RootPart.OwnerMask & (uint)PermissionMask.Move) != 0;
- if(sp.IsGod)
- {
- // do locked on objects owned by admin
- if(!unlocked && spID == taskOwnerID)
- return objflags | LOCKED_GOD_FLAGS;
- else
- return objflags | GOD_FLAGS;
- }
- //bypass option == owner rights
- if (m_bypassPermissions)
- {
- returnMask = ApplyObjectModifyMasks(task.OwnerMask, objflags, true); //??
- returnMask |= EXTRAOWNERMASK;
- if((returnMask & (uint)PrimFlags.ObjectModify) != 0)
- returnMask |= (uint)PrimFlags.ObjectOwnerModify;
- return returnMask;
- }
- uint grpEffectiveOwnerPerms = grp.EffectiveOwnerPerms;
- // owner
- if (spID == taskOwnerID)
- {
- returnMask = ApplyObjectModifyMasks(grpEffectiveOwnerPerms, objflags, unlocked);
- returnMask |= EXTRAOWNERMASK;
- if((returnMask & (uint)PrimFlags.ObjectModify) != 0)
- returnMask |= (uint)PrimFlags.ObjectOwnerModify;
- return returnMask;
- }
- // if not god or owner, do attachments as everyone
- if (task.ParentGroup.IsAttachment)
- {
- returnMask = ApplyObjectModifyMasks(grp.EffectiveEveryOnePerms, objflags, unlocked);
- if (taskOwnerID != UUID.Zero)
- returnMask |= (uint)PrimFlags.ObjectAnyOwner;
- return returnMask;
- }
- UUID taskGroupID = task.GroupID;
- bool notGroupdOwned = taskOwnerID != taskGroupID;
- if ((grpEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
- grpEffectiveOwnerPerms &= ~(uint)PermissionMask.Copy;
- // if friends with rights then owner
- if (notGroupdOwned && IsFriendWithPerms(spID, taskOwnerID))
- {
- returnMask = ApplyObjectModifyMasks(grpEffectiveOwnerPerms, objflags, unlocked);
- returnMask |= EXTRAOWNERMASK;
- if((returnMask & (uint)PrimFlags.ObjectModify) != 0)
- returnMask |= (uint)PrimFlags.ObjectOwnerModify;
- return returnMask;
- }
- // group owned or shared ?
- IClientAPI client = sp.ControllingClient;
- ulong powers = 0;
- if(taskGroupID != UUID.Zero && GroupMemberPowers(taskGroupID, sp, ref powers))
- {
- if(notGroupdOwned)
- {
- // group sharing or everyone
- returnMask = ApplyObjectModifyMasks(grp.EffectiveGroupOrEveryOnePerms, objflags, unlocked);
- if (taskOwnerID != UUID.Zero)
- returnMask |= (uint)PrimFlags.ObjectAnyOwner;
- return returnMask;
- }
- // object is owned by group, check role powers
- if((powers & (ulong)GroupPowers.ObjectManipulate) == 0)
- {
- // group sharing or everyone
- returnMask = ApplyObjectModifyMasks(grp.EffectiveGroupOrEveryOnePerms, objflags, unlocked);
- returnMask |=
- (uint)PrimFlags.ObjectGroupOwned |
- (uint)PrimFlags.ObjectAnyOwner;
- return returnMask;
- }
- returnMask = ApplyObjectModifyMasks(grpEffectiveOwnerPerms, objflags, unlocked);
- returnMask |=
- (uint)PrimFlags.ObjectGroupOwned |
- (uint)PrimFlags.ObjectYouOwner |
- (uint)PrimFlags.ObjectAnyOwner;
- if ((returnMask & (uint)PrimFlags.ObjectModify) != 0)
- returnMask |= (uint)PrimFlags.ObjectOwnerModify;
- return returnMask;
- }
- // fallback is everyone rights
- returnMask = ApplyObjectModifyMasks(grp.EffectiveEveryOnePerms, objflags, unlocked);
- if (taskOwnerID != UUID.Zero)
- returnMask |= (uint)PrimFlags.ObjectAnyOwner;
- return returnMask;
- }
- private uint ApplyObjectModifyMasks(uint setPermissionMask, uint objectFlagsMask, bool unlocked)
- {
- // We are adding the temporary objectflags to the object's objectflags based on the
- // permission flag given. These change the F flags on the client.
- if ((setPermissionMask & (uint)PermissionMask.Copy) != 0)
- {
- objectFlagsMask |= (uint)PrimFlags.ObjectCopy;
- }
- if (unlocked)
- {
- if ((setPermissionMask & (uint)PermissionMask.Move) != 0)
- {
- objectFlagsMask |= (uint)PrimFlags.ObjectMove;
- }
- if ((setPermissionMask & (uint)PermissionMask.Modify) != 0)
- {
- objectFlagsMask |= (uint)PrimFlags.ObjectModify;
- }
- }
- if ((setPermissionMask & (uint)PermissionMask.Transfer) != 0)
- {
- objectFlagsMask |= (uint)PrimFlags.ObjectTransfer;
- }
- return objectFlagsMask;
- }
- // OARs still need this method that handles offline users
- public PermissionClass GetPermissionClass(UUID user, SceneObjectPart obj)
- {
- if (obj == null)
- return PermissionClass.Everyone;
- if (m_bypassPermissions)
- return PermissionClass.Owner;
- // Object owners should be able to edit their own content
- UUID objectOwner = obj.OwnerID;
- if (user == objectOwner)
- return PermissionClass.Owner;
- // Admin should be able to edit anything in the sim (including admin objects)
- if (IsAdministrator(user))
- return PermissionClass.Owner;
- if(!obj.ParentGroup.IsAttachment)
- {
- if (IsFriendWithPerms(user, objectOwner) )
- return PermissionClass.Owner;
- // Group permissions
- if (obj.GroupID != UUID.Zero && IsGroupMember(obj.GroupID, user, 0))
- return PermissionClass.Group;
- }
- return PermissionClass.Everyone;
- }
- // get effective object permissions using user UUID. User rights will be fixed
- protected uint GetObjectPermissions(UUID currentUser, SceneObjectGroup group, bool denyOnLocked)
- {
- if (group == null)
- return 0;
- SceneObjectPart root = group.RootPart;
- if (root == null)
- return 0;
- UUID objectOwner = group.OwnerID;
- bool locked = denyOnLocked && ((root.OwnerMask & (uint)PermissionMask.Move) == 0);
- if (IsAdministrator(currentUser))
- {
- // do lock on admin owned objects
- if(locked && currentUser == objectOwner)
- return (uint)(PermissionMask.AllEffective & ~(PermissionMask.Modify | PermissionMask.Move));
- return (uint)PermissionMask.AllEffective;
- }
- uint lockmask = (uint)PermissionMask.AllEffective;
- if(locked)
- lockmask &= ~(uint)(PermissionMask.Modify | PermissionMask.Move);
- uint grpEffectiveOwnerPerms = group.EffectiveOwnerPerms & lockmask;
- if (currentUser == objectOwner)
- return grpEffectiveOwnerPerms & lockmask;
-
- if (group.IsAttachment)
- return 0;
- if ((grpEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
- grpEffectiveOwnerPerms &= ~(uint)PermissionMask.Copy;
- UUID sogGroupID = group.GroupID;
- bool notgroudOwned = sogGroupID != objectOwner;
- if (notgroudOwned && IsFriendWithPerms(currentUser, objectOwner))
- return grpEffectiveOwnerPerms & lockmask;
- ulong powers = 0;
- if (sogGroupID != UUID.Zero && GroupMemberPowers(sogGroupID, currentUser, ref powers))
- {
- if(notgroudOwned)
- return group.EffectiveGroupOrEveryOnePerms & lockmask;
- if((powers & (ulong)GroupPowers.ObjectManipulate) == 0)
- return group.EffectiveGroupOrEveryOnePerms & lockmask;
- return grpEffectiveOwnerPerms & lockmask;
- }
- return group.EffectiveEveryOnePerms & lockmask;
- }
- // get effective object permissions using present presence. So some may depend on requested rights (ie God)
- protected uint GetObjectPermissions(ScenePresence sp, SceneObjectGroup group, bool denyOnLocked)
- {
- if (sp == null || sp.IsDeleted || group == null || group.IsDeleted)
- return 0;
- SceneObjectPart root = group.RootPart;
- if (root == null)
- return 0;
- UUID spID = sp.UUID;
- UUID objectOwner = group.OwnerID;
- bool locked = denyOnLocked && ((root.OwnerMask & (uint)PermissionMask.Move) == 0);
- if (sp.IsGod)
- {
- if(locked && spID == objectOwner)
- return (uint)(PermissionMask.AllEffective & ~(PermissionMask.Modify | PermissionMask.Move));
- return (uint)PermissionMask.AllEffective;
- }
- uint lockmask = (uint)PermissionMask.AllEffective;
- if(locked)
- lockmask &= ~(uint)(PermissionMask.Modify | PermissionMask.Move);
- uint ownerperms = group.EffectiveOwnerPerms;
- if (spID == objectOwner)
- return ownerperms & lockmask;
-
- if (group.IsAttachment)
- return 0;
- if ((ownerperms & (uint)PermissionMask.Transfer) == 0)
- ownerperms &= ~(uint)PermissionMask.Copy;
- UUID sogGroupID = group.GroupID;
- bool notgroudOwned = sogGroupID != objectOwner;
- if (notgroudOwned && IsFriendWithPerms(spID, objectOwner))
- {
- return ownerperms & lockmask;
- }
- ulong powers = 0;
- if (sogGroupID != UUID.Zero && GroupMemberPowers(sogGroupID, sp, ref powers))
- {
- if(notgroudOwned)
- return group.EffectiveGroupOrEveryOnePerms & lockmask;
- if((powers & (ulong)GroupPowers.ObjectManipulate) == 0)
- return group.EffectiveGroupOrEveryOnePerms & lockmask;
- return ownerperms & lockmask;
- }
- return group.EffectiveEveryOnePerms & lockmask;
- }
- private uint GetObjectItemPermissions(UUID userID, TaskInventoryItem ti)
- {
- UUID tiOwnerID = ti.OwnerID;
- if(tiOwnerID == userID)
- return ti.CurrentPermissions;
-
- if(IsAdministrator(userID))
- return (uint)PermissionMask.AllEffective;
- // ??
- if (IsFriendWithPerms(userID, tiOwnerID))
- return ti.CurrentPermissions;
- UUID tiGroupID = ti.GroupID;
- if(tiGroupID != UUID.Zero)
- {
- ulong powers = 0;
- if(GroupMemberPowers(tiGroupID, userID, ref powers))
- {
- if(tiGroupID == ti.OwnerID)
- {
- if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- return ti.CurrentPermissions;
- }
- return ti.GroupPermissions;
- }
- }
- return 0;
- }
- private uint GetObjectItemPermissions(ScenePresence sp, TaskInventoryItem ti, bool notEveryone)
- {
- UUID tiOwnerID = ti.OwnerID;
- UUID spID = sp.UUID;
- if(tiOwnerID == spID)
- return ti.CurrentPermissions;
-
- // ??
- if (IsFriendWithPerms(spID, tiOwnerID))
- return ti.CurrentPermissions;
- UUID tiGroupID = ti.GroupID;
- if(tiGroupID != UUID.Zero)
- {
- ulong powers = 0;
- if(GroupMemberPowers(tiGroupID, spID, ref powers))
- {
- if(tiGroupID == ti.OwnerID)
- {
- if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- return ti.CurrentPermissions;
- }
- uint p = ti.GroupPermissions;
- if(!notEveryone)
- p |= ti.EveryonePermissions;
- return p;
- }
- }
- if(notEveryone)
- return 0;
- return ti.EveryonePermissions;
- }
- #endregion
- #region Generic Permissions
- protected bool GenericCommunicationPermission(UUID user, UUID target)
- {
- // Setting this to true so that cool stuff can happen until we define what determines Generic Communication Permission
- bool permission = true;
- string reason = "Only registered users may communicate with another account.";
- // Uhh, we need to finish this before we enable it.. because it's blocking all sorts of goodies and features
- if (IsAdministrator(user))
- permission = true;
- if (IsEstateManager(user))
- permission = true;
- if (!permission)
- SendPermissionError(user, reason);
- return permission;
- }
- public bool GenericEstatePermission(UUID user)
- {
- // Estate admins should be able to use estate tools
- if (IsEstateManager(user))
- return true;
- // Administrators always have permission
- if (IsAdministrator(user))
- return true;
- return false;
- }
- protected bool GenericParcelOwnerPermission(UUID user, ILandObject parcel, ulong groupPowers, bool allowEstateManager)
- {
- if (parcel.LandData.OwnerID == user)
- return true;
- if (parcel.LandData.IsGroupOwned && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
- return true;
- if (allowEstateManager && IsEstateManager(user))
- return true;
- if (IsAdministrator(user))
- return true;
- return false;
- }
- #endregion
- #region Permission Checks
- private bool CanAbandonParcel(UUID user, ILandObject parcel)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandRelease, false);
- }
- private bool CanReclaimParcel(UUID user, ILandObject parcel)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return GenericParcelOwnerPermission(user, parcel, 0,true);
- }
- private bool CanDeedParcel(UUID user, ILandObject parcel)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if(parcel.LandData.GroupID == UUID.Zero)
- return false;
- if (IsAdministrator(user))
- return true;
- if (parcel.LandData.OwnerID != user) // Only the owner can deed!
- return false;
- ScenePresence sp = m_scene.GetScenePresence(user);
- if(sp == null)
- return false;
- IClientAPI client = sp.ControllingClient;
- if ((client.GetGroupPowers(parcel.LandData.GroupID) & (ulong)GroupPowers.LandDeed) == 0)
- return false;
- return true;
- }
- private bool CanDeedObject(ScenePresence sp, SceneObjectGroup sog, UUID targetGroupID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if(sog == null || sog.IsDeleted || sp == null || sp.IsDeleted || targetGroupID == UUID.Zero)
- return false;
- // object has group already?
- if(sog.GroupID != targetGroupID)
- return false;
- // is effectivelly shared?
- if(sog.EffectiveGroupPerms == 0)
- return false;
- if(sp.IsGod)
- return true;
- // owned by requester?
- if(sog.OwnerID != sp.UUID)
- return false;
- // owner can transfer?
- if((sog.EffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
- return false;
-
- // group member ?
- ulong powers = 0;
- if(!GroupMemberPowers(targetGroupID, sp, ref powers))
- return false;
- // has group rights?
- if ((powers & (ulong)GroupPowers.DeedObject) == 0)
- return false;
- return true;
- }
- private bool CanDuplicateObject(SceneObjectGroup sog, ScenePresence sp)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
- return false;
- uint perms = GetObjectPermissions(sp, sog, false);
- if((perms & (uint)PermissionMask.Copy) == 0)
- return false;
- if(sog.OwnerID != sp.UUID && (perms & (uint)PermissionMask.Transfer) == 0)
- return false;
- //If they can rez, they can duplicate
- return CanRezObject(0, sp.UUID, sog.AbsolutePosition);
- }
- private bool CanDeleteObject(SceneObjectGroup sog, ScenePresence sp)
- {
- // ignoring locked. viewers should warn and ask for confirmation
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
- return false;
- if(sog.IsAttachment)
- return false;
- UUID sogOwnerID = sog.OwnerID;
- UUID spID = sp.UUID;
- if(sogOwnerID == spID)
- return true;
- if (sp.IsGod)
- return true;
- if (IsFriendWithPerms(sog.UUID, sogOwnerID))
- return true;
- UUID sogGroupID = sog.GroupID;
- if (sogGroupID != UUID.Zero)
- {
- ulong powers = 0;
- if(GroupMemberPowers(sogGroupID, sp, ref powers))
- {
- if(sogGroupID == sogOwnerID)
- {
- if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- return true;
- }
- return (sog.EffectiveGroupPerms & (uint)PermissionMask.Modify) != 0;
- }
- }
- return false;
- }
- private bool CanDeleteObjectByIDs(UUID objectID, UUID userID)
- {
- // ignoring locked. viewers should warn and ask for confirmation
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
- if (sog == null)
- return false;
- if(sog.IsAttachment)
- return false;
- UUID sogOwnerID = sog.OwnerID;
- if(sogOwnerID == userID)
- return true;
- if (IsAdministrator(userID))
- return true;
- if (IsFriendWithPerms(objectID, sogOwnerID))
- return true;
- UUID sogGroupID = sog.GroupID;
- if (sogGroupID != UUID.Zero)
- {
- ulong powers = 0;
- if(GroupMemberPowers(sogGroupID, userID, ref powers))
- {
- if(sogGroupID == sogOwnerID)
- {
- if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- return true;
- }
- return (sog.EffectiveGroupPerms & (uint)PermissionMask.Modify) != 0;
- }
- }
- return false;
- }
- private bool CanEditObjectByIDs(UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- return true;
- }
- private bool CanEditObject(SceneObjectGroup sog, ScenePresence sp)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if(sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
- return false;
- uint perms = GetObjectPermissions(sp, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- return true;
- }
- private bool CanEditObjectPerms(SceneObjectGroup sog, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (sog == null)
- return false;
- if(sog.OwnerID == userID || IsAdministrator(userID))
- return true;
- UUID sogGroupID = sog.GroupID;
- if(sogGroupID == UUID.Zero || sogGroupID != sog.OwnerID)
- return false;
- uint perms = sog.EffectiveOwnerPerms;
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- ulong powers = 0;
- if(GroupMemberPowers(sogGroupID, userID, ref powers))
- {
- if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- return true;
- }
- return false;
- }
- private bool CanEditObjectInventory(UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- return true;
- }
- private bool CanEditParcelProperties(UUID userID, ILandObject parcel, GroupPowers p, bool allowManager)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return GenericParcelOwnerPermission(userID, parcel, (ulong)p, false);
- }
- /// <summary>
- /// Check whether the specified user can edit the given script
- /// </summary>
- /// <param name="script"></param>
- /// <param name="objectID"></param>
- /// <param name="user"></param>
- /// <param name="scene"></param>
- /// <returns></returns>
- private bool CanEditScript(UUID script, UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (m_allowedScriptEditors == UserSet.Administrators && !IsAdministrator(userID))
- return false;
- // Ordinarily, if you can view it, you can edit it
- // There is no viewing a no mod script
- //
- return CanViewScript(script, objectID, userID);
- }
- /// <summary>
- /// Check whether the specified user can edit the given notecard
- /// </summary>
- /// <param name="notecard"></param>
- /// <param name="objectID"></param>
- /// <param name="user"></param>
- /// <param name="scene"></param>
- /// <returns></returns>
- private bool CanEditNotecard(UUID notecard, UUID objectID, UUID user)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (objectID == UUID.Zero) // User inventory
- {
- IInventoryService invService = m_scene.InventoryService;
- InventoryItemBase assetRequestItem = invService.GetItem(user, notecard);
- if (assetRequestItem == null && LibraryRootFolder != null) // Library item
- {
- assetRequestItem = LibraryRootFolder.FindItem(notecard);
- if (assetRequestItem != null) // Implicitly readable
- return true;
- }
- // Notecards must be both mod and copy to be saveable
- // This is because of they're not copy, you can't read
- // them, and if they're not mod, well, then they're
- // not mod. Duh.
- //
- if ((assetRequestItem.CurrentPermissions &
- ((uint)PermissionMask.Modify |
- (uint)PermissionMask.Copy)) !=
- ((uint)PermissionMask.Modify |
- (uint)PermissionMask.Copy))
- return false;
- }
- else // Prim inventory
- {
- SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
- if (part == null)
- return false;
- SceneObjectGroup sog = part.ParentGroup;
- if (sog == null)
- return false;
- // check object mod right
- uint perms = GetObjectPermissions(user, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
- if (ti == null)
- return false;
-
- if (ti.OwnerID != user)
- {
- UUID tiGroupID = ti.GroupID;
- if (tiGroupID == UUID.Zero)
- return false;
- ulong powers = 0;
- if(!GroupMemberPowers(tiGroupID, user, ref powers))
- return false;
- if(tiGroupID == ti.OwnerID && (powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- {
- if ((ti.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy)) ==
- ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy))
- return true;
- }
- if ((ti.GroupPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy)) ==
- ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy))
- return true;
- return false;
- }
- // Require full perms
- if ((ti.CurrentPermissions & ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy)) !=
- ((uint)PermissionMask.Modify | (uint)PermissionMask.Copy))
- return false;
- }
- return true;
- }
- private bool CanInstantMessage(UUID user, UUID target)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- // If the sender is an object, check owner instead
- //
- SceneObjectPart part = m_scene.GetSceneObjectPart(user);
- if (part != null)
- user = part.OwnerID;
- return GenericCommunicationPermission(user, target);
- }
- private bool CanInventoryTransfer(UUID user, UUID target)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return GenericCommunicationPermission(user, target);
- }
- private bool CanIssueEstateCommand(UUID user, bool ownerCommand)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (IsAdministrator(user))
- return true;
- if (ownerCommand)
- return m_scene.RegionInfo.EstateSettings.IsEstateOwner(user);
- return IsEstateManager(user);
- }
- private bool CanMoveObject(SceneObjectGroup sog, ScenePresence sp)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if(sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
- return false;
- if (m_bypassPermissions)
- {
- if (sog.OwnerID != sp.UUID && sog.IsAttachment)
- return false;
- return m_bypassPermissionsValue;
- }
- uint perms = GetObjectPermissions(sp, sog, true);
- if((perms & (uint)PermissionMask.Move) == 0)
- return false;
- return true;
- }
- private bool CanObjectEntry(SceneObjectGroup sog, bool enteringRegion, Vector3 newPoint)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- float newX = newPoint.X;
- float newY = newPoint.Y;
- // allow outside region this is needed for crossings
- if (newX < -1f || newX > (m_scene.RegionInfo.RegionSizeX + 1.0f) ||
- newY < -1f || newY > (m_scene.RegionInfo.RegionSizeY + 1.0f) )
- return true;
- if(sog == null || sog.IsDeleted)
- return false;
- if (m_bypassPermissions)
- return m_bypassPermissionsValue;
- ILandObject parcel = m_scene.LandChannel.GetLandObject(newX, newY);
- if (parcel == null)
- return false;
- if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowAPrimitiveEntry)) != 0)
- return true;
- if (!enteringRegion)
- {
- Vector3 oldPoint = sog.AbsolutePosition;
- ILandObject fromparcel = m_scene.LandChannel.GetLandObject(oldPoint.X, oldPoint.Y);
- if (fromparcel != null && fromparcel.Equals(parcel)) // it already entered parcel ????
- return true;
- }
- UUID userID = sog.OwnerID;
- LandData landdata = parcel.LandData;
- if (landdata.OwnerID == userID)
- return true;
- if (IsAdministrator(userID))
- return true;
- UUID landGroupID = landdata.GroupID;
- if (landGroupID != UUID.Zero)
- {
- if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowGroupObjectEntry)) != 0)
- return IsGroupMember(landGroupID, userID, 0);
- if (landdata.IsGroupOwned && IsGroupMember(landGroupID, userID, (ulong)GroupPowers.AllowRez))
- return true;
- }
- //Otherwise, false!
- return false;
- }
- private bool OnObjectEnterWithScripts(SceneObjectGroup sog, ILandObject parcel)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if(sog == null || sog.IsDeleted)
- return false;
- if (m_bypassPermissions)
- return m_bypassPermissionsValue;
- if (parcel == null)
- return true;
- int checkflags = ((int)ParcelFlags.AllowAPrimitiveEntry);
- bool scripts = (sog.ScriptCount() > 0);
- if(scripts)
- checkflags |= ((int)ParcelFlags.AllowOtherScripts);
- if ((parcel.LandData.Flags & checkflags) == checkflags)
- return true;
- UUID userID = sog.OwnerID;
- LandData landdata = parcel.LandData;
- if (landdata.OwnerID == userID)
- return true;
- if (IsAdministrator(userID))
- return true;
- UUID landGroupID = landdata.GroupID;
- if (landGroupID != UUID.Zero)
- {
- checkflags = (int)ParcelFlags.AllowGroupObjectEntry;
- if(scripts)
- checkflags |= ((int)ParcelFlags.AllowGroupScripts);
- if ((parcel.LandData.Flags & checkflags) == checkflags)
- return IsGroupMember(landGroupID, userID, 0);
- if (landdata.IsGroupOwned && IsGroupMember(landGroupID, userID, (ulong)GroupPowers.AllowRez))
- return true;
- }
- //Otherwise, false!
- return false;
- }
- private bool CanReturnObjects(ILandObject land, ScenePresence sp, List<SceneObjectGroup> objects)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if(sp == null)
- return true; // assuming that in this case rights are as owner
- UUID userID = sp.UUID;
- bool isPrivUser = sp.IsGod || IsEstateManager(userID);
- IClientAPI client = sp.ControllingClient;
- ulong powers = 0;
- ILandObject l;
- foreach (SceneObjectGroup g in new List<SceneObjectGroup>(objects))
- {
- if(g.IsAttachment)
- {
- objects.Remove(g);
- continue;
- }
- if (isPrivUser || g.OwnerID == userID)
- continue;
- // This is a short cut for efficiency. If land is non-null,
- // then all objects are on that parcel and we can save
- // ourselves the checking for each prim. Much faster.
- //
- if (land != null)
- {
- l = land;
- }
- else
- {
- Vector3 pos = g.AbsolutePosition;
- l = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
- }
- // If it's not over any land, then we can't do a thing
- if (l == null || l.LandData == null)
- {
- objects.Remove(g);
- continue;
- }
- LandData ldata = l.LandData;
- // If we own the land outright, then allow
- //
- if (ldata.OwnerID == userID)
- continue;
- // Group voodoo
- //
- if (ldata.IsGroupOwned)
- {
- UUID lGroupID = ldata.GroupID;
- // Not a group member, or no rights at all
- //
- powers = client.GetGroupPowers(lGroupID);
- if(powers == 0)
- {
- objects.Remove(g);
- continue;
- }
-
- // Group deeded object?
- //
- if (g.OwnerID == lGroupID &&
- (powers & (ulong)GroupPowers.ReturnGroupOwned) == 0)
- {
- objects.Remove(g);
- continue;
- }
- // Group set object?
- //
- if (g.GroupID == lGroupID &&
- (powers & (ulong)GroupPowers.ReturnGroupSet) == 0)
- {
- objects.Remove(g);
- continue;
- }
- if ((powers & (ulong)GroupPowers.ReturnNonGroup) == 0)
- {
- objects.Remove(g);
- continue;
- }
- // So we can remove all objects from this group land.
- // Fine.
- //
- continue;
- }
- // By default, we can't remove
- //
- objects.Remove(g);
- }
- if (objects.Count == 0)
- return false;
- return true;
- }
- private bool CanRezObject(int objectCount, UUID userID, Vector3 objectPosition)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions)
- return m_bypassPermissionsValue;
- // m_log.DebugFormat("[PERMISSIONS MODULE]: Checking rez object at {0} in {1}", objectPosition, m_scene.Name);
- ILandObject parcel = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
- if (parcel == null || parcel.LandData == null)
- return false;
- LandData landdata = parcel.LandData;
- if ((userID == landdata.OwnerID))
- return true;
- if ((landdata.Flags & (uint)ParcelFlags.CreateObjects) != 0)
- return true;
- if(IsAdministrator(userID))
- return true;
- if(landdata.GroupID != UUID.Zero)
- {
- if ((landdata.Flags & (uint)ParcelFlags.CreateGroupObjects) != 0)
- return IsGroupMember(landdata.GroupID, userID, 0);
- if (landdata.IsGroupOwned && IsGroupMember(landdata.GroupID, userID, (ulong)GroupPowers.AllowRez))
- return true;
- }
- return false;
- }
- private bool CanRunConsoleCommand(UUID user)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return IsAdministrator(user);
- }
- private bool CanRunScript(TaskInventoryItem scriptitem, SceneObjectPart part)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if(scriptitem == null || part == null)
- return false;
- SceneObjectGroup sog = part.ParentGroup;
- if(sog == null)
- return false;
- Vector3 pos = sog.AbsolutePosition;
- ILandObject parcel = m_scene.LandChannel.GetLandObjectClippedXY(pos.X, pos.Y);
- if (parcel == null)
- return false;
- LandData ldata = parcel.LandData;
- if(ldata == null)
- return false;
- uint lflags = ldata.Flags;
-
- if ((lflags & (uint)ParcelFlags.AllowOtherScripts) != 0)
- return true;
- if ((part.OwnerID == ldata.OwnerID))
- return true;
- if (((lflags & (uint)ParcelFlags.AllowGroupScripts) != 0)
- && (ldata.GroupID != UUID.Zero) && (ldata.GroupID == part.GroupID))
- return true;
-
- return GenericEstatePermission(part.OwnerID);
- }
- private bool CanSellParcel(UUID user, ILandObject parcel)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandSetSale, true);
- }
- private bool CanSellGroupObject(UUID userID, UUID groupID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return IsGroupMember(groupID, userID, (ulong)GroupPowers.ObjectSetForSale);
- }
- private bool CanSellObjectByUserID(SceneObjectGroup sog, UUID userID, byte saleType)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (sog == null || sog.IsDeleted || userID == UUID.Zero)
- return false;
- // sell is not a attachment op
- if(sog.IsAttachment)
- return false;
- if(IsAdministrator(userID))
- return true;
- uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms;
- if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
- return false;
- if(saleType == (byte)SaleType.Copy &&
- (sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0)
- return false;
- UUID sogOwnerID = sog.OwnerID;
- if(sogOwnerID == userID)
- return true;
- // else only group owned can be sold by members with powers
- UUID sogGroupID = sog.GroupID;
- if(sog.OwnerID != sogGroupID || sogGroupID == UUID.Zero)
- return false;
- return IsGroupMember(sogGroupID, userID, (ulong)GroupPowers.ObjectSetForSale);
- }
- private bool CanSellObject(SceneObjectGroup sog, ScenePresence sp, byte saleType)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
- return false;
- // sell is not a attachment op
- if(sog.IsAttachment)
- return false;
- if(sp.IsGod)
- return true;
- uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms;
- if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
- return false;
- if(saleType == (byte)SaleType.Copy &&
- (sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0)
- return false;
- UUID userID = sp.UUID;
- UUID sogOwnerID = sog.OwnerID;
- if(sogOwnerID == userID)
- return true;
- // else only group owned can be sold by members with powers
- UUID sogGroupID = sog.GroupID;
- if(sog.OwnerID != sogGroupID || sogGroupID == UUID.Zero)
- return false;
- ulong powers = 0;
- if(!GroupMemberPowers(sogGroupID, sp, ref powers))
- return false;
- if((powers & (ulong)GroupPowers.ObjectSetForSale) == 0)
- return false;
- return true;
- }
- private bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp)
- {
- // ignore locked, viewers shell ask for confirmation
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
- return false;
- // take is not a attachment op
- if(sog.IsAttachment)
- return false;
- UUID sogOwnerID = sog.OwnerID;
- UUID spID = sp.UUID;
- if(sogOwnerID == spID)
- return true;
- if (sp.IsGod)
- return true;
- if((sog.EffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
- return false;
-
- if (IsFriendWithPerms(sog.UUID, sogOwnerID))
- return true;
- UUID sogGroupID = sog.GroupID;
- if (sogGroupID != UUID.Zero)
- {
- ulong powers = 0;
- if(GroupMemberPowers(sogGroupID, sp, ref powers))
- {
- if(sogGroupID == sogOwnerID)
- {
- if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- return true;
- }
- return (sog.EffectiveGroupPerms & (uint)PermissionMask.Modify) != 0;
- }
- }
- return false;
- }
- private bool CanTakeCopyObject(SceneObjectGroup sog, ScenePresence sp)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
- return false;
- // refuse on attachments
- if(sog.IsAttachment && !sp.IsGod)
- return false;
- uint perms = GetObjectPermissions(sp, sog, true);
- if((perms & (uint)PermissionMask.Copy) == 0)
- {
- //sp.ControllingClient.SendAgentAlertMessage("Copying this item has been denied by the permissions system", false);
- return false;
- }
- if(sog.OwnerID != sp.UUID && (perms & (uint)PermissionMask.Transfer) == 0)
- return false;
- return true;
- }
- private bool CanTerraformLand(UUID userID, Vector3 position)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- // Estate override
- if (GenericEstatePermission(userID))
- return true;
- float X = position.X;
- float Y = position.Y;
- int id = (int)position.Z;
- ILandObject parcel;
- if(id >= 0 && X < 0 && Y < 0)
- parcel = m_scene.LandChannel.GetLandObject(id);
- else
- {
- parcel = m_scene.LandChannel.GetLandObjectClippedXY(X, Y);
- }
- if (parcel == null)
- return false;
- LandData landdata = parcel.LandData;
- if (landdata == null)
- return false;
-
- if ((landdata.Flags & ((int)ParcelFlags.AllowTerraform)) != 0)
- return true;
- if(landdata.OwnerID == userID)
- return true;
-
- if (landdata.IsGroupOwned && parcel.LandData.GroupID != UUID.Zero &&
- IsGroupMember(landdata.GroupID, userID, (ulong)GroupPowers.AllowEditLand))
- return true;
- return false;
- }
- /// <summary>
- /// Check whether the specified user can view the given script
- /// </summary>
- /// <param name="script"></param>
- /// <param name="objectID"></param>
- /// <param name="user"></param>
- /// <param name="scene"></param>
- /// <returns></returns>
- private bool CanViewScript(UUID script, UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- // A god is a god is a god
- if (IsAdministrator(userID))
- return true;
- if (objectID == UUID.Zero) // User inventory
- {
- IInventoryService invService = m_scene.InventoryService;
- InventoryItemBase assetRequestItem = invService.GetItem(userID, script);
- if (assetRequestItem == null && LibraryRootFolder != null) // Library item
- {
- assetRequestItem = LibraryRootFolder.FindItem(script);
- if (assetRequestItem != null) // Implicitly readable
- return true;
- }
- // SL is rather harebrained here. In SL, a script you
- // have mod/copy no trans is readable. This subverts
- // permissions, but is used in some products, most
- // notably Hippo door plugin and HippoRent 5 networked
- // prim counter.
- // To enable this broken SL-ism, remove Transfer from
- // the below expressions.
- // Trying to improve on SL perms by making a script
- // readable only if it's really full perms
- //
- if ((assetRequestItem.CurrentPermissions &
- /*
- ((uint)PermissionMask.Modify |
- (uint)PermissionMask.Copy |
- (uint)PermissionMask.Transfer)) !=
- ((uint)PermissionMask.Modify |
- (uint)PermissionMask.Copy |
- (uint)PermissionMask.Transfer))
- */
- (uint)(PermissionMask.Modify | PermissionMask.Copy)) !=
- (uint)(PermissionMask.Modify | PermissionMask.Copy))
- return false;
- }
- else // Prim inventory
- {
- SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
- if (part == null)
- return false;
- SceneObjectGroup sog = part.ParentGroup;
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- TaskInventoryItem ti = part.Inventory.GetInventoryItem(script);
- // if (ti == null || ti.InvType != (int)InventoryType.LSL)
- if (ti == null) // legacy may not have type
- return false;
- uint itperms = GetObjectItemPermissions(userID, ti);
- // Require full perms
- if ((itperms &
- /*
- ((uint)(PermissionMask.Modify |
- (uint)PermissionMask.Copy |
- (uint)PermissionMask.Transfer)) !=
- ((uint)PermissionMask.Modify |
- (uint)PermissionMask.Copy |
- (uint)PermissionMask.Transfer))
- */
- (uint)(PermissionMask.Modify | PermissionMask.Copy)) !=
- (uint)(PermissionMask.Modify | PermissionMask.Copy))
- return false;
- }
- return true;
- }
- /// <summary>
- /// Check whether the specified user can view the given notecard
- /// </summary>
- /// <param name="script"></param>
- /// <param name="objectID"></param>
- /// <param name="user"></param>
- /// <param name="scene"></param>
- /// <returns></returns>
- private bool CanViewNotecard(UUID notecard, UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- // A god is a god is a god
- if (IsAdministrator(userID))
- return true;
- if (objectID == UUID.Zero) // User inventory
- {
- IInventoryService invService = m_scene.InventoryService;
- InventoryItemBase assetRequestItem = invService.GetItem(userID, notecard);
- if (assetRequestItem == null && LibraryRootFolder != null) // Library item
- {
- assetRequestItem = LibraryRootFolder.FindItem(notecard);
- if (assetRequestItem != null) // Implicitly readable
- return true;
- }
- // Notecards are always readable unless no copy
- //
- if ((assetRequestItem.CurrentPermissions &
- (uint)PermissionMask.Copy) !=
- (uint)PermissionMask.Copy)
- return false;
- }
- else // Prim inventory
- {
- SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
- if (part == null)
- return false;
- SceneObjectGroup sog = part.ParentGroup;
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
- // if (ti == null || ti.InvType != (int)InventoryType.Notecard)
- if (ti == null)
- return false;
- uint itperms = GetObjectItemPermissions(userID, ti);
- // Notecards are always readable unless no copy
- //
- if ((itperms &
- (uint)PermissionMask.Copy) !=
- (uint)PermissionMask.Copy)
- return false;
- }
- return true;
- }
- #endregion
- private bool CanLinkObject(UUID userID, UUID objectID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- return true;
- }
- private bool CanDelinkObject(UUID userID, UUID objectID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- return true;
- }
- private bool CanBuyLand(UUID userID, ILandObject parcel)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return true;
- }
- private bool CanCopyObjectInventory(UUID itemID, UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
- if (part == null)
- return false;
- SceneObjectGroup sog = part.ParentGroup;
- if (sog == null)
- return false;
- if(sog.OwnerID == userID || IsAdministrator(userID))
- return true;
-
- if(sog.IsAttachment)
- return false;
- UUID sogGroupID = sog.GroupID;
- if(sogGroupID == UUID.Zero || sogGroupID != sog.OwnerID)
- return false;
- TaskInventoryItem ti = part.Inventory.GetInventoryItem(itemID);
- if(ti == null)
- return false;
- ulong powers = 0;
- if(GroupMemberPowers(sogGroupID, userID, ref powers))
- {
- if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
- return true;
- if((ti.EveryonePermissions & (uint)PermissionMask.Copy) != 0)
- return true;
- }
- return false;
- }
- // object inventory to object inventory item drag and drop
- private bool CanDoObjectInvToObjectInv(TaskInventoryItem item, SceneObjectPart sourcePart, SceneObjectPart destPart)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (sourcePart == null || destPart == null || item == null)
- return false;
- if (m_bypassPermissions)
- return true;
- SceneObjectGroup srcsog = sourcePart.ParentGroup;
- SceneObjectGroup destsog = destPart.ParentGroup;
- if (srcsog == null || destsog == null)
- return false;
- uint destsogEffectiveOwnerPerms = destsog.EffectiveOwnerPerms;
- // dest is locked
- if ((destsogEffectiveOwnerPerms & (uint)PermissionMask.Move) == 0)
- return false;
- uint itperms = item.CurrentPermissions;
- uint srcsogEffectiveOwnerPerms = srcsog.EffectiveOwnerPerms;
- // if item is no copy the source is modifed
- if ((itperms & (uint)PermissionMask.Copy) == 0)
- {
- if(srcsog.IsAttachment || destsog.IsAttachment)
- return false;
-
- if((srcsogEffectiveOwnerPerms & (uint)PermissionMask.Modify) == 0)
- return false;
- }
- bool notSameOwner = srcsog.OwnerID != destsog.OwnerID;
- if(notSameOwner)
- {
- if((itperms & (uint)PermissionMask.Transfer) == 0)
- return false;
- if(destsog.IsAttachment && (destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
- return false;
- if((destsogEffectiveOwnerPerms & (uint)PermissionMask.Modify) == 0)
- return false;
- }
- else
- {
- if((destsogEffectiveOwnerPerms & (uint)PermissionMask.Modify) == 0)
- return false;
- }
- return true;
- }
- private bool CanDropInObjectInv(InventoryItemBase item, ScenePresence sp, SceneObjectPart destPart)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (sp == null || sp.IsDeleted || destPart == null || item == null)
- return false;
- SceneObjectGroup destsog = destPart.ParentGroup;
- if (destsog == null || destsog.IsDeleted)
- return false;
- if (m_bypassPermissions)
- return true;
- if(sp.IsGod)
- return true;
- // dest is locked
- if((destsog.EffectiveOwnerPerms & (uint)PermissionMask.Move) == 0)
- return false;
- UUID destOwner = destsog.OwnerID;
- UUID spID = sp.UUID;
- bool spNotOwner = spID != destOwner;
- // scripts can't be droped
- if(spNotOwner && item.InvType == (int)InventoryType.LSL)
- return false;
- if(spNotOwner || item.Owner != destOwner)
- {
- // no copy item will be moved if it has transfer
- uint itperms = item.CurrentPermissions;
- if((itperms & (uint)PermissionMask.Transfer) == 0)
- return false;
- }
- // allowdrop is a root part thing and does bypass modify rights
- if((destsog.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) != 0)
- return true;
- uint perms = GetObjectPermissions(spID, destsog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- return true;
- }
- private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
- if (part == null)
- return false;
- SceneObjectGroup sog = part.ParentGroup;
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- TaskInventoryItem ti = part.Inventory.GetInventoryItem(itemID);
- if(ti == null)
- return false;
- //TODO item perm ?
- return true;
- }
- /// <summary>
- /// Check whether the specified user is allowed to directly create the given inventory type in a prim's
- /// inventory (e.g. the New Script button in the 1.21 Linden Lab client).
- /// </summary>
- /// <param name="invType"></param>
- /// <param name="objectID"></param>
- /// <param name="userID"></param>
- /// <returns></returns>
- private bool CanCreateObjectInventory(int invType, UUID objectID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- ScenePresence p = m_scene.GetScenePresence(userID);
- if (p == null)
- return false;
- SceneObjectGroup sog = m_scene.GetGroupByPrim(objectID);
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(userID, sog, true);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- if ((int)InventoryType.LSL == invType)
- {
- if (m_allowedScriptCreators == UserSet.Administrators)
- return false;
- }
- return true;
- }
- /// <summary>
- /// Check whether the specified user is allowed to create the given inventory type in their inventory.
- /// </summary>
- /// <param name="invType"></param>
- /// <param name="userID"></param>
- /// <returns></returns>
- private bool CanCreateUserInventory(int invType, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- if ((int)InventoryType.LSL == invType)
- if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
- return false;
- return true;
- }
- /// <summary>
- /// Check whether the specified user is allowed to copy the given inventory type in their inventory.
- /// </summary>
- /// <param name="itemID"></param>
- /// <param name="userID"></param>
- /// <returns></returns>
- private bool CanCopyUserInventory(UUID itemID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return true;
- }
- /// <summary>
- /// Check whether the specified user is allowed to edit the given inventory item within their own inventory.
- /// </summary>
- /// <param name="itemID"></param>
- /// <param name="userID"></param>
- /// <returns></returns>
- private bool CanEditUserInventory(UUID itemID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return true;
- }
- /// <summary>
- /// Check whether the specified user is allowed to delete the given inventory item from their own inventory.
- /// </summary>
- /// <param name="itemID"></param>
- /// <param name="userID"></param>
- /// <returns></returns>
- private bool CanDeleteUserInventory(UUID itemID, UUID userID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return true;
- }
- private bool CanTeleport(UUID userID, Scene scene)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- return true;
- }
- private bool CanResetScript(UUID primID, UUID script, UUID agentID)
- {
- DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
- if (m_bypassPermissions) return m_bypassPermissionsValue;
- SceneObjectGroup sog = m_scene.GetGroupByPrim(primID);
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(agentID, sog, false);
- if((perms & (uint)PermissionMask.Modify) == 0) // ??
- return false;
- return true;
- }
- private bool CanCompileScript(UUID ownerUUID, int scriptType)
- {
- //m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType);
- switch (scriptType) {
- case 0:
- if (GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString())) {
- return(true);
- }
- break;
- case 1:
- if (GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString())) {
- return(true);
- }
- break;
- case 2:
- if (GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString())) {
- return(true);
- }
- break;
- case 3:
- if (GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString()))
- {
- return (true);
- }
- break;
- case 4:
- if (GrantYP.Count == 0 || GrantYP.ContainsKey(ownerUUID.ToString()))
- {
- return (true);
- }
- break;
- }
- return(false);
- }
- private bool CanControlPrimMedia(UUID agentID, UUID primID, int face)
- {
- // m_log.DebugFormat(
- // "[PERMISSONS]: Performing CanControlPrimMedia check with agentID {0}, primID {1}, face {2}",
- // agentID, primID, face);
- if (null == MoapModule)
- return false;
- SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
- if (null == part)
- return false;
- MediaEntry me = MoapModule.GetMediaEntry(part, face);
- // If there is no existing media entry then it can be controlled (in this context, created).
- if (null == me)
- return true;
- // m_log.DebugFormat(
- // "[PERMISSIONS]: Checking CanControlPrimMedia for {0} on {1} face {2} with control permissions {3}",
- // agentID, primID, face, me.ControlPermissions);
- SceneObjectGroup sog = part.ParentGroup;
- if (sog == null)
- return false;
- uint perms = GetObjectPermissions(agentID, sog, false);
- if((perms & (uint)PermissionMask.Modify) == 0)
- return false;
- return true;
- }
- private bool CanInteractWithPrimMedia(UUID agentID, UUID primID, int face)
- {
- // m_log.DebugFormat(
- // "[PERMISSONS]: Performing CanInteractWithPrimMedia check with agentID {0}, primID {1}, face {2}",
- // agentID, primID, face);
- if (null == MoapModule)
- return false;
- SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
- if (null == part)
- return false;
- MediaEntry me = MoapModule.GetMediaEntry(part, face);
- // If there is no existing media entry then it can be controlled (in this context, created).
- if (null == me)
- return true;
- // m_log.DebugFormat(
- // "[PERMISSIONS]: Checking CanInteractWithPrimMedia for {0} on {1} face {2} with interact permissions {3}",
- // agentID, primID, face, me.InteractPermissions);
- return GenericPrimMediaPermission(part, agentID, me.InteractPermissions);
- }
- private bool GenericPrimMediaPermission(SceneObjectPart part, UUID agentID, MediaPermission perms)
- {
- // if (IsAdministrator(agentID))
- // return true;
- if ((perms & MediaPermission.Anyone) == MediaPermission.Anyone)
- return true;
- if ((perms & MediaPermission.Owner) == MediaPermission.Owner)
- {
- if (agentID == part.OwnerID)
- return true;
- }
- if ((perms & MediaPermission.Group) == MediaPermission.Group)
- {
- if (IsGroupMember(part.GroupID, agentID, 0))
- return true;
- }
- return false;
- }
- }
- }
|