diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs | 194 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MSSQL/MSSQLManager.cs | 211 | ||||
-rw-r--r-- | OpenSim/Framework/Data.MSSQL/Properties/AssemblyInfo.cs | 33 |
3 files changed, 438 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs new file mode 100644 index 0000000..ca9196a5 --- /dev/null +++ b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs | |||
@@ -0,0 +1,194 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Security.Cryptography; | ||
32 | using System.Text; | ||
33 | using libsecondlife; | ||
34 | |||
35 | namespace OpenSim.Framework.Data.MSSQL | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// A grid data interface for Microsoft SQL Server | ||
39 | /// </summary> | ||
40 | public class SqlGridData : IGridData | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Database manager | ||
44 | /// </summary> | ||
45 | private MSSqlManager database; | ||
46 | |||
47 | /// <summary> | ||
48 | /// Initialises the Grid Interface | ||
49 | /// </summary> | ||
50 | public void Initialise() | ||
51 | { | ||
52 | database = new MSSqlManager("localhost", "db", "user", "password", "false"); | ||
53 | } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Shuts down the grid interface | ||
57 | /// </summary> | ||
58 | public void Close() | ||
59 | { | ||
60 | database.Close(); | ||
61 | } | ||
62 | |||
63 | /// <summary> | ||
64 | /// Returns the storage system name | ||
65 | /// </summary> | ||
66 | /// <returns>A string containing the storage system name</returns> | ||
67 | public string getName() | ||
68 | { | ||
69 | return "Sql OpenGridData"; | ||
70 | } | ||
71 | |||
72 | /// <summary> | ||
73 | /// Returns the storage system version | ||
74 | /// </summary> | ||
75 | /// <returns>A string containing the storage system version</returns> | ||
76 | public string getVersion() | ||
77 | { | ||
78 | return "0.1"; | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Returns a list of regions within the specified ranges | ||
83 | /// </summary> | ||
84 | /// <param name="a">minimum X coordinate</param> | ||
85 | /// <param name="b">minimum Y coordinate</param> | ||
86 | /// <param name="c">maximum X coordinate</param> | ||
87 | /// <param name="d">maximum Y coordinate</param> | ||
88 | /// <returns>An array of region profiles</returns> | ||
89 | public SimProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) | ||
90 | { | ||
91 | return null; | ||
92 | } | ||
93 | |||
94 | /// <summary> | ||
95 | /// Returns a sim profile from it's location | ||
96 | /// </summary> | ||
97 | /// <param name="handle">Region location handle</param> | ||
98 | /// <returns>Sim profile</returns> | ||
99 | public SimProfileData GetProfileByHandle(ulong handle) | ||
100 | { | ||
101 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
102 | param["handle"] = handle.ToString(); | ||
103 | |||
104 | IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); | ||
105 | IDataReader reader = result.ExecuteReader(); | ||
106 | |||
107 | SimProfileData row = database.getRow(reader); | ||
108 | reader.Close(); | ||
109 | result.Dispose(); | ||
110 | |||
111 | return row; | ||
112 | } | ||
113 | |||
114 | /// <summary> | ||
115 | /// Returns a sim profile from it's UUID | ||
116 | /// </summary> | ||
117 | /// <param name="uuid">The region UUID</param> | ||
118 | /// <returns>The sim profile</returns> | ||
119 | public SimProfileData GetProfileByLLUUID(LLUUID uuid) | ||
120 | { | ||
121 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
122 | param["uuid"] = uuid.ToStringHyphenated(); | ||
123 | |||
124 | IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); | ||
125 | IDataReader reader = result.ExecuteReader(); | ||
126 | |||
127 | SimProfileData row = database.getRow(reader); | ||
128 | reader.Close(); | ||
129 | result.Dispose(); | ||
130 | |||
131 | return row; | ||
132 | } | ||
133 | |||
134 | /// <summary> | ||
135 | /// Adds a new specified region to the database | ||
136 | /// </summary> | ||
137 | /// <param name="profile">The profile to add</param> | ||
138 | /// <returns>A dataresponse enum indicating success</returns> | ||
139 | public DataResponse AddProfile(SimProfileData profile) | ||
140 | { | ||
141 | if (database.insertRow(profile)) | ||
142 | { | ||
143 | return DataResponse.RESPONSE_OK; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | return DataResponse.RESPONSE_ERROR; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | /// <summary> | ||
152 | /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. | ||
153 | /// </summary> | ||
154 | /// <param name="uuid">The UUID of the challenger</param> | ||
155 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
156 | /// <param name="authkey">The secret</param> | ||
157 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
158 | public bool AuthenticateSim(LLUUID uuid, ulong handle, string authkey) | ||
159 | { | ||
160 | bool throwHissyFit = false; // Should be true by 1.0 | ||
161 | |||
162 | if (throwHissyFit) | ||
163 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
164 | |||
165 | SimProfileData data = GetProfileByLLUUID(uuid); | ||
166 | |||
167 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
172 | /// </summary> | ||
173 | /// <remarks>This requires a security audit.</remarks> | ||
174 | /// <param name="uuid"></param> | ||
175 | /// <param name="handle"></param> | ||
176 | /// <param name="authhash"></param> | ||
177 | /// <param name="challenge"></param> | ||
178 | /// <returns></returns> | ||
179 | public bool AuthenticateSim(LLUUID uuid, ulong handle, string authhash, string challenge) | ||
180 | { | ||
181 | SHA512Managed HashProvider = new SHA512Managed(); | ||
182 | ASCIIEncoding TextProvider = new ASCIIEncoding(); | ||
183 | |||
184 | byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge); | ||
185 | byte[] hash = HashProvider.ComputeHash(stream); | ||
186 | return false; | ||
187 | } | ||
188 | public ReservationData GetReservationAtPoint(uint x, uint y) | ||
189 | { | ||
190 | return null; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | } | ||
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs new file mode 100644 index 0000000..49bf31c --- /dev/null +++ b/OpenSim/Framework/Data.MSSQL/MSSQLManager.cs | |||
@@ -0,0 +1,211 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Data.SqlClient; | ||
32 | using libsecondlife; | ||
33 | |||
34 | namespace OpenSim.Framework.Data.MSSQL | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// A management class for the MS SQL Storage Engine | ||
38 | /// </summary> | ||
39 | class MSSqlManager | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// The database connection object | ||
43 | /// </summary> | ||
44 | IDbConnection dbcon; | ||
45 | |||
46 | /// <summary> | ||
47 | /// Initialises and creates a new Sql connection and maintains it. | ||
48 | /// </summary> | ||
49 | /// <param name="hostname">The Sql server being connected to</param> | ||
50 | /// <param name="database">The name of the Sql database being used</param> | ||
51 | /// <param name="username">The username logging into the database</param> | ||
52 | /// <param name="password">The password for the user logging in</param> | ||
53 | /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param> | ||
54 | public MSSqlManager(string hostname, string database, string username, string password, string cpooling) | ||
55 | { | ||
56 | try | ||
57 | { | ||
58 | string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; | ||
59 | dbcon = new SqlConnection(connectionString); | ||
60 | |||
61 | dbcon.Open(); | ||
62 | } | ||
63 | catch (Exception e) | ||
64 | { | ||
65 | throw new Exception("Error initialising Sql Database: " + e.ToString()); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// Shuts down the database connection | ||
71 | /// </summary> | ||
72 | public void Close() | ||
73 | { | ||
74 | dbcon.Close(); | ||
75 | dbcon = null; | ||
76 | } | ||
77 | |||
78 | /// <summary> | ||
79 | /// Runs a query with protection against SQL Injection by using parameterised input. | ||
80 | /// </summary> | ||
81 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | ||
82 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | ||
83 | /// <returns>A Sql DB Command</returns> | ||
84 | public IDbCommand Query(string sql, Dictionary<string, string> parameters) | ||
85 | { | ||
86 | SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand(); | ||
87 | dbcommand.CommandText = sql; | ||
88 | foreach (KeyValuePair<string, string> param in parameters) | ||
89 | { | ||
90 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); | ||
91 | } | ||
92 | |||
93 | return (IDbCommand)dbcommand; | ||
94 | } | ||
95 | |||
96 | /// <summary> | ||
97 | /// Runs a database reader object and returns a region row | ||
98 | /// </summary> | ||
99 | /// <param name="reader">An active database reader</param> | ||
100 | /// <returns>A region row</returns> | ||
101 | public SimProfileData getRow(IDataReader reader) | ||
102 | { | ||
103 | SimProfileData regionprofile = new SimProfileData(); | ||
104 | |||
105 | if (reader.Read()) | ||
106 | { | ||
107 | // Region Main | ||
108 | regionprofile.regionHandle = (ulong)reader["regionHandle"]; | ||
109 | regionprofile.regionName = (string)reader["regionName"]; | ||
110 | regionprofile.UUID = new LLUUID((string)reader["uuid"]); | ||
111 | |||
112 | // Secrets | ||
113 | regionprofile.regionRecvKey = (string)reader["regionRecvKey"]; | ||
114 | regionprofile.regionSecret = (string)reader["regionSecret"]; | ||
115 | regionprofile.regionSendKey = (string)reader["regionSendKey"]; | ||
116 | |||
117 | // Region Server | ||
118 | regionprofile.regionDataURI = (string)reader["regionDataURI"]; | ||
119 | regionprofile.regionOnline = false; // Needs to be pinged before this can be set. | ||
120 | regionprofile.serverIP = (string)reader["serverIP"]; | ||
121 | regionprofile.serverPort = (uint)reader["serverPort"]; | ||
122 | regionprofile.serverURI = (string)reader["serverURI"]; | ||
123 | |||
124 | // Location | ||
125 | regionprofile.regionLocX = (uint)((int)reader["locX"]); | ||
126 | regionprofile.regionLocY = (uint)((int)reader["locY"]); | ||
127 | regionprofile.regionLocZ = (uint)((int)reader["locZ"]); | ||
128 | |||
129 | // Neighbours - 0 = No Override | ||
130 | regionprofile.regionEastOverrideHandle = (ulong)reader["eastOverrideHandle"]; | ||
131 | regionprofile.regionWestOverrideHandle = (ulong)reader["westOverrideHandle"]; | ||
132 | regionprofile.regionSouthOverrideHandle = (ulong)reader["southOverrideHandle"]; | ||
133 | regionprofile.regionNorthOverrideHandle = (ulong)reader["northOverrideHandle"]; | ||
134 | |||
135 | // Assets | ||
136 | regionprofile.regionAssetURI = (string)reader["regionAssetURI"]; | ||
137 | regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; | ||
138 | regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"]; | ||
139 | |||
140 | // Userserver | ||
141 | regionprofile.regionUserURI = (string)reader["regionUserURI"]; | ||
142 | regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"]; | ||
143 | regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"]; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | throw new Exception("No rows to return"); | ||
148 | } | ||
149 | return regionprofile; | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// Creates a new region in the database | ||
154 | /// </summary> | ||
155 | /// <param name="profile">The region profile to insert</param> | ||
156 | /// <returns>Successful?</returns> | ||
157 | public bool insertRow(SimProfileData profile) | ||
158 | { | ||
159 | string sql = "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; | ||
160 | sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; | ||
161 | sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; | ||
162 | |||
163 | sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; | ||
164 | sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; | ||
165 | sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; | ||
166 | |||
167 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||
168 | |||
169 | parameters["regionHandle"] = profile.regionHandle.ToString(); | ||
170 | parameters["regionName"] = profile.regionName; | ||
171 | parameters["uuid"] = profile.UUID.ToString(); | ||
172 | parameters["regionRecvKey"] = profile.regionRecvKey; | ||
173 | parameters["regionSendKey"] = profile.regionSendKey; | ||
174 | parameters["regionDataURI"] = profile.regionDataURI; | ||
175 | parameters["serverIP"] = profile.serverIP; | ||
176 | parameters["serverPort"] = profile.serverPort.ToString(); | ||
177 | parameters["serverURI"] = profile.serverURI; | ||
178 | parameters["locX"] = profile.regionLocX.ToString(); | ||
179 | parameters["locY"] = profile.regionLocY.ToString(); | ||
180 | parameters["locZ"] = profile.regionLocZ.ToString(); | ||
181 | parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); | ||
182 | parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); | ||
183 | parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); | ||
184 | parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); | ||
185 | parameters["regionAssetURI"] = profile.regionAssetURI; | ||
186 | parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; | ||
187 | parameters["regionAssetSendKey"] = profile.regionAssetSendKey; | ||
188 | parameters["regionUserURI"] = profile.regionUserURI; | ||
189 | parameters["regionUserRecvKey"] = profile.regionUserRecvKey; | ||
190 | parameters["regionUserSendKey"] = profile.regionUserSendKey; | ||
191 | |||
192 | bool returnval = false; | ||
193 | |||
194 | try | ||
195 | { | ||
196 | IDbCommand result = Query(sql, parameters); | ||
197 | |||
198 | if (result.ExecuteNonQuery() == 1) | ||
199 | returnval = true; | ||
200 | |||
201 | result.Dispose(); | ||
202 | } | ||
203 | catch (Exception) | ||
204 | { | ||
205 | return false; | ||
206 | } | ||
207 | |||
208 | return returnval; | ||
209 | } | ||
210 | } | ||
211 | } | ||
diff --git a/OpenSim/Framework/Data.MSSQL/Properties/AssemblyInfo.cs b/OpenSim/Framework/Data.MSSQL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..066c739 --- /dev/null +++ b/OpenSim/Framework/Data.MSSQL/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.InteropServices; | ||
3 | // General Information about an assembly is controlled through the following | ||
4 | // set of attributes. Change these attribute values to modify the information | ||
5 | // associated with an assembly. | ||
6 | [assembly: AssemblyTitle("OpenSim.Framework.Data.MSSQL")] | ||
7 | [assembly: AssemblyDescription("")] | ||
8 | [assembly: AssemblyConfiguration("")] | ||
9 | [assembly: AssemblyCompany("")] | ||
10 | [assembly: AssemblyProduct("OpenSim.Framework.Data.MSSQL")] | ||
11 | [assembly: AssemblyCopyright("Copyright © 2007")] | ||
12 | [assembly: AssemblyTrademark("")] | ||
13 | [assembly: AssemblyCulture("")] | ||
14 | |||
15 | // Setting ComVisible to false makes the types in this assembly not visible | ||
16 | // to COM components. If you need to access a type in this assembly from | ||
17 | // COM, set the ComVisible attribute to true on that type. | ||
18 | [assembly: ComVisible(false)] | ||
19 | |||
20 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
21 | [assembly: Guid("0e1c1ca4-2cf2-4315-b0e7-432c02feea8a")] | ||
22 | |||
23 | // Version information for an assembly consists of the following four values: | ||
24 | // | ||
25 | // Major Version | ||
26 | // Minor Version | ||
27 | // Build Number | ||
28 | // Revision | ||
29 | // | ||
30 | // You can specify all the values or you can default the Revision and Build Numbers | ||
31 | // by using the '*' as shown below: | ||
32 | [assembly: AssemblyVersion("1.0.0.0")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||