From ca7b9ebb9bf12a5cf37efe96e1d4994685ac7286 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Thu, 18 Jan 2007 06:39:03 +0000 Subject: [PATCH] Bug 235624. Fix GUI hang on multiple file imports. --- CASA/gui/CasaMain.cs | 11 +++--- CASA/gui/ImportSecrets.cs | 5 ++- CASA/gui/MiCasa.cs | 53 +++++++++++++++++++------- CASA/sharp/NSSCSWrapper/SecretStore.cs | 12 +++++- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/CASA/gui/CasaMain.cs b/CASA/gui/CasaMain.cs index f87a30d3..ca3a712b 100644 --- a/CASA/gui/CasaMain.cs +++ b/CASA/gui/CasaMain.cs @@ -2188,11 +2188,12 @@ namespace Novell.CASA.GUI } public void on_importSecrets_activate(object obj, EventArgs args) - { - ImportSecrets importSecrets = new ImportSecrets(config, objMiCasa); - importSecrets.Run(); - if (objMiCasa != null) - objMiCasa.AggregateStore(); + { + if (objMiCasa != null) + { + objMiCasa.DoFileImport(config); + objMiCasa.AggregateStore(); + } } diff --git a/CASA/gui/ImportSecrets.cs b/CASA/gui/ImportSecrets.cs index 0dbfee88..44383775 100644 --- a/CASA/gui/ImportSecrets.cs +++ b/CASA/gui/ImportSecrets.cs @@ -43,8 +43,9 @@ namespace Novell.CASA.GUI Gtk.CheckButton cbShowValues; #endregion - public ImportSecrets(Config config, MiCasa objMiCasa) - { + public ImportSecrets(SecretStore ss, Config config, MiCasa objMiCasa) + { + m_ss = ss; m_config = config; m_objMiCasa = objMiCasa; } diff --git a/CASA/gui/MiCasa.cs b/CASA/gui/MiCasa.cs index 79a6f95e..9d87398f 100644 --- a/CASA/gui/MiCasa.cs +++ b/CASA/gui/MiCasa.cs @@ -1425,7 +1425,10 @@ public class MiCasa : Store string value = null; if (tvKeyValue.Selection.GetSelected(out model, out iter)) - { + { + byte[] baValue = new byte[0]; + byte[] baTarget = new byte[0]; + selected = (string)model.GetValue(iter, 0); value = (string)model.GetValue(iter, 1); @@ -1435,24 +1438,24 @@ public class MiCasa : Store SecretStore ss = GetMiCasaStore(); Secret secret = ss.GetSecret(entrySecretID.Text); value = secret.GetKeyValue(selected); - - - + // strip of header data - byte[] baValue = System.Text.Encoding.ASCII.GetBytes(value); - byte[] baTarget = new byte[baValue.Length - 16]; - - Array.Copy(baValue, 13, baTarget, 0, baValue.Length - 16); - try + baValue = System.Text.Encoding.ASCII.GetBytes(value); + if (baValue.Length > 16) + { + baTarget = new byte[baValue.Length - 16]; + Array.Copy(baValue, 13, baTarget, 0, baValue.Length - 16); + } +/* try { baValue = Convert.FromBase64String(System.Text.Encoding.ASCII.GetString(baTarget)); value = System.Text.Encoding.ASCII.GetString(baValue); } catch (Exception e) - { + { value = e.ToString(); } - +*/ } if (selected != null && selected.Length > 0) @@ -1462,16 +1465,31 @@ public class MiCasa : Store // display decoded value //textviewClear.Buffer.Text = value; - char[] array = value.ToCharArray(); + //char[] array = value.ToCharArray(); try { - byte[] bytes = Convert.FromBase64CharArray(array, 0, array.Length); - textviewClear.Buffer.Text = System.Text.Encoding.ASCII.GetString(bytes); + if (baTarget.Length > 0) + { + baValue = Convert.FromBase64String(System.Text.Encoding.ASCII.GetString(baTarget)); + value = System.Text.Encoding.ASCII.GetString(baValue); + textviewClear.Buffer.Text = value; + } + else + { + textviewClear.Buffer.Text = value; + } + + //byte[] bytes = Convert.FromBase64CharArray(array, 0, array.Length); + //textviewClear.Buffer.Text = System.Text.Encoding.ASCII.GetString(bytes); } catch (Exception e) { + // decode failed, open it all textviewClear.Buffer.Text = e.ToString(); + + bttnExpand_Clicked(null, null); + textviewEncoded.Buffer.Text = value; } // hook up button handlers @@ -1531,6 +1549,13 @@ public class MiCasa : Store } } + + internal void DoFileImport(Config config) + { + ImportSecrets importSecrets = new ImportSecrets(GetMiCasaStore(), config, this); + importSecrets.Run(); + } + } } ///################################################################## diff --git a/CASA/sharp/NSSCSWrapper/SecretStore.cs b/CASA/sharp/NSSCSWrapper/SecretStore.cs index 42bf5e79..6e00d753 100644 --- a/CASA/sharp/NSSCSWrapper/SecretStore.cs +++ b/CASA/sharp/NSSCSWrapper/SecretStore.cs @@ -46,6 +46,11 @@ namespace Novell.CASA DoSetup(); } + ~SecretStore() + { + ReleaseInstance(); + } + private void DoSetup() { m_NativeCalls = new NativeCalls(); @@ -61,8 +66,11 @@ namespace Novell.CASA public void ReleaseInstance() { - if (m_hsc != IntPtr.Zero) - m_NativeCalls.CloseSecretStore(m_hsc); + if (m_hsc != IntPtr.Zero) + { + m_NativeCalls.CloseSecretStore(m_hsc); + m_hsc = IntPtr.Zero; + } } /*