LoginService.cs 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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. 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. // XXYY We don't need this
  390. //m_userManager.ResetAttachments(userProfile.ID);
  391. CreateAgent(userProfile, request);
  392. // We need to commit the agent right here, even though the userProfile info is not complete
  393. // at this point. There is another commit further down.
  394. // This is for the new sessionID to be stored so that the region can check it for session authentication.
  395. // CustomiseResponse->PrepareLoginToRegion
  396. CommitAgent(ref userProfile);
  397. try
  398. {
  399. UUID agentID = userProfile.ID;
  400. //InventoryData inventData = GetInventorySkeleton(agentID);
  401. InventoryData inventData = null;
  402. try
  403. {
  404. inventData = GetInventorySkeleton(agentID);
  405. }
  406. catch (Exception e)
  407. {
  408. m_log.ErrorFormat(
  409. "[LOGIN END]: LLSD Error retrieving inventory skeleton of agent {0}, {1} - {2}",
  410. agentID, e.GetType(), e.Message);
  411. return logResponse.CreateLoginFailedResponseLLSD();// .CreateLoginInventoryFailedResponseLLSD ();
  412. }
  413. ArrayList AgentInventoryArray = inventData.InventoryArray;
  414. Hashtable InventoryRootHash = new Hashtable();
  415. InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
  416. ArrayList InventoryRoot = new ArrayList();
  417. InventoryRoot.Add(InventoryRootHash);
  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. // Get the default region handle
  877. ulong defaultHandle = Utils.UIntsToLong(m_defaultHomeX * Constants.RegionSize, m_defaultHomeY * Constants.RegionSize);
  878. // If we haven't already tried the default region, reset regionInfo
  879. if (regionInfo != null && defaultHandle != regionInfo.RegionHandle)
  880. regionInfo = null;
  881. if (regionInfo == null)
  882. {
  883. m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead");
  884. regionInfo = GetRegionInfo(defaultHandle);
  885. }
  886. if (regionInfo == null)
  887. {
  888. m_log.ErrorFormat("[LOGIN]: Sending user to any region");
  889. regionInfo = RequestClosestRegion(String.Empty);
  890. }
  891. theUser.CurrentAgent.Position = new Vector3(128f, 128f, 0f);
  892. response.StartLocation = "safe";
  893. return PrepareLoginToRegion(regionInfo, theUser, response, client);
  894. }
  895. protected abstract RegionInfo RequestClosestRegion(string region);
  896. protected abstract RegionInfo GetRegionInfo(ulong homeRegionHandle);
  897. protected abstract RegionInfo GetRegionInfo(UUID homeRegionId);
  898. /// <summary>
  899. /// Prepare a login to the given region. This involves both telling the region to expect a connection
  900. /// and appropriately customising the response to the user.
  901. /// </summary>
  902. /// <param name="sim"></param>
  903. /// <param name="user"></param>
  904. /// <param name="response"></param>
  905. /// <param name="remoteClient"></param>
  906. /// <returns>true if the region was successfully contacted, false otherwise</returns>
  907. protected abstract bool PrepareLoginToRegion(
  908. RegionInfo regionInfo, UserProfileData user, LoginResponse response, IPEndPoint client);
  909. /// <summary>
  910. /// Add active gestures of the user to the login response.
  911. /// </summary>
  912. /// <param name="response">
  913. /// A <see cref="LoginResponse"/>
  914. /// </param>
  915. /// <param name="theUser">
  916. /// A <see cref="UserProfileData"/>
  917. /// </param>
  918. protected void AddActiveGestures(LoginResponse response, UserProfileData theUser)
  919. {
  920. List<InventoryItemBase> gestures = null;
  921. try
  922. {
  923. if (m_InventoryService != null)
  924. gestures = m_InventoryService.GetActiveGestures(theUser.ID);
  925. else
  926. gestures = m_interInventoryService.GetActiveGestures(theUser.ID);
  927. }
  928. catch (Exception e)
  929. {
  930. m_log.Debug("[LOGIN]: Unable to retrieve active gestures from inventory server. Reason: " + e.Message);
  931. }
  932. //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count);
  933. ArrayList list = new ArrayList();
  934. if (gestures != null)
  935. {
  936. foreach (InventoryItemBase gesture in gestures)
  937. {
  938. Hashtable item = new Hashtable();
  939. item["item_id"] = gesture.ID.ToString();
  940. item["asset_id"] = gesture.AssetID.ToString();
  941. list.Add(item);
  942. }
  943. }
  944. response.ActiveGestures = list;
  945. }
  946. /// <summary>
  947. /// Get the initial login inventory skeleton (in other words, the folder structure) for the given user.
  948. /// </summary>
  949. /// <param name="userID"></param>
  950. /// <returns></returns>
  951. /// <exception cref='System.Exception'>This will be thrown if there is a problem with the inventory service</exception>
  952. protected InventoryData GetInventorySkeleton(UUID userID)
  953. {
  954. List<InventoryFolderBase> folders = null;
  955. if (m_InventoryService != null)
  956. {
  957. folders = m_InventoryService.GetInventorySkeleton(userID);
  958. }
  959. else
  960. {
  961. folders = m_interInventoryService.GetInventorySkeleton(userID);
  962. }
  963. // If we have user auth but no inventory folders for some reason, create a new set of folders.
  964. if (folders == null || folders.Count == 0)
  965. {
  966. m_log.InfoFormat(
  967. "[LOGIN]: A root inventory folder for user {0} was not found. Requesting creation.", userID);
  968. // Although the create user function creates a new agent inventory along with a new user profile, some
  969. // tools are creating the user profile directly in the database without creating the inventory. At
  970. // this time we'll accomodate them by lazily creating the user inventory now if it doesn't already
  971. // exist.
  972. if (m_interInventoryService != null)
  973. {
  974. if (!m_interInventoryService.CreateNewUserInventory(userID))
  975. {
  976. throw new Exception(
  977. String.Format(
  978. "The inventory creation request for user {0} did not succeed."
  979. + " Please contact your inventory service provider for more information.",
  980. userID));
  981. }
  982. }
  983. else if ((m_InventoryService != null) && !m_InventoryService.CreateUserInventory(userID))
  984. {
  985. throw new Exception(
  986. String.Format(
  987. "The inventory creation request for user {0} did not succeed."
  988. + " Please contact your inventory service provider for more information.",
  989. userID));
  990. }
  991. m_log.InfoFormat("[LOGIN]: A new inventory skeleton was successfully created for user {0}", userID);
  992. if (m_InventoryService != null)
  993. folders = m_InventoryService.GetInventorySkeleton(userID);
  994. else
  995. folders = m_interInventoryService.GetInventorySkeleton(userID);
  996. if (folders == null || folders.Count == 0)
  997. {
  998. throw new Exception(
  999. String.Format(
  1000. "A root inventory folder for user {0} could not be retrieved from the inventory service",
  1001. userID));
  1002. }
  1003. }
  1004. UUID rootID = UUID.Zero;
  1005. ArrayList AgentInventoryArray = new ArrayList();
  1006. Hashtable TempHash;
  1007. foreach (InventoryFolderBase InvFolder in folders)
  1008. {
  1009. if (InvFolder.ParentID == UUID.Zero)
  1010. {
  1011. rootID = InvFolder.ID;
  1012. }
  1013. TempHash = new Hashtable();
  1014. TempHash["name"] = InvFolder.Name;
  1015. TempHash["parent_id"] = InvFolder.ParentID.ToString();
  1016. TempHash["version"] = (Int32)InvFolder.Version;
  1017. TempHash["type_default"] = (Int32)InvFolder.Type;
  1018. TempHash["folder_id"] = InvFolder.ID.ToString();
  1019. AgentInventoryArray.Add(TempHash);
  1020. }
  1021. return new InventoryData(AgentInventoryArray, rootID);
  1022. }
  1023. protected virtual bool AllowLoginWithoutInventory()
  1024. {
  1025. return false;
  1026. }
  1027. public XmlRpcResponse XmlRPCCheckAuthSession(XmlRpcRequest request, IPEndPoint remoteClient)
  1028. {
  1029. XmlRpcResponse response = new XmlRpcResponse();
  1030. Hashtable requestData = (Hashtable)request.Params[0];
  1031. string authed = "FALSE";
  1032. if (requestData.Contains("avatar_uuid") && requestData.Contains("session_id"))
  1033. {
  1034. UUID guess_aid;
  1035. UUID guess_sid;
  1036. UUID.TryParse((string)requestData["avatar_uuid"], out guess_aid);
  1037. if (guess_aid == UUID.Zero)
  1038. {
  1039. return Util.CreateUnknownUserErrorResponse();
  1040. }
  1041. UUID.TryParse((string)requestData["session_id"], out guess_sid);
  1042. if (guess_sid == UUID.Zero)
  1043. {
  1044. return Util.CreateUnknownUserErrorResponse();
  1045. }
  1046. if (m_userManager.VerifySession(guess_aid, guess_sid))
  1047. {
  1048. authed = "TRUE";
  1049. m_log.InfoFormat("[UserManager]: CheckAuthSession TRUE for user {0}", guess_aid);
  1050. }
  1051. else
  1052. {
  1053. m_log.InfoFormat("[UserManager]: CheckAuthSession FALSE");
  1054. return Util.CreateUnknownUserErrorResponse();
  1055. }
  1056. }
  1057. Hashtable responseData = new Hashtable();
  1058. responseData["auth_session"] = authed;
  1059. response.Value = responseData;
  1060. return response;
  1061. }
  1062. }
  1063. }