Bug 176460. Added a filewatcher on file in question
This commit is contained in:
		| @@ -1,3 +1,7 @@ | |||||||
|  | -------------------------------------------------------------------- | ||||||
|  | Mon Jul 05 12:22:53 MST 2006 - jnorman@novell.com | ||||||
|  | - Bug 176460.  Added a filewatcher on file in question  | ||||||
|  |  | ||||||
| -------------------------------------------------------------------- | -------------------------------------------------------------------- | ||||||
| Mon Jul 03 13:01:53 MST 2006 - jnorman@novell.com | Mon Jul 03 13:01:53 MST 2006 - jnorman@novell.com | ||||||
| - Bug 164181.  Prevent multiple instances of CASAManager on windows. | - Bug 164181.  Prevent multiple instances of CASAManager on windows. | ||||||
|   | |||||||
| @@ -1479,7 +1479,7 @@ namespace Novell.CASA.GUI | |||||||
| 			// check Current MP | 			// check Current MP | ||||||
| 			if (entryOldMP.Text != "") | 			if (entryOldMP.Text != "") | ||||||
| 			{ | 			{ | ||||||
| 				int rcode = miCASA.SetMasterPassword(1, entryOldMP.Text); | 				int rcode = miCASA.SetMasterPassword(0, entryOldMP.Text); | ||||||
| 				if (rcode != 0) | 				if (rcode != 0) | ||||||
| 				{ | 				{ | ||||||
| 					DisplayError("Current Master Password is not correct"); | 					DisplayError("Current Master Password is not correct"); | ||||||
|   | |||||||
							
								
								
									
										127
									
								
								CASA/micasad/cache/MPFileWatcher.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								CASA/micasad/cache/MPFileWatcher.cs
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,127 @@ | |||||||
|  | using System; | ||||||
|  | using System.IO; | ||||||
|  |  | ||||||
|  | using sscs.common; | ||||||
|  |  | ||||||
|  | namespace sscs.cache | ||||||
|  | { | ||||||
|  | 	/// <summary> | ||||||
|  | 	/// Summary description for MPFileWatcher. | ||||||
|  | 	/// </summary> | ||||||
|  | 	public class MPFileWatcher | ||||||
|  | 	{ | ||||||
|  | 		FileSystemWatcher fwatcher; | ||||||
|  | 		private string m_dir = null; | ||||||
|  | 		private string m_filename = null; | ||||||
|  | 		private byte[] m_baMP = new byte[32]; | ||||||
|  | 		private byte[] m_baMPIV = new byte[32]; | ||||||
|  | 		private bool m_bIgnoreFileDeletes = false; | ||||||
|  |  | ||||||
|  | 		public MPFileWatcher(string MPFilePath, string MPFileName) | ||||||
|  | 		{	 | ||||||
|  | 			m_dir = MPFilePath; | ||||||
|  | 			m_filename = MPFileName; | ||||||
|  |  | ||||||
|  | 			if ((MPFilePath != null) && (MPFileName != null)) | ||||||
|  | 			{ | ||||||
|  | 				LogMessage("Starting MPFile watcher on " + MPFilePath + "/" + MPFileName.Substring(1)); | ||||||
|  | 				fwatcher = new FileSystemWatcher(MPFilePath); | ||||||
|  | 				fwatcher.Filter = MPFileName.Substring(1)+"*"; | ||||||
|  | 				fwatcher.Deleted += new FileSystemEventHandler(fwatcher_Deleted); | ||||||
|  | 				fwatcher.Renamed += new RenamedEventHandler(fwatcher_Renamed); | ||||||
|  | 				fwatcher.Changed += new FileSystemEventHandler(fwatcher_Changed); | ||||||
|  | 				fwatcher.EnableRaisingEvents = true; | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			if (File.Exists(MPFilePath + MPFileName)) | ||||||
|  | 			{ | ||||||
|  | 				LoadAndCacheMPFiles(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		~MPFileWatcher() | ||||||
|  | 		{ | ||||||
|  | 			if (fwatcher != null) | ||||||
|  | 				fwatcher.EnableRaisingEvents = false; | ||||||
|  | 			fwatcher = null; | ||||||
|  | 		} | ||||||
|  | 		internal void pauseWatcher() | ||||||
|  | 		{ | ||||||
|  | 			m_bIgnoreFileDeletes = true; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		internal void resumeWatcher() | ||||||
|  | 		{ | ||||||
|  | 			m_bIgnoreFileDeletes = false; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private void fwatcher_Deleted(object sender, FileSystemEventArgs e) | ||||||
|  | 		{ | ||||||
|  | 			if (!m_bIgnoreFileDeletes) | ||||||
|  | 			{ | ||||||
|  | 				LogMessage("MP file deleted"); | ||||||
|  | 				ReWriteFiles(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private void fwatcher_Changed(object sender, FileSystemEventArgs e) | ||||||
|  | 		{ | ||||||
|  | 			LogMessage("MP file Changed"); | ||||||
|  | 			LoadAndCacheMPFiles(); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private void fwatcher_Renamed(object sender, RenamedEventArgs e) | ||||||
|  | 		{ | ||||||
|  | 			LogMessage("MP file renamed"); | ||||||
|  | 			fwatcher_Deleted(sender, e); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private void LoadAndCacheMPFiles() | ||||||
|  | 		{ | ||||||
|  | 			LogMessage("Loading and caching MP files"); | ||||||
|  |  | ||||||
|  | 			try  | ||||||
|  | 			{ | ||||||
|  | 				FileStream fs = new FileStream(m_dir + m_filename, FileMode.Open); | ||||||
|  | 				fs.Read(m_baMP, 0, m_baMP.Length); | ||||||
|  | 				fs.Flush(); | ||||||
|  | 				fs.Close(); | ||||||
|  |  | ||||||
|  | 				fs = new FileStream(m_dir + m_filename + ".IV", FileMode.Open); | ||||||
|  | 				fs.Read(m_baMPIV, 0, m_baMPIV.Length); | ||||||
|  | 				fs.Flush(); | ||||||
|  | 				fs.Close(); | ||||||
|  | 			} | ||||||
|  | 			catch (Exception e) | ||||||
|  | 			{ | ||||||
|  | 				LogMessage(e.ToString()); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		private void ReWriteFiles() | ||||||
|  | 		{ | ||||||
|  | 			try | ||||||
|  | 			{ | ||||||
|  | 				FileStream fs = new FileStream(m_dir + m_filename, FileMode.Create); | ||||||
|  | 				fs.Write(m_baMP, 0, m_baMP.Length); | ||||||
|  | 				fs.Flush(); | ||||||
|  | 				fs.Close(); | ||||||
|  |  | ||||||
|  | 				fs = new FileStream(m_dir + m_filename + ".IV", FileMode.Create); | ||||||
|  | 				fs.Write(m_baMPIV, 0, m_baMPIV.Length); | ||||||
|  | 				fs.Flush(); | ||||||
|  | 				fs.Close();			 | ||||||
|  | 			} | ||||||
|  | 			catch (Exception e) | ||||||
|  | 			{ | ||||||
|  | 				LogMessage(e.ToString()); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private void LogMessage(string message) | ||||||
|  | 		{ | ||||||
|  | 			Console.WriteLine(message); | ||||||
|  | 			CSSSLogger.DbgLog("MPFileWatcher:" + message); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										11
									
								
								CASA/micasad/cache/SecretStore.cs
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								CASA/micasad/cache/SecretStore.cs
									
									
									
									
										vendored
									
									
								
							| @@ -55,6 +55,8 @@ namespace sscs.cache | |||||||
|         private LocalStorage lss = null;  |         private LocalStorage lss = null;  | ||||||
|         bool bIsStorePersistent = false;  |         bool bIsStorePersistent = false;  | ||||||
| 		 | 		 | ||||||
|  | 		private MPFileWatcher mpWatcher = null; | ||||||
|  |  | ||||||
|         private DateTime createTime; |         private DateTime createTime; | ||||||
|         public DateTime CreateTime |         public DateTime CreateTime | ||||||
|         { |         { | ||||||
| @@ -83,6 +85,13 @@ namespace sscs.cache | |||||||
|             keyChainList    = Hashtable.Synchronized(tKeyChainList); |             keyChainList    = Hashtable.Synchronized(tKeyChainList); | ||||||
|              |              | ||||||
|             ssMutex = new Mutex();   |             ssMutex = new Mutex();   | ||||||
|  |  | ||||||
|  | 			// start a MPFileWatcher if necessary | ||||||
|  | 			if (mpWatcher == null) | ||||||
|  | 			{ | ||||||
|  | 				mpWatcher = new MPFileWatcher(GetUserHomeDirectory(), ConstStrings.MICASA_PASSCODE_BY_MASTERPASSWD_FILE); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         internal bool IsStorePersistent() |         internal bool IsStorePersistent() | ||||||
| @@ -721,7 +730,9 @@ namespace sscs.cache | |||||||
| 			byte[] baPasscode = CASACrypto.GetMasterPasscodeUsingMasterPasswd(sCurrentPWD, sMasterFilePath, false); | 			byte[] baPasscode = CASACrypto.GetMasterPasscodeUsingMasterPasswd(sCurrentPWD, sMasterFilePath, false); | ||||||
| 			if (baPasscode != null) | 			if (baPasscode != null) | ||||||
| 			{ | 			{ | ||||||
|  | 				mpWatcher.pauseWatcher(); | ||||||
| 				CASACrypto.EncryptAndStoreMasterPasscodeUsingString(baPasscode, sNewPWD, sMasterFilePath); | 				CASACrypto.EncryptAndStoreMasterPasscodeUsingString(baPasscode, sNewPWD, sMasterFilePath); | ||||||
|  | 				mpWatcher.resumeWatcher(); | ||||||
| 				return true; | 				return true; | ||||||
| 			} | 			} | ||||||
| 			return false; | 			return false; | ||||||
|   | |||||||
| @@ -158,6 +158,11 @@ | |||||||
|                     SubType = "Code" |                     SubType = "Code" | ||||||
|                     BuildAction = "Compile" |                     BuildAction = "Compile" | ||||||
|                 /> |                 /> | ||||||
|  |                 <File | ||||||
|  |                     RelPath = "cache\MPFileWatcher.cs" | ||||||
|  |                     SubType = "Code" | ||||||
|  |                     BuildAction = "Compile" | ||||||
|  |                 /> | ||||||
|                 <File |                 <File | ||||||
|                     RelPath = "cache\Secret.cs" |                     RelPath = "cache\Secret.cs" | ||||||
|                     SubType = "Code" |                     SubType = "Code" | ||||||
| @@ -260,7 +265,7 @@ | |||||||
|                 /> |                 /> | ||||||
|                 <File |                 <File | ||||||
|                     RelPath = "init\ProjectInstaller.cs" |                     RelPath = "init\ProjectInstaller.cs" | ||||||
|                     SubType = "Code" |                     SubType = "Component" | ||||||
|                     BuildAction = "Compile" |                     BuildAction = "Compile" | ||||||
|                 /> |                 /> | ||||||
|                 <File |                 <File | ||||||
| @@ -270,7 +275,7 @@ | |||||||
|                 /> |                 /> | ||||||
|                 <File |                 <File | ||||||
|                     RelPath = "init\WinSecretStoreClientService.cs" |                     RelPath = "init\WinSecretStoreClientService.cs" | ||||||
|                     SubType = "Code" |                     SubType = "Component" | ||||||
|                     BuildAction = "Compile" |                     BuildAction = "Compile" | ||||||
|                 /> |                 /> | ||||||
|                 <File |                 <File | ||||||
| @@ -359,6 +364,11 @@ | |||||||
|                     SubType = "Code" |                     SubType = "Code" | ||||||
|                     BuildAction = "Compile" |                     BuildAction = "Compile" | ||||||
|                 /> |                 /> | ||||||
|  |                 <File | ||||||
|  |                     RelPath = "verbs\RemoveKey.cs" | ||||||
|  |                     SubType = "Code" | ||||||
|  |                     BuildAction = "Compile" | ||||||
|  |                 /> | ||||||
|                 <File |                 <File | ||||||
|                     RelPath = "verbs\RemoveKeyChain.cs" |                     RelPath = "verbs\RemoveKeyChain.cs" | ||||||
|                     SubType = "Code" |                     SubType = "Code" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user