diff options
Re-imported OpenGridServices from trunk
Diffstat (limited to 'OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs')
-rw-r--r-- | OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs b/OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs new file mode 100644 index 0000000..92169c4 --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs | |||
@@ -0,0 +1,190 @@ | |||
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.Text; | ||
31 | using OpenGrid.Framework.Data; | ||
32 | |||
33 | namespace OpenGrid.Framework.Data.MSSQL | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// A grid data interface for Microsoft SQL Server | ||
37 | /// </summary> | ||
38 | public class SqlGridData : IGridData | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Database manager | ||
42 | /// </summary> | ||
43 | private MSSqlManager database; | ||
44 | |||
45 | /// <summary> | ||
46 | /// Initialises the Grid Interface | ||
47 | /// </summary> | ||
48 | public void Initialise() | ||
49 | { | ||
50 | database = new MSSqlManager("localhost", "db", "user", "password", "false"); | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Shuts down the grid interface | ||
55 | /// </summary> | ||
56 | public void Close() | ||
57 | { | ||
58 | database.Close(); | ||
59 | } | ||
60 | |||
61 | /// <summary> | ||
62 | /// Returns the storage system name | ||
63 | /// </summary> | ||
64 | /// <returns>A string containing the storage system name</returns> | ||
65 | public string getName() | ||
66 | { | ||
67 | return "Sql OpenGridData"; | ||
68 | } | ||
69 | |||
70 | /// <summary> | ||
71 | /// Returns the storage system version | ||
72 | /// </summary> | ||
73 | /// <returns>A string containing the storage system version</returns> | ||
74 | public string getVersion() | ||
75 | { | ||
76 | return "0.1"; | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Returns a list of regions within the specified ranges | ||
81 | /// </summary> | ||
82 | /// <param name="a">minimum X coordinate</param> | ||
83 | /// <param name="b">minimum Y coordinate</param> | ||
84 | /// <param name="c">maximum X coordinate</param> | ||
85 | /// <param name="d">maximum Y coordinate</param> | ||
86 | /// <returns>An array of region profiles</returns> | ||
87 | public SimProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) | ||
88 | { | ||
89 | return null; | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Returns a sim profile from it's location | ||
94 | /// </summary> | ||
95 | /// <param name="handle">Region location handle</param> | ||
96 | /// <returns>Sim profile</returns> | ||
97 | public SimProfileData GetProfileByHandle(ulong handle) | ||
98 | { | ||
99 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
100 | param["handle"] = handle.ToString(); | ||
101 | |||
102 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); | ||
103 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
104 | |||
105 | SimProfileData row = database.getRow(reader); | ||
106 | reader.Close(); | ||
107 | result.Dispose(); | ||
108 | |||
109 | return row; | ||
110 | } | ||
111 | |||
112 | /// <summary> | ||
113 | /// Returns a sim profile from it's UUID | ||
114 | /// </summary> | ||
115 | /// <param name="uuid">The region UUID</param> | ||
116 | /// <returns>The sim profile</returns> | ||
117 | public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid) | ||
118 | { | ||
119 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
120 | param["uuid"] = uuid.ToStringHyphenated(); | ||
121 | |||
122 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); | ||
123 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
124 | |||
125 | SimProfileData row = database.getRow(reader); | ||
126 | reader.Close(); | ||
127 | result.Dispose(); | ||
128 | |||
129 | return row; | ||
130 | } | ||
131 | |||
132 | /// <summary> | ||
133 | /// Adds a new specified region to the database | ||
134 | /// </summary> | ||
135 | /// <param name="profile">The profile to add</param> | ||
136 | /// <returns>A dataresponse enum indicating success</returns> | ||
137 | public DataResponse AddProfile(SimProfileData profile) | ||
138 | { | ||
139 | if (database.insertRow(profile)) | ||
140 | { | ||
141 | return DataResponse.RESPONSE_OK; | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | return DataResponse.RESPONSE_ERROR; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. | ||
151 | /// </summary> | ||
152 | /// <param name="uuid">The UUID of the challenger</param> | ||
153 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
154 | /// <param name="authkey">The secret</param> | ||
155 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
156 | public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authkey) | ||
157 | { | ||
158 | bool throwHissyFit = false; // Should be true by 1.0 | ||
159 | |||
160 | if (throwHissyFit) | ||
161 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
162 | |||
163 | SimProfileData data = GetProfileByLLUUID(uuid); | ||
164 | |||
165 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
166 | } | ||
167 | |||
168 | /// <summary> | ||
169 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
170 | /// </summary> | ||
171 | /// <remarks>This requires a security audit.</remarks> | ||
172 | /// <param name="uuid"></param> | ||
173 | /// <param name="handle"></param> | ||
174 | /// <param name="authhash"></param> | ||
175 | /// <param name="challenge"></param> | ||
176 | /// <returns></returns> | ||
177 | public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authhash, string challenge) | ||
178 | { | ||
179 | System.Security.Cryptography.SHA512Managed HashProvider = new System.Security.Cryptography.SHA512Managed(); | ||
180 | System.Text.ASCIIEncoding TextProvider = new ASCIIEncoding(); | ||
181 | |||
182 | byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge); | ||
183 | byte[] hash = HashProvider.ComputeHash(stream); | ||
184 | |||
185 | return false; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | |||
190 | } | ||