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.

0.7.4.1
Diva Canto 2012-03-17 15:36:20 -07:00
parent 92b1ade78e
commit 7dfa0309c6
5 changed files with 184 additions and 40 deletions

View File

@ -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<UserData> 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);
}
}
}
}
}

View File

@ -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<Scene> m_Scenes = new List<Scene>();
protected bool m_Enabled;
protected List<Scene> m_Scenes = new List<Scene>();
// The cache
Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>();
protected Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>();
#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<ILibraryService>(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
@ -105,6 +92,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
}
public void AddRegion(Scene scene)
{
if (m_Enabled)
{
m_Scenes.Add(scene);
@ -112,12 +101,16 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient);
scene.EventManager.OnPrimsLoaded += new EventManager.PrimsLoaded(EventManager_OnPrimsLoaded);
}
}
public void RemoveRegion(Scene scene)
{
if (m_Enabled)
{
scene.UnregisterModuleInterface<IUserManagement>(this);
m_Scenes.Remove(scene);
}
}
public void RegionLoaded(Scene s)
{
@ -183,16 +176,31 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
{
//EventManager.TriggerAvatarPickerRequest();
List<UserAccount> 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<UserAccount> accs = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query);
List<UserData> users = new List<UserData>();
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<UserData> 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;
}

View File

@ -9,6 +9,7 @@
<Extension path = "/OpenSim/RegionModules">
<RegionModule id="UserManagementModule" type="OpenSim.Region.CoreModules.Framework.UserManagement.UserManagementModule" />
<RegionModule id="HGUserManagementModule" type="OpenSim.Region.CoreModules.Framework.UserManagement.HGUserManagementModule" />
<RegionModule id="EntityTransferModule" type="OpenSim.Region.CoreModules.Framework.EntityTransfer.EntityTransferModule" />
<RegionModule id="HGEntityTransferModule" type="OpenSim.Region.CoreModules.Framework.EntityTransfer.HGEntityTransferModule" />
<RegionModule id="InventoryAccessModule" type="OpenSim.Region.CoreModules.Framework.InventoryAccess.BasicInventoryAccessModule" />

View File

@ -27,6 +27,7 @@
LandServices = "RemoteLandServicesConnector"
FriendsModule = "HGFriendsModule"
MapImageService = "MapImageServiceModule"
UserManagementModule = "HGUserManagementModule"
LandServiceInConnector = true
NeighbourServiceInConnector = true

View File

@ -23,6 +23,7 @@
EntityTransferModule = "HGEntityTransferModule"
InventoryAccessModule = "HGInventoryAccessModule"
FriendsModule = "HGFriendsModule"
UserManagementModule = "HGUserManagementModule"
InventoryServiceInConnector = true
AssetServiceInConnector = true