PermissionsModule.cs 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983
  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.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Services.Interfaces;
  37. // Temporary fix of wrong GroupPowers constants in OpenMetaverse library
  38. enum GroupPowers : long
  39. {
  40. None = 0,
  41. LandEjectAndFreeze = 1,
  42. Invite = 2,
  43. ReturnGroupSet = 2,
  44. Eject = 4,
  45. ReturnNonGroup = 4,
  46. ChangeOptions = 8,
  47. LandGardening = 8,
  48. CreateRole = 16,
  49. DeedObject = 16,
  50. ModerateChat = 32,
  51. DeleteRole = 32,
  52. RoleProperties = 64,
  53. ObjectManipulate = 64,
  54. ObjectSetForSale = 128,
  55. AssignMemberLimited = 128,
  56. AssignMember = 256,
  57. Accountable = 256,
  58. RemoveMember = 512,
  59. SendNotices = 1024,
  60. ChangeActions = 1024,
  61. ChangeIdentity = 2048,
  62. ReceiveNotices = 2048,
  63. StartProposal = 4096,
  64. LandDeed = 4096,
  65. VoteOnProposal = 8192,
  66. LandRelease = 8192,
  67. LandSetSale = 16384,
  68. LandDivideJoin = 32768,
  69. ReturnGroupOwned = 65536,
  70. JoinChat = 65536,
  71. FindPlaces = 131072,
  72. LandChangeIdentity = 262144,
  73. SetLandingPoint = 524288,
  74. ChangeMedia = 1048576,
  75. LandEdit = 2097152,
  76. LandOptions = 4194304,
  77. AllowEditLand = 8388608,
  78. AllowFly = 16777216,
  79. AllowRez = 33554432,
  80. AllowLandmark = 67108864,
  81. AllowVoiceChat = 134217728,
  82. AllowSetHome = 268435456,
  83. LandManageAllowed = 536870912,
  84. LandManageBanned = 1073741824
  85. }
  86. namespace OpenSim.Region.CoreModules.World.Permissions
  87. {
  88. public class PermissionsModule : IRegionModule
  89. {
  90. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  91. protected Scene m_scene;
  92. private InventoryFolderImpl m_libraryRootFolder;
  93. protected InventoryFolderImpl LibraryRootFolder
  94. {
  95. get
  96. {
  97. if (m_libraryRootFolder != null)
  98. return m_libraryRootFolder;
  99. ILibraryService lib = m_scene.RequestModuleInterface<ILibraryService>();
  100. if (lib != null)
  101. {
  102. m_libraryRootFolder = lib.LibraryRootFolder;
  103. }
  104. return m_libraryRootFolder;
  105. }
  106. }
  107. #region Constants
  108. // These are here for testing. They will be taken out
  109. //private uint PERM_ALL = (uint)2147483647;
  110. private uint PERM_COPY = (uint)32768;
  111. //private uint PERM_MODIFY = (uint)16384;
  112. private uint PERM_MOVE = (uint)524288;
  113. private uint PERM_TRANS = (uint)8192;
  114. private uint PERM_LOCKED = (uint)540672;
  115. /// <value>
  116. /// Different user set names that come in from the configuration file.
  117. /// </value>
  118. enum UserSet
  119. {
  120. All,
  121. Administrators
  122. };
  123. #endregion
  124. #region Bypass Permissions / Debug Permissions Stuff
  125. // Bypasses the permissions engine
  126. private bool m_bypassPermissions = true;
  127. private bool m_bypassPermissionsValue = true;
  128. private bool m_propagatePermissions = false;
  129. private bool m_debugPermissions = false;
  130. private bool m_allowGridGods = false;
  131. private bool m_RegionOwnerIsGod = false;
  132. private bool m_RegionManagerIsGod = false;
  133. private bool m_ParcelOwnerIsGod = false;
  134. /// <value>
  135. /// The set of users that are allowed to create scripts. This is only active if permissions are not being
  136. /// bypassed. This overrides normal permissions.
  137. /// </value>
  138. private UserSet m_allowedScriptCreators = UserSet.All;
  139. /// <value>
  140. /// The set of users that are allowed to edit (save) scripts. This is only active if
  141. /// permissions are not being bypassed. This overrides normal permissions.-
  142. /// </value>
  143. private UserSet m_allowedScriptEditors = UserSet.All;
  144. private Dictionary<string, bool> GrantLSL = new Dictionary<string, bool>();
  145. private Dictionary<string, bool> GrantCS = new Dictionary<string, bool>();
  146. private Dictionary<string, bool> GrantVB = new Dictionary<string, bool>();
  147. private Dictionary<string, bool> GrantJS = new Dictionary<string, bool>();
  148. private Dictionary<string, bool> GrantYP = new Dictionary<string, bool>();
  149. private IFriendsModule m_friendsModule;
  150. private IGroupsModule m_groupsModule;
  151. private IMoapModule m_moapModule;
  152. #endregion
  153. #region IRegionModule Members
  154. public void Initialise(Scene scene, IConfigSource config)
  155. {
  156. m_scene = scene;
  157. IConfig myConfig = config.Configs["Startup"];
  158. string permissionModules = myConfig.GetString("permissionmodules", "DefaultPermissionsModule");
  159. List<string> modules = new List<string>(permissionModules.Split(','));
  160. if (!modules.Contains("DefaultPermissionsModule"))
  161. return;
  162. m_allowGridGods = myConfig.GetBoolean("allow_grid_gods", false);
  163. m_bypassPermissions = !myConfig.GetBoolean("serverside_object_permissions", false);
  164. m_propagatePermissions = myConfig.GetBoolean("propagate_permissions", true);
  165. m_RegionOwnerIsGod = myConfig.GetBoolean("region_owner_is_god", true);
  166. m_RegionManagerIsGod = myConfig.GetBoolean("region_manager_is_god", false);
  167. m_ParcelOwnerIsGod = myConfig.GetBoolean("parcel_owner_is_god", true);
  168. m_allowedScriptCreators
  169. = ParseUserSetConfigSetting(myConfig, "allowed_script_creators", m_allowedScriptCreators);
  170. m_allowedScriptEditors
  171. = ParseUserSetConfigSetting(myConfig, "allowed_script_editors", m_allowedScriptEditors);
  172. if (m_bypassPermissions)
  173. m_log.Info("[PERMISSIONS]: serviceside_object_permissions = false in ini file so disabling all region service permission checks");
  174. else
  175. m_log.Debug("[PERMISSIONS]: Enabling all region service permission checks");
  176. //Register functions with Scene External Checks!
  177. m_scene.Permissions.OnBypassPermissions += BypassPermissions;
  178. m_scene.Permissions.OnSetBypassPermissions += SetBypassPermissions;
  179. m_scene.Permissions.OnPropagatePermissions += PropagatePermissions;
  180. m_scene.Permissions.OnGenerateClientFlags += GenerateClientFlags;
  181. m_scene.Permissions.OnAbandonParcel += CanAbandonParcel;
  182. m_scene.Permissions.OnReclaimParcel += CanReclaimParcel;
  183. m_scene.Permissions.OnDeedParcel += CanDeedParcel;
  184. m_scene.Permissions.OnDeedObject += CanDeedObject;
  185. m_scene.Permissions.OnIsGod += IsGod;
  186. m_scene.Permissions.OnIsAdministrator += IsAdministrator;
  187. m_scene.Permissions.OnDuplicateObject += CanDuplicateObject;
  188. m_scene.Permissions.OnDeleteObject += CanDeleteObject; //MAYBE FULLY IMPLEMENTED
  189. m_scene.Permissions.OnEditObject += CanEditObject; //MAYBE FULLY IMPLEMENTED
  190. m_scene.Permissions.OnEditParcel += CanEditParcel; //MAYBE FULLY IMPLEMENTED
  191. m_scene.Permissions.OnInstantMessage += CanInstantMessage;
  192. m_scene.Permissions.OnInventoryTransfer += CanInventoryTransfer; //NOT YET IMPLEMENTED
  193. m_scene.Permissions.OnIssueEstateCommand += CanIssueEstateCommand; //FULLY IMPLEMENTED
  194. m_scene.Permissions.OnMoveObject += CanMoveObject; //MAYBE FULLY IMPLEMENTED
  195. m_scene.Permissions.OnObjectEntry += CanObjectEntry;
  196. m_scene.Permissions.OnReturnObjects += CanReturnObjects; //NOT YET IMPLEMENTED
  197. m_scene.Permissions.OnRezObject += CanRezObject; //MAYBE FULLY IMPLEMENTED
  198. m_scene.Permissions.OnRunConsoleCommand += CanRunConsoleCommand;
  199. m_scene.Permissions.OnRunScript += CanRunScript; //NOT YET IMPLEMENTED
  200. m_scene.Permissions.OnCompileScript += CanCompileScript;
  201. m_scene.Permissions.OnSellParcel += CanSellParcel;
  202. m_scene.Permissions.OnTakeObject += CanTakeObject;
  203. m_scene.Permissions.OnTakeCopyObject += CanTakeCopyObject;
  204. m_scene.Permissions.OnTerraformLand += CanTerraformLand;
  205. m_scene.Permissions.OnLinkObject += CanLinkObject; //NOT YET IMPLEMENTED
  206. m_scene.Permissions.OnDelinkObject += CanDelinkObject; //NOT YET IMPLEMENTED
  207. m_scene.Permissions.OnBuyLand += CanBuyLand; //NOT YET IMPLEMENTED
  208. m_scene.Permissions.OnViewNotecard += CanViewNotecard; //NOT YET IMPLEMENTED
  209. m_scene.Permissions.OnViewScript += CanViewScript; //NOT YET IMPLEMENTED
  210. m_scene.Permissions.OnEditNotecard += CanEditNotecard; //NOT YET IMPLEMENTED
  211. m_scene.Permissions.OnEditScript += CanEditScript; //NOT YET IMPLEMENTED
  212. m_scene.Permissions.OnCreateObjectInventory += CanCreateObjectInventory; //NOT IMPLEMENTED HERE
  213. m_scene.Permissions.OnEditObjectInventory += CanEditObjectInventory;//MAYBE FULLY IMPLEMENTED
  214. m_scene.Permissions.OnCopyObjectInventory += CanCopyObjectInventory; //NOT YET IMPLEMENTED
  215. m_scene.Permissions.OnDeleteObjectInventory += CanDeleteObjectInventory; //NOT YET IMPLEMENTED
  216. m_scene.Permissions.OnResetScript += CanResetScript;
  217. m_scene.Permissions.OnCreateUserInventory += CanCreateUserInventory; //NOT YET IMPLEMENTED
  218. m_scene.Permissions.OnCopyUserInventory += CanCopyUserInventory; //NOT YET IMPLEMENTED
  219. m_scene.Permissions.OnEditUserInventory += CanEditUserInventory; //NOT YET IMPLEMENTED
  220. m_scene.Permissions.OnDeleteUserInventory += CanDeleteUserInventory; //NOT YET IMPLEMENTED
  221. m_scene.Permissions.OnTeleport += CanTeleport; //NOT YET IMPLEMENTED
  222. m_scene.Permissions.OnControlPrimMedia += CanControlPrimMedia;
  223. m_scene.Permissions.OnInteractWithPrimMedia += CanInteractWithPrimMedia;
  224. m_scene.AddCommand(this, "bypass permissions",
  225. "bypass permissions <true / false>",
  226. "Bypass permission checks",
  227. HandleBypassPermissions);
  228. m_scene.AddCommand(this, "force permissions",
  229. "force permissions <true / false>",
  230. "Force permissions on or off",
  231. HandleForcePermissions);
  232. m_scene.AddCommand(this, "debug permissions",
  233. "debug permissions <true / false>",
  234. "Enable permissions debugging",
  235. HandleDebugPermissions);
  236. string grant = myConfig.GetString("GrantLSL","");
  237. if (grant.Length > 0) {
  238. foreach (string uuidl in grant.Split(',')) {
  239. string uuid = uuidl.Trim(" \t".ToCharArray());
  240. GrantLSL.Add(uuid, true);
  241. }
  242. }
  243. grant = myConfig.GetString("GrantCS","");
  244. if (grant.Length > 0) {
  245. foreach (string uuidl in grant.Split(',')) {
  246. string uuid = uuidl.Trim(" \t".ToCharArray());
  247. GrantCS.Add(uuid, true);
  248. }
  249. }
  250. grant = myConfig.GetString("GrantVB","");
  251. if (grant.Length > 0) {
  252. foreach (string uuidl in grant.Split(',')) {
  253. string uuid = uuidl.Trim(" \t".ToCharArray());
  254. GrantVB.Add(uuid, true);
  255. }
  256. }
  257. grant = myConfig.GetString("GrantJS", "");
  258. if (grant.Length > 0)
  259. {
  260. foreach (string uuidl in grant.Split(','))
  261. {
  262. string uuid = uuidl.Trim(" \t".ToCharArray());
  263. GrantJS.Add(uuid, true);
  264. }
  265. }
  266. grant = myConfig.GetString("GrantYP", "");
  267. if (grant.Length > 0)
  268. {
  269. foreach (string uuidl in grant.Split(','))
  270. {
  271. string uuid = uuidl.Trim(" \t".ToCharArray());
  272. GrantYP.Add(uuid, true);
  273. }
  274. }
  275. }
  276. public void HandleBypassPermissions(string module, string[] args)
  277. {
  278. if (m_scene.ConsoleScene() != null &&
  279. m_scene.ConsoleScene() != m_scene)
  280. {
  281. return;
  282. }
  283. if (args.Length > 2)
  284. {
  285. bool val;
  286. if (!bool.TryParse(args[2], out val))
  287. return;
  288. m_bypassPermissions = val;
  289. m_log.InfoFormat(
  290. "[PERMISSIONS]: Set permissions bypass to {0} for {1}",
  291. m_bypassPermissions, m_scene.RegionInfo.RegionName);
  292. }
  293. }
  294. public void HandleForcePermissions(string module, string[] args)
  295. {
  296. if (m_scene.ConsoleScene() != null &&
  297. m_scene.ConsoleScene() != m_scene)
  298. {
  299. return;
  300. }
  301. if (!m_bypassPermissions)
  302. {
  303. m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first");
  304. return;
  305. }
  306. if (args.Length > 2)
  307. {
  308. bool val;
  309. if (!bool.TryParse(args[2], out val))
  310. return;
  311. m_bypassPermissionsValue = val;
  312. m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName);
  313. }
  314. }
  315. public void HandleDebugPermissions(string module, string[] args)
  316. {
  317. if (m_scene.ConsoleScene() != null &&
  318. m_scene.ConsoleScene() != m_scene)
  319. {
  320. return;
  321. }
  322. if (args.Length > 2)
  323. {
  324. bool val;
  325. if (!bool.TryParse(args[2], out val))
  326. return;
  327. m_debugPermissions = val;
  328. m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName);
  329. }
  330. }
  331. public void PostInitialise()
  332. {
  333. m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
  334. if (m_friendsModule == null)
  335. m_log.Warn("[PERMISSIONS]: Friends module not found, friend permissions will not work");
  336. m_groupsModule = m_scene.RequestModuleInterface<IGroupsModule>();
  337. if (m_groupsModule == null)
  338. m_log.Warn("[PERMISSIONS]: Groups module not found, group permissions will not work");
  339. m_moapModule = m_scene.RequestModuleInterface<IMoapModule>();
  340. // This log line will be commented out when no longer required for debugging
  341. // if (m_moapModule == null)
  342. // m_log.Warn("[PERMISSIONS]: Media on a prim module not found, media on a prim permissions will not work");
  343. }
  344. public void Close()
  345. {
  346. }
  347. public string Name
  348. {
  349. get { return "PermissionsModule"; }
  350. }
  351. public bool IsSharedModule
  352. {
  353. get { return false; }
  354. }
  355. #endregion
  356. #region Helper Functions
  357. protected void SendPermissionError(UUID user, string reason)
  358. {
  359. m_scene.EventManager.TriggerPermissionError(user, reason);
  360. }
  361. protected void DebugPermissionInformation(string permissionCalled)
  362. {
  363. if (m_debugPermissions)
  364. m_log.Debug("[PERMISSIONS]: " + permissionCalled + " was called from " + m_scene.RegionInfo.RegionName);
  365. }
  366. // Checks if the given group is active and if the user is a group member
  367. // with the powers requested (powers = 0 for no powers check)
  368. protected bool IsGroupMember(UUID groupID, UUID userID, ulong powers)
  369. {
  370. if (null == m_groupsModule)
  371. return false;
  372. GroupMembershipData gmd = m_groupsModule.GetMembershipData(groupID, userID);
  373. if (gmd != null)
  374. {
  375. if (((gmd.GroupPowers != 0) && powers == 0) || (gmd.GroupPowers & powers) == powers)
  376. return true;
  377. }
  378. return false;
  379. }
  380. /// <summary>
  381. /// Parse a user set configuration setting
  382. /// </summary>
  383. /// <param name="config"></param>
  384. /// <param name="settingName"></param>
  385. /// <param name="defaultValue">The default value for this attribute</param>
  386. /// <returns>The parsed value</returns>
  387. private static UserSet ParseUserSetConfigSetting(IConfig config, string settingName, UserSet defaultValue)
  388. {
  389. UserSet userSet = defaultValue;
  390. string rawSetting = config.GetString(settingName, defaultValue.ToString());
  391. // Temporary measure to allow 'gods' to be specified in config for consistency's sake. In the long term
  392. // this should disappear.
  393. if ("gods" == rawSetting.ToLower())
  394. rawSetting = UserSet.Administrators.ToString();
  395. // Doing it this was so that we can do a case insensitive conversion
  396. try
  397. {
  398. userSet = (UserSet)Enum.Parse(typeof(UserSet), rawSetting, true);
  399. }
  400. catch
  401. {
  402. m_log.ErrorFormat(
  403. "[PERMISSIONS]: {0} is not a valid {1} value, setting to {2}",
  404. rawSetting, settingName, userSet);
  405. }
  406. m_log.DebugFormat("[PERMISSIONS]: {0} {1}", settingName, userSet);
  407. return userSet;
  408. }
  409. /// <summary>
  410. /// Is the given user an administrator (in other words, a god)?
  411. /// </summary>
  412. /// <param name="user"></param>
  413. /// <returns></returns>
  414. protected bool IsAdministrator(UUID user)
  415. {
  416. if (user == UUID.Zero) return false;
  417. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  418. {
  419. if (m_scene.RegionInfo.EstateSettings.EstateOwner == user && m_RegionOwnerIsGod)
  420. return true;
  421. }
  422. if (IsEstateManager(user) && m_RegionManagerIsGod)
  423. return true;
  424. if (m_allowGridGods)
  425. {
  426. ScenePresence sp = m_scene.GetScenePresence(user);
  427. if (sp != null)
  428. {
  429. if (sp.UserLevel >= 200)
  430. return true;
  431. return false;
  432. }
  433. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, user);
  434. if (account != null)
  435. {
  436. if (account.UserLevel >= 200)
  437. return true;
  438. }
  439. }
  440. return false;
  441. }
  442. protected bool IsFriendWithPerms(UUID user,UUID objectOwner)
  443. {
  444. if (user == UUID.Zero)
  445. return false;
  446. if (m_friendsModule == null)
  447. return false;
  448. uint friendPerms = m_friendsModule.GetFriendPerms(user, objectOwner);
  449. if ((friendPerms & (uint)FriendRights.CanModifyObjects) != 0)
  450. return true;
  451. return false;
  452. }
  453. protected bool IsEstateManager(UUID user)
  454. {
  455. if (user == UUID.Zero) return false;
  456. return m_scene.RegionInfo.EstateSettings.IsEstateManager(user);
  457. }
  458. #endregion
  459. public bool PropagatePermissions()
  460. {
  461. if (m_bypassPermissions)
  462. return false;
  463. return m_propagatePermissions;
  464. }
  465. public bool BypassPermissions()
  466. {
  467. return m_bypassPermissions;
  468. }
  469. public void SetBypassPermissions(bool value)
  470. {
  471. m_bypassPermissions=value;
  472. }
  473. #region Object Permissions
  474. public uint GenerateClientFlags(UUID user, UUID objID)
  475. {
  476. // Here's the way this works,
  477. // ObjectFlags and Permission flags are two different enumerations
  478. // ObjectFlags, however, tells the client to change what it will allow the user to do.
  479. // So, that means that all of the permissions type ObjectFlags are /temporary/ and only
  480. // supposed to be set when customizing the objectflags for the client.
  481. // These temporary objectflags get computed and added in this function based on the
  482. // Permission mask that's appropriate!
  483. // Outside of this method, they should never be added to objectflags!
  484. // -teravus
  485. SceneObjectPart task = m_scene.GetSceneObjectPart(objID);
  486. // this shouldn't ever happen.. return no permissions/objectflags.
  487. if (task == null)
  488. return (uint)0;
  489. uint objflags = task.GetEffectiveObjectFlags();
  490. UUID objectOwner = task.OwnerID;
  491. // Remove any of the objectFlags that are temporary. These will get added back if appropriate
  492. // in the next bit of code
  493. // libomv will moan about PrimFlags.ObjectYouOfficer being
  494. // deprecated
  495. #pragma warning disable 0612
  496. objflags &= (uint)
  497. ~(PrimFlags.ObjectCopy | // Tells client you can copy the object
  498. PrimFlags.ObjectModify | // tells client you can modify the object
  499. PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
  500. PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
  501. PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
  502. PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
  503. PrimFlags.ObjectOwnerModify | // Tells client that you're the owner of the object
  504. PrimFlags.ObjectYouOfficer // Tells client that you've got group object editing permission. Used when ObjectGroupOwned is set
  505. );
  506. #pragma warning restore 0612
  507. // Creating the three ObjectFlags options for this method to choose from.
  508. // Customize the OwnerMask
  509. uint objectOwnerMask = ApplyObjectModifyMasks(task.OwnerMask, objflags);
  510. objectOwnerMask |= (uint)PrimFlags.ObjectYouOwner | (uint)PrimFlags.ObjectAnyOwner | (uint)PrimFlags.ObjectOwnerModify;
  511. // Customize the GroupMask
  512. uint objectGroupMask = ApplyObjectModifyMasks(task.GroupMask, objflags);
  513. // Customize the EveryoneMask
  514. uint objectEveryoneMask = ApplyObjectModifyMasks(task.EveryoneMask, objflags);
  515. if (objectOwner != UUID.Zero)
  516. objectEveryoneMask |= (uint)PrimFlags.ObjectAnyOwner;
  517. if (m_bypassPermissions)
  518. return objectOwnerMask;
  519. // Object owners should be able to edit their own content
  520. if (user == objectOwner)
  521. return objectOwnerMask;
  522. if (IsFriendWithPerms(user, objectOwner))
  523. return objectOwnerMask;
  524. // Estate users should be able to edit anything in the sim if RegionOwnerIsGod is set
  525. if (m_RegionOwnerIsGod && IsEstateManager(user) && !IsAdministrator(objectOwner))
  526. return objectOwnerMask;
  527. // Admin should be able to edit anything in the sim (including admin objects)
  528. if (IsAdministrator(user))
  529. return objectOwnerMask;
  530. // Users should be able to edit what is over their land.
  531. Vector3 taskPos = task.AbsolutePosition;
  532. ILandObject parcel = m_scene.LandChannel.GetLandObject(taskPos.X, taskPos.Y);
  533. if (parcel != null && parcel.LandData.OwnerID == user && m_ParcelOwnerIsGod)
  534. {
  535. // Admin objects should not be editable by the above
  536. if (!IsAdministrator(objectOwner))
  537. return objectOwnerMask;
  538. }
  539. // Group permissions
  540. if ((task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0))
  541. return objectGroupMask | objectEveryoneMask;
  542. return objectEveryoneMask;
  543. }
  544. private uint ApplyObjectModifyMasks(uint setPermissionMask, uint objectFlagsMask)
  545. {
  546. // We are adding the temporary objectflags to the object's objectflags based on the
  547. // permission flag given. These change the F flags on the client.
  548. if ((setPermissionMask & (uint)PermissionMask.Copy) != 0)
  549. {
  550. objectFlagsMask |= (uint)PrimFlags.ObjectCopy;
  551. }
  552. if ((setPermissionMask & (uint)PermissionMask.Move) != 0)
  553. {
  554. objectFlagsMask |= (uint)PrimFlags.ObjectMove;
  555. }
  556. if ((setPermissionMask & (uint)PermissionMask.Modify) != 0)
  557. {
  558. objectFlagsMask |= (uint)PrimFlags.ObjectModify;
  559. }
  560. if ((setPermissionMask & (uint)PermissionMask.Transfer) != 0)
  561. {
  562. objectFlagsMask |= (uint)PrimFlags.ObjectTransfer;
  563. }
  564. return objectFlagsMask;
  565. }
  566. /// <summary>
  567. /// General permissions checks for any operation involving an object. These supplement more specific checks
  568. /// implemented by callers.
  569. /// </summary>
  570. /// <param name="currentUser"></param>
  571. /// <param name="objId"></param>
  572. /// <param name="denyOnLocked"></param>
  573. /// <returns></returns>
  574. protected bool GenericObjectPermission(UUID currentUser, UUID objId, bool denyOnLocked)
  575. {
  576. // Default: deny
  577. bool permission = false;
  578. bool locked = false;
  579. if (!m_scene.Entities.ContainsKey(objId))
  580. {
  581. return false;
  582. }
  583. // If it's not an object, we cant edit it.
  584. if ((!(m_scene.Entities[objId] is SceneObjectGroup)))
  585. {
  586. return false;
  587. }
  588. SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objId];
  589. UUID objectOwner = group.OwnerID;
  590. locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
  591. // People shouldn't be able to do anything with locked objects, except the Administrator
  592. // The 'set permissions' runs through a different permission check, so when an object owner
  593. // sets an object locked, the only thing that they can do is unlock it.
  594. //
  595. // Nobody but the object owner can set permissions on an object
  596. //
  597. if (locked && (!IsAdministrator(currentUser)) && denyOnLocked)
  598. {
  599. return false;
  600. }
  601. // Object owners should be able to edit their own content
  602. if (currentUser == objectOwner)
  603. {
  604. permission = true;
  605. }
  606. else if (group.IsAttachment)
  607. {
  608. permission = false;
  609. }
  610. // m_log.DebugFormat(
  611. // "[PERMISSIONS]: group.GroupID = {0}, part.GroupMask = {1}, isGroupMember = {2} for {3}",
  612. // group.GroupID,
  613. // m_scene.GetSceneObjectPart(objId).GroupMask,
  614. // IsGroupMember(group.GroupID, currentUser, 0),
  615. // currentUser);
  616. // Group members should be able to edit group objects
  617. if ((group.GroupID != UUID.Zero)
  618. && ((m_scene.GetSceneObjectPart(objId).GroupMask & (uint)PermissionMask.Modify) != 0)
  619. && IsGroupMember(group.GroupID, currentUser, 0))
  620. {
  621. // Return immediately, so that the administrator can shares group objects
  622. return true;
  623. }
  624. // Users should be able to edit what is over their land.
  625. ILandObject parcel = m_scene.LandChannel.GetLandObject(group.AbsolutePosition.X, group.AbsolutePosition.Y);
  626. if ((parcel != null) && (parcel.LandData.OwnerID == currentUser))
  627. {
  628. permission = true;
  629. }
  630. // Estate users should be able to edit anything in the sim
  631. if (IsEstateManager(currentUser))
  632. {
  633. permission = true;
  634. }
  635. // Admin objects should not be editable by the above
  636. if (IsAdministrator(objectOwner))
  637. {
  638. permission = false;
  639. }
  640. // Admin should be able to edit anything in the sim (including admin objects)
  641. if (IsAdministrator(currentUser))
  642. {
  643. permission = true;
  644. }
  645. return permission;
  646. }
  647. #endregion
  648. #region Generic Permissions
  649. protected bool GenericCommunicationPermission(UUID user, UUID target)
  650. {
  651. // Setting this to true so that cool stuff can happen until we define what determines Generic Communication Permission
  652. bool permission = true;
  653. string reason = "Only registered users may communicate with another account.";
  654. // Uhh, we need to finish this before we enable it.. because it's blocking all sorts of goodies and features
  655. if (IsAdministrator(user))
  656. permission = true;
  657. if (IsEstateManager(user))
  658. permission = true;
  659. if (!permission)
  660. SendPermissionError(user, reason);
  661. return permission;
  662. }
  663. public bool GenericEstatePermission(UUID user)
  664. {
  665. // Default: deny
  666. bool permission = false;
  667. // Estate admins should be able to use estate tools
  668. if (IsEstateManager(user))
  669. permission = true;
  670. // Administrators always have permission
  671. if (IsAdministrator(user))
  672. permission = true;
  673. return permission;
  674. }
  675. protected bool GenericParcelPermission(UUID user, ILandObject parcel, ulong groupPowers)
  676. {
  677. bool permission = false;
  678. if (parcel.LandData.OwnerID == user)
  679. {
  680. permission = true;
  681. }
  682. if ((parcel.LandData.GroupID != UUID.Zero) && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
  683. {
  684. permission = true;
  685. }
  686. if (IsEstateManager(user))
  687. {
  688. permission = true;
  689. }
  690. if (IsAdministrator(user))
  691. {
  692. permission = true;
  693. }
  694. return permission;
  695. }
  696. protected bool GenericParcelOwnerPermission(UUID user, ILandObject parcel, ulong groupPowers)
  697. {
  698. if (parcel.LandData.OwnerID == user)
  699. {
  700. // Returning immediately so that group deeded objects on group deeded land don't trigger a NRE on
  701. // the subsequent redundant checks when using lParcelMediaCommandList()
  702. // See http://opensimulator.org/mantis/view.php?id=3999 for more details
  703. return true;
  704. }
  705. if (parcel.LandData.IsGroupOwned && IsGroupMember(parcel.LandData.GroupID, user, groupPowers))
  706. {
  707. return true;
  708. }
  709. if (IsEstateManager(user))
  710. {
  711. return true;
  712. }
  713. if (IsAdministrator(user))
  714. {
  715. return true;
  716. }
  717. return false;
  718. }
  719. protected bool GenericParcelPermission(UUID user, Vector3 pos, ulong groupPowers)
  720. {
  721. ILandObject parcel = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
  722. if (parcel == null) return false;
  723. return GenericParcelPermission(user, parcel, groupPowers);
  724. }
  725. #endregion
  726. #region Permission Checks
  727. private bool CanAbandonParcel(UUID user, ILandObject parcel, Scene scene)
  728. {
  729. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  730. if (m_bypassPermissions) return m_bypassPermissionsValue;
  731. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandRelease);
  732. }
  733. private bool CanReclaimParcel(UUID user, ILandObject parcel, Scene scene)
  734. {
  735. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  736. if (m_bypassPermissions) return m_bypassPermissionsValue;
  737. return GenericParcelOwnerPermission(user, parcel, 0);
  738. }
  739. private bool CanDeedParcel(UUID user, ILandObject parcel, Scene scene)
  740. {
  741. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  742. if (m_bypassPermissions) return m_bypassPermissionsValue;
  743. if (parcel.LandData.OwnerID != user) // Only the owner can deed!
  744. return false;
  745. ScenePresence sp = scene.GetScenePresence(user);
  746. IClientAPI client = sp.ControllingClient;
  747. if ((client.GetGroupPowers(parcel.LandData.GroupID) & (ulong)GroupPowers.LandDeed) == 0)
  748. return false;
  749. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandDeed);
  750. }
  751. private bool CanDeedObject(UUID user, UUID group, Scene scene)
  752. {
  753. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  754. if (m_bypassPermissions) return m_bypassPermissionsValue;
  755. ScenePresence sp = scene.GetScenePresence(user);
  756. IClientAPI client = sp.ControllingClient;
  757. if ((client.GetGroupPowers(group) & (ulong)GroupPowers.DeedObject) == 0)
  758. return false;
  759. return true;
  760. }
  761. private bool IsGod(UUID user, Scene scene)
  762. {
  763. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  764. if (m_bypassPermissions) return m_bypassPermissionsValue;
  765. return IsAdministrator(user);
  766. }
  767. private bool CanDuplicateObject(int objectCount, UUID objectID, UUID owner, Scene scene, Vector3 objectPosition)
  768. {
  769. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  770. if (m_bypassPermissions) return m_bypassPermissionsValue;
  771. if (!GenericObjectPermission(owner, objectID, true))
  772. {
  773. //They can't even edit the object
  774. return false;
  775. }
  776. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  777. if (part == null)
  778. return false;
  779. if (part.OwnerID == owner)
  780. return ((part.OwnerMask & PERM_COPY) != 0);
  781. if (part.GroupID != UUID.Zero)
  782. {
  783. if ((part.OwnerID == part.GroupID) && ((owner != part.LastOwnerID) || ((part.GroupMask & PERM_TRANS) == 0)))
  784. return false;
  785. if ((part.GroupMask & PERM_COPY) == 0)
  786. return false;
  787. }
  788. //If they can rez, they can duplicate
  789. return CanRezObject(objectCount, owner, objectPosition, scene);
  790. }
  791. private bool CanDeleteObject(UUID objectID, UUID deleter, Scene scene)
  792. {
  793. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  794. if (m_bypassPermissions) return m_bypassPermissionsValue;
  795. return GenericObjectPermission(deleter, objectID, false);
  796. }
  797. private bool CanEditObject(UUID objectID, UUID editorID, Scene scene)
  798. {
  799. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  800. if (m_bypassPermissions) return m_bypassPermissionsValue;
  801. return GenericObjectPermission(editorID, objectID, false);
  802. }
  803. private bool CanEditObjectInventory(UUID objectID, UUID editorID, Scene scene)
  804. {
  805. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  806. if (m_bypassPermissions) return m_bypassPermissionsValue;
  807. SceneObjectPart part = m_scene.GetSceneObjectPart(objectID);
  808. // If we selected a sub-prim to edit, the objectID won't represent the object, but only a part.
  809. // We have to check the permissions of the group, though.
  810. if (part.ParentID != 0)
  811. {
  812. objectID = part.ParentUUID;
  813. part = m_scene.GetSceneObjectPart(objectID);
  814. }
  815. return GenericObjectPermission(editorID, objectID, false);
  816. }
  817. private bool CanEditParcel(UUID user, ILandObject parcel, Scene scene)
  818. {
  819. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  820. if (m_bypassPermissions) return m_bypassPermissionsValue;
  821. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandDivideJoin);
  822. }
  823. /// <summary>
  824. /// Check whether the specified user can edit the given script
  825. /// </summary>
  826. /// <param name="script"></param>
  827. /// <param name="objectID"></param>
  828. /// <param name="user"></param>
  829. /// <param name="scene"></param>
  830. /// <returns></returns>
  831. private bool CanEditScript(UUID script, UUID objectID, UUID user, Scene scene)
  832. {
  833. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  834. if (m_bypassPermissions) return m_bypassPermissionsValue;
  835. if (m_allowedScriptEditors == UserSet.Administrators && !IsAdministrator(user))
  836. return false;
  837. // Ordinarily, if you can view it, you can edit it
  838. // There is no viewing a no mod script
  839. //
  840. return CanViewScript(script, objectID, user, scene);
  841. }
  842. /// <summary>
  843. /// Check whether the specified user can edit the given notecard
  844. /// </summary>
  845. /// <param name="notecard"></param>
  846. /// <param name="objectID"></param>
  847. /// <param name="user"></param>
  848. /// <param name="scene"></param>
  849. /// <returns></returns>
  850. private bool CanEditNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  851. {
  852. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  853. if (m_bypassPermissions) return m_bypassPermissionsValue;
  854. if (objectID == UUID.Zero) // User inventory
  855. {
  856. IInventoryService invService = m_scene.InventoryService;
  857. InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
  858. assetRequestItem = invService.GetItem(assetRequestItem);
  859. if (assetRequestItem == null && LibraryRootFolder != null) // Library item
  860. {
  861. assetRequestItem = LibraryRootFolder.FindItem(notecard);
  862. if (assetRequestItem != null) // Implicitly readable
  863. return true;
  864. }
  865. // Notecards must be both mod and copy to be saveable
  866. // This is because of they're not copy, you can't read
  867. // them, and if they're not mod, well, then they're
  868. // not mod. Duh.
  869. //
  870. if ((assetRequestItem.CurrentPermissions &
  871. ((uint)PermissionMask.Modify |
  872. (uint)PermissionMask.Copy)) !=
  873. ((uint)PermissionMask.Modify |
  874. (uint)PermissionMask.Copy))
  875. return false;
  876. }
  877. else // Prim inventory
  878. {
  879. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  880. if (part == null)
  881. return false;
  882. if (part.OwnerID != user)
  883. {
  884. if (part.GroupID == UUID.Zero)
  885. return false;
  886. if (!IsGroupMember(part.GroupID, user, 0))
  887. return false;
  888. if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
  889. return false;
  890. }
  891. else
  892. {
  893. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  894. return false;
  895. }
  896. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  897. if (ti == null)
  898. return false;
  899. if (ti.OwnerID != user)
  900. {
  901. if (ti.GroupID == UUID.Zero)
  902. return false;
  903. if (!IsGroupMember(ti.GroupID, user, 0))
  904. return false;
  905. }
  906. // Require full perms
  907. if ((ti.CurrentPermissions &
  908. ((uint)PermissionMask.Modify |
  909. (uint)PermissionMask.Copy)) !=
  910. ((uint)PermissionMask.Modify |
  911. (uint)PermissionMask.Copy))
  912. return false;
  913. }
  914. return true;
  915. }
  916. private bool CanInstantMessage(UUID user, UUID target, Scene startScene)
  917. {
  918. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  919. if (m_bypassPermissions) return m_bypassPermissionsValue;
  920. // If the sender is an object, check owner instead
  921. //
  922. SceneObjectPart part = startScene.GetSceneObjectPart(user);
  923. if (part != null)
  924. user = part.OwnerID;
  925. return GenericCommunicationPermission(user, target);
  926. }
  927. private bool CanInventoryTransfer(UUID user, UUID target, Scene startScene)
  928. {
  929. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  930. if (m_bypassPermissions) return m_bypassPermissionsValue;
  931. return GenericCommunicationPermission(user, target);
  932. }
  933. private bool CanIssueEstateCommand(UUID user, Scene requestFromScene, bool ownerCommand)
  934. {
  935. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  936. if (m_bypassPermissions) return m_bypassPermissionsValue;
  937. if (IsAdministrator(user))
  938. return true;
  939. if (m_scene.RegionInfo.EstateSettings.IsEstateOwner(user))
  940. return true;
  941. if (ownerCommand)
  942. return false;
  943. return GenericEstatePermission(user);
  944. }
  945. private bool CanMoveObject(UUID objectID, UUID moverID, Scene scene)
  946. {
  947. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  948. if (m_bypassPermissions)
  949. {
  950. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  951. if (part.OwnerID != moverID)
  952. {
  953. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  954. {
  955. if (part.ParentGroup.IsAttachment)
  956. return false;
  957. }
  958. }
  959. return m_bypassPermissionsValue;
  960. }
  961. bool permission = GenericObjectPermission(moverID, objectID, true);
  962. if (!permission)
  963. {
  964. if (!m_scene.Entities.ContainsKey(objectID))
  965. {
  966. return false;
  967. }
  968. // The client
  969. // may request to edit linked parts, and therefore, it needs
  970. // to also check for SceneObjectPart
  971. // If it's not an object, we cant edit it.
  972. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  973. {
  974. return false;
  975. }
  976. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  977. // UUID taskOwner = null;
  978. // Added this because at this point in time it wouldn't be wise for
  979. // the administrator object permissions to take effect.
  980. // UUID objectOwner = task.OwnerID;
  981. // Anyone can move
  982. if ((task.RootPart.EveryoneMask & PERM_MOVE) != 0)
  983. permission = true;
  984. // Locked
  985. if ((task.RootPart.OwnerMask & PERM_LOCKED) == 0)
  986. permission = false;
  987. }
  988. else
  989. {
  990. bool locked = false;
  991. if (!m_scene.Entities.ContainsKey(objectID))
  992. {
  993. return false;
  994. }
  995. // If it's not an object, we cant edit it.
  996. if ((!(m_scene.Entities[objectID] is SceneObjectGroup)))
  997. {
  998. return false;
  999. }
  1000. SceneObjectGroup group = (SceneObjectGroup)m_scene.Entities[objectID];
  1001. UUID objectOwner = group.OwnerID;
  1002. locked = ((group.RootPart.OwnerMask & PERM_LOCKED) == 0);
  1003. // This is an exception to the generic object permission.
  1004. // Administrators who lock their objects should not be able to move them,
  1005. // however generic object permission should return true.
  1006. // This keeps locked objects from being affected by random click + drag actions by accident
  1007. // and allows the administrator to grab or delete a locked object.
  1008. // Administrators and estate managers are still able to click+grab locked objects not
  1009. // owned by them in the scene
  1010. // This is by design.
  1011. if (locked && (moverID == objectOwner))
  1012. return false;
  1013. }
  1014. return permission;
  1015. }
  1016. private bool CanObjectEntry(UUID objectID, bool enteringRegion, Vector3 newPoint, Scene scene)
  1017. {
  1018. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1019. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1020. if ((newPoint.X > 257f || newPoint.X < -1f || newPoint.Y > 257f || newPoint.Y < -1f))
  1021. {
  1022. return true;
  1023. }
  1024. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  1025. ILandObject land = m_scene.LandChannel.GetLandObject(newPoint.X, newPoint.Y);
  1026. if (!enteringRegion)
  1027. {
  1028. ILandObject fromland = m_scene.LandChannel.GetLandObject(task.AbsolutePosition.X, task.AbsolutePosition.Y);
  1029. if (fromland == land) // Not entering
  1030. return true;
  1031. }
  1032. if (land == null)
  1033. {
  1034. return false;
  1035. }
  1036. if ((land.LandData.Flags & ((int)ParcelFlags.AllowAPrimitiveEntry)) != 0)
  1037. {
  1038. return true;
  1039. }
  1040. if (!m_scene.Entities.ContainsKey(objectID))
  1041. {
  1042. return false;
  1043. }
  1044. // If it's not an object, we cant edit it.
  1045. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  1046. {
  1047. return false;
  1048. }
  1049. if (GenericParcelPermission(task.OwnerID, newPoint, 0))
  1050. {
  1051. return true;
  1052. }
  1053. //Otherwise, false!
  1054. return false;
  1055. }
  1056. private bool CanReturnObjects(ILandObject land, UUID user, List<SceneObjectGroup> objects, Scene scene)
  1057. {
  1058. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1059. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1060. GroupPowers powers;
  1061. ILandObject l;
  1062. ScenePresence sp = scene.GetScenePresence(user);
  1063. if (sp == null)
  1064. return false;
  1065. IClientAPI client = sp.ControllingClient;
  1066. foreach (SceneObjectGroup g in new List<SceneObjectGroup>(objects))
  1067. {
  1068. // Any user can return their own objects at any time
  1069. //
  1070. if (GenericObjectPermission(user, g.UUID, false))
  1071. continue;
  1072. // This is a short cut for efficiency. If land is non-null,
  1073. // then all objects are on that parcel and we can save
  1074. // ourselves the checking for each prim. Much faster.
  1075. //
  1076. if (land != null)
  1077. {
  1078. l = land;
  1079. }
  1080. else
  1081. {
  1082. Vector3 pos = g.AbsolutePosition;
  1083. l = scene.LandChannel.GetLandObject(pos.X, pos.Y);
  1084. }
  1085. // If it's not over any land, then we can't do a thing
  1086. if (l == null)
  1087. {
  1088. objects.Remove(g);
  1089. continue;
  1090. }
  1091. // If we own the land outright, then allow
  1092. //
  1093. if (l.LandData.OwnerID == user)
  1094. continue;
  1095. // Group voodoo
  1096. //
  1097. if (l.LandData.IsGroupOwned)
  1098. {
  1099. powers = (GroupPowers)client.GetGroupPowers(l.LandData.GroupID);
  1100. // Not a group member, or no rights at all
  1101. //
  1102. if (powers == (GroupPowers)0)
  1103. {
  1104. objects.Remove(g);
  1105. continue;
  1106. }
  1107. // Group deeded object?
  1108. //
  1109. if (g.OwnerID == l.LandData.GroupID &&
  1110. (powers & GroupPowers.ReturnGroupOwned) == (GroupPowers)0)
  1111. {
  1112. objects.Remove(g);
  1113. continue;
  1114. }
  1115. // Group set object?
  1116. //
  1117. if (g.GroupID == l.LandData.GroupID &&
  1118. (powers & GroupPowers.ReturnGroupSet) == (GroupPowers)0)
  1119. {
  1120. objects.Remove(g);
  1121. continue;
  1122. }
  1123. if ((powers & GroupPowers.ReturnNonGroup) == (GroupPowers)0)
  1124. {
  1125. objects.Remove(g);
  1126. continue;
  1127. }
  1128. // So we can remove all objects from this group land.
  1129. // Fine.
  1130. //
  1131. continue;
  1132. }
  1133. // By default, we can't remove
  1134. //
  1135. objects.Remove(g);
  1136. }
  1137. if (objects.Count == 0)
  1138. return false;
  1139. return true;
  1140. }
  1141. private bool CanRezObject(int objectCount, UUID owner, Vector3 objectPosition, Scene scene)
  1142. {
  1143. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1144. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1145. bool permission = false;
  1146. ILandObject land = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y);
  1147. if (land == null) return false;
  1148. if ((land.LandData.Flags & ((int)ParcelFlags.CreateObjects)) ==
  1149. (int)ParcelFlags.CreateObjects)
  1150. permission = true;
  1151. if (IsAdministrator(owner))
  1152. {
  1153. permission = true;
  1154. }
  1155. // Powers are zero, because GroupPowers.AllowRez is not a precondition for rezzing objects
  1156. if (GenericParcelPermission(owner, objectPosition, 0))
  1157. {
  1158. permission = true;
  1159. }
  1160. return permission;
  1161. }
  1162. private bool CanRunConsoleCommand(UUID user, Scene requestFromScene)
  1163. {
  1164. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1165. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1166. return IsAdministrator(user);
  1167. }
  1168. private bool CanRunScript(UUID script, UUID objectID, UUID user, Scene scene)
  1169. {
  1170. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1171. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1172. return true;
  1173. }
  1174. private bool CanSellParcel(UUID user, ILandObject parcel, Scene scene)
  1175. {
  1176. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1177. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1178. return GenericParcelOwnerPermission(user, parcel, (ulong)GroupPowers.LandSetSale);
  1179. }
  1180. private bool CanTakeObject(UUID objectID, UUID stealer, Scene scene)
  1181. {
  1182. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1183. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1184. return GenericObjectPermission(stealer,objectID, false);
  1185. }
  1186. private bool CanTakeCopyObject(UUID objectID, UUID userID, Scene inScene)
  1187. {
  1188. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1189. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1190. bool permission = GenericObjectPermission(userID, objectID, false);
  1191. if (!permission)
  1192. {
  1193. if (!m_scene.Entities.ContainsKey(objectID))
  1194. {
  1195. return false;
  1196. }
  1197. // If it's not an object, we cant edit it.
  1198. if (!(m_scene.Entities[objectID] is SceneObjectGroup))
  1199. {
  1200. return false;
  1201. }
  1202. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  1203. // UUID taskOwner = null;
  1204. // Added this because at this point in time it wouldn't be wise for
  1205. // the administrator object permissions to take effect.
  1206. // UUID objectOwner = task.OwnerID;
  1207. if ((task.RootPart.EveryoneMask & PERM_COPY) != 0)
  1208. permission = true;
  1209. if (task.OwnerID != userID)
  1210. {
  1211. if ((task.GetEffectivePermissions() & (PERM_COPY | PERM_TRANS)) != (PERM_COPY | PERM_TRANS))
  1212. permission = false;
  1213. }
  1214. else
  1215. {
  1216. if ((task.GetEffectivePermissions() & PERM_COPY) != PERM_COPY)
  1217. permission = false;
  1218. }
  1219. }
  1220. else
  1221. {
  1222. SceneObjectGroup task = (SceneObjectGroup)m_scene.Entities[objectID];
  1223. if ((task.GetEffectivePermissions() & (PERM_COPY | PERM_TRANS)) != (PERM_COPY | PERM_TRANS))
  1224. permission = false;
  1225. }
  1226. return permission;
  1227. }
  1228. private bool CanTerraformLand(UUID user, Vector3 position, Scene requestFromScene)
  1229. {
  1230. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1231. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1232. // Estate override
  1233. if (GenericEstatePermission(user))
  1234. return true;
  1235. float X = position.X;
  1236. float Y = position.Y;
  1237. if (X > ((int)Constants.RegionSize - 1))
  1238. X = ((int)Constants.RegionSize - 1);
  1239. if (Y > ((int)Constants.RegionSize - 1))
  1240. Y = ((int)Constants.RegionSize - 1);
  1241. if (X < 0)
  1242. X = 0;
  1243. if (Y < 0)
  1244. Y = 0;
  1245. ILandObject parcel = m_scene.LandChannel.GetLandObject(X, Y);
  1246. if (parcel == null)
  1247. return false;
  1248. // Others allowed to terraform?
  1249. if ((parcel.LandData.Flags & ((int)ParcelFlags.AllowTerraform)) != 0)
  1250. return true;
  1251. // Land owner can terraform too
  1252. if (parcel != null && GenericParcelPermission(user, parcel, (ulong)GroupPowers.AllowEditLand))
  1253. return true;
  1254. return false;
  1255. }
  1256. /// <summary>
  1257. /// Check whether the specified user can view the given script
  1258. /// </summary>
  1259. /// <param name="script"></param>
  1260. /// <param name="objectID"></param>
  1261. /// <param name="user"></param>
  1262. /// <param name="scene"></param>
  1263. /// <returns></returns>
  1264. private bool CanViewScript(UUID script, UUID objectID, UUID user, Scene scene)
  1265. {
  1266. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1267. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1268. if (objectID == UUID.Zero) // User inventory
  1269. {
  1270. IInventoryService invService = m_scene.InventoryService;
  1271. InventoryItemBase assetRequestItem = new InventoryItemBase(script, user);
  1272. assetRequestItem = invService.GetItem(assetRequestItem);
  1273. if (assetRequestItem == null && LibraryRootFolder != null) // Library item
  1274. {
  1275. assetRequestItem = LibraryRootFolder.FindItem(script);
  1276. if (assetRequestItem != null) // Implicitly readable
  1277. return true;
  1278. }
  1279. // SL is rather harebrained here. In SL, a script you
  1280. // have mod/copy no trans is readable. This subverts
  1281. // permissions, but is used in some products, most
  1282. // notably Hippo door plugin and HippoRent 5 networked
  1283. // prim counter.
  1284. // To enable this broken SL-ism, remove Transfer from
  1285. // the below expressions.
  1286. // Trying to improve on SL perms by making a script
  1287. // readable only if it's really full perms
  1288. //
  1289. if ((assetRequestItem.CurrentPermissions &
  1290. ((uint)PermissionMask.Modify |
  1291. (uint)PermissionMask.Copy |
  1292. (uint)PermissionMask.Transfer)) !=
  1293. ((uint)PermissionMask.Modify |
  1294. (uint)PermissionMask.Copy |
  1295. (uint)PermissionMask.Transfer))
  1296. return false;
  1297. }
  1298. else // Prim inventory
  1299. {
  1300. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  1301. if (part == null)
  1302. return false;
  1303. if (part.OwnerID != user)
  1304. {
  1305. if (part.GroupID == UUID.Zero)
  1306. return false;
  1307. if (!IsGroupMember(part.GroupID, user, 0))
  1308. return false;
  1309. if ((part.GroupMask & (uint)PermissionMask.Modify) == 0)
  1310. return false;
  1311. }
  1312. else
  1313. {
  1314. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1315. return false;
  1316. }
  1317. TaskInventoryItem ti = part.Inventory.GetInventoryItem(script);
  1318. if (ti == null)
  1319. return false;
  1320. if (ti.OwnerID != user)
  1321. {
  1322. if (ti.GroupID == UUID.Zero)
  1323. return false;
  1324. if (!IsGroupMember(ti.GroupID, user, 0))
  1325. return false;
  1326. }
  1327. // Require full perms
  1328. if ((ti.CurrentPermissions &
  1329. ((uint)PermissionMask.Modify |
  1330. (uint)PermissionMask.Copy |
  1331. (uint)PermissionMask.Transfer)) !=
  1332. ((uint)PermissionMask.Modify |
  1333. (uint)PermissionMask.Copy |
  1334. (uint)PermissionMask.Transfer))
  1335. return false;
  1336. }
  1337. return true;
  1338. }
  1339. /// <summary>
  1340. /// Check whether the specified user can view the given notecard
  1341. /// </summary>
  1342. /// <param name="script"></param>
  1343. /// <param name="objectID"></param>
  1344. /// <param name="user"></param>
  1345. /// <param name="scene"></param>
  1346. /// <returns></returns>
  1347. private bool CanViewNotecard(UUID notecard, UUID objectID, UUID user, Scene scene)
  1348. {
  1349. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1350. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1351. if (objectID == UUID.Zero) // User inventory
  1352. {
  1353. IInventoryService invService = m_scene.InventoryService;
  1354. InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
  1355. assetRequestItem = invService.GetItem(assetRequestItem);
  1356. if (assetRequestItem == null && LibraryRootFolder != null) // Library item
  1357. {
  1358. assetRequestItem = LibraryRootFolder.FindItem(notecard);
  1359. if (assetRequestItem != null) // Implicitly readable
  1360. return true;
  1361. }
  1362. // Notecards are always readable unless no copy
  1363. //
  1364. if ((assetRequestItem.CurrentPermissions &
  1365. (uint)PermissionMask.Copy) !=
  1366. (uint)PermissionMask.Copy)
  1367. return false;
  1368. }
  1369. else // Prim inventory
  1370. {
  1371. SceneObjectPart part = scene.GetSceneObjectPart(objectID);
  1372. if (part == null)
  1373. return false;
  1374. if (part.OwnerID != user)
  1375. {
  1376. if (part.GroupID == UUID.Zero)
  1377. return false;
  1378. if (!IsGroupMember(part.GroupID, user, 0))
  1379. return false;
  1380. }
  1381. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1382. return false;
  1383. TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);
  1384. if (ti == null)
  1385. return false;
  1386. if (ti.OwnerID != user)
  1387. {
  1388. if (ti.GroupID == UUID.Zero)
  1389. return false;
  1390. if (!IsGroupMember(ti.GroupID, user, 0))
  1391. return false;
  1392. }
  1393. // Notecards are always readable unless no copy
  1394. //
  1395. if ((ti.CurrentPermissions &
  1396. (uint)PermissionMask.Copy) !=
  1397. (uint)PermissionMask.Copy)
  1398. return false;
  1399. }
  1400. return true;
  1401. }
  1402. #endregion
  1403. private bool CanLinkObject(UUID userID, UUID objectID)
  1404. {
  1405. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1406. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1407. return GenericObjectPermission(userID, objectID, false);
  1408. }
  1409. private bool CanDelinkObject(UUID userID, UUID objectID)
  1410. {
  1411. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1412. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1413. return GenericObjectPermission(userID, objectID, false);
  1414. }
  1415. private bool CanBuyLand(UUID userID, ILandObject parcel, Scene scene)
  1416. {
  1417. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1418. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1419. return true;
  1420. }
  1421. private bool CanCopyObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1422. {
  1423. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1424. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1425. return true;
  1426. }
  1427. private bool CanDeleteObjectInventory(UUID itemID, UUID objectID, UUID userID)
  1428. {
  1429. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1430. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1431. return true;
  1432. }
  1433. /// <summary>
  1434. /// Check whether the specified user is allowed to directly create the given inventory type in a prim's
  1435. /// inventory (e.g. the New Script button in the 1.21 Linden Lab client).
  1436. /// </summary>
  1437. /// <param name="invType"></param>
  1438. /// <param name="objectID"></param>
  1439. /// <param name="userID"></param>
  1440. /// <returns></returns>
  1441. private bool CanCreateObjectInventory(int invType, UUID objectID, UUID userID)
  1442. {
  1443. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1444. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1445. if ((int)InventoryType.LSL == invType)
  1446. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1447. return false;
  1448. return true;
  1449. }
  1450. /// <summary>
  1451. /// Check whether the specified user is allowed to create the given inventory type in their inventory.
  1452. /// </summary>
  1453. /// <param name="invType"></param>
  1454. /// <param name="userID"></param>
  1455. /// <returns></returns>
  1456. private bool CanCreateUserInventory(int invType, UUID userID)
  1457. {
  1458. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1459. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1460. if ((int)InventoryType.LSL == invType)
  1461. if (m_allowedScriptCreators == UserSet.Administrators && !IsAdministrator(userID))
  1462. return false;
  1463. return true;
  1464. }
  1465. /// <summary>
  1466. /// Check whether the specified user is allowed to copy the given inventory type in their inventory.
  1467. /// </summary>
  1468. /// <param name="itemID"></param>
  1469. /// <param name="userID"></param>
  1470. /// <returns></returns>
  1471. private bool CanCopyUserInventory(UUID itemID, UUID userID)
  1472. {
  1473. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1474. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1475. return true;
  1476. }
  1477. /// <summary>
  1478. /// Check whether the specified user is allowed to edit the given inventory item within their own inventory.
  1479. /// </summary>
  1480. /// <param name="itemID"></param>
  1481. /// <param name="userID"></param>
  1482. /// <returns></returns>
  1483. private bool CanEditUserInventory(UUID itemID, UUID userID)
  1484. {
  1485. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1486. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1487. return true;
  1488. }
  1489. /// <summary>
  1490. /// Check whether the specified user is allowed to delete the given inventory item from their own inventory.
  1491. /// </summary>
  1492. /// <param name="itemID"></param>
  1493. /// <param name="userID"></param>
  1494. /// <returns></returns>
  1495. private bool CanDeleteUserInventory(UUID itemID, UUID userID)
  1496. {
  1497. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1498. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1499. return true;
  1500. }
  1501. private bool CanTeleport(UUID userID, Scene scene)
  1502. {
  1503. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1504. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1505. return true;
  1506. }
  1507. private bool CanResetScript(UUID prim, UUID script, UUID agentID, Scene scene)
  1508. {
  1509. DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
  1510. if (m_bypassPermissions) return m_bypassPermissionsValue;
  1511. SceneObjectPart part = m_scene.GetSceneObjectPart(prim);
  1512. // If we selected a sub-prim to reset, prim won't represent the object, but only a part.
  1513. // We have to check the permissions of the object, though.
  1514. if (part.ParentID != 0) prim = part.ParentUUID;
  1515. // You can reset the scripts in any object you can edit
  1516. return GenericObjectPermission(agentID, prim, false);
  1517. }
  1518. private bool CanCompileScript(UUID ownerUUID, int scriptType, Scene scene)
  1519. {
  1520. //m_log.DebugFormat("check if {0} is allowed to compile {1}", ownerUUID, scriptType);
  1521. switch (scriptType) {
  1522. case 0:
  1523. if (GrantLSL.Count == 0 || GrantLSL.ContainsKey(ownerUUID.ToString())) {
  1524. return(true);
  1525. }
  1526. break;
  1527. case 1:
  1528. if (GrantCS.Count == 0 || GrantCS.ContainsKey(ownerUUID.ToString())) {
  1529. return(true);
  1530. }
  1531. break;
  1532. case 2:
  1533. if (GrantVB.Count == 0 || GrantVB.ContainsKey(ownerUUID.ToString())) {
  1534. return(true);
  1535. }
  1536. break;
  1537. case 3:
  1538. if (GrantJS.Count == 0 || GrantJS.ContainsKey(ownerUUID.ToString()))
  1539. {
  1540. return (true);
  1541. }
  1542. break;
  1543. case 4:
  1544. if (GrantYP.Count == 0 || GrantYP.ContainsKey(ownerUUID.ToString()))
  1545. {
  1546. return (true);
  1547. }
  1548. break;
  1549. }
  1550. return(false);
  1551. }
  1552. private bool CanControlPrimMedia(UUID agentID, UUID primID, int face)
  1553. {
  1554. // m_log.DebugFormat(
  1555. // "[PERMISSONS]: Performing CanControlPrimMedia check with agentID {0}, primID {1}, face {2}",
  1556. // agentID, primID, face);
  1557. if (null == m_moapModule)
  1558. return false;
  1559. SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
  1560. if (null == part)
  1561. return false;
  1562. MediaEntry me = m_moapModule.GetMediaEntry(part, face);
  1563. // If there is no existing media entry then it can be controlled (in this context, created).
  1564. if (null == me)
  1565. return true;
  1566. // m_log.DebugFormat(
  1567. // "[PERMISSIONS]: Checking CanControlPrimMedia for {0} on {1} face {2} with control permissions {3}",
  1568. // agentID, primID, face, me.ControlPermissions);
  1569. return GenericPrimMediaPermission(part, agentID, me.ControlPermissions);
  1570. }
  1571. private bool CanInteractWithPrimMedia(UUID agentID, UUID primID, int face)
  1572. {
  1573. // m_log.DebugFormat(
  1574. // "[PERMISSONS]: Performing CanInteractWithPrimMedia check with agentID {0}, primID {1}, face {2}",
  1575. // agentID, primID, face);
  1576. if (null == m_moapModule)
  1577. return false;
  1578. SceneObjectPart part = m_scene.GetSceneObjectPart(primID);
  1579. if (null == part)
  1580. return false;
  1581. MediaEntry me = m_moapModule.GetMediaEntry(part, face);
  1582. // If there is no existing media entry then it can be controlled (in this context, created).
  1583. if (null == me)
  1584. return true;
  1585. // m_log.DebugFormat(
  1586. // "[PERMISSIONS]: Checking CanInteractWithPrimMedia for {0} on {1} face {2} with interact permissions {3}",
  1587. // agentID, primID, face, me.InteractPermissions);
  1588. return GenericPrimMediaPermission(part, agentID, me.InteractPermissions);
  1589. }
  1590. private bool GenericPrimMediaPermission(SceneObjectPart part, UUID agentID, MediaPermission perms)
  1591. {
  1592. // if (IsAdministrator(agentID))
  1593. // return true;
  1594. if ((perms & MediaPermission.Anyone) == MediaPermission.Anyone)
  1595. return true;
  1596. if ((perms & MediaPermission.Owner) == MediaPermission.Owner)
  1597. {
  1598. if (agentID == part.OwnerID)
  1599. return true;
  1600. }
  1601. if ((perms & MediaPermission.Group) == MediaPermission.Group)
  1602. {
  1603. if (IsGroupMember(part.GroupID, agentID, 0))
  1604. return true;
  1605. }
  1606. return false;
  1607. }
  1608. }
  1609. }