explicitly remove useragentserviceconnector dns lookup, effectively removed on a previus commit. This should not be needed with required mono versions and proper configured DNS (that must honour short TTL needed by dynamic DNS ); add some uri validation

0.9.1.0-post-fixes
UbitUmarov 2019-10-06 18:24:06 +01:00
parent c5e2afa9f8
commit 1b70b569ad
1 changed files with 42 additions and 58 deletions

View File

@ -50,42 +50,12 @@ namespace OpenSim.Services.Connectors.Hypergrid
LogManager.GetLogger( LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType); MethodBase.GetCurrentMethod().DeclaringType);
private string m_ServerURLHost;
private string m_ServerURL; private string m_ServerURL;
private GridRegion m_Gatekeeper; private GridRegion m_Gatekeeper;
public UserAgentServiceConnector(string url) : this(url, false) public UserAgentServiceConnector(string url)
{ {
} setServiceURL(url);
public UserAgentServiceConnector(string url, bool dnsLookup)
{
m_ServerURL = m_ServerURLHost = url;
if (dnsLookup)
{
// Doing this here, because XML-RPC or mono have some strong ideas about
// caching DNS translations.
try
{
Uri m_Uri = new Uri(m_ServerURL);
IPAddress ip = Util.GetHostFromDNS(m_Uri.Host);
if(ip != null)
{
m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString());
if (!m_ServerURL.EndsWith("/"))
m_ServerURL += "/";
}
else
m_log.DebugFormat("[USER AGENT CONNECTOR]: Failed to resolv address of {0}", url);
}
catch (Exception e)
{
m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", url, e.Message);
}
}
//m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL);
} }
public UserAgentServiceConnector(IConfigSource config) public UserAgentServiceConnector(IConfigSource config)
@ -97,20 +67,38 @@ namespace OpenSim.Services.Connectors.Hypergrid
throw new Exception("UserAgent connector init error"); throw new Exception("UserAgent connector init error");
} }
string serviceURI = serviceConfig.GetString("UserAgentServerURI", string serviceURI = serviceConfig.GetString("UserAgentServerURI", String.Empty);
String.Empty);
if (serviceURI == String.Empty) if (String.IsNullOrWhiteSpace(serviceURI))
{ {
m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService"); m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService");
throw new Exception("UserAgent connector init error"); throw new Exception("UserAgent connector init error");
} }
m_ServerURL = m_ServerURLHost = serviceURI; if (!setServiceURL(serviceURI))
{
throw new Exception("UserAgent connector init error");
}
}
private bool setServiceURL(string url)
{
// validate url getting some extended error messages
try
{
Uri tmpuri = new Uri(url);
}
catch (Exception e)
{
m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", url, e.Message);
return false;
}
m_ServerURL = url;
if (!m_ServerURL.EndsWith("/")) if (!m_ServerURL.EndsWith("/"))
m_ServerURL += "/"; m_ServerURL += "/";
//m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0}", m_ServerURL); return true;
} }
protected override string AgentPath() protected override string AgentPath()
@ -183,20 +171,20 @@ namespace OpenSim.Services.Connectors.Hypergrid
} }
catch (Exception e) catch (Exception e)
{ {
m_log.DebugFormat("[USER AGENT CONNECTOR]: {0} call to {1} failed: {2}", methodName, m_ServerURLHost, e.Message); m_log.DebugFormat("[USER AGENT CONNECTOR]: {0} call to {1} failed: {2}", methodName, m_ServerURL, e.Message);
throw; throw;
} }
if (response.IsFault) if (response.IsFault)
{ {
throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned an error: {2}", methodName, m_ServerURLHost, response.FaultString)); throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned an error: {2}", methodName, m_ServerURL, response.FaultString));
} }
hash = (Hashtable)response.Value; hash = (Hashtable)response.Value;
if (hash == null) if (hash == null)
{ {
throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned null", methodName, m_ServerURLHost)); throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned null", methodName, m_ServerURL));
} }
return hash; return hash;
@ -359,14 +347,14 @@ namespace OpenSim.Services.Connectors.Hypergrid
} }
catch catch
{ {
m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURLHost); m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURL);
// reason = "Exception: " + e.Message; // reason = "Exception: " + e.Message;
return friendsOnline; return friendsOnline;
} }
if (response.IsFault) if (response.IsFault)
{ {
m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURLHost, response.FaultString); m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURL, response.FaultString);
// reason = "XMLRPC Fault"; // reason = "XMLRPC Fault";
return friendsOnline; return friendsOnline;
} }
@ -378,7 +366,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
{ {
if (hash == null) if (hash == null)
{ {
m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost); m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
// reason = "Internal error 1"; // reason = "Internal error 1";
return friendsOnline; return friendsOnline;
} }
@ -431,14 +419,14 @@ namespace OpenSim.Services.Connectors.Hypergrid
} }
catch catch
{ {
m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURLHost); m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURL);
// reason = "Exception: " + e.Message; // reason = "Exception: " + e.Message;
return online; return online;
} }
if (response.IsFault) if (response.IsFault)
{ {
m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURLHost, response.FaultString); m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURL, response.FaultString);
// reason = "XMLRPC Fault"; // reason = "XMLRPC Fault";
return online; return online;
} }
@ -450,7 +438,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
{ {
if (hash == null) if (hash == null)
{ {
m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost); m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
// reason = "Internal error 1"; // reason = "Internal error 1";
return online; return online;
} }
@ -559,13 +547,13 @@ namespace OpenSim.Services.Connectors.Hypergrid
if (!hash.ContainsKey("UUID")) if (!hash.ContainsKey("UUID"))
{ {
throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} didn't return a UUID", m_ServerURLHost)); throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} didn't return a UUID", m_ServerURL));
} }
UUID uuid; UUID uuid;
if (!UUID.TryParse(hash["UUID"].ToString(), out uuid)) if (!UUID.TryParse(hash["UUID"].ToString(), out uuid))
{ {
throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} returned an invalid UUID: {1}", m_ServerURLHost, hash["UUID"].ToString())); throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} returned an invalid UUID: {1}", m_ServerURL, hash["UUID"].ToString()));
} }
return uuid; return uuid;
@ -573,26 +561,22 @@ namespace OpenSim.Services.Connectors.Hypergrid
private bool GetBoolResponse(XmlRpcRequest request, out string reason) private bool GetBoolResponse(XmlRpcRequest request, out string reason)
{ {
//m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURLHost); //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURL);
XmlRpcResponse response = null; XmlRpcResponse response = null;
try try
{ {
// We can not use m_ServerURL here anymore because it causes response = request.Send(m_ServerURL, 10000);
// the HTTP request to be built without a host name. This messes
// with OSGrid's NGINX and can make OSGrid avatars unable to TP
// to other grids running recent mono.
response = request.Send(m_ServerURLHost, 10000);
} }
catch (Exception e) catch (Exception e)
{ {
m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURLHost); m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURL);
reason = "Exception: " + e.Message; reason = "Exception: " + e.Message;
return false; return false;
} }
if (response.IsFault) if (response.IsFault)
{ {
m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURLHost, response.FaultString); m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURL, response.FaultString);
reason = "XMLRPC Fault"; reason = "XMLRPC Fault";
return false; return false;
} }
@ -604,7 +588,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
{ {
if (hash == null) if (hash == null)
{ {
m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost); m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
reason = "Internal error 1"; reason = "Internal error 1";
return false; return false;
} }
@ -615,7 +599,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
else else
{ {
reason = "Internal error 2"; reason = "Internal error 2";
m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURLHost); m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURL);
} }
return success; return success;