LoginService.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Net;
  32. using System.Reflection;
  33. using System.Text.RegularExpressions;
  34. using System.Threading;
  35. using System.Web;
  36. using log4net;
  37. using Nwc.XmlRpc;
  38. using OpenMetaverse;
  39. using OpenMetaverse.StructuredData;
  40. using OpenSim.Framework;
  41. using OpenSim.Framework.Communications.Cache;
  42. using OpenSim.Framework.Statistics;
  43. using OpenSim.Services.Interfaces;
  44. namespace OpenSim.Framework.Communications.Services
  45. {
  46. public abstract class LoginService
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. protected string m_welcomeMessage = "Welcome to OpenSim";
  50. protected int m_minLoginLevel = 0;
  51. protected UserManagerBase m_userManager = null;
  52. protected Mutex m_loginMutex = new Mutex(false);
  53. /// <summary>
  54. /// Used during login to send the skeleton of the OpenSim Library to the client.
  55. /// </summary>
  56. protected LibraryRootFolder m_libraryRootFolder;
  57. protected uint m_defaultHomeX;
  58. protected uint m_defaultHomeY;
  59. protected bool m_warn_already_logged = true;
  60. /// <summary>
  61. /// Used by the login service to make requests to the inventory service.
  62. /// </summary>
  63. protected IInterServiceInventoryServices m_interInventoryService;
  64. // Hack
  65. protected IInventoryService m_InventoryService;
  66. /// <summary>
  67. /// Constructor
  68. /// </summary>
  69. /// <param name="userManager"></param>
  70. /// <param name="libraryRootFolder"></param>
  71. /// <param name="welcomeMess"></param>
  72. public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder,
  73. string welcomeMess)
  74. {
  75. m_userManager = userManager;
  76. m_libraryRootFolder = libraryRootFolder;
  77. if (welcomeMess != String.Empty)
  78. {
  79. m_welcomeMessage = welcomeMess;
  80. }
  81. }
  82. /// <summary>
  83. /// If the user is already logged in, try to notify the region that the user they've got is dead.
  84. /// </summary>
  85. /// <param name="theUser"></param>
  86. public virtual void LogOffUser(UserProfileData theUser, string message)
  87. {
  88. }
  89. /// <summary>
  90. /// Called when we receive the client's initial XMLRPC login_to_simulator request message
  91. /// </summary>
  92. /// <param name="request">The XMLRPC request</param>
  93. /// <returns>The response to send</returns>
  94. public virtual XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  95. {
  96. // Temporary fix
  97. m_loginMutex.WaitOne();
  98. try
  99. {
  100. //CFK: CustomizeResponse contains sufficient strings to alleviate the need for this.
  101. //CKF: m_log.Info("[LOGIN]: Attempting login now...");
  102. XmlRpcResponse response = new XmlRpcResponse();
  103. Hashtable requestData = (Hashtable)request.Params[0];
  104. SniffLoginKey((Uri)request.Params[2], requestData);
  105. bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") &&
  106. (requestData.Contains("passwd") || requestData.Contains("web_login_key")));
  107. string startLocationRequest = "last";
  108. UserProfileData userProfile;
  109. LoginResponse logResponse = new LoginResponse();
  110. string firstname;
  111. string lastname;
  112. if (GoodXML)
  113. {
  114. if (requestData.Contains("start"))
  115. {
  116. startLocationRequest = (string)requestData["start"];
  117. }
  118. firstname = (string)requestData["first"];
  119. lastname = (string)requestData["last"];
  120. m_log.InfoFormat(
  121. "[LOGIN BEGIN]: XMLRPC Received login request message from user '{0}' '{1}'",
  122. firstname, lastname);
  123. string clientVersion = "Unknown";
  124. if (requestData.Contains("version"))
  125. {
  126. clientVersion = (string)requestData["version"];
  127. }
  128. m_log.DebugFormat(
  129. "[LOGIN]: XMLRPC Client is {0}, start location is {1}", clientVersion, startLocationRequest);
  130. if (!TryAuthenticateXmlRpcLogin(request, firstname, lastname, out userProfile))
  131. {
  132. return logResponse.CreateLoginFailedResponse();
  133. }
  134. }
  135. else
  136. {
  137. m_log.Info(
  138. "[LOGIN END]: XMLRPC login_to_simulator login message did not contain all the required data");
  139. return logResponse.CreateGridErrorResponse();
  140. }
  141. if (userProfile.GodLevel < m_minLoginLevel)
  142. {
  143. return logResponse.CreateLoginBlockedResponse();
  144. }
  145. else
  146. {
  147. // If we already have a session...
  148. if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline)
  149. {
  150. //TODO: The following statements can cause trouble:
  151. // If agentOnline could not turn from true back to false normally
  152. // because of some problem, for instance, the crashment of server or client,
  153. // the user cannot log in any longer.
  154. userProfile.CurrentAgent.AgentOnline = false;
  155. m_userManager.CommitAgent(ref userProfile);
  156. // try to tell the region that their user is dead.
  157. LogOffUser(userProfile, " XMLRPC You were logged off because you logged in from another location");
  158. if (m_warn_already_logged)
  159. {
  160. // This is behavior for for grid, reject login
  161. m_log.InfoFormat(
  162. "[LOGIN END]: XMLRPC Notifying user {0} {1} that they are already logged in",
  163. firstname, lastname);
  164. return logResponse.CreateAlreadyLoggedInResponse();
  165. }
  166. else
  167. {
  168. // This is behavior for standalone (silent logout of last hung session)
  169. m_log.InfoFormat(
  170. "[LOGIN]: XMLRPC User {0} {1} is already logged in, not notifying user, kicking old presence and starting new login.",
  171. firstname, lastname);
  172. }
  173. }
  174. // Otherwise...
  175. // Create a new agent session
  176. m_userManager.ResetAttachments(userProfile.ID);
  177. CreateAgent(userProfile, request);
  178. // We need to commit the agent right here, even though the userProfile info is not complete
  179. // at this point. There is another commit further down.
  180. // This is for the new sessionID to be stored so that the region can check it for session authentication.
  181. // CustomiseResponse->PrepareLoginToRegion
  182. CommitAgent(ref userProfile);
  183. try
  184. {
  185. UUID agentID = userProfile.ID;
  186. InventoryData inventData = null;
  187. try
  188. {
  189. inventData = GetInventorySkeleton(agentID);
  190. }
  191. catch (Exception e)
  192. {
  193. m_log.ErrorFormat(
  194. "[LOGIN END]: Error retrieving inventory skeleton of agent {0} - {1}",
  195. agentID, e);
  196. // Let's not panic
  197. if (!AllowLoginWithoutInventory())
  198. return logResponse.CreateLoginInventoryFailedResponse();
  199. }
  200. if (inventData != null)
  201. {
  202. ArrayList AgentInventoryArray = inventData.InventoryArray;
  203. Hashtable InventoryRootHash = new Hashtable();
  204. InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
  205. ArrayList InventoryRoot = new ArrayList();
  206. InventoryRoot.Add(InventoryRootHash);
  207. userProfile.RootInventoryFolderID = inventData.RootFolderID;
  208. logResponse.InventoryRoot = InventoryRoot;
  209. logResponse.InventorySkeleton = AgentInventoryArray;
  210. }
  211. // Inventory Library Section
  212. Hashtable InventoryLibRootHash = new Hashtable();
  213. InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
  214. ArrayList InventoryLibRoot = new ArrayList();
  215. InventoryLibRoot.Add(InventoryLibRootHash);
  216. logResponse.InventoryLibRoot = InventoryLibRoot;
  217. logResponse.InventoryLibraryOwner = GetLibraryOwner();
  218. logResponse.InventoryLibrary = GetInventoryLibrary();
  219. logResponse.CircuitCode = Util.RandomClass.Next();
  220. logResponse.Lastname = userProfile.SurName;
  221. logResponse.Firstname = userProfile.FirstName;
  222. logResponse.AgentID = agentID;
  223. logResponse.SessionID = userProfile.CurrentAgent.SessionID;
  224. logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID;
  225. logResponse.Message = GetMessage();
  226. logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID));
  227. logResponse.StartLocation = startLocationRequest;
  228. if (CustomiseResponse(logResponse, userProfile, startLocationRequest, remoteClient))
  229. {
  230. userProfile.LastLogin = userProfile.CurrentAgent.LoginTime;
  231. CommitAgent(ref userProfile);
  232. // If we reach this point, then the login has successfully logged onto the grid
  233. if (StatsManager.UserStats != null)
  234. StatsManager.UserStats.AddSuccessfulLogin();
  235. m_log.DebugFormat(
  236. "[LOGIN END]: XMLRPC Authentication of user {0} {1} successful. Sending response to client.",
  237. firstname, lastname);
  238. return logResponse.ToXmlRpcResponse();
  239. }
  240. else
  241. {
  242. m_log.ErrorFormat("[LOGIN END]: XMLRPC informing user {0} {1} that login failed due to an unavailable region", firstname, lastname);
  243. return logResponse.CreateDeadRegionResponse();
  244. }
  245. }
  246. catch (Exception e)
  247. {
  248. m_log.Error("[LOGIN END]: XMLRPC Login failed, " + e);
  249. m_log.Error(e.StackTrace);
  250. }
  251. }
  252. m_log.Info("[LOGIN END]: XMLRPC Login failed. Sending back blank XMLRPC response");
  253. return response;
  254. }
  255. finally
  256. {
  257. m_loginMutex.ReleaseMutex();
  258. }
  259. }
  260. protected virtual bool TryAuthenticateXmlRpcLogin(
  261. XmlRpcRequest request, string firstname, string lastname, out UserProfileData userProfile)
  262. {
  263. Hashtable requestData = (Hashtable)request.Params[0];
  264. userProfile = GetTheUser(firstname, lastname);
  265. if (userProfile == null)
  266. {
  267. m_log.Debug("[LOGIN END]: XMLRPC Could not find a profile for " + firstname + " " + lastname);
  268. return false;
  269. }
  270. else
  271. {
  272. if (requestData.Contains("passwd"))
  273. {
  274. string passwd = (string)requestData["passwd"];
  275. bool authenticated = AuthenticateUser(userProfile, passwd);
  276. if (!authenticated)
  277. m_log.DebugFormat("[LOGIN END]: XMLRPC User {0} {1} failed password authentication",
  278. firstname, lastname);
  279. return authenticated;
  280. }
  281. if (requestData.Contains("web_login_key"))
  282. {
  283. try
  284. {
  285. UUID webloginkey = new UUID((string)requestData["web_login_key"]);
  286. bool authenticated = AuthenticateUser(userProfile, webloginkey);
  287. if (!authenticated)
  288. m_log.DebugFormat("[LOGIN END]: XMLRPC User {0} {1} failed web login key authentication",
  289. firstname, lastname);
  290. return authenticated;
  291. }
  292. catch (Exception e)
  293. {
  294. m_log.DebugFormat(
  295. "[LOGIN END]: XMLRPC Bad web_login_key: {0} for user {1} {2}, exception {3}",
  296. requestData["web_login_key"], firstname, lastname, e);
  297. return false;
  298. }
  299. }
  300. m_log.DebugFormat(
  301. "[LOGIN END]: XMLRPC login request for {0} {1} contained neither a password nor a web login key",
  302. firstname, lastname);
  303. }
  304. return false;
  305. }
  306. protected virtual bool TryAuthenticateLLSDLogin(string firstname, string lastname, string passwd, out UserProfileData userProfile)
  307. {
  308. bool GoodLogin = false;
  309. userProfile = GetTheUser(firstname, lastname);
  310. if (userProfile == null)
  311. {
  312. m_log.Info("[LOGIN]: LLSD Could not find a profile for " + firstname + " " + lastname);
  313. return false;
  314. }
  315. GoodLogin = AuthenticateUser(userProfile, passwd);
  316. return GoodLogin;
  317. }
  318. /// <summary>
  319. /// Called when we receive the client's initial LLSD login_to_simulator request message
  320. /// </summary>
  321. /// <param name="request">The LLSD request</param>
  322. /// <returns>The response to send</returns>
  323. public OSD LLSDLoginMethod(OSD request, IPEndPoint remoteClient)
  324. {
  325. // Temporary fix
  326. m_loginMutex.WaitOne();
  327. try
  328. {
  329. // bool GoodLogin = false;
  330. string startLocationRequest = "last";
  331. UserProfileData userProfile = null;
  332. LoginResponse logResponse = new LoginResponse();
  333. if (request.Type == OSDType.Map)
  334. {
  335. OSDMap map = (OSDMap)request;
  336. if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
  337. {
  338. string firstname = map["first"].AsString();
  339. string lastname = map["last"].AsString();
  340. string passwd = map["passwd"].AsString();
  341. if (map.ContainsKey("start"))
  342. {
  343. m_log.Info("[LOGIN]: LLSD StartLocation Requested: " + map["start"].AsString());
  344. startLocationRequest = map["start"].AsString();
  345. }
  346. m_log.Info("[LOGIN]: LLSD Login Requested for: '" + firstname + "' '" + lastname + "' / " + passwd);
  347. if (!TryAuthenticateLLSDLogin(firstname, lastname, passwd, out userProfile))
  348. {
  349. return logResponse.CreateLoginFailedResponseLLSD();
  350. }
  351. }
  352. else
  353. return logResponse.CreateLoginFailedResponseLLSD();
  354. }
  355. else
  356. return logResponse.CreateLoginFailedResponseLLSD();
  357. if (userProfile.GodLevel < m_minLoginLevel)
  358. {
  359. return logResponse.CreateLoginBlockedResponseLLSD();
  360. }
  361. else
  362. {
  363. // If we already have a session...
  364. if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline)
  365. {
  366. userProfile.CurrentAgent.AgentOnline = false;
  367. m_userManager.CommitAgent(ref userProfile);
  368. // try to tell the region that their user is dead.
  369. LogOffUser(userProfile, " LLSD You were logged off because you logged in from another location");
  370. if (m_warn_already_logged)
  371. {
  372. // This is behavior for for grid, reject login
  373. m_log.InfoFormat(
  374. "[LOGIN END]: LLSD Notifying user {0} {1} that they are already logged in",
  375. userProfile.FirstName, userProfile.SurName);
  376. userProfile.CurrentAgent = null;
  377. return logResponse.CreateAlreadyLoggedInResponseLLSD();
  378. }
  379. else
  380. {
  381. // This is behavior for standalone (silent logout of last hung session)
  382. m_log.InfoFormat(
  383. "[LOGIN]: LLSD User {0} {1} is already logged in, not notifying user, kicking old presence and starting new login.",
  384. userProfile.FirstName, userProfile.SurName);
  385. }
  386. }
  387. // Otherwise...
  388. // Create a new agent session
  389. m_userManager.ResetAttachments(userProfile.ID);
  390. CreateAgent(userProfile, request);
  391. // We need to commit the agent right here, even though the userProfile info is not complete
  392. // at this point. There is another commit further down.
  393. // This is for the new sessionID to be stored so that the region can check it for session authentication.
  394. // CustomiseResponse->PrepareLoginToRegion
  395. CommitAgent(ref userProfile);
  396. try
  397. {
  398. UUID agentID = userProfile.ID;
  399. //InventoryData inventData = GetInventorySkeleton(agentID);
  400. InventoryData inventData = null;
  401. try
  402. {
  403. inventData = GetInventorySkeleton(agentID);
  404. }
  405. catch (Exception e)
  406. {
  407. m_log.ErrorFormat(
  408. "[LOGIN END]: LLSD Error retrieving inventory skeleton of agent {0}, {1} - {2}",
  409. agentID, e.GetType(), e.Message);
  410. return logResponse.CreateLoginFailedResponseLLSD();// .CreateLoginInventoryFailedResponseLLSD ();
  411. }
  412. ArrayList AgentInventoryArray = inventData.InventoryArray;
  413. Hashtable InventoryRootHash = new Hashtable();
  414. InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
  415. ArrayList InventoryRoot = new ArrayList();
  416. InventoryRoot.Add(InventoryRootHash);
  417. userProfile.RootInventoryFolderID = inventData.RootFolderID;
  418. // Inventory Library Section
  419. Hashtable InventoryLibRootHash = new Hashtable();
  420. InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
  421. ArrayList InventoryLibRoot = new ArrayList();
  422. InventoryLibRoot.Add(InventoryLibRootHash);
  423. logResponse.InventoryLibRoot = InventoryLibRoot;
  424. logResponse.InventoryLibraryOwner = GetLibraryOwner();
  425. logResponse.InventoryRoot = InventoryRoot;
  426. logResponse.InventorySkeleton = AgentInventoryArray;
  427. logResponse.InventoryLibrary = GetInventoryLibrary();
  428. logResponse.CircuitCode = (Int32)Util.RandomClass.Next();
  429. logResponse.Lastname = userProfile.SurName;
  430. logResponse.Firstname = userProfile.FirstName;
  431. logResponse.AgentID = agentID;
  432. logResponse.SessionID = userProfile.CurrentAgent.SessionID;
  433. logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID;
  434. logResponse.Message = GetMessage();
  435. logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID));
  436. logResponse.StartLocation = startLocationRequest;
  437. try
  438. {
  439. CustomiseResponse(logResponse, userProfile, startLocationRequest, remoteClient);
  440. }
  441. catch (Exception ex)
  442. {
  443. m_log.Info("[LOGIN]: LLSD " + ex.ToString());
  444. return logResponse.CreateDeadRegionResponseLLSD();
  445. }
  446. userProfile.LastLogin = userProfile.CurrentAgent.LoginTime;
  447. CommitAgent(ref userProfile);
  448. // If we reach this point, then the login has successfully logged onto the grid
  449. if (StatsManager.UserStats != null)
  450. StatsManager.UserStats.AddSuccessfulLogin();
  451. m_log.DebugFormat(
  452. "[LOGIN END]: LLSD Authentication of user {0} {1} successful. Sending response to client.",
  453. userProfile.FirstName, userProfile.SurName);
  454. return logResponse.ToLLSDResponse();
  455. }
  456. catch (Exception ex)
  457. {
  458. m_log.Info("[LOGIN]: LLSD " + ex.ToString());
  459. return logResponse.CreateFailedResponseLLSD();
  460. }
  461. }
  462. }
  463. finally
  464. {
  465. m_loginMutex.ReleaseMutex();
  466. }
  467. }
  468. public Hashtable ProcessHTMLLogin(Hashtable keysvals)
  469. {
  470. // Matches all unspecified characters
  471. // Currently specified,; lowercase letters, upper case letters, numbers, underline
  472. // period, space, parens, and dash.
  473. Regex wfcut = new Regex("[^a-zA-Z0-9_\\.\\$ \\(\\)\\-]");
  474. Hashtable returnactions = new Hashtable();
  475. int statuscode = 200;
  476. string firstname = String.Empty;
  477. string lastname = String.Empty;
  478. string location = String.Empty;
  479. string region = String.Empty;
  480. string grid = String.Empty;
  481. string channel = String.Empty;
  482. string version = String.Empty;
  483. string lang = String.Empty;
  484. string password = String.Empty;
  485. string errormessages = String.Empty;
  486. // the client requires the HTML form field be named 'username'
  487. // however, the data it sends when it loads the first time is 'firstname'
  488. // another one of those little nuances.
  489. if (keysvals.Contains("firstname"))
  490. firstname = wfcut.Replace((string)keysvals["firstname"], String.Empty, 99999);
  491. if (keysvals.Contains("username"))
  492. firstname = wfcut.Replace((string)keysvals["username"], String.Empty, 99999);
  493. if (keysvals.Contains("lastname"))
  494. lastname = wfcut.Replace((string)keysvals["lastname"], String.Empty, 99999);
  495. if (keysvals.Contains("location"))
  496. location = wfcut.Replace((string)keysvals["location"], String.Empty, 99999);
  497. if (keysvals.Contains("region"))
  498. region = wfcut.Replace((string)keysvals["region"], String.Empty, 99999);
  499. if (keysvals.Contains("grid"))
  500. grid = wfcut.Replace((string)keysvals["grid"], String.Empty, 99999);
  501. if (keysvals.Contains("channel"))
  502. channel = wfcut.Replace((string)keysvals["channel"], String.Empty, 99999);
  503. if (keysvals.Contains("version"))
  504. version = wfcut.Replace((string)keysvals["version"], String.Empty, 99999);
  505. if (keysvals.Contains("lang"))
  506. lang = wfcut.Replace((string)keysvals["lang"], String.Empty, 99999);
  507. if (keysvals.Contains("password"))
  508. password = wfcut.Replace((string)keysvals["password"], String.Empty, 99999);
  509. // load our login form.
  510. string loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages);
  511. if (keysvals.ContainsKey("show_login_form"))
  512. {
  513. UserProfileData user = GetTheUser(firstname, lastname);
  514. bool goodweblogin = false;
  515. if (user != null)
  516. goodweblogin = AuthenticateUser(user, password);
  517. if (goodweblogin)
  518. {
  519. UUID webloginkey = UUID.Random();
  520. m_userManager.StoreWebLoginKey(user.ID, webloginkey);
  521. //statuscode = 301;
  522. // string redirectURL = "about:blank?redirect-http-hack=" +
  523. // HttpUtility.UrlEncode("secondlife:///app/login?first_name=" + firstname + "&last_name=" +
  524. // lastname +
  525. // "&location=" + location + "&grid=Other&web_login_key=" + webloginkey.ToString());
  526. //m_log.Info("[WEB]: R:" + redirectURL);
  527. returnactions["int_response_code"] = statuscode;
  528. //returnactions["str_redirect_location"] = redirectURL;
  529. //returnactions["str_response_string"] = "<HTML><BODY>GoodLogin</BODY></HTML>";
  530. returnactions["str_response_string"] = webloginkey.ToString();
  531. }
  532. else
  533. {
  534. errormessages = "The Username and password supplied did not match our records. Check your caps lock and try again";
  535. loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages);
  536. returnactions["int_response_code"] = statuscode;
  537. returnactions["str_response_string"] = loginform;
  538. }
  539. }
  540. else
  541. {
  542. returnactions["int_response_code"] = statuscode;
  543. returnactions["str_response_string"] = loginform;
  544. }
  545. return returnactions;
  546. }
  547. public string GetLoginForm(string firstname, string lastname, string location, string region,
  548. string grid, string channel, string version, string lang,
  549. string password, string errormessages)
  550. {
  551. // inject our values in the form at the markers
  552. string loginform = String.Empty;
  553. string file = Path.Combine(Util.configDir(), "http_loginform.html");
  554. if (!File.Exists(file))
  555. {
  556. loginform = GetDefaultLoginForm();
  557. }
  558. else
  559. {
  560. StreamReader sr = File.OpenText(file);
  561. loginform = sr.ReadToEnd();
  562. sr.Close();
  563. }
  564. loginform = loginform.Replace("[$firstname]", firstname);
  565. loginform = loginform.Replace("[$lastname]", lastname);
  566. loginform = loginform.Replace("[$location]", location);
  567. loginform = loginform.Replace("[$region]", region);
  568. loginform = loginform.Replace("[$grid]", grid);
  569. loginform = loginform.Replace("[$channel]", channel);
  570. loginform = loginform.Replace("[$version]", version);
  571. loginform = loginform.Replace("[$lang]", lang);
  572. loginform = loginform.Replace("[$password]", password);
  573. loginform = loginform.Replace("[$errors]", errormessages);
  574. return loginform;
  575. }
  576. public string GetDefaultLoginForm()
  577. {
  578. string responseString =
  579. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
  580. responseString += "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
  581. responseString += "<head>";
  582. responseString += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
  583. responseString += "<meta http-equiv=\"cache-control\" content=\"no-cache\">";
  584. responseString += "<meta http-equiv=\"Pragma\" content=\"no-cache\">";
  585. responseString += "<title>OpenSim Login</title>";
  586. responseString += "<body><br />";
  587. responseString += "<div id=\"login_box\">";
  588. responseString += "<form action=\"/go.cgi\" method=\"GET\" id=\"login-form\">";
  589. responseString += "<div id=\"message\">[$errors]</div>";
  590. responseString += "<fieldset id=\"firstname\">";
  591. responseString += "<legend>First Name:</legend>";
  592. responseString += "<input type=\"text\" id=\"firstname_input\" size=\"15\" maxlength=\"100\" name=\"username\" value=\"[$firstname]\" />";
  593. responseString += "</fieldset>";
  594. responseString += "<fieldset id=\"lastname\">";
  595. responseString += "<legend>Last Name:</legend>";
  596. responseString += "<input type=\"text\" size=\"15\" maxlength=\"100\" name=\"lastname\" value=\"[$lastname]\" />";
  597. responseString += "</fieldset>";
  598. responseString += "<fieldset id=\"password\">";
  599. responseString += "<legend>Password:</legend>";
  600. responseString += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
  601. responseString += "<tr>";
  602. responseString += "<td colspan=\"2\"><input type=\"password\" size=\"15\" maxlength=\"100\" name=\"password\" value=\"[$password]\" /></td>";
  603. responseString += "</tr>";
  604. responseString += "<tr>";
  605. responseString += "<td valign=\"middle\"><input type=\"checkbox\" name=\"remember_password\" id=\"remember_password\" [$remember_password] style=\"margin-left:0px;\"/></td>";
  606. responseString += "<td><label for=\"remember_password\">Remember password</label></td>";
  607. responseString += "</tr>";
  608. responseString += "</table>";
  609. responseString += "</fieldset>";
  610. responseString += "<input type=\"hidden\" name=\"show_login_form\" value=\"FALSE\" />";
  611. responseString += "<input type=\"hidden\" name=\"method\" value=\"login\" />";
  612. responseString += "<input type=\"hidden\" id=\"grid\" name=\"grid\" value=\"[$grid]\" />";
  613. responseString += "<input type=\"hidden\" id=\"region\" name=\"region\" value=\"[$region]\" />";
  614. responseString += "<input type=\"hidden\" id=\"location\" name=\"location\" value=\"[$location]\" />";
  615. responseString += "<input type=\"hidden\" id=\"channel\" name=\"channel\" value=\"[$channel]\" />";
  616. responseString += "<input type=\"hidden\" id=\"version\" name=\"version\" value=\"[$version]\" />";
  617. responseString += "<input type=\"hidden\" id=\"lang\" name=\"lang\" value=\"[$lang]\" />";
  618. responseString += "<div id=\"submitbtn\">";
  619. responseString += "<input class=\"input_over\" type=\"submit\" value=\"Connect\" />";
  620. responseString += "</div>";
  621. responseString += "<div id=\"connecting\" style=\"visibility:hidden\"> Connecting...</div>";
  622. responseString += "<div id=\"helplinks\"><!---";
  623. responseString += "<a href=\"#join now link\" target=\"_blank\"></a> | ";
  624. responseString += "<a href=\"#forgot password link\" target=\"_blank\"></a>";
  625. responseString += "---></div>";
  626. responseString += "<div id=\"channelinfo\"> [$channel] | [$version]=[$lang]</div>";
  627. responseString += "</form>";
  628. responseString += "<script language=\"JavaScript\">";
  629. responseString += "document.getElementById('firstname_input').focus();";
  630. responseString += "</script>";
  631. responseString += "</div>";
  632. responseString += "</div>";
  633. responseString += "</body>";
  634. responseString += "</html>";
  635. return responseString;
  636. }
  637. /// <summary>
  638. /// Saves a target agent to the database
  639. /// </summary>
  640. /// <param name="profile">The users profile</param>
  641. /// <returns>Successful?</returns>
  642. public bool CommitAgent(ref UserProfileData profile)
  643. {
  644. return m_userManager.CommitAgent(ref profile);
  645. }
  646. /// <summary>
  647. /// Checks a user against it's password hash
  648. /// </summary>
  649. /// <param name="profile">The users profile</param>
  650. /// <param name="password">The supplied password</param>
  651. /// <returns>Authenticated?</returns>
  652. public virtual bool AuthenticateUser(UserProfileData profile, string password)
  653. {
  654. bool passwordSuccess = false;
  655. //m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID);
  656. // Web Login method seems to also occasionally send the hashed password itself
  657. // we do this to get our hash in a form that the server password code can consume
  658. // when the web-login-form submits the password in the clear (supposed to be over SSL!)
  659. if (!password.StartsWith("$1$"))
  660. password = "$1$" + Util.Md5Hash(password);
  661. password = password.Remove(0, 3); //remove $1$
  662. string s = Util.Md5Hash(password + ":" + profile.PasswordSalt);
  663. // Testing...
  664. //m_log.Info("[LOGIN]: SubHash:" + s + " userprofile:" + profile.passwordHash);
  665. //m_log.Info("[LOGIN]: userprofile:" + profile.passwordHash + " SubCT:" + password);
  666. passwordSuccess = (profile.PasswordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase)
  667. || profile.PasswordHash.Equals(password, StringComparison.InvariantCulture));
  668. return passwordSuccess;
  669. }
  670. public virtual bool AuthenticateUser(UserProfileData profile, UUID webloginkey)
  671. {
  672. bool passwordSuccess = false;
  673. m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID);
  674. // Match web login key unless it's the default weblogin key UUID.Zero
  675. passwordSuccess = ((profile.WebLoginKey == webloginkey) && profile.WebLoginKey != UUID.Zero);
  676. return passwordSuccess;
  677. }
  678. /// <summary>
  679. ///
  680. /// </summary>
  681. /// <param name="profile"></param>
  682. /// <param name="request"></param>
  683. public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
  684. {
  685. m_userManager.CreateAgent(profile, request);
  686. }
  687. public void CreateAgent(UserProfileData profile, OSD request)
  688. {
  689. m_userManager.CreateAgent(profile, request);
  690. }
  691. /// <summary>
  692. ///
  693. /// </summary>
  694. /// <param name="firstname"></param>
  695. /// <param name="lastname"></param>
  696. /// <returns></returns>
  697. public virtual UserProfileData GetTheUser(string firstname, string lastname)
  698. {
  699. return m_userManager.GetUserProfile(firstname, lastname);
  700. }
  701. /// <summary>
  702. ///
  703. /// </summary>
  704. /// <returns></returns>
  705. public virtual string GetMessage()
  706. {
  707. return m_welcomeMessage;
  708. }
  709. private static LoginResponse.BuddyList ConvertFriendListItem(List<FriendListItem> LFL)
  710. {
  711. LoginResponse.BuddyList buddylistreturn = new LoginResponse.BuddyList();
  712. foreach (FriendListItem fl in LFL)
  713. {
  714. LoginResponse.BuddyList.BuddyInfo buddyitem = new LoginResponse.BuddyList.BuddyInfo(fl.Friend);
  715. buddyitem.BuddyID = fl.Friend;
  716. buddyitem.BuddyRightsHave = (int)fl.FriendListOwnerPerms;
  717. buddyitem.BuddyRightsGiven = (int)fl.FriendPerms;
  718. buddylistreturn.AddNewBuddy(buddyitem);
  719. }
  720. return buddylistreturn;
  721. }
  722. /// <summary>
  723. /// Converts the inventory library skeleton into the form required by the rpc request.
  724. /// </summary>
  725. /// <returns></returns>
  726. protected virtual ArrayList GetInventoryLibrary()
  727. {
  728. Dictionary<UUID, InventoryFolderImpl> rootFolders
  729. = m_libraryRootFolder.RequestSelfAndDescendentFolders();
  730. ArrayList folderHashes = new ArrayList();
  731. foreach (InventoryFolderBase folder in rootFolders.Values)
  732. {
  733. Hashtable TempHash = new Hashtable();
  734. TempHash["name"] = folder.Name;
  735. TempHash["parent_id"] = folder.ParentID.ToString();
  736. TempHash["version"] = (Int32)folder.Version;
  737. TempHash["type_default"] = (Int32)folder.Type;
  738. TempHash["folder_id"] = folder.ID.ToString();
  739. folderHashes.Add(TempHash);
  740. }
  741. return folderHashes;
  742. }
  743. /// <summary>
  744. ///
  745. /// </summary>
  746. /// <returns></returns>
  747. protected virtual ArrayList GetLibraryOwner()
  748. {
  749. //for now create random inventory library owner
  750. Hashtable TempHash = new Hashtable();
  751. TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000";
  752. ArrayList inventoryLibOwner = new ArrayList();
  753. inventoryLibOwner.Add(TempHash);
  754. return inventoryLibOwner;
  755. }
  756. public class InventoryData
  757. {
  758. public ArrayList InventoryArray = null;
  759. public UUID RootFolderID = UUID.Zero;
  760. public InventoryData(ArrayList invList, UUID rootID)
  761. {
  762. InventoryArray = invList;
  763. RootFolderID = rootID;
  764. }
  765. }
  766. protected void SniffLoginKey(Uri uri, Hashtable requestData)
  767. {
  768. string uri_str = uri.ToString();
  769. string[] parts = uri_str.Split(new char[] { '=' });
  770. if (parts.Length > 1)
  771. {
  772. string web_login_key = parts[1];
  773. requestData.Add("web_login_key", web_login_key);
  774. m_log.InfoFormat("[LOGIN]: Login with web_login_key {0}", web_login_key);
  775. }
  776. }
  777. /// <summary>
  778. /// Customises the login response and fills in missing values. This method also tells the login region to
  779. /// expect a client connection.
  780. /// </summary>
  781. /// <param name="response">The existing response</param>
  782. /// <param name="theUser">The user profile</param>
  783. /// <param name="startLocationRequest">The requested start location</param>
  784. /// <returns>true on success, false if the region was not successfully told to expect a user connection</returns>
  785. public bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest, IPEndPoint client)
  786. {
  787. // add active gestures to login-response
  788. AddActiveGestures(response, theUser);
  789. // HomeLocation
  790. RegionInfo homeInfo = null;
  791. // use the homeRegionID if it is stored already. If not, use the regionHandle as before
  792. UUID homeRegionId = theUser.HomeRegionID;
  793. ulong homeRegionHandle = theUser.HomeRegion;
  794. if (homeRegionId != UUID.Zero)
  795. {
  796. homeInfo = GetRegionInfo(homeRegionId);
  797. }
  798. else
  799. {
  800. homeInfo = GetRegionInfo(homeRegionHandle);
  801. }
  802. if (homeInfo != null)
  803. {
  804. response.Home =
  805. string.Format(
  806. "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
  807. (homeInfo.RegionLocX * Constants.RegionSize),
  808. (homeInfo.RegionLocY * Constants.RegionSize),
  809. theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
  810. theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
  811. }
  812. else
  813. {
  814. m_log.InfoFormat("not found the region at {0} {1}", theUser.HomeRegionX, theUser.HomeRegionY);
  815. // Emergency mode: Home-region isn't available, so we can't request the region info.
  816. // Use the stored home regionHandle instead.
  817. // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again
  818. ulong regionX = homeRegionHandle >> 32;
  819. ulong regionY = homeRegionHandle & 0xffffffff;
  820. response.Home =
  821. string.Format(
  822. "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
  823. regionX, regionY,
  824. theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z,
  825. theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z);
  826. m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}",
  827. theUser.FirstName, theUser.SurName,
  828. regionX, regionY);
  829. }
  830. // StartLocation
  831. RegionInfo regionInfo = null;
  832. if (startLocationRequest == "home")
  833. {
  834. regionInfo = homeInfo;
  835. theUser.CurrentAgent.Position = theUser.HomeLocation;
  836. response.LookAt = String.Format("[r{0},r{1},r{2}]", theUser.HomeLookAt.X.ToString(),
  837. theUser.HomeLookAt.Y.ToString(), theUser.HomeLookAt.Z.ToString());
  838. }
  839. else if (startLocationRequest == "last")
  840. {
  841. UUID lastRegion = theUser.CurrentAgent.Region;
  842. regionInfo = GetRegionInfo(lastRegion);
  843. response.LookAt = String.Format("[r{0},r{1},r{2}]", theUser.CurrentAgent.LookAt.X.ToString(),
  844. theUser.CurrentAgent.LookAt.Y.ToString(), theUser.CurrentAgent.LookAt.Z.ToString());
  845. }
  846. else
  847. {
  848. Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$");
  849. Match uriMatch = reURI.Match(startLocationRequest);
  850. if (uriMatch == null)
  851. {
  852. m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest);
  853. }
  854. else
  855. {
  856. string region = uriMatch.Groups["region"].ToString();
  857. regionInfo = RequestClosestRegion(region);
  858. if (regionInfo == null)
  859. {
  860. m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region);
  861. }
  862. else
  863. {
  864. theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value),
  865. float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["z"].Value));
  866. }
  867. }
  868. response.LookAt = "[r0,r1,r0]";
  869. // can be: last, home, safe, url
  870. response.StartLocation = "url";
  871. }
  872. if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response, client)))
  873. {
  874. return true;
  875. }
  876. // StartLocation not available, send him to a nearby region instead
  877. // regionInfo = m_gridService.RequestClosestRegion("");
  878. //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName);
  879. // Send him to default region instead
  880. ulong defaultHandle = (((ulong)m_defaultHomeX * Constants.RegionSize) << 32) |
  881. ((ulong)m_defaultHomeY * Constants.RegionSize);
  882. if ((regionInfo != null) && (defaultHandle == regionInfo.RegionHandle))
  883. {
  884. m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region");
  885. return false;
  886. }
  887. m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead");
  888. regionInfo = GetRegionInfo(defaultHandle);
  889. if (regionInfo == null)
  890. {
  891. m_log.ErrorFormat("[LOGIN]: No default region available. Aborting.");
  892. return false;
  893. }
  894. theUser.CurrentAgent.Position = new Vector3(128, 128, 0);
  895. response.StartLocation = "safe";
  896. return PrepareLoginToRegion(regionInfo, theUser, response, client);
  897. }
  898. protected abstract RegionInfo RequestClosestRegion(string region);
  899. protected abstract RegionInfo GetRegionInfo(ulong homeRegionHandle);
  900. protected abstract RegionInfo GetRegionInfo(UUID homeRegionId);
  901. protected abstract bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response, IPEndPoint client);
  902. /// <summary>
  903. /// Add active gestures of the user to the login response.
  904. /// </summary>
  905. /// <param name="response">
  906. /// A <see cref="LoginResponse"/>
  907. /// </param>
  908. /// <param name="theUser">
  909. /// A <see cref="UserProfileData"/>
  910. /// </param>
  911. protected void AddActiveGestures(LoginResponse response, UserProfileData theUser)
  912. {
  913. List<InventoryItemBase> gestures = null;
  914. try
  915. {
  916. if (m_InventoryService != null)
  917. gestures = m_InventoryService.GetActiveGestures(theUser.ID);
  918. else
  919. gestures = m_interInventoryService.GetActiveGestures(theUser.ID);
  920. }
  921. catch (Exception e)
  922. {
  923. m_log.Debug("[LOGIN]: Unable to retrieve active gestures from inventory server. Reason: " + e.Message);
  924. }
  925. //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count);
  926. ArrayList list = new ArrayList();
  927. if (gestures != null)
  928. {
  929. foreach (InventoryItemBase gesture in gestures)
  930. {
  931. Hashtable item = new Hashtable();
  932. item["item_id"] = gesture.ID.ToString();
  933. item["asset_id"] = gesture.AssetID.ToString();
  934. list.Add(item);
  935. }
  936. }
  937. response.ActiveGestures = list;
  938. }
  939. /// <summary>
  940. /// Get the initial login inventory skeleton (in other words, the folder structure) for the given user.
  941. /// </summary>
  942. /// <param name="userID"></param>
  943. /// <returns></returns>
  944. /// <exception cref='System.Exception'>This will be thrown if there is a problem with the inventory service</exception>
  945. protected InventoryData GetInventorySkeleton(UUID userID)
  946. {
  947. List<InventoryFolderBase> folders = null;
  948. if (m_InventoryService != null)
  949. {
  950. folders = m_InventoryService.GetInventorySkeleton(userID);
  951. }
  952. else
  953. {
  954. folders = m_interInventoryService.GetInventorySkeleton(userID);
  955. }
  956. // If we have user auth but no inventory folders for some reason, create a new set of folders.
  957. if (folders == null || folders.Count == 0)
  958. {
  959. m_log.InfoFormat(
  960. "[LOGIN]: A root inventory folder for user {0} was not found. Requesting creation.", userID);
  961. // Although the create user function creates a new agent inventory along with a new user profile, some
  962. // tools are creating the user profile directly in the database without creating the inventory. At
  963. // this time we'll accomodate them by lazily creating the user inventory now if it doesn't already
  964. // exist.
  965. if ((m_interInventoryService != null) && !m_interInventoryService.CreateNewUserInventory(userID))
  966. {
  967. throw new Exception(
  968. String.Format(
  969. "The inventory creation request for user {0} did not succeed."
  970. + " Please contact your inventory service provider for more information.",
  971. userID));
  972. }
  973. m_log.InfoFormat("[LOGIN]: A new inventory skeleton was successfully created for user {0}", userID);
  974. if (m_InventoryService != null)
  975. folders = m_InventoryService.GetInventorySkeleton(userID);
  976. else
  977. folders = m_interInventoryService.GetInventorySkeleton(userID);
  978. if (folders == null || folders.Count == 0)
  979. {
  980. throw new Exception(
  981. String.Format(
  982. "A root inventory folder for user {0} could not be retrieved from the inventory service",
  983. userID));
  984. }
  985. }
  986. UUID rootID = UUID.Zero;
  987. ArrayList AgentInventoryArray = new ArrayList();
  988. Hashtable TempHash;
  989. foreach (InventoryFolderBase InvFolder in folders)
  990. {
  991. if (InvFolder.ParentID == UUID.Zero)
  992. {
  993. rootID = InvFolder.ID;
  994. }
  995. TempHash = new Hashtable();
  996. TempHash["name"] = InvFolder.Name;
  997. TempHash["parent_id"] = InvFolder.ParentID.ToString();
  998. TempHash["version"] = (Int32)InvFolder.Version;
  999. TempHash["type_default"] = (Int32)InvFolder.Type;
  1000. TempHash["folder_id"] = InvFolder.ID.ToString();
  1001. AgentInventoryArray.Add(TempHash);
  1002. }
  1003. return new InventoryData(AgentInventoryArray, rootID);
  1004. }
  1005. protected virtual bool AllowLoginWithoutInventory()
  1006. {
  1007. return false;
  1008. }
  1009. public XmlRpcResponse XmlRPCCheckAuthSession(XmlRpcRequest request, IPEndPoint remoteClient)
  1010. {
  1011. XmlRpcResponse response = new XmlRpcResponse();
  1012. Hashtable requestData = (Hashtable)request.Params[0];
  1013. string authed = "FALSE";
  1014. if (requestData.Contains("avatar_uuid") && requestData.Contains("session_id"))
  1015. {
  1016. UUID guess_aid;
  1017. UUID guess_sid;
  1018. UUID.TryParse((string)requestData["avatar_uuid"], out guess_aid);
  1019. if (guess_aid == UUID.Zero)
  1020. {
  1021. return Util.CreateUnknownUserErrorResponse();
  1022. }
  1023. UUID.TryParse((string)requestData["session_id"], out guess_sid);
  1024. if (guess_sid == UUID.Zero)
  1025. {
  1026. return Util.CreateUnknownUserErrorResponse();
  1027. }
  1028. if (m_userManager.VerifySession(guess_aid, guess_sid))
  1029. {
  1030. authed = "TRUE";
  1031. m_log.InfoFormat("[UserManager]: CheckAuthSession TRUE for user {0}", guess_aid);
  1032. }
  1033. else
  1034. {
  1035. m_log.InfoFormat("[UserManager]: CheckAuthSession FALSE");
  1036. return Util.CreateUnknownUserErrorResponse();
  1037. }
  1038. }
  1039. Hashtable responseData = new Hashtable();
  1040. responseData["auth_session"] = authed;
  1041. response.Value = responseData;
  1042. return response;
  1043. }
  1044. }
  1045. }