GatekeeperService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using System.Text.RegularExpressions;
  32. using OpenSim.Framework;
  33. using OpenSim.Services.Interfaces;
  34. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  35. using OpenSim.Server.Base;
  36. using OpenSim.Services.Connectors.InstantMessage;
  37. using OpenSim.Services.Connectors.Hypergrid;
  38. using OpenMetaverse;
  39. using Nini.Config;
  40. using log4net;
  41. namespace OpenSim.Services.HypergridService
  42. {
  43. public class GatekeeperService : IGatekeeperService
  44. {
  45. private static readonly ILog m_log =
  46. LogManager.GetLogger(
  47. MethodBase.GetCurrentMethod().DeclaringType);
  48. private static bool m_Initialized = false;
  49. private static IGridService m_GridService;
  50. private static IPresenceService m_PresenceService;
  51. private static IUserAccountService m_UserAccountService;
  52. private static IUserAgentService m_UserAgentService;
  53. private static ISimulationService m_SimulationService;
  54. private static IGridUserService m_GridUserService;
  55. private static IBansService m_BansService;
  56. private static string m_AllowedClients = string.Empty;
  57. private static string m_DeniedClients = string.Empty;
  58. private static bool m_ForeignAgentsAllowed = true;
  59. private static List<string> m_ForeignsAllowedExceptions = new List<string>();
  60. private static List<string> m_ForeignsDisallowedExceptions = new List<string>();
  61. private static UUID m_ScopeID;
  62. private static bool m_AllowTeleportsToAnyRegion;
  63. private static string m_ExternalName;
  64. private static Uri m_Uri;
  65. private static GridRegion m_DefaultGatewayRegion;
  66. private bool m_allowDuplicatePresences = false;
  67. public GatekeeperService(IConfigSource config, ISimulationService simService)
  68. {
  69. if (!m_Initialized)
  70. {
  71. m_Initialized = true;
  72. IConfig serverConfig = config.Configs["GatekeeperService"];
  73. if (serverConfig == null)
  74. throw new Exception(String.Format("No section GatekeeperService in config file"));
  75. string accountService = serverConfig.GetString("UserAccountService", String.Empty);
  76. string homeUsersService = serverConfig.GetString("UserAgentService", string.Empty);
  77. string gridService = serverConfig.GetString("GridService", String.Empty);
  78. string presenceService = serverConfig.GetString("PresenceService", String.Empty);
  79. string simulationService = serverConfig.GetString("SimulationService", String.Empty);
  80. string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
  81. string bansService = serverConfig.GetString("BansService", String.Empty);
  82. // These are mandatory, the others aren't
  83. if (gridService == string.Empty || presenceService == string.Empty)
  84. throw new Exception("Incomplete specifications, Gatekeeper Service cannot function.");
  85. string scope = serverConfig.GetString("ScopeID", UUID.Zero.ToString());
  86. UUID.TryParse(scope, out m_ScopeID);
  87. //m_WelcomeMessage = serverConfig.GetString("WelcomeMessage", "Welcome to OpenSim!");
  88. m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true);
  89. m_ExternalName = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
  90. new string[] { "Startup", "Hypergrid", "GatekeeperService" }, String.Empty);
  91. m_ExternalName = serverConfig.GetString("ExternalName", m_ExternalName);
  92. if (m_ExternalName != string.Empty && !m_ExternalName.EndsWith("/"))
  93. m_ExternalName = m_ExternalName + "/";
  94. try
  95. {
  96. m_Uri = new Uri(m_ExternalName);
  97. }
  98. catch
  99. {
  100. m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed gatekeeper address {0}", m_ExternalName);
  101. }
  102. Object[] args = new Object[] { config };
  103. m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
  104. m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
  105. if (accountService != string.Empty)
  106. m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
  107. if (homeUsersService != string.Empty)
  108. m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args);
  109. if (gridUserService != string.Empty)
  110. m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
  111. if (bansService != string.Empty)
  112. m_BansService = ServerUtils.LoadPlugin<IBansService>(bansService, args);
  113. if (simService != null)
  114. m_SimulationService = simService;
  115. else if (simulationService != string.Empty)
  116. m_SimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args);
  117. string[] possibleAccessControlConfigSections = new string[] { "AccessControl", "GatekeeperService" };
  118. m_AllowedClients = Util.GetConfigVarFromSections<string>(
  119. config, "AllowedClients", possibleAccessControlConfigSections, string.Empty);
  120. m_DeniedClients = Util.GetConfigVarFromSections<string>(
  121. config, "DeniedClients", possibleAccessControlConfigSections, string.Empty);
  122. m_ForeignAgentsAllowed = serverConfig.GetBoolean("ForeignAgentsAllowed", true);
  123. LoadDomainExceptionsFromConfig(serverConfig, "AllowExcept", m_ForeignsAllowedExceptions);
  124. LoadDomainExceptionsFromConfig(serverConfig, "DisallowExcept", m_ForeignsDisallowedExceptions);
  125. if (m_GridService == null || m_PresenceService == null || m_SimulationService == null)
  126. throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function.");
  127. IConfig presenceConfig = config.Configs["PresenceService"];
  128. if (presenceConfig != null)
  129. {
  130. m_allowDuplicatePresences = presenceConfig.GetBoolean("AllowDuplicatePresences", m_allowDuplicatePresences);
  131. }
  132. m_log.Debug("[GATEKEEPER SERVICE]: Starting...");
  133. }
  134. }
  135. public GatekeeperService(IConfigSource config)
  136. : this(config, null)
  137. {
  138. }
  139. protected void LoadDomainExceptionsFromConfig(IConfig config, string variable, List<string> exceptions)
  140. {
  141. string value = config.GetString(variable, string.Empty);
  142. string[] parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  143. foreach (string s in parts)
  144. exceptions.Add(s.Trim());
  145. }
  146. public bool LinkRegion(string regionName, out UUID regionID, out ulong regionHandle, out string externalName, out string imageURL, out string reason, out int sizeX, out int sizeY)
  147. {
  148. regionID = UUID.Zero;
  149. regionHandle = 0;
  150. sizeX = (int)Constants.RegionSize;
  151. sizeY = (int)Constants.RegionSize;
  152. externalName = m_ExternalName + ((regionName != string.Empty) ? " " + regionName : "");
  153. imageURL = string.Empty;
  154. reason = string.Empty;
  155. GridRegion region = null;
  156. m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName == string.Empty)? "default region" : regionName);
  157. if (!m_AllowTeleportsToAnyRegion || regionName == string.Empty)
  158. {
  159. List<GridRegion> defs = m_GridService.GetDefaultHypergridRegions(m_ScopeID);
  160. if (defs != null && defs.Count > 0)
  161. {
  162. region = defs[0];
  163. m_DefaultGatewayRegion = region;
  164. }
  165. else
  166. {
  167. reason = "Grid setup problem. Try specifying a particular region here.";
  168. m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to send information. Please specify a default region for this grid!");
  169. return false;
  170. }
  171. }
  172. else
  173. {
  174. region = m_GridService.GetRegionByName(m_ScopeID, regionName);
  175. if (region == null)
  176. {
  177. reason = "Region not found";
  178. return false;
  179. }
  180. }
  181. regionID = region.RegionID;
  182. regionHandle = region.RegionHandle;
  183. sizeX = region.RegionSizeX;
  184. sizeY = region.RegionSizeY;
  185. string regionimage = "regionImage" + regionID.ToString();
  186. regionimage = regionimage.Replace("-", "");
  187. imageURL = region.ServerURI + "index.php?method=" + regionimage;
  188. return true;
  189. }
  190. public GridRegion GetHyperlinkRegion(UUID regionID, UUID agentID, string agentHomeURI, out string message)
  191. {
  192. message = null;
  193. if (!m_AllowTeleportsToAnyRegion)
  194. {
  195. // Don't even check the given regionID
  196. m_log.DebugFormat(
  197. "[GATEKEEPER SERVICE]: Returning gateway region {0} {1} @ {2} to user {3}{4} as teleporting to arbitrary regions is not allowed.",
  198. m_DefaultGatewayRegion.RegionName,
  199. m_DefaultGatewayRegion.RegionID,
  200. m_DefaultGatewayRegion.ServerURI,
  201. agentID,
  202. agentHomeURI == null ? "" : " @ " + agentHomeURI);
  203. message = "Teleporting to the default region.";
  204. return m_DefaultGatewayRegion;
  205. }
  206. GridRegion region = m_GridService.GetRegionByUUID(m_ScopeID, regionID);
  207. if (region == null)
  208. {
  209. m_log.DebugFormat(
  210. "[GATEKEEPER SERVICE]: Could not find region with ID {0} as requested by user {1}{2}. Returning null.",
  211. regionID, agentID, (agentHomeURI == null) ? "" : " @ " + agentHomeURI);
  212. message = "The teleport destination could not be found.";
  213. return null;
  214. }
  215. m_log.DebugFormat(
  216. "[GATEKEEPER SERVICE]: Returning region {0} {1} @ {2} to user {3}{4}.",
  217. region.RegionName,
  218. region.RegionID,
  219. region.ServerURI,
  220. agentID,
  221. agentHomeURI == null ? "" : " @ " + agentHomeURI);
  222. return region;
  223. }
  224. #region Login Agent
  225. public bool LoginAgent(GridRegion source, AgentCircuitData aCircuit, GridRegion destination, out string reason)
  226. {
  227. reason = string.Empty;
  228. string authURL = string.Empty;
  229. if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
  230. authURL = aCircuit.ServiceURLs["HomeURI"].ToString();
  231. m_log.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2} ({3}) at {4} using viewer {5}, channel {6}, IP {7}, Mac {8}, Id0 {9}, Teleport Flags: {10}. From region {11}",
  232. aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionID,
  233. aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, (TeleportFlags)aCircuit.teleportFlags,
  234. (source == null) ? "Unknown" : string.Format("{0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI));
  235. string curViewer = Util.GetViewerName(aCircuit);
  236. //
  237. // Check client
  238. //
  239. if (m_AllowedClients != string.Empty)
  240. {
  241. Regex arx = new Regex(m_AllowedClients);
  242. Match am = arx.Match(curViewer);
  243. if (!am.Success)
  244. {
  245. reason = "Login failed: client " + curViewer + " is not allowed";
  246. m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer);
  247. return false;
  248. }
  249. }
  250. if (m_DeniedClients != string.Empty)
  251. {
  252. Regex drx = new Regex(m_DeniedClients);
  253. Match dm = drx.Match(curViewer);
  254. if (dm.Success)
  255. {
  256. reason = "Login failed: client " + curViewer + " is denied";
  257. m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer);
  258. return false;
  259. }
  260. }
  261. //
  262. // Authenticate the user
  263. //
  264. if (!Authenticate(aCircuit))
  265. {
  266. reason = "Unable to verify identity";
  267. m_log.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname);
  268. return false;
  269. }
  270. m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL);
  271. //
  272. // Check for impersonations
  273. //
  274. UserAccount account = null;
  275. if (m_UserAccountService != null)
  276. {
  277. // Check to see if we have a local user with that UUID
  278. account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID);
  279. if (account != null)
  280. {
  281. // Make sure this is the user coming home, and not a foreign user with same UUID as a local user
  282. if (m_UserAgentService != null)
  283. {
  284. if (!m_UserAgentService.IsAgentComingHome(aCircuit.SessionID, m_ExternalName))
  285. {
  286. // Can't do, sorry
  287. reason = "Unauthorized";
  288. m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.",
  289. aCircuit.firstname, aCircuit.lastname);
  290. return false;
  291. }
  292. }
  293. }
  294. }
  295. //
  296. // Foreign agents allowed? Exceptions?
  297. //
  298. if (account == null)
  299. {
  300. bool allowed = m_ForeignAgentsAllowed;
  301. if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions))
  302. allowed = false;
  303. if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions))
  304. allowed = true;
  305. if (!allowed)
  306. {
  307. reason = "Destination does not allow visitors from your world";
  308. m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agents are not permitted {0} {1} @ {2}. Refusing service.",
  309. aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs["HomeURI"]);
  310. return false;
  311. }
  312. }
  313. //
  314. // Is the user banned?
  315. // This uses a Ban service that's more powerful than the configs
  316. //
  317. string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit));
  318. if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL))
  319. {
  320. reason = "You are banned from this world";
  321. m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui);
  322. return false;
  323. }
  324. UUID agentID = aCircuit.AgentID;
  325. if(agentID == new UUID("6571e388-6218-4574-87db-f9379718315e"))
  326. {
  327. // really?
  328. reason = "Invalid account ID";
  329. return false;
  330. }
  331. if(m_GridUserService != null)
  332. {
  333. string PrincipalIDstr = agentID.ToString();
  334. GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr);
  335. if(!m_allowDuplicatePresences)
  336. {
  337. if(guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero)
  338. {
  339. if(SendAgentGodKillToRegion(UUID.Zero, agentID, guinfo))
  340. {
  341. m_log.InfoFormat(
  342. "[GATEKEEPER SERVICE]: Login failed for {0} {1}, reason: already logged in",
  343. account.FirstName, account.LastName);
  344. reason = "You appear to be already logged in on the destination grid " +
  345. "Please wait a a minute or two and retry. " +
  346. "If this takes longer than a few minutes please contact the grid owner.";
  347. return false;
  348. }
  349. }
  350. }
  351. }
  352. m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name);
  353. bool isFirstLogin = false;
  354. //
  355. // Login the presence, if it's not there yet (by the login service)
  356. //
  357. PresenceInfo presence = m_PresenceService.GetAgent(aCircuit.SessionID);
  358. if (presence != null) // it has been placed there by the login service
  359. isFirstLogin = true;
  360. else
  361. {
  362. if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID))
  363. {
  364. reason = "Unable to login presence";
  365. m_log.InfoFormat("[GATEKEEPER SERVICE]: Presence login failed for foreign agent {0} {1}. Refusing service.",
  366. aCircuit.firstname, aCircuit.lastname);
  367. return false;
  368. }
  369. }
  370. //
  371. // Get the region
  372. //
  373. destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID);
  374. if (destination == null)
  375. {
  376. reason = "Destination region not found";
  377. return false;
  378. }
  379. m_log.DebugFormat(
  380. "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name);
  381. //
  382. // Adjust the visible name
  383. //
  384. if (account != null)
  385. {
  386. aCircuit.firstname = account.FirstName;
  387. aCircuit.lastname = account.LastName;
  388. }
  389. if (account == null)
  390. {
  391. if (!aCircuit.lastname.StartsWith("@"))
  392. aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname;
  393. try
  394. {
  395. Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString());
  396. aCircuit.lastname = "@" + uri.Authority;
  397. }
  398. catch
  399. {
  400. m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]);
  401. aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString();
  402. }
  403. }
  404. //
  405. // Finally launch the agent at the destination
  406. //
  407. Constants.TeleportFlags loginFlag = isFirstLogin ? Constants.TeleportFlags.ViaLogin : Constants.TeleportFlags.ViaHGLogin;
  408. // Preserve our TeleportFlags we have gathered so-far
  409. loginFlag |= (Constants.TeleportFlags) aCircuit.teleportFlags;
  410. m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0}, Teleport Flags: {1}", aCircuit.Name, loginFlag);
  411. EntityTransferContext ctx = new EntityTransferContext();
  412. if (!m_SimulationService.QueryAccess(
  413. destination, aCircuit.AgentID, aCircuit.ServiceURLs["HomeURI"].ToString(),
  414. true, aCircuit.startpos, new List<UUID>(), ctx, out reason))
  415. return false;
  416. bool didit = m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, ctx, out reason);
  417. if(didit)
  418. {
  419. m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name);
  420. if(!isFirstLogin && m_GridUserService != null && account == null)
  421. {
  422. // Also login foreigners with GridUser service
  423. string userId = aCircuit.AgentID.ToString();
  424. string first = aCircuit.firstname, last = aCircuit.lastname;
  425. if (last.StartsWith("@"))
  426. {
  427. string[] parts = aCircuit.firstname.Split('.');
  428. if (parts.Length >= 2)
  429. {
  430. first = parts[0];
  431. last = parts[1];
  432. }
  433. }
  434. userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last;
  435. m_GridUserService.LoggedIn(userId);
  436. }
  437. }
  438. return didit;
  439. }
  440. protected bool Authenticate(AgentCircuitData aCircuit)
  441. {
  442. if (!CheckAddress(aCircuit.ServiceSessionID))
  443. return false;
  444. if (string.IsNullOrEmpty(aCircuit.IPAddress))
  445. {
  446. m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide a client IP address.");
  447. return false;
  448. }
  449. string userURL = string.Empty;
  450. if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
  451. userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
  452. if (userURL == string.Empty)
  453. {
  454. m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide an authentication server URL");
  455. return false;
  456. }
  457. if (userURL == m_ExternalName)
  458. {
  459. return m_UserAgentService.VerifyAgent(aCircuit.SessionID, aCircuit.ServiceSessionID);
  460. }
  461. else
  462. {
  463. IUserAgentService userAgentService = new UserAgentServiceConnector(userURL);
  464. try
  465. {
  466. return userAgentService.VerifyAgent(aCircuit.SessionID, aCircuit.ServiceSessionID);
  467. }
  468. catch
  469. {
  470. m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to contact authentication service at {0}", userURL);
  471. return false;
  472. }
  473. }
  474. }
  475. // Check that the service token was generated for *this* grid.
  476. // If it wasn't then that's a fake agent.
  477. protected bool CheckAddress(string serviceToken)
  478. {
  479. string[] parts = serviceToken.Split(new char[] { ';' });
  480. if (parts.Length < 2)
  481. return false;
  482. char[] trailing_slash = new char[] { '/' };
  483. string addressee = parts[0].TrimEnd(trailing_slash);
  484. string externalname = m_ExternalName.TrimEnd(trailing_slash);
  485. m_log.DebugFormat("[GATEKEEPER SERVICE]: Verifying {0} against {1}", addressee, externalname);
  486. Uri uri;
  487. try
  488. {
  489. uri = new Uri(addressee);
  490. }
  491. catch
  492. {
  493. m_log.DebugFormat("[GATEKEEPER SERVICE]: Visitor provided malformed service address {0}", addressee);
  494. return false;
  495. }
  496. return string.Equals(uri.GetLeftPart(UriPartial.Authority), m_Uri.GetLeftPart(UriPartial.Authority), StringComparison.OrdinalIgnoreCase) ;
  497. }
  498. #endregion
  499. #region Misc
  500. private bool IsException(AgentCircuitData aCircuit, List<string> exceptions)
  501. {
  502. bool exception = false;
  503. if (exceptions.Count > 0) // we have exceptions
  504. {
  505. // Retrieve the visitor's origin
  506. string userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
  507. if (!userURL.EndsWith("/"))
  508. userURL += "/";
  509. if (exceptions.Find(delegate(string s)
  510. {
  511. if (!s.EndsWith("/"))
  512. s += "/";
  513. return s == userURL;
  514. }) != null)
  515. exception = true;
  516. }
  517. return exception;
  518. }
  519. private bool SendAgentGodKillToRegion(UUID scopeID, UUID agentID , GridUserInfo guinfo)
  520. {
  521. UUID regionID = guinfo.LastRegionID;
  522. GridRegion regInfo = m_GridService.GetRegionByUUID(scopeID, regionID);
  523. if(regInfo == null)
  524. return false;
  525. string regURL = regInfo.ServerURI;
  526. if(String.IsNullOrEmpty(regURL))
  527. return false;
  528. UUID guuid = new UUID("6571e388-6218-4574-87db-f9379718315e");
  529. GridInstantMessage msg = new GridInstantMessage();
  530. msg.imSessionID = UUID.Zero.Guid;
  531. msg.fromAgentID = guuid.Guid;
  532. msg.toAgentID = agentID.Guid;
  533. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  534. msg.fromAgentName = "GRID";
  535. msg.message = string.Format("New login detected");
  536. msg.dialog = 250; // God kick
  537. msg.fromGroup = false;
  538. msg.offline = (byte)0;
  539. msg.ParentEstateID = 0;
  540. msg.Position = Vector3.Zero;
  541. msg.RegionID = scopeID.Guid;
  542. msg.binaryBucket = new byte[1] {0};
  543. InstantMessageServiceConnector.SendInstantMessage(regURL,msg);
  544. m_GridUserService.LoggedOut(agentID.ToString(),
  545. UUID.Zero, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt);
  546. return true;
  547. }
  548. #endregion
  549. }
  550. }