From 35260faead29c590bf01c1eb02130cfac22c38ad Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 16 Sep 2009 18:20:55 +0100
Subject: on iar save/load, let the user know if they put in the wrong password
 refactor GetUserInfo() to eliminate copypasta

---
 .../Inventory/Archiver/InventoryArchiverModule.cs  | 39 ++++++++++------------
 OpenSim/Region/Framework/Scenes/Scene.cs           |  5 +--
 2 files changed, 18 insertions(+), 26 deletions(-)

(limited to 'OpenSim')

diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
index 1937637..9f49da9 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs
@@ -125,10 +125,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
         {
             if (m_scenes.Count > 0)
             {
-                CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
-                string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(pass) + ":" + userInfo.UserProfile.PasswordSalt);
-                if (userInfo.UserProfile.PasswordHash != md5PasswdHash)
-                    return false;
+                CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass);
 
                 if (userInfo != null)
                 {
@@ -153,11 +150,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
         {
             if (m_scenes.Count > 0)
             {
-                CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
-                string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(pass) + ":" + userInfo.UserProfile.PasswordSalt);
-                if (userInfo.UserProfile.PasswordHash != md5PasswdHash)
-                    return false;
-
+                CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass);
                 
                 if (userInfo != null)
                 {
@@ -182,11 +175,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
         {
             if (m_scenes.Count > 0)
             {            
-                CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
-                string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(pass) + ":" + userInfo.UserProfile.PasswordSalt);
-                if (userInfo.UserProfile.PasswordHash != md5PasswdHash)
-                    return false;
-
+                CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass);
                         
                 if (userInfo != null)
                 {
@@ -214,11 +203,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
         {
             if (m_scenes.Count > 0)
             {   
-                CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
-                string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(pass) + ":" + userInfo.UserProfile.PasswordSalt);
-                if (userInfo.UserProfile.PasswordHash != md5PasswdHash)
-                    return false;
-
+                CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass);
                 
                 if (userInfo != null)
                 {
@@ -251,7 +236,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
             if (cmdparams.Length < 6)
             {
                 m_log.Error(
-                    "[INVENTORY ARCHIVER]: usage is load iar <first name> <last name> <inventory path> <password> [<load file path>]");
+                    "[INVENTORY ARCHIVER]: usage is load iar <first name> <last name> <inventory path> <user password> [<load file path>]");
                 return;
             }
 
@@ -282,7 +267,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
             if (cmdparams.Length < 5)
             {
                 m_log.Error(
-                    "[INVENTORY ARCHIVER]: usage is save iar <first name> <last name> <inventory path> <password> [<save file path>]");
+                    "[INVENTORY ARCHIVER]: usage is save iar <first name> <last name> <inventory path> <user password> [<save file path>]");
                 return;
             }
 
@@ -334,8 +319,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
         /// </summary>
         /// <param name="firstName"></param>
         /// <param name="lastName"></param>
+        /// <param name="pass">User password</param>
         /// <returns></returns>
-        protected CachedUserInfo GetUserInfo(string firstName, string lastName)
+        protected CachedUserInfo GetUserInfo(string firstName, string lastName, string pass)
         {
             CachedUserInfo userInfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(firstName, lastName);
             if (null == userInfo)
@@ -345,6 +331,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
                     firstName, lastName);
                 return null;
             }
+
+            string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(pass) + ":" + userInfo.UserProfile.PasswordSalt);
+            if (userInfo.UserProfile.PasswordHash != md5PasswdHash)
+            {
+                m_log.ErrorFormat(
+                    "[INVENTORY ARCHIVER]: Password for user {0} {1} incorrect.  Please try again.", 
+                    firstName, lastName);
+                return null;
+            }
             
             return userInfo;
         }
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 0c2f991..a8028a6 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -994,9 +994,7 @@ namespace OpenSim.Region.Framework.Scenes
 
                     // Loop it
                     if (m_frame == Int32.MaxValue)
-                        m_frame = 0;
-
-                    
+                        m_frame = 0;                   
 
                     otherMS = Environment.TickCount;
                     // run through all entities looking for updates (slow)
@@ -1017,7 +1015,6 @@ namespace OpenSim.Region.Framework.Scenes
                         m_sceneGraph.UpdateEntities();
                     }
 
-
                     // run through entities that have scheduled themselves for
                     // updates looking for updates(faster)
                     if (m_frame % m_update_entitiesquick == 0)
-- 
cgit v1.1