mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 17:05:55 +08:00
change usermanagement user homeurl verification and local grid detection, using new GridInfo and OSHHTPHost
This commit is contained in:
@@ -120,7 +120,8 @@ namespace OpenSim.Framework
|
||||
List<Tkey1> expired = new List<Tkey1>(m_dictionary.Count);
|
||||
foreach(KeyValuePair<Tkey1,int> kvp in m_dictionary)
|
||||
{
|
||||
if(kvp.Value < now)
|
||||
int expire = kvp.Value;
|
||||
if (expire > 0 && expire < now)
|
||||
expired.Add(kvp.Key);
|
||||
}
|
||||
|
||||
@@ -186,8 +187,14 @@ namespace OpenSim.Framework
|
||||
public void Add(Tkey1 key, int expireMS)
|
||||
{
|
||||
bool gotLock = false;
|
||||
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
|
||||
int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
|
||||
int now;
|
||||
if (expireMS > 0)
|
||||
{
|
||||
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
|
||||
now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
|
||||
}
|
||||
else
|
||||
now = int.MinValue;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -303,8 +310,14 @@ namespace OpenSim.Framework
|
||||
m_rwLock.EnterWriteLock();
|
||||
gotWriteLock = true;
|
||||
}
|
||||
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
|
||||
int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
|
||||
int now;
|
||||
if (expireMS > 0)
|
||||
{
|
||||
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
|
||||
now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
|
||||
}
|
||||
else
|
||||
now = int.MinValue;
|
||||
|
||||
m_dictionary[key] = now;
|
||||
return true;
|
||||
|
||||
@@ -317,6 +317,11 @@ namespace OpenSim.Framework
|
||||
get { return (Flags == OSHTTPURIFlags.None) ? "" : URI + "/"; }
|
||||
}
|
||||
|
||||
public string HostAndPort
|
||||
{
|
||||
get { return (Flags == OSHTTPURIFlags.None) ? "" : Host + ":" + Port.ToString(); }
|
||||
}
|
||||
|
||||
public int CompareTo(OSHHTPHost other)
|
||||
{
|
||||
if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0)
|
||||
@@ -337,7 +342,7 @@ namespace OpenSim.Framework
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return URI.GetHashCode();
|
||||
return Host.GetHashCode() + Port;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,6 +611,17 @@ namespace OpenSim.Framework
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int IsLocalGrid(OSHHTPHost othergatekeeper)
|
||||
{
|
||||
if (!othergatekeeper.IsValidHost)
|
||||
return -1;
|
||||
if (othergatekeeper.Equals(m_gateKeeperURL))
|
||||
return 1;
|
||||
if (m_gateKeeperAlias != null && m_gateKeeperAlias.Contains(othergatekeeper))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int IsLocalHome(string otherhome)
|
||||
{
|
||||
OSHHTPHost tmp = new OSHHTPHost(otherhome, false);
|
||||
|
||||
@@ -475,6 +475,8 @@ namespace OpenSim.Framework
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static bool buildHGRegionURI(string inputName, out string serverURI, out string regionName)
|
||||
{
|
||||
serverURI = string.Empty;
|
||||
@@ -490,7 +492,7 @@ namespace OpenSim.Framework
|
||||
// grid.example.com
|
||||
|
||||
string host;
|
||||
uint port = 80;
|
||||
int port = 80;
|
||||
|
||||
string[] parts = inputName.Split(new char[] { ':' });
|
||||
int indx;
|
||||
@@ -518,7 +520,7 @@ namespace OpenSim.Framework
|
||||
if(indx < 0)
|
||||
{
|
||||
// If it's a number then assume it's a port. Otherwise, it's a region name.
|
||||
if (!UInt32.TryParse(parts[1], out port))
|
||||
if (!int.TryParse(parts[1], out port))
|
||||
{
|
||||
port = 80;
|
||||
regionName = parts[1];
|
||||
@@ -529,7 +531,7 @@ namespace OpenSim.Framework
|
||||
string portstr = parts[1].Substring(0, indx);
|
||||
if(indx + 2 < parts[1].Length)
|
||||
regionName = parts[1].Substring(indx + 1);
|
||||
if (!UInt32.TryParse(portstr, out port))
|
||||
if (!int.TryParse(portstr, out port))
|
||||
port = 80;
|
||||
}
|
||||
}
|
||||
@@ -3596,28 +3598,53 @@ namespace OpenSim.Framework
|
||||
/// <param name="secret">the secret part</param>
|
||||
public static bool ParseUniversalUserIdentifier(string value, out UUID uuid, out string url, out string firstname, out string lastname, out string secret)
|
||||
{
|
||||
uuid = UUID.Zero; url = string.Empty; firstname = "Unknown"; lastname = "UserUPUUI"; secret = string.Empty;
|
||||
uuid = UUID.Zero;
|
||||
url = string.Empty;
|
||||
firstname = "Unknown";
|
||||
lastname = "UserUPUUI";
|
||||
secret = string.Empty;
|
||||
|
||||
string[] parts = value.Split(';');
|
||||
if (parts.Length >= 1)
|
||||
if (!UUID.TryParse(parts[0], out uuid))
|
||||
return false;
|
||||
if (parts.Length < 1)
|
||||
return false;
|
||||
|
||||
if (!UUID.TryParse(parts[0], out uuid))
|
||||
return false;
|
||||
|
||||
if (parts.Length >= 2)
|
||||
url = parts[1];
|
||||
|
||||
if (parts.Length >= 3)
|
||||
{
|
||||
string[] name = parts[2].Split();
|
||||
if (name.Length == 2)
|
||||
url = parts[1].ToLower();
|
||||
|
||||
if (parts.Length >= 3)
|
||||
{
|
||||
firstname = name[0];
|
||||
lastname = name[1];
|
||||
string[] name = parts[2].Split();
|
||||
if (name.Length == 2)
|
||||
{
|
||||
firstname = name[0];
|
||||
lastname = name[1];
|
||||
}
|
||||
|
||||
if (parts.Length >= 4)
|
||||
secret = parts[3];
|
||||
}
|
||||
}
|
||||
if (parts.Length >= 4)
|
||||
secret = parts[3];
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ParseUniversalUserIdentifier(string value, out UUID uuid, out string url)
|
||||
{
|
||||
uuid = UUID.Zero;
|
||||
url = string.Empty;
|
||||
|
||||
string[] parts = value.Split(';');
|
||||
if (parts.Length < 1)
|
||||
return false;
|
||||
|
||||
if (!UUID.TryParse(parts[0], out uuid))
|
||||
return false;
|
||||
|
||||
if (parts.Length >= 2)
|
||||
url = parts[1].ToLower();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,12 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
public class UserManagementModule : ISharedRegionModule, IUserManagement, IPeople
|
||||
{
|
||||
private const int BADURLEXPIRE = 2 * 60;
|
||||
private const int NOEXPIRE = int.MinValue;
|
||||
private const int LOCALEXPIRE = 3600000;
|
||||
private const int HGEXPIRE = 3600000;
|
||||
private const int BADEXPIRE = 3600000;
|
||||
private const int BADHGEXPIRE =600000;
|
||||
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected bool m_Enabled;
|
||||
@@ -62,7 +68,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
protected GridInfo m_thisGridInfo;
|
||||
|
||||
// The cache
|
||||
protected ExpiringCacheOS<UUID, UserData> m_userCacheByID = new ExpiringCacheOS<UUID, UserData>(60000);
|
||||
protected ExpiringCacheOS<UUID, UserData> m_userCacheByID = new ExpiringCacheOS<UUID, UserData>(120000);
|
||||
|
||||
protected bool m_DisplayChangingHomeURI = false;
|
||||
|
||||
@@ -246,29 +252,16 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
client.SendAvatarPickerReply(RequestID, users);
|
||||
}
|
||||
|
||||
public bool CheckUrl(string url, out bool islocal, out Uri uri)
|
||||
public bool CheckUrl(string url, out bool islocal, out OSHHTPHost host)
|
||||
{
|
||||
islocal = false;
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
host = new OSHHTPHost(url);
|
||||
int type = m_thisGridInfo.IsLocalGrid(host);
|
||||
if(type < 0 )
|
||||
{
|
||||
uri = null;
|
||||
islocal = true;
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
uri = new Uri(url, UriKind.Absolute);
|
||||
}
|
||||
catch
|
||||
{
|
||||
uri = null;
|
||||
islocal = true;
|
||||
islocal = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
string host = uri.DnsSafeHost.ToLower();
|
||||
|
||||
islocal = m_thisGridInfo.IsLocalHome(host) == 1;
|
||||
islocal = type == 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -474,7 +467,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
|
||||
if(userdata.LastWebFail > 0)
|
||||
{
|
||||
if(Util.GetTimeStamp() - userdata.LastWebFail > BADURLEXPIRE) // 5 minutes
|
||||
if(Util.GetTimeStamp() - userdata.LastWebFail > BADURLEXPIRE)
|
||||
return string.Empty;
|
||||
userdata.LastWebFail = -1;
|
||||
}
|
||||
@@ -656,7 +649,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
userdata.IsUnknownUser = false;
|
||||
userdata.IsLocal = true;
|
||||
userdata.HasGridUserTried = true;
|
||||
AddUser(account);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,9 +665,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
UUID u;
|
||||
if (uInfo.UserID.Length >= 36 && Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp))
|
||||
{
|
||||
bool islocal;
|
||||
Uri uri;
|
||||
bool isvalid = CheckUrl(url, out islocal, out uri);
|
||||
bool isvalid = CheckUrl(url, out bool islocal, out OSHHTPHost host);
|
||||
|
||||
if (isvalid)
|
||||
{
|
||||
@@ -690,8 +680,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
else
|
||||
{
|
||||
userdata.FirstName = first.Replace(" ", ".") + "." + last.Replace(" ", ".");
|
||||
userdata.HomeURL = uri.AbsoluteUri;
|
||||
userdata.LastName = "@" + uri.Authority;
|
||||
userdata.HomeURL = host.URI;
|
||||
userdata.LastName = "@" + host.HostAndPort;
|
||||
userdata.IsLocal = false;
|
||||
userdata.IsUnknownUser = false;
|
||||
}
|
||||
@@ -704,65 +694,61 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
}
|
||||
/* END: do not wrap this code in any lock here */
|
||||
|
||||
m_userCacheByID.Add(uuid, userdata, 1800000);
|
||||
return !userdata.IsUnknownUser;
|
||||
}
|
||||
|
||||
public void AddUser(UserAccount account)
|
||||
{
|
||||
UUID id = account.PrincipalID;
|
||||
if (!m_userCacheByID.ContainsKey(id))
|
||||
{
|
||||
UserData user = new UserData();
|
||||
user.Id = id;
|
||||
user.FirstName = account.FirstName;
|
||||
user.LastName = account.LastName;
|
||||
user.HomeURL = string.Empty;
|
||||
user.IsUnknownUser = false;
|
||||
user.HasGridUserTried = true;
|
||||
user.IsLocal = account.LocalToGrid;
|
||||
m_userCacheByID.Add(id, user, 1800000);
|
||||
}
|
||||
bool local = account.LocalToGrid;
|
||||
|
||||
UserData user = new UserData();
|
||||
user.Id = id;
|
||||
user.FirstName = account.FirstName;
|
||||
user.LastName = account.LastName;
|
||||
user.HomeURL = string.Empty;
|
||||
user.IsUnknownUser = false;
|
||||
user.HasGridUserTried = true;
|
||||
user.IsLocal = local;
|
||||
m_userCacheByID.Add(id, user, local ? LOCALEXPIRE : HGEXPIRE);
|
||||
}
|
||||
|
||||
public virtual void AddUser(UUID uuid, string first, string last, bool isNPC = false, int expire = 1800000)
|
||||
public virtual void AddUser(UUID uuid, string first, string last, bool isNPC = false, int expire = LOCALEXPIRE)
|
||||
{
|
||||
if (!m_userCacheByID.ContainsKey(uuid))
|
||||
UserData user = new UserData();
|
||||
user.Id = uuid;
|
||||
user.FirstName = first;
|
||||
user.LastName = last;
|
||||
user.HasGridUserTried = isNPC;
|
||||
if (!isNPC && last.StartsWith("@"))
|
||||
{
|
||||
UserData user = new UserData();
|
||||
user.Id = uuid;
|
||||
user.FirstName = first;
|
||||
user.LastName = last;
|
||||
user.HasGridUserTried = isNPC;
|
||||
if (!isNPC && last.StartsWith("@"))
|
||||
string url = last.Substring(1);
|
||||
bool local;
|
||||
if (CheckUrl(url, out local, out OSHHTPHost host))
|
||||
{
|
||||
string url = last.Substring(1);
|
||||
bool local;
|
||||
Uri uri;
|
||||
if(CheckUrl(url, out local, out uri))
|
||||
{
|
||||
if(local)
|
||||
{
|
||||
user.IsLocal = true;
|
||||
user.HomeURL = string.Empty;
|
||||
user.HasGridUserTried = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
user.IsLocal = false;
|
||||
user.HomeURL = uri.AbsoluteUri;
|
||||
user.HasGridUserTried = false;
|
||||
}
|
||||
user.IsUnknownUser = false;
|
||||
if (local)
|
||||
{
|
||||
user.IsLocal = true;
|
||||
user.HomeURL = string.Empty;
|
||||
user.HasGridUserTried = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
user.IsLocal = false;
|
||||
user.HomeURL = host.URI;
|
||||
user.HasGridUserTried = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user.IsUnknownUser = false;
|
||||
user.IsLocal = true;
|
||||
user.HasGridUserTried = true;
|
||||
}
|
||||
m_userCacheByID.Add(uuid, user, isNPC ? int.MaxValue / 16 : expire);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.IsUnknownUser = false;
|
||||
user.IsLocal = true;
|
||||
user.HasGridUserTried = true;
|
||||
}
|
||||
m_userCacheByID.Add(uuid, user, isNPC ? NOEXPIRE : expire);
|
||||
}
|
||||
|
||||
public virtual void AddUser(UUID uuid, string first, string last, string homeURL)
|
||||
@@ -790,8 +776,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
oldUser.IsUnknownUser = false;
|
||||
|
||||
bool local;
|
||||
Uri uri;
|
||||
if (CheckUrl(homeURL, out local, out uri))
|
||||
if (CheckUrl(homeURL, out local, out OSHHTPHost host))
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
@@ -800,13 +785,15 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
oldUser.IsLocal = true;
|
||||
oldUser.HomeURL = string.Empty;
|
||||
oldUser.HasGridUserTried = true;
|
||||
m_userCacheByID.Add(uuid, oldUser, LOCALEXPIRE);
|
||||
}
|
||||
else
|
||||
{
|
||||
oldUser.FirstName = first.Replace(" ", ".") + "." + last.Replace(" ", ".");
|
||||
oldUser.LastName = "@" + uri.Authority;
|
||||
oldUser.HomeURL = uri.AbsoluteUri;
|
||||
oldUser.LastName = "@" + host.HostAndPort;
|
||||
oldUser.HomeURL = host.URI;
|
||||
oldUser.IsLocal = false;
|
||||
m_userCacheByID.Add(uuid, oldUser, HGEXPIRE);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -817,8 +804,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
oldUser.HomeURL = string.Empty;
|
||||
oldUser.HasGridUserTried = true;
|
||||
oldUser.IsUnknownUser = true;
|
||||
m_userCacheByID.Add(uuid, oldUser, BADEXPIRE);
|
||||
}
|
||||
m_userCacheByID.Add(uuid, oldUser, 300000);
|
||||
}
|
||||
|
||||
public virtual void AddUser(UUID id, string creatorData)
|
||||
@@ -869,14 +856,13 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
}
|
||||
|
||||
bool local;
|
||||
Uri uri;
|
||||
|
||||
var oldUser = new UserData();
|
||||
oldUser.Id = id;
|
||||
oldUser.HasGridUserTried = false;
|
||||
oldUser.IsUnknownUser = false;
|
||||
|
||||
if (CheckUrl(homeURL, out local, out uri))
|
||||
if (CheckUrl(homeURL, out local, out OSHHTPHost host))
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
@@ -889,8 +875,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
else
|
||||
{
|
||||
oldUser.FirstName = firstname + "." + lastname.Replace(" ", ".");
|
||||
oldUser.LastName = "@" + uri.Authority;
|
||||
oldUser.HomeURL = uri.AbsoluteUri;
|
||||
oldUser.LastName = "@" + host.HostAndPort;
|
||||
oldUser.HomeURL = host.URI;
|
||||
oldUser.IsLocal = false;
|
||||
}
|
||||
}
|
||||
@@ -942,8 +928,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
||||
|
||||
protected virtual void Init(IConfigSource config)
|
||||
{
|
||||
AddUser(UUID.Zero, "Unknown", "User", false, int.MaxValue / 16);
|
||||
AddUser(Constants.m_MrOpenSimID, "Mr", "Opensim", false, int.MaxValue / 16);
|
||||
AddUser(UUID.Zero, "Unknown", "User", false, NOEXPIRE);
|
||||
AddUser(Constants.m_MrOpenSimID, "Mr", "Opensim", false, NOEXPIRE);
|
||||
RegisterConsoleCmds();
|
||||
|
||||
IConfig userManagementConfig = config.Configs["UserManagement"];
|
||||
|
||||
Reference in New Issue
Block a user