diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Data/PGSQL/PGSQLAuthenticationData.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/PGSQL/PGSQLAuthenticationData.cs (renamed from OpenSim/Data/MSSQL/MSSQLAuthenticationData.cs) | 119 |
1 files changed, 73 insertions, 46 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLAuthenticationData.cs b/OpenSim/Data/PGSQL/PGSQLAuthenticationData.cs index 1ae78c4..d174112 100644 --- a/OpenSim/Data/MSSQL/MSSQLAuthenticationData.cs +++ b/OpenSim/Data/PGSQL/PGSQLAuthenticationData.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -28,32 +28,38 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Data; | ||
32 | using OpenMetaverse; | 31 | using OpenMetaverse; |
33 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
34 | using System.Data.SqlClient; | ||
35 | using System.Reflection; | 33 | using System.Reflection; |
36 | using System.Text; | 34 | using System.Text; |
35 | using System.Data; | ||
36 | using Npgsql; | ||
37 | using NpgsqlTypes; | ||
37 | 38 | ||
38 | namespace OpenSim.Data.MSSQL | 39 | namespace OpenSim.Data.PGSQL |
39 | { | 40 | { |
40 | public class MSSQLAuthenticationData : IAuthenticationData | 41 | public class PGSQLAuthenticationData : IAuthenticationData |
41 | { | 42 | { |
42 | private string m_Realm; | 43 | private string m_Realm; |
43 | private List<string> m_ColumnNames = null; | 44 | private List<string> m_ColumnNames = null; |
44 | private int m_LastExpire = 0; | 45 | private int m_LastExpire = 0; |
45 | private string m_ConnectionString; | 46 | private string m_ConnectionString; |
46 | private MSSQLManager m_database; | 47 | private PGSQLManager m_database; |
48 | |||
49 | protected virtual Assembly Assembly | ||
50 | { | ||
51 | get { return GetType().Assembly; } | ||
52 | } | ||
47 | 53 | ||
48 | public MSSQLAuthenticationData(string connectionString, string realm) | 54 | public PGSQLAuthenticationData(string connectionString, string realm) |
49 | { | 55 | { |
50 | m_Realm = realm; | 56 | m_Realm = realm; |
51 | m_ConnectionString = connectionString; | 57 | m_ConnectionString = connectionString; |
52 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 58 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
53 | { | 59 | { |
54 | conn.Open(); | 60 | conn.Open(); |
55 | Migration m = new Migration(conn, GetType().Assembly, "AuthStore"); | 61 | Migration m = new Migration(conn, GetType().Assembly, "AuthStore"); |
56 | m_database = new MSSQLManager(m_ConnectionString); | 62 | m_database = new PGSQLManager(m_ConnectionString); |
57 | m.Update(); | 63 | m.Update(); |
58 | } | 64 | } |
59 | } | 65 | } |
@@ -63,14 +69,14 @@ namespace OpenSim.Data.MSSQL | |||
63 | AuthenticationData ret = new AuthenticationData(); | 69 | AuthenticationData ret = new AuthenticationData(); |
64 | ret.Data = new Dictionary<string, object>(); | 70 | ret.Data = new Dictionary<string, object>(); |
65 | 71 | ||
66 | string sql = string.Format("select * from {0} where UUID = @principalID", m_Realm); | 72 | string sql = string.Format("select * from {0} where uuid = :principalID", m_Realm); |
67 | 73 | ||
68 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 74 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
69 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 75 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) |
70 | { | 76 | { |
71 | cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID)); | 77 | cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); |
72 | conn.Open(); | 78 | conn.Open(); |
73 | using (SqlDataReader result = cmd.ExecuteReader()) | 79 | using (NpgsqlDataReader result = cmd.ExecuteReader()) |
74 | { | 80 | { |
75 | if (result.Read()) | 81 | if (result.Read()) |
76 | { | 82 | { |
@@ -87,7 +93,7 @@ namespace OpenSim.Data.MSSQL | |||
87 | 93 | ||
88 | foreach (string s in m_ColumnNames) | 94 | foreach (string s in m_ColumnNames) |
89 | { | 95 | { |
90 | if (s == "UUID") | 96 | if (s == "UUID"||s == "uuid") |
91 | continue; | 97 | continue; |
92 | 98 | ||
93 | ret.Data[s] = result[s].ToString(); | 99 | ret.Data[s] = result[s].ToString(); |
@@ -103,12 +109,31 @@ namespace OpenSim.Data.MSSQL | |||
103 | { | 109 | { |
104 | if (data.Data.ContainsKey("UUID")) | 110 | if (data.Data.ContainsKey("UUID")) |
105 | data.Data.Remove("UUID"); | 111 | data.Data.Remove("UUID"); |
112 | if (data.Data.ContainsKey("uuid")) | ||
113 | data.Data.Remove("uuid"); | ||
114 | |||
115 | /* | ||
116 | Dictionary<string, object> oAuth = new Dictionary<string, object>(); | ||
106 | 117 | ||
118 | foreach (KeyValuePair<string, object> oDado in data.Data) | ||
119 | { | ||
120 | if (oDado.Key != oDado.Key.ToLower()) | ||
121 | { | ||
122 | oAuth.Add(oDado.Key.ToLower(), oDado.Value); | ||
123 | } | ||
124 | } | ||
125 | foreach (KeyValuePair<string, object> oDado in data.Data) | ||
126 | { | ||
127 | if (!oAuth.ContainsKey(oDado.Key.ToLower())) { | ||
128 | oAuth.Add(oDado.Key.ToLower(), oDado.Value); | ||
129 | } | ||
130 | } | ||
131 | */ | ||
107 | string[] fields = new List<string>(data.Data.Keys).ToArray(); | 132 | string[] fields = new List<string>(data.Data.Keys).ToArray(); |
108 | StringBuilder updateBuilder = new StringBuilder(); | 133 | StringBuilder updateBuilder = new StringBuilder(); |
109 | 134 | ||
110 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 135 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
111 | using (SqlCommand cmd = new SqlCommand()) | 136 | using (NpgsqlCommand cmd = new NpgsqlCommand()) |
112 | { | 137 | { |
113 | updateBuilder.AppendFormat("update {0} set ", m_Realm); | 138 | updateBuilder.AppendFormat("update {0} set ", m_Realm); |
114 | 139 | ||
@@ -117,27 +142,28 @@ namespace OpenSim.Data.MSSQL | |||
117 | { | 142 | { |
118 | if (!first) | 143 | if (!first) |
119 | updateBuilder.Append(", "); | 144 | updateBuilder.Append(", "); |
120 | updateBuilder.AppendFormat("{0} = @{0}",field); | 145 | updateBuilder.AppendFormat("\"{0}\" = :{0}",field); |
121 | 146 | ||
122 | first = false; | 147 | first = false; |
123 | cmd.Parameters.Add(m_database.CreateParameter("@" + field, data.Data[field])); | 148 | |
149 | cmd.Parameters.Add(m_database.CreateParameter("" + field, data.Data[field])); | ||
124 | } | 150 | } |
125 | 151 | ||
126 | updateBuilder.Append(" where UUID = @principalID"); | 152 | updateBuilder.Append(" where uuid = :principalID"); |
127 | 153 | ||
128 | cmd.CommandText = updateBuilder.ToString(); | 154 | cmd.CommandText = updateBuilder.ToString(); |
129 | cmd.Connection = conn; | 155 | cmd.Connection = conn; |
130 | cmd.Parameters.Add(m_database.CreateParameter("@principalID", data.PrincipalID)); | 156 | cmd.Parameters.Add(m_database.CreateParameter("principalID", data.PrincipalID)); |
131 | 157 | ||
132 | conn.Open(); | 158 | conn.Open(); |
133 | if (cmd.ExecuteNonQuery() < 1) | 159 | if (cmd.ExecuteNonQuery() < 1) |
134 | { | 160 | { |
135 | StringBuilder insertBuilder = new StringBuilder(); | 161 | StringBuilder insertBuilder = new StringBuilder(); |
136 | 162 | ||
137 | insertBuilder.AppendFormat("insert into {0} (UUID, ", m_Realm); | 163 | insertBuilder.AppendFormat("insert into {0} (uuid, \"", m_Realm); |
138 | insertBuilder.Append(String.Join(", ", fields)); | 164 | insertBuilder.Append(String.Join("\", \"", fields)); |
139 | insertBuilder.Append(") values (@principalID, @"); | 165 | insertBuilder.Append("\") values (:principalID, :"); |
140 | insertBuilder.Append(String.Join(", @", fields)); | 166 | insertBuilder.Append(String.Join(", :", fields)); |
141 | insertBuilder.Append(")"); | 167 | insertBuilder.Append(")"); |
142 | 168 | ||
143 | cmd.CommandText = insertBuilder.ToString(); | 169 | cmd.CommandText = insertBuilder.ToString(); |
@@ -153,11 +179,11 @@ namespace OpenSim.Data.MSSQL | |||
153 | 179 | ||
154 | public bool SetDataItem(UUID principalID, string item, string value) | 180 | public bool SetDataItem(UUID principalID, string item, string value) |
155 | { | 181 | { |
156 | string sql = string.Format("update {0} set {1} = @{1} where UUID = @UUID", m_Realm, item); | 182 | string sql = string.Format("update {0} set {1} = :{1} where uuid = :UUID", m_Realm, item); |
157 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 183 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
158 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 184 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) |
159 | { | 185 | { |
160 | cmd.Parameters.Add(m_database.CreateParameter("@" + item, value)); | 186 | cmd.Parameters.Add(m_database.CreateParameter("" + item, value)); |
161 | conn.Open(); | 187 | conn.Open(); |
162 | if (cmd.ExecuteNonQuery() > 0) | 188 | if (cmd.ExecuteNonQuery() > 0) |
163 | return true; | 189 | return true; |
@@ -170,13 +196,13 @@ namespace OpenSim.Data.MSSQL | |||
170 | if (System.Environment.TickCount - m_LastExpire > 30000) | 196 | if (System.Environment.TickCount - m_LastExpire > 30000) |
171 | DoExpire(); | 197 | DoExpire(); |
172 | 198 | ||
173 | string sql = "insert into tokens (UUID, token, validity) values (@principalID, @token, @lifetime)"; | 199 | string sql = "insert into tokens (uuid, token, validity) values (:principalID, :token, :lifetime)"; |
174 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 200 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
175 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 201 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) |
176 | { | 202 | { |
177 | cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID)); | 203 | cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); |
178 | cmd.Parameters.Add(m_database.CreateParameter("@token", token)); | 204 | cmd.Parameters.Add(m_database.CreateParameter("token", token)); |
179 | cmd.Parameters.Add(m_database.CreateParameter("@lifetime", DateTime.Now.AddMinutes(lifetime))); | 205 | cmd.Parameters.Add(m_database.CreateParameter("lifetime", DateTime.Now.AddMinutes(lifetime))); |
180 | conn.Open(); | 206 | conn.Open(); |
181 | 207 | ||
182 | if (cmd.ExecuteNonQuery() > 0) | 208 | if (cmd.ExecuteNonQuery() > 0) |
@@ -193,13 +219,14 @@ namespace OpenSim.Data.MSSQL | |||
193 | DoExpire(); | 219 | DoExpire(); |
194 | 220 | ||
195 | DateTime validDate = DateTime.Now.AddMinutes(lifetime); | 221 | DateTime validDate = DateTime.Now.AddMinutes(lifetime); |
196 | string sql = "update tokens set validity = @validDate where UUID = @principalID and token = @token and validity > GetDate()"; | 222 | string sql = "update tokens set validity = :validDate where uuid = :principalID and token = :token and validity > (CURRENT_DATE + CURRENT_TIME)"; |
197 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 223 | |
198 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 224 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
225 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
199 | { | 226 | { |
200 | cmd.Parameters.Add(m_database.CreateParameter("@principalID", principalID)); | 227 | cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); |
201 | cmd.Parameters.Add(m_database.CreateParameter("@token", token)); | 228 | cmd.Parameters.Add(m_database.CreateParameter("token", token)); |
202 | cmd.Parameters.Add(m_database.CreateParameter("@validDate", validDate)); | 229 | cmd.Parameters.Add(m_database.CreateParameter("validDate", validDate)); |
203 | conn.Open(); | 230 | conn.Open(); |
204 | 231 | ||
205 | if (cmd.ExecuteNonQuery() > 0) | 232 | if (cmd.ExecuteNonQuery() > 0) |
@@ -213,12 +240,12 @@ namespace OpenSim.Data.MSSQL | |||
213 | private void DoExpire() | 240 | private void DoExpire() |
214 | { | 241 | { |
215 | DateTime currentDateTime = DateTime.Now; | 242 | DateTime currentDateTime = DateTime.Now; |
216 | string sql = "delete from tokens where validity < @currentDateTime"; | 243 | string sql = "delete from tokens where validity < :currentDateTime"; |
217 | using (SqlConnection conn = new SqlConnection(m_ConnectionString)) | 244 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
218 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 245 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) |
219 | { | 246 | { |
220 | conn.Open(); | 247 | conn.Open(); |
221 | cmd.Parameters.Add(m_database.CreateParameter("@currentDateTime", currentDateTime)); | 248 | cmd.Parameters.Add(m_database.CreateParameter("currentDateTime", currentDateTime)); |
222 | cmd.ExecuteNonQuery(); | 249 | cmd.ExecuteNonQuery(); |
223 | } | 250 | } |
224 | m_LastExpire = System.Environment.TickCount; | 251 | m_LastExpire = System.Environment.TickCount; |