diff --git a/OpenSim/Data/IRegionData.cs b/OpenSim/Data/IRegionData.cs index 140bc961af..9ed5dd02e3 100644 --- a/OpenSim/Data/IRegionData.cs +++ b/OpenSim/Data/IRegionData.cs @@ -72,6 +72,9 @@ namespace OpenSim.Data RegionOnline = 4, // Set when a region comes online, unset when it unregisters and DeleteOnUnregister is false NoDirectLogin = 8, // Region unavailable for direct logins (by name) Persistent = 16, // Don't remove on unregister - LockedOut = 32 // Don't allow registration + LockedOut = 32, // Don't allow registration + NoMove = 64, // Don't allow moving this region + Reservation = 128, // This is an inactive reservation + Authenticate = 256 // Require authentication } } diff --git a/OpenSim/Data/MySQL/Resources/007_GridStore.sql b/OpenSim/Data/MySQL/Resources/007_GridStore.sql new file mode 100644 index 0000000000..3f88d3d907 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/007_GridStore.sql @@ -0,0 +1,6 @@ +BEGIN; + +ALTER TABLE `regions` ADD COLUMN `PrincipalID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; + +COMMIT; + diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index 4f93ce56b2..5c55c0b473 100644 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs @@ -34,6 +34,7 @@ using log4net; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Data; +using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenMetaverse; @@ -50,6 +51,8 @@ namespace OpenSim.Services.GridService private static GridService m_RootInstance = null; protected IConfigSource m_config; + protected IAuthenticationService m_AuthenticationService = null; + public GridService(IConfigSource config) : base(config) { @@ -60,6 +63,14 @@ namespace OpenSim.Services.GridService if (gridConfig != null) { m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true); + + string authService = gridConfig.GetString("AuthenticationService", String.Empty); + + if (authService != String.Empty) + { + Object[] args = new Object[] { config }; + m_AuthenticationService = ServerUtils.LoadPlugin(authService, args); + } } if (m_RootInstance == null) @@ -90,6 +101,46 @@ namespace OpenSim.Services.GridService // This needs better sanity testing. What if regionInfo is registering in // overlapping coords? RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); + if (region != null) + { + // There is a preexisting record + // + // Get it's flags + // + OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(region.Data["Flags"]); + + // Is this a reservation? + // + if ((rflags & OpenSim.Data.RegionFlags.Reservation) != 0) + { + // Regions reserved for the null key cannot be taken. + // + if (region.Data["PrincipalID"] == UUID.Zero.ToString()) + return false; + + // Treat it as an auth request + // + // NOTE: Fudging the flags value here, so these flags + // should not be used elsewhere. Don't optimize + // this with the later retrieval of the same flags! + // + rflags |= OpenSim.Data.RegionFlags.Authenticate; + } + + if ((rflags & OpenSim.Data.RegionFlags.Authenticate) != 0) + { + // Can we authenticate at all? + // + if (m_AuthenticationService == null) + return false; + + if (!m_AuthenticationService.Verify(new UUID(region.Data["PrincipalID"].ToString()), regionInfos.Token, 30)) + return false; + + return false; + } + } + if ((region != null) && (region.RegionID != regionInfos.RegionID)) { m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", @@ -99,6 +150,9 @@ namespace OpenSim.Services.GridService if ((region != null) && (region.RegionID == regionInfos.RegionID) && ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) { + if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Data.RegionFlags.NoMove) != 0) + return false; + // Region reregistering in other coordinates. Delete the old entry m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) was previously registered at {2}-{3}. Deleting old entry.", regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY); @@ -119,10 +173,13 @@ namespace OpenSim.Services.GridService if (region != null) { - if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Data.RegionFlags.LockedOut) != 0) + int oldFlags = Convert.ToInt32(region.Data["flags"]); + if ((oldFlags & (int)OpenSim.Data.RegionFlags.LockedOut) != 0) return false; - rdata.Data["flags"] = region.Data["flags"]; // Preserve fields + oldFlags &= ~(int)OpenSim.Data.RegionFlags.Reservation; + + rdata.Data["flags"] = oldFlags.ToString(); // Preserve flags } else { diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index cd27145ee7..6b6b34797a 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -159,6 +159,7 @@ namespace OpenSim.Services.Interfaces public byte Access; public int Maturity; public string RegionSecret; + public string Token; public GridRegion() { @@ -306,6 +307,7 @@ namespace OpenSim.Services.Interfaces kvp["access"] = Access.ToString(); kvp["regionSecret"] = RegionSecret; kvp["owner_uuid"] = EstateOwner.ToString(); + kvp["token"] = Token.ToString(); // Maturity doesn't seem to exist in the DB return kvp; } @@ -363,6 +365,9 @@ namespace OpenSim.Services.Interfaces if (kvp.ContainsKey("owner_uuid")) EstateOwner = new UUID(kvp["owner_uuid"].ToString()); + if (kvp.ContainsKey("token")) + Token = kvp["token"].ToString(); + } } diff --git a/prebuild.xml b/prebuild.xml index fbb782a750..284913a68c 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1056,6 +1056,7 @@ +