aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
diff options
context:
space:
mode:
authorMW2007-05-26 13:40:19 +0000
committerMW2007-05-26 13:40:19 +0000
commit3436961bb5c01d659d09be134368f4f69460cef9 (patch)
tree3753ba4d7818df2a6bce0bbe863ff033cdfd568a /OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
downloadopensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.zip
opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz
opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2
opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz
Start of rewrite 5279!
Diffstat (limited to 'OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs')
-rw-r--r--OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs201
1 files changed, 201 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
new file mode 100644
index 0000000..6ac8cc3
--- /dev/null
+++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
@@ -0,0 +1,201 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenGrid.Framework.Data;
5
6namespace OpenGrid.Framework.Data.MySQL
7{
8 public class MySQLGridData : IGridData
9 {
10 private MySQLManager database;
11
12 /// <summary>
13 /// Initialises the Grid Interface
14 /// </summary>
15 public void Initialise()
16 {
17 IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
18 string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
19 string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
20 string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
21 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
22 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
23 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
24
25 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
26 }
27
28 /// <summary>
29 /// Shuts down the grid interface
30 /// </summary>
31 public void Close()
32 {
33 database.Close();
34 }
35
36 public string getName()
37 {
38 return "MySql OpenGridData";
39 }
40
41 public string getVersion()
42 {
43 return "0.1";
44 }
45
46 public SimProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
47 {
48 try
49 {
50 lock (database)
51 {
52 Dictionary<string, string> param = new Dictionary<string, string>();
53 param["?xmin"] = xmin.ToString();
54 param["?ymin"] = ymin.ToString();
55 param["?xmax"] = xmax.ToString();
56 param["?ymax"] = ymax.ToString();
57
58 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", param);
59 System.Data.IDataReader reader = result.ExecuteReader();
60
61 SimProfileData row;
62
63 List<SimProfileData> rows = new List<SimProfileData>();
64
65 while ((row = database.getSimRow(reader)) != null)
66 {
67 rows.Add(row);
68 }
69 reader.Close();
70 result.Dispose();
71
72 return rows.ToArray();
73
74 }
75 }
76 catch (Exception e)
77 {
78 Console.WriteLine(e.ToString());
79 return null;
80 }
81 }
82
83 /// <summary>
84 /// Returns a sim profile from it's location
85 /// </summary>
86 /// <param name="handle">Region location handle</param>
87 /// <returns>Sim profile</returns>
88 public SimProfileData GetProfileByHandle(ulong handle)
89 {
90 try
91 {
92 lock (database)
93 {
94 Dictionary<string, string> param = new Dictionary<string, string>();
95 param["?handle"] = handle.ToString();
96
97 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
98 System.Data.IDataReader reader = result.ExecuteReader();
99
100 SimProfileData row = database.getSimRow(reader);
101 reader.Close();
102 result.Dispose();
103
104 return row;
105 }
106 }
107 catch (Exception e)
108 {
109 Console.WriteLine(e.ToString());
110 return null;
111 }
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(libsecondlife.LLUUID uuid)
120 {
121 try
122 {
123 lock (database)
124 {
125 Dictionary<string, string> param = new Dictionary<string, string>();
126 param["?uuid"] = uuid.ToStringHyphenated();
127
128 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
129 System.Data.IDataReader reader = result.ExecuteReader();
130
131 SimProfileData row = database.getSimRow(reader);
132 reader.Close();
133 result.Dispose();
134
135 return row;
136 }
137 }
138 catch (Exception e)
139 {
140 Console.WriteLine(e.ToString());
141 return null;
142 }
143 }
144
145 public DataResponse AddProfile(SimProfileData profile)
146 {
147 lock (database)
148 {
149 if (database.insertRow(profile))
150 {
151 return DataResponse.RESPONSE_OK;
152 }
153 else
154 {
155 return DataResponse.RESPONSE_ERROR;
156 }
157 }
158 }
159
160 /// <summary>
161 /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
162 /// </summary>
163 /// <param name="uuid">The UUID of the challenger</param>
164 /// <param name="handle">The attempted regionHandle of the challenger</param>
165 /// <param name="authkey">The secret</param>
166 /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
167 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authkey)
168 {
169 bool throwHissyFit = false; // Should be true by 1.0
170
171 if (throwHissyFit)
172 throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
173
174 SimProfileData data = GetProfileByLLUUID(uuid);
175
176 return (handle == data.regionHandle && authkey == data.regionSecret);
177 }
178
179 /// <summary>
180 /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
181 /// </summary>
182 /// <remarks>This requires a security audit.</remarks>
183 /// <param name="uuid"></param>
184 /// <param name="handle"></param>
185 /// <param name="authhash"></param>
186 /// <param name="challenge"></param>
187 /// <returns></returns>
188 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authhash, string challenge)
189 {
190 System.Security.Cryptography.SHA512Managed HashProvider = new System.Security.Cryptography.SHA512Managed();
191 System.Text.ASCIIEncoding TextProvider = new ASCIIEncoding();
192
193 byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge);
194 byte[] hash = HashProvider.ComputeHash(stream);
195
196 return false;
197 }
198 }
199
200
201}