* Moved the nifty MySQLEstateData connectionstring password-stripper out into the Util project

0.6.3-post-fixes
lbsa71 2009-02-17 14:12:57 +00:00
parent 3130784934
commit 93465df5e3
2 changed files with 35 additions and 31 deletions

View File

@ -58,31 +58,15 @@ namespace OpenSim.Data.MySQL
{ {
m_connectionString = connectionString; m_connectionString = connectionString;
int passPosition = 0;
int passEndPosition = 0;
string displayConnectionString = null;
try try
{ // hide the password in the connection string {
passPosition = m_connectionString.IndexOf("password", StringComparison.OrdinalIgnoreCase); m_log.Info("[REGION DB]: MySql - connecting: " + Util.GetDisplayConnectionString(m_connectionString));
passPosition = m_connectionString.IndexOf("=", passPosition);
if (passPosition < m_connectionString.Length)
passPosition += 1;
passEndPosition = m_connectionString.IndexOf(";", passPosition);
displayConnectionString = m_connectionString.Substring(0, passPosition);
displayConnectionString += "***";
displayConnectionString += m_connectionString.Substring(passEndPosition, m_connectionString.Length - passEndPosition);
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Debug("Exception: password not found in connection string\n" + e.ToString()); m_log.Debug("Exception: password not found in connection string\n" + e.ToString());
} }
m_log.Info("[REGION DB]: MySql - connecting: " + displayConnectionString);
//m_log.Info("[ESTATE DB]: MySql - connecting: "+m_connectionString);
m_connection = new MySqlConnection(m_connectionString); m_connection = new MySqlConnection(m_connectionString);
m_connection.Open(); m_connection.Open();
@ -159,7 +143,7 @@ namespace OpenSim.Data.MySQL
EstateSettings es = new EstateSettings(); EstateSettings es = new EstateSettings();
es.OnSave += StoreEstateSettings; es.OnSave += StoreEstateSettings;
string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID"; string sql = "select estate_settings." + String.Join(",estate_settings.", FieldList) + " from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID";
CheckConnection(); CheckConnection();
@ -206,7 +190,7 @@ namespace OpenSim.Data.MySQL
names.Remove("EstateID"); names.Remove("EstateID");
sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( ?"+String.Join(", ?", names.ToArray())+")"; sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")";
cmd.CommandText = sql; cmd.CommandText = sql;
cmd.Parameters.Clear(); cmd.Parameters.Clear();
@ -216,13 +200,13 @@ namespace OpenSim.Data.MySQL
if (m_FieldMap[name].GetValue(es) is bool) if (m_FieldMap[name].GetValue(es) is bool)
{ {
if ((bool)m_FieldMap[name].GetValue(es)) if ((bool)m_FieldMap[name].GetValue(es))
cmd.Parameters.AddWithValue("?"+name, "1"); cmd.Parameters.AddWithValue("?" + name, "1");
else else
cmd.Parameters.AddWithValue("?"+name, "0"); cmd.Parameters.AddWithValue("?" + name, "0");
} }
else else
{ {
cmd.Parameters.AddWithValue("?"+name, m_FieldMap[name].GetValue(es).ToString()); cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
} }
} }
@ -255,7 +239,7 @@ namespace OpenSim.Data.MySQL
// Munge and transfer the ban list // Munge and transfer the ban list
// //
cmd.Parameters.Clear(); cmd.Parameters.Clear();
cmd.CommandText = "insert into estateban select "+es.EstateID.ToString()+", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID"; cmd.CommandText = "insert into estateban select " + es.EstateID.ToString() + ", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID";
cmd.Parameters.AddWithValue("?UUID", regionID.ToString()); cmd.Parameters.AddWithValue("?UUID", regionID.ToString());
try try
@ -279,7 +263,7 @@ namespace OpenSim.Data.MySQL
public void StoreEstateSettings(EstateSettings es) public void StoreEstateSettings(EstateSettings es)
{ {
string sql = "replace into estate_settings ("+String.Join(",", FieldList)+") values ( ?"+String.Join(", ?", FieldList)+")"; string sql = "replace into estate_settings (" + String.Join(",", FieldList) + ") values ( ?" + String.Join(", ?", FieldList) + ")";
CheckConnection(); CheckConnection();
@ -292,13 +276,13 @@ namespace OpenSim.Data.MySQL
if (m_FieldMap[name].GetValue(es) is bool) if (m_FieldMap[name].GetValue(es) is bool)
{ {
if ((bool)m_FieldMap[name].GetValue(es)) if ((bool)m_FieldMap[name].GetValue(es))
cmd.Parameters.AddWithValue("?"+name, "1"); cmd.Parameters.AddWithValue("?" + name, "1");
else else
cmd.Parameters.AddWithValue("?"+name, "0"); cmd.Parameters.AddWithValue("?" + name, "0");
} }
else else
{ {
cmd.Parameters.AddWithValue("?"+name, m_FieldMap[name].GetValue(es).ToString()); cmd.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
} }
} }
@ -369,14 +353,14 @@ namespace OpenSim.Data.MySQL
MySqlCommand cmd = m_connection.CreateCommand(); MySqlCommand cmd = m_connection.CreateCommand();
cmd.CommandText = "delete from "+table+" where EstateID = ?EstateID"; cmd.CommandText = "delete from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString()); cmd.Parameters.AddWithValue("?EstateID", EstateID.ToString());
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Parameters.Clear(); cmd.Parameters.Clear();
cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( ?EstateID, ?uuid )"; cmd.CommandText = "insert into " + table + " (EstateID, uuid) values ( ?EstateID, ?uuid )";
foreach (UUID uuid in data) foreach (UUID uuid in data)
{ {
@ -396,7 +380,7 @@ namespace OpenSim.Data.MySQL
MySqlCommand cmd = m_connection.CreateCommand(); MySqlCommand cmd = m_connection.CreateCommand();
cmd.CommandText = "select uuid from "+table+" where EstateID = ?EstateID"; cmd.CommandText = "select uuid from " + table + " where EstateID = ?EstateID";
cmd.Parameters.AddWithValue("?EstateID", EstateID); cmd.Parameters.AddWithValue("?EstateID", EstateID);
IDataReader r = cmd.ExecuteReader(); IDataReader r = cmd.ExecuteReader();

View File

@ -898,5 +898,25 @@ namespace OpenSim.Framework
{ {
return UUIDPattern.IsMatch(s); return UUIDPattern.IsMatch(s);
} }
public static string GetDisplayConnectionString(string connectionString)
{
int passPosition = 0;
int passEndPosition = 0;
string displayConnectionString = null;
// hide the password in the connection string
passPosition = connectionString.IndexOf("password", StringComparison.OrdinalIgnoreCase);
passPosition = connectionString.IndexOf("=", passPosition);
if (passPosition < connectionString.Length)
passPosition += 1;
passEndPosition = connectionString.IndexOf(";", passPosition);
displayConnectionString = connectionString.Substring(0, passPosition);
displayConnectionString += "***";
displayConnectionString += connectionString.Substring(passEndPosition, connectionString.Length - passEndPosition);
return displayConnectionString;
}
} }
} }