diff --git a/CASA/CASA.changes b/CASA/CASA.changes index 9dd8fa38..23fc6c00 100644 --- a/CASA/CASA.changes +++ b/CASA/CASA.changes @@ -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 - Bug 164181. Prevent multiple instances of CASAManager on windows. diff --git a/CASA/gui/CasaMain.cs b/CASA/gui/CasaMain.cs index 80a1d824..e41d5c8b 100644 --- a/CASA/gui/CasaMain.cs +++ b/CASA/gui/CasaMain.cs @@ -1479,7 +1479,7 @@ namespace Novell.CASA.GUI // check Current MP if (entryOldMP.Text != "") { - int rcode = miCASA.SetMasterPassword(1, entryOldMP.Text); + int rcode = miCASA.SetMasterPassword(0, entryOldMP.Text); if (rcode != 0) { DisplayError("Current Master Password is not correct"); diff --git a/CASA/micasad/cache/MPFileWatcher.cs b/CASA/micasad/cache/MPFileWatcher.cs new file mode 100644 index 00000000..1abc8020 --- /dev/null +++ b/CASA/micasad/cache/MPFileWatcher.cs @@ -0,0 +1,127 @@ +using System; +using System.IO; + +using sscs.common; + +namespace sscs.cache +{ + /// + /// Summary description for MPFileWatcher. + /// + 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); + } + } +} diff --git a/CASA/micasad/cache/SecretStore.cs b/CASA/micasad/cache/SecretStore.cs index cbd9a79c..93bf2ae2 100644 --- a/CASA/micasad/cache/SecretStore.cs +++ b/CASA/micasad/cache/SecretStore.cs @@ -54,6 +54,8 @@ namespace sscs.cache private LocalStorage lss = null; bool bIsStorePersistent = false; + + private MPFileWatcher mpWatcher = null; private DateTime createTime; public DateTime CreateTime @@ -83,6 +85,13 @@ namespace sscs.cache keyChainList = Hashtable.Synchronized(tKeyChainList); ssMutex = new Mutex(); + + // start a MPFileWatcher if necessary + if (mpWatcher == null) + { + mpWatcher = new MPFileWatcher(GetUserHomeDirectory(), ConstStrings.MICASA_PASSCODE_BY_MASTERPASSWD_FILE); + } + } internal bool IsStorePersistent() @@ -721,7 +730,9 @@ namespace sscs.cache byte[] baPasscode = CASACrypto.GetMasterPasscodeUsingMasterPasswd(sCurrentPWD, sMasterFilePath, false); if (baPasscode != null) { + mpWatcher.pauseWatcher(); CASACrypto.EncryptAndStoreMasterPasscodeUsingString(baPasscode, sNewPWD, sMasterFilePath); + mpWatcher.resumeWatcher(); return true; } return false; diff --git a/CASA/micasad/micasad.csproj b/CASA/micasad/micasad.csproj index f015f932..f055a87c 100644 --- a/CASA/micasad/micasad.csproj +++ b/CASA/micasad/micasad.csproj @@ -158,6 +158,11 @@ SubType = "Code" BuildAction = "Compile" /> + +