From 7dfa0309c63263fb15dc9e3883f5717f28e21c0c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 17 Mar 2012 15:36:20 -0700 Subject: More on HG access control. This commit splits the UserManagementModule into the Basic one and the HG one, so that we can do everything that needs to be done for HG ACLs to work without interfering with the vanilla opensim. For the moment, it finds foreign users who have left a trace in the region, e.g. an object. This makes it possible to ban/IM/etc these users using the regular avatar picker. TODO: contact the UAS directly given a name of the form First.Last @foo.com. --- .../UserManagement/HGUserManagementModule.cs | 119 +++++++++++++++++++++ .../UserManagement/UserManagementModule.cs | 102 +++++++++++------- .../Resources/CoreModulePlugin.addin.xml | 1 + bin/config-include/GridHypergrid.ini | 1 + bin/config-include/StandaloneHypergrid.ini | 1 + 5 files changed, 184 insertions(+), 40 deletions(-) create mode 100644 OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs new file mode 100644 index 0000000..6543bf2 --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs @@ -0,0 +1,119 @@ +/* + * 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.IO; +using System.Reflection; + +using OpenSim.Framework; +using OpenSim.Framework.Console; +using OpenSim.Region.Framework; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenSim.Services.Connectors.Hypergrid; + +using OpenMetaverse; +using OpenMetaverse.Packets; +using log4net; +using Nini.Config; + +namespace OpenSim.Region.CoreModules.Framework.UserManagement +{ + public class HGUserManagementModule : UserManagementModule, ISharedRegionModule, IUserManagement + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + + #region ISharedRegionModule + + public new void Initialise(IConfigSource config) + { + string umanmod = config.Configs["Modules"].GetString("UserManagementModule", base.Name); + if (umanmod == Name) + { + m_Enabled = true; + RegisterConsoleCmds(); + m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name); + } + } + + public override string Name + { + get { return "HGUserManagementModule"; } + } + + #endregion ISharedRegionModule + + protected override void AddAdditionalUsers(UUID avatarID, string query, List users) + { + string[] words = query.Split(new char[] { ' ' }); + + for (int i = 0; i < words.Length; i++) + { + if (words[i].Length < 3) + { + if (i != words.Length - 1) + Array.Copy(words, i + 1, words, i, words.Length - i - 1); + Array.Resize(ref words, words.Length - 1); + } + } + + if (words.Length == 0 || words.Length > 2) + return; + + if (words.Length == 2) // First.Last @foo.com, maybe? + { + bool found = false; + foreach (UserData d in m_UserCache.Values) + { + if (d.LastName.StartsWith("@") && (d.FirstName.Equals(words[0]) || d.LastName.Equals(words[1]))) + { + users.Add(d); + found = true; + break; + } + } + if (!found) // This is it! Let's ask the other world + { + // TODO + //UserAgentServiceConnector uasConn = new UserAgentServiceConnector(words[0]); + //uasConn.GetUserInfo(...); + } + } + else + { + foreach (UserData d in m_UserCache.Values) + { + if (d.LastName.StartsWith("@") && (d.FirstName.StartsWith(query) || d.LastName.StartsWith(query))) + users.Add(d); + } + } + } + + } +} \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 39e0661..23ef0fc 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -44,7 +44,7 @@ using Nini.Config; namespace OpenSim.Region.CoreModules.Framework.UserManagement { - class UserData + public class UserData { public UUID Id { get; set; } public string FirstName { get; set; } @@ -57,36 +57,23 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private List m_Scenes = new List(); + protected bool m_Enabled; + protected List m_Scenes = new List(); // The cache - Dictionary m_UserCache = new Dictionary(); + protected Dictionary m_UserCache = new Dictionary(); #region ISharedRegionModule public void Initialise(IConfigSource config) { - //m_Enabled = config.Configs["Modules"].GetBoolean("LibraryModule", m_Enabled); - //if (m_Enabled) - //{ - // IConfig libConfig = config.Configs["LibraryService"]; - // if (libConfig != null) - // { - // string dllName = libConfig.GetString("LocalServiceModule", string.Empty); - // m_log.Debug("[LIBRARY MODULE]: Library service dll is " + dllName); - // if (dllName != string.Empty) - // { - // Object[] args = new Object[] { config }; - // m_Library = ServerUtils.LoadPlugin(dllName, args); - // } - // } - //} - MainConsole.Instance.Commands.AddCommand("Users", true, - "show names", - "show names", - "Show the bindings between user UUIDs and user names", - String.Empty, - HandleShowUsers); + string umanmod = config.Configs["Modules"].GetString("UserManagementModule", Name); + if (umanmod == Name) + { + m_Enabled = true; + RegisterConsoleCmds(); + m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name); + } } public bool IsSharedModule @@ -94,9 +81,9 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement get { return true; } } - public string Name + public virtual string Name { - get { return "UserManagement Module"; } + get { return "BasicUserManagementModule"; } } public Type ReplaceableInterface @@ -106,17 +93,23 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement public void AddRegion(Scene scene) { - m_Scenes.Add(scene); + if (m_Enabled) + { + m_Scenes.Add(scene); - scene.RegisterModuleInterface(this); - scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient); - scene.EventManager.OnPrimsLoaded += new EventManager.PrimsLoaded(EventManager_OnPrimsLoaded); + scene.RegisterModuleInterface(this); + scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient); + scene.EventManager.OnPrimsLoaded += new EventManager.PrimsLoaded(EventManager_OnPrimsLoaded); + } } public void RemoveRegion(Scene scene) { - scene.UnregisterModuleInterface(this); - m_Scenes.Remove(scene); + if (m_Enabled) + { + scene.UnregisterModuleInterface(this); + m_Scenes.Remove(scene); + } } public void RegionLoaded(Scene s) @@ -183,16 +176,31 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement { //EventManager.TriggerAvatarPickerRequest(); - List accounts = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query); + m_log.DebugFormat("[USER MANAGEMENT MODULE]: HandleAvatarPickerRequest for {0}", query); - if (accounts == null) - return; + List accs = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query); + + List users = new List(); + if (accs != null) + { + m_log.DebugFormat("[USER MANAGEMENT MODULE]: Found {0} users", accs.Count); + foreach (UserAccount acc in accs) + { + UserData ud = new UserData(); + ud.FirstName = acc.FirstName; + ud.LastName = acc.LastName; + ud.Id = acc.PrincipalID; + users.Add(ud); + } + } + + AddAdditionalUsers(avatarID, query, users); AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply); // TODO: don't create new blocks if recycling an old packet AvatarPickerReplyPacket.DataBlock[] searchData = - new AvatarPickerReplyPacket.DataBlock[accounts.Count]; + new AvatarPickerReplyPacket.DataBlock[users.Count]; AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock(); agentData.AgentID = avatarID; @@ -201,16 +209,16 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement //byte[] bytes = new byte[AvatarResponses.Count*32]; int i = 0; - foreach (UserAccount item in accounts) + foreach (UserData item in users) { - UUID translatedIDtem = item.PrincipalID; + UUID translatedIDtem = item.Id; searchData[i] = new AvatarPickerReplyPacket.DataBlock(); searchData[i].AvatarID = translatedIDtem; searchData[i].FirstName = Utils.StringToBytes((string)item.FirstName); searchData[i].LastName = Utils.StringToBytes((string)item.LastName); i++; } - if (accounts.Count == 0) + if (users.Count == 0) { searchData = new AvatarPickerReplyPacket.DataBlock[0]; } @@ -232,6 +240,10 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement client.SendAvatarPickerReply(agent_data, data_args); } + protected virtual void AddAdditionalUsers(UUID avatarID, string query, List users) + { + } + #endregion Event Handlers private void CacheCreators(SceneObjectGroup sog) @@ -487,13 +499,23 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement #endregion IUserManagement + protected void RegisterConsoleCmds() + { + MainConsole.Instance.Commands.AddCommand("Users", true, + "show names", + "show names", + "Show the bindings between user UUIDs and user names", + String.Empty, + HandleShowUsers); + } + private void HandleShowUsers(string module, string[] cmd) { lock (m_UserCache) { if (m_UserCache.Count == 0) { - MainConsole.Instance.Output("No users not found"); + MainConsole.Instance.Output("No users found"); return; } diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml index e22fd38..dc6efed 100644 --- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml +++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml @@ -9,6 +9,7 @@ + diff --git a/bin/config-include/GridHypergrid.ini b/bin/config-include/GridHypergrid.ini index da447f1..31a4059 100644 --- a/bin/config-include/GridHypergrid.ini +++ b/bin/config-include/GridHypergrid.ini @@ -27,6 +27,7 @@ LandServices = "RemoteLandServicesConnector" FriendsModule = "HGFriendsModule" MapImageService = "MapImageServiceModule" + UserManagementModule = "HGUserManagementModule" LandServiceInConnector = true NeighbourServiceInConnector = true diff --git a/bin/config-include/StandaloneHypergrid.ini b/bin/config-include/StandaloneHypergrid.ini index 286d0a1..ee51067 100644 --- a/bin/config-include/StandaloneHypergrid.ini +++ b/bin/config-include/StandaloneHypergrid.ini @@ -23,6 +23,7 @@ EntityTransferModule = "HGEntityTransferModule" InventoryAccessModule = "HGInventoryAccessModule" FriendsModule = "HGFriendsModule" + UserManagementModule = "HGUserManagementModule" InventoryServiceInConnector = true AssetServiceInConnector = true -- cgit v1.1