LoginService.cs 55 KB

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