From 0413d052a3ec541164049e7d39278c57fb92ed06 Mon Sep 17 00:00:00 2001 From: diva Date: Tue, 14 Apr 2009 19:35:35 +0000 Subject: Adds session authentication upon NewUserConnections. Adds user key authentication (in safemode only) upon CreateChildAgents. All of this for Hypergrid users too. This addresses assorted spoofing vulnerabilities. --- .../Communications/Hypergrid/HGUserServices.cs | 221 ++++++++++++++------- 1 file changed, 149 insertions(+), 72 deletions(-) (limited to 'OpenSim/Region/Communications/Hypergrid/HGUserServices.cs') diff --git a/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs index ef08421..05ae5a9 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs @@ -31,7 +31,10 @@ using System.Collections.Generic; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Communications.Clients; using OpenSim.Region.Communications.OGS1; +using OpenSim.Region.Communications.Local; namespace OpenSim.Region.Communications.Hypergrid { @@ -40,32 +43,30 @@ namespace OpenSim.Region.Communications.Hypergrid /// so it always fails for foreign users. /// Later it needs to talk with the foreign users' user servers. /// - public class HGUserServices : IUserService, IAvatarService, IMessagingService + public class HGUserServices : OGS1UserServices { //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - //private HGCommunicationsGridMode m_parent; - private OGS1UserServices m_remoteUserServices; + //private CommunicationsManager m_parent; + //private OGS1UserServices m_remoteUserServices; + private LocalUserServices m_localUserServices; - public HGUserServices(HGCommunicationsGridMode parent) + // Constructor called when running in grid mode + public HGUserServices(CommunicationsManager parent) + : base(parent) { - //m_parent = parent; - m_remoteUserServices = new OGS1UserServices(parent); } - public UserProfileData ConvertXMLRPCDataToUserProfile(Hashtable data) + // Constructor called when running in standalone + public HGUserServices(LocalUserServices local) { - return m_remoteUserServices.ConvertXMLRPCDataToUserProfile(data); + m_localUserServices = local; } - public UserProfileData GetUserProfile(Uri uri) + // Called for standalone mode only, to set up the communications manager + public void SetCommunicationsManager(CommunicationsManager parent) { - throw new System.NotImplementedException(); - } - - public Uri GetUserUri(UserProfileData userProfile) - { - throw new NotImplementedException(); + m_commsManager = parent; } /// @@ -73,25 +74,15 @@ namespace OpenSim.Region.Communications.Hypergrid /// /// /// null if the request fails - public UserAgentData GetAgentByUUID(UUID userId) + public override UserAgentData GetAgentByUUID(UUID userId) { - return m_remoteUserServices.GetAgentByUUID(userId); - } - - public AvatarAppearance ConvertXMLRPCDataToAvatarAppearance(Hashtable data) - { - return m_remoteUserServices.ConvertXMLRPCDataToAvatarAppearance(data); - } + string url = string.Empty; + if ((m_localUserServices != null) && !IsForeignUser(userId, out url)) + return m_localUserServices.GetAgentByUUID(userId); - public List ConvertXMLRPCDataToAvatarPickerList(UUID queryID, Hashtable data) - { - return m_remoteUserServices.ConvertXMLRPCDataToAvatarPickerList(queryID, data); + return base.GetAgentByUUID(userId); } - public List ConvertXMLRPCDataToFriendListItemList(Hashtable data) - { - return m_remoteUserServices.ConvertXMLRPCDataToFriendListItemList(data); - } /// /// Logs off a user on the user server @@ -101,9 +92,13 @@ namespace OpenSim.Region.Communications.Hypergrid /// regionhandle /// final position /// final lookat - public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat) + public override void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat) { - m_remoteUserServices.LogOffUser(userid, regionid, regionhandle, position, lookat); + string url = string.Empty; + if ((m_localUserServices != null) && !IsForeignUser(userid, out url)) + m_localUserServices.LogOffUser(userid, regionid, regionhandle, position, lookat); + else + base.LogOffUser(userid, regionid, regionhandle, position, lookat); } /// @@ -115,19 +110,29 @@ namespace OpenSim.Region.Communications.Hypergrid /// final position x /// final position y /// final position z - public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz) + public override void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz) { - m_remoteUserServices.LogOffUser(userid, regionid, regionhandle, posx, posy, posz); + string url = string.Empty; + if ((m_localUserServices != null) && !IsForeignUser(userid, out url)) + m_localUserServices.LogOffUser(userid, regionid, regionhandle, posx, posy, posz); + else + base.LogOffUser(userid, regionid, regionhandle, posx, posy, posz); } - public UserProfileData GetUserProfile(string firstName, string lastName) + public override UserProfileData GetUserProfile(string firstName, string lastName) { + if (m_localUserServices != null) + return m_localUserServices.GetUserProfile(firstName, lastName); + return GetUserProfile(firstName + " " + lastName); } - public List GenerateAgentPickerRequestResponse(UUID queryID, string query) + public override List GenerateAgentPickerRequestResponse(UUID queryID, string query) { - return m_remoteUserServices.GenerateAgentPickerRequestResponse(queryID, query); + if (m_localUserServices != null) + return m_localUserServices.GenerateAgentPickerRequestResponse(queryID, query); + + return base.GenerateAgentPickerRequestResponse(queryID, query); } /// @@ -135,9 +140,11 @@ namespace OpenSim.Region.Communications.Hypergrid /// /// /// null if the request fails - public UserProfileData GetUserProfile(string name) + public override UserProfileData GetUserProfile(string name) { - return m_remoteUserServices.GetUserProfile(name); + // This doesn't exist in LocalUserServices + + return base.GetUserProfile(name); } /// @@ -145,14 +152,24 @@ namespace OpenSim.Region.Communications.Hypergrid /// /// /// null if the request fails - public UserProfileData GetUserProfile(UUID avatarID) + public override UserProfileData GetUserProfile(UUID avatarID) { - return m_remoteUserServices.GetUserProfile(avatarID); + string url = string.Empty; + // Unfortunately we can't query for foreigners here, + // because we'll end up in an infinite loop... + //if ((m_localUserServices != null) && (!IsForeignUser(avatarID, out url))) + if (m_localUserServices != null) + return m_localUserServices.GetUserProfile(avatarID); + + return base.GetUserProfile(avatarID); } - public void ClearUserAgent(UUID avatarID) + public override void ClearUserAgent(UUID avatarID) { - m_remoteUserServices.ClearUserAgent(avatarID); + if (m_localUserServices != null) + m_localUserServices.ClearUserAgent(avatarID); + else + base.ClearUserAgent(avatarID); } /// @@ -160,9 +177,12 @@ namespace OpenSim.Region.Communications.Hypergrid /// /// /// - public UserProfileData SetupMasterUser(string firstName, string lastName) + public override UserProfileData SetupMasterUser(string firstName, string lastName) { - return m_remoteUserServices.SetupMasterUser(firstName, lastName); + if (m_localUserServices != null) + return m_localUserServices.SetupMasterUser(firstName, lastName); + + return base.SetupMasterUser(firstName, lastName); } /// @@ -170,9 +190,12 @@ namespace OpenSim.Region.Communications.Hypergrid /// /// /// - public UserProfileData SetupMasterUser(string firstName, string lastName, string password) + public override UserProfileData SetupMasterUser(string firstName, string lastName, string password) { - return m_remoteUserServices.SetupMasterUser(firstName, lastName, password); + if (m_localUserServices != null) + return m_localUserServices.SetupMasterUser(firstName, lastName, password); + + return base.SetupMasterUser(firstName, lastName, password); } /// @@ -180,36 +203,47 @@ namespace OpenSim.Region.Communications.Hypergrid /// /// /// - public UserProfileData SetupMasterUser(UUID uuid) + public override UserProfileData SetupMasterUser(UUID uuid) { - return m_remoteUserServices.SetupMasterUser(uuid); + if (m_localUserServices != null) + return m_localUserServices.SetupMasterUser(uuid); + + return base.SetupMasterUser(uuid); } - public UUID AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY) + public override bool ResetUserPassword(string firstName, string lastName, string newPassword) { - return m_remoteUserServices.AddUserProfile(firstName, lastName, pass, regX, regY); + if (m_localUserServices != null) + return m_localUserServices.ResetUserPassword(firstName, lastName, newPassword); + else + return base.ResetUserPassword(firstName, lastName, newPassword); } - - public bool ResetUserPassword(string firstName, string lastName, string newPassword) - { - return m_remoteUserServices.ResetUserPassword(firstName, lastName, newPassword); - } - public bool UpdateUserProfile(UserProfileData userProfile) + public override bool UpdateUserProfile(UserProfileData userProfile) { - return m_remoteUserServices.UpdateUserProfile(userProfile); + string url = string.Empty; + if ((m_localUserServices != null) && (!IsForeignUser(userProfile.ID, out url))) + return m_localUserServices.UpdateUserProfile(userProfile); + + return base.UpdateUserProfile(userProfile); } #region IUserServices Friend Methods + + // NOTE: We're still not dealing with foreign user friends + /// /// Adds a new friend to the database for XUser /// /// The agent that who's friends list is being added to /// The agent that being added to the friends list of the friends list owner /// A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects - public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) + public override void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) { - m_remoteUserServices.AddNewUserFriend(friendlistowner, friend, perms); + if (m_localUserServices != null) + m_localUserServices.AddNewUserFriend(friendlistowner, friend, perms); + else + base.AddNewUserFriend(friendlistowner, friend, perms); } /// @@ -217,9 +251,12 @@ namespace OpenSim.Region.Communications.Hypergrid /// /// The agent that who's friends list is being updated /// The Ex-friend agent - public void RemoveUserFriend(UUID friendlistowner, UUID friend) + public override void RemoveUserFriend(UUID friendlistowner, UUID friend) { - m_remoteUserServices.RemoveUserFriend(friend, friend); + if (m_localUserServices != null) + m_localUserServices.RemoveUserFriend(friendlistowner, friend); + else + base.RemoveUserFriend(friend, friend); } /// @@ -228,39 +265,79 @@ namespace OpenSim.Region.Communications.Hypergrid /// The agent that who's friends list is being updated /// The agent that is getting or loosing permissions /// A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects - public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) + public override void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) { - m_remoteUserServices.UpdateUserFriendPerms(friendlistowner, friend, perms); + if (m_localUserServices != null) + m_localUserServices.UpdateUserFriendPerms(friendlistowner, friend, perms); + else + base.UpdateUserFriendPerms(friendlistowner, friend, perms); } /// /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner /// /// The agent that we're retreiving the friends Data. - public List GetUserFriendList(UUID friendlistowner) + public override List GetUserFriendList(UUID friendlistowner) { - return m_remoteUserServices.GetUserFriendList(friendlistowner); + if (m_localUserServices != null) + return m_localUserServices.GetUserFriendList(friendlistowner); + + return base.GetUserFriendList(friendlistowner); } #endregion /// Appearance - public AvatarAppearance GetUserAppearance(UUID user) + public override AvatarAppearance GetUserAppearance(UUID user) { - return m_remoteUserServices.GetUserAppearance(user); + string url = string.Empty; + if ((m_localUserServices != null) && (!IsForeignUser(user, out url))) + return m_localUserServices.GetUserAppearance(user); + else + return base.GetUserAppearance(user); } - public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) + public override void UpdateUserAppearance(UUID user, AvatarAppearance appearance) { - m_remoteUserServices.UpdateUserAppearance(user, appearance); + string url = string.Empty; + if ((m_localUserServices != null) && (!IsForeignUser(user, out url))) + m_localUserServices.UpdateUserAppearance(user, appearance); + else + base.UpdateUserAppearance(user, appearance); } #region IMessagingService - public Dictionary GetFriendRegionInfos(List uuids) + public override Dictionary GetFriendRegionInfos(List uuids) { - return m_remoteUserServices.GetFriendRegionInfos(uuids); + if (m_localUserServices != null) + return m_localUserServices.GetFriendRegionInfos(uuids); + + return base.GetFriendRegionInfos(uuids); } #endregion + protected override string GetUserServerURL(UUID userID) + { + string serverURL = string.Empty; + if (IsForeignUser(userID, out serverURL)) + return serverURL; + + return m_commsManager.NetworkServersInfo.UserURL; + } + + private bool IsForeignUser(UUID userID, out string userServerURL) + { + userServerURL = string.Empty; + CachedUserInfo uinfo = m_commsManager.UserProfileCacheService.GetUserDetails(userID); + if (uinfo != null) + { + if (!HGNetworkServersInfo.Singleton.IsLocalUser(uinfo.UserProfile)) + { + userServerURL = ((ForeignUserProfileData)(uinfo.UserProfile)).UserServerURI; + return true; + } + } + return false; + } } } -- cgit v1.1