From 72c87b8e2e53bfeb3d12d6f29b1f2cf8ce753229 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Tue, 14 Feb 2006 00:40:33 +0000 Subject: [PATCH] Bug 133386 fixes --- c_adlib/AD_Facade.cs | 855 ++++++++++++++-------------- c_adlib/GKEngine.cs | 20 +- c_adlib/KWalletEngine.cs | 1005 +++++++++++++++++---------------- c_adlib/ad_gk/GnomeKeyring.cs | 34 +- 4 files changed, 975 insertions(+), 939 deletions(-) diff --git a/c_adlib/AD_Facade.cs b/c_adlib/AD_Facade.cs index bc1edb3f..1cf20548 100644 --- a/c_adlib/AD_Facade.cs +++ b/c_adlib/AD_Facade.cs @@ -20,415 +20,446 @@ * ***********************************************************************/ -using System; -using System.Collections; -using System.Xml; -using System.IO; -using System.Collections.Specialized; -using Novell.CASA.DataEngines.Common; -using Novell.CASA.CASAPolicy; -#if LINUX -using Novell.CASA.GUI; -#endif - -namespace Novell.CASA.DataEngines -{ - - public class AD - { - - private miCASAEngine micasaengine; -#if LINUX - private GKEngine gkEngine = null; - private KWalletEngine kwEngine = null; -#endif - private AggregationPol aggPol; - - - public AD() - { - // Always Aggregate miCASA. - micasaengine = new miCASAEngine(); -#if LINUX - kwEngine = new KWalletEngine(); - gkEngine = new GKEngine(); -#endif -/* - - // Reading Policy to see what else needs to be Aggregated. - aggPol = (AggregationPol) ICASAPol.GetPolicy(CASAPolType.AGGREGATION_POL); - if (aggPol != null ) - { - ArrayList stores = aggPol.StoreList; - IEnumerator enumerator = stores.GetEnumerator(); - - while(enumerator.MoveNext()) - { - string storeID = (((Store)(enumerator.Current)).StoreName); - - if(storeID.Equals(ConstStrings.KW)) - { - Logger.DbgLog("A-D Lib: KWallet Set up for Aggregation"); - kwEngine = new KWalletEngine(); - } - else if(storeID.Equals(ConstStrings.GK)) - { - Logger.DbgLog("A-D Lib:Gnome Keyring Set up for Aggregation"); - gkEngine = new GKEngine(); - } - // Console.WriteLine("StoreName = " + ((Store)(enumerator.Current)).StoreName + "StoreId = " + ((Store)(enumerator.Current)).StoreId); - } - } - */ - - } - - public XmlDocument Aggregate() - { -#if LINUX - gkEngine = null; - kwEngine = null; -#endif - //Read the Policy Just before you aggregate - - // Reading Policy to see what else needs to be Aggregated. - aggPol = (AggregationPol) ICASAPol.GetPolicy(CASAPolType.AGGREGATION_POL); - if (aggPol != null ) - { - ArrayList stores = aggPol.StoreList; - IEnumerator enumerator = stores.GetEnumerator(); - - while(enumerator.MoveNext()) - { - string storeID = (((Store)(enumerator.Current)).StoreName); - -#if LINUX - if(storeID.Equals(ConstStrings.KW)) - { - Logger.DbgLog("A-D Lib: KWallet Set up for Aggregation"); - kwEngine = new KWalletEngine(); - } - else if(storeID.Equals(ConstStrings.GK)) - { - Logger.DbgLog("A-D Lib:Gnome Keyring Set up for Aggregation"); - gkEngine = new GKEngine(); - } -#endif - // Console.WriteLine("StoreName = " + ((Store)(enumerator.Current)).StoreName + "StoreId = " + ((Store)(enumerator.Current)).StoreId); - } - } - - - - XmlDocument ccf = new XmlDocument(); - XmlElement elem = ccf.CreateElement("CCF"); - ccf.AppendChild(elem); - - // TBD: Lookup Policy here and maybe send it via constructors - XmlNode micasaEnum = micasaengine.Aggregate(); - if (micasaEnum != null) //Atleast should come incase of no secrets - { - XmlNode gotit = ccf.ImportNode(micasaEnum,true); - ccf.DocumentElement.AppendChild(gotit); - } - else - { - // Null comes only when it failed to talk to miCASA. -#if LINUX - Logger.DbgLog("A-D Lib:Failed to Connect to miCASA"); -#endif - } - -#if LINUX - if (gkEngine != null) - { - XmlNode gkSecrets = gkEngine.Aggregate(); - if( null != gkSecrets ) - { - XmlNode gkImportedNode = ccf.ImportNode(gkSecrets,true); - ccf.DocumentElement.AppendChild(gkImportedNode); - } - else - { - Logger.DbgLog("A-D Lib:Failed to Connect to Gnome Keyring"); - - } - } - - - if(kwEngine != null ) - { - XmlNode KwEnum = kwEngine.Aggregate(); - if (KwEnum != null) //Atleast should come incase of no secrets - { - XmlNode kwImported = ccf.ImportNode(KwEnum,true); - ccf.DocumentElement.AppendChild(kwImported); - } - else - { - // Null comes only when it failed to talk to Kwallet. - Logger.DbgLog("A-D Lib:Failed to Connect to KWallet"); - } - } - -#endif - - - return ccf; - - } - - - - /******************************************************************************** - Modifying a Secret - - SetSecret will modify the Value(s) of a Key(s) for an existing secret - SetSecret will also add new secrets - - public int SetSecret(XmlNode secret, int StoreID) - - Parameters - - secret : Secrets XMLNode - 1. If a Key node of a secret is missing then that key will be deleted - 2. For Gnome keyring, Key having Id "GkPassword" cannot be deleted as - Gnome Api's do not allow it. - 3. All Time nodes for a Secret need not be passed as they cannot be set. - 4. Keyring attributes have a fixed datatype of Int and String. - Currently we support only String types. To support int types CCF needs to be modified accordingly. - 5. SetSecret overloaded method, without the opnType parameter, is not supported for GnomeKeyring - - opnType : Operation Type - ConstStrings.OPERATION_ADD_SECRET - ConstStrings.OPERATION_MODIFY_SECRET - - StoreID : int value - Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET = 3; - Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_GK = 4 - - Returns - An Error code or 0 if operation is successfull. - *********************************************************************************/ - - public int SetSecret(XmlNode secret, int opnType, int StoreID) - { - if (StoreID == ConstStrings.CASA_STORE_MICASA) - return micasaengine.SetSecret(secret, opnType); -#if LINUX - if (StoreID == ConstStrings.CASA_STORE_KWALLET) - return kwEngine.SetSecret(secret, opnType); - if (StoreID == ConstStrings.CASA_STORE_GK) - return gkEngine.SetSecret(secret, opnType); -#endif - else - { -#if LINUX - Logger.DbgLog("A-D Lib:Failed to Set Secret in to miCASA"); -#endif - return -1; - - } - - } - - - - /******************************************************************************** - Modifying a Secret - - SetSecret will modify the Value(s) of a Key(s) for an existing secret - SetSecret will also add new secrets - - public int SetSecret(XmlNode secret, int StoreID) - - Parameters - - secret : Secrets XMLNode - 1. If a Key node of a secret is missing then that key will be deleted - 2. For Gnome keyring, Key having Id "GkPassword" cannot be deleted as - Gnome Api's do not allow it. - 3. All Time nodes for a Secret need not be passed as they cannot be set. - 4. Keyring attributes have a fixed datatype of Int and String. - Currently we support only String types. To support int types CCF needs to be modified accordingly. - - StoreID : int value - Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET = 3; - Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_GK = 4 - - Returns - An Error code or 0 if operation is successfull. - *********************************************************************************/ - - public int SetSecret(XmlNode secret, int StoreID) - { - if (StoreID == ConstStrings.CASA_STORE_MICASA) - return micasaengine.SetSecret(secret); -#if LINUX - if (StoreID == ConstStrings.CASA_STORE_KWALLET) - return kwEngine.SetSecret(secret); - if (StoreID == ConstStrings.CASA_STORE_GK) - return gkEngine.SetSecret(secret); -#endif - else - { -#if LINUX - Logger.DbgLog("A-D Lib:Failed to Set Secret in to miCASA"); -#endif - return -1; - - } - - } - - - public int GetSecret(XmlNode secret, int StoreID) - { - - //TBD: Check for Store ID and call the right DataEngine. - if (StoreID == ConstStrings.CASA_STORE_MICASA) - return micasaengine.GetSecret(secret); - else - { -#if LINUX - Logger.DbgLog("A-D Lib: Failed to Get Secret in to miCASA"); -#endif - return -1; - } - } - - - /******************************************************************************* - Remove will delete a Secret. - - public int Remove(XmlNode secret, int StoreID) - - - Parameters - - secret : Secrets XmlNode - 1. This node will be deleted from its parent. - - - StoreID : int value - Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET = 3; - Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_GK = 4 - - - Returns - An Error code or 0 if operation is successfull. - - *********************************************************************************/ - - public int Remove(XmlNode secret, int StoreID) - { - - if (StoreID == ConstStrings.CASA_STORE_MICASA) - return micasaengine.Remove(secret); -#if LINUX - if (StoreID == ConstStrings.CASA_STORE_KWALLET) - return kwEngine.Remove(secret); - if (StoreID == ConstStrings.CASA_STORE_GK) - return gkEngine.Remove(secret); -#endif - return -1; - } - - public int AggregateStore(XmlDocument outDoc, int StoreID) - { - // This need not be policy aware. GUI knows what its doing. - - XmlNode secEnum; - DataEngine engine; - - XmlNode toproot = outDoc.DocumentElement; - if (toproot == null) - { - XmlElement elem = outDoc.CreateElement("CCF"); - outDoc.AppendChild(elem); - } - - if ( StoreID == ConstStrings.CASA_STORE_MICASA ) // If its miCASA - { - engine = micasaengine; - secEnum = engine.Aggregate(); - if (secEnum != null ) - { - XmlNode root = outDoc.DocumentElement; - XmlNodeList miCASANodes = root.SelectNodes("descendant::miCASA"); - // Console.WriteLine("ADLIB: Count is " + miCASANodes.Count); - if (miCASANodes.Count != 0) // If there is something remove it - { - root.RemoveChild(miCASANodes[0]); - } - XmlNode gotit = outDoc.ImportNode(secEnum,true); - root.AppendChild(gotit); - return ConstStrings.CASA_SUCCESS; - } - else - return ConstStrings.CASA_STORE_NOT_AVAILABLE; - } -#if LINUX - else if( StoreID == ConstStrings.CASA_STORE_GK ) - { - gkEngine = new GKEngine(); - secEnum = gkEngine.Aggregate(); - if (secEnum != null ) - { - XmlNode root = outDoc.DocumentElement; - XmlNodeList gkNode = root.SelectNodes("descendant::GK"); - if (gkNode.Count != 0) // If there is something remove it - { - root.RemoveChild(gkNode[0]); - } - XmlNode gkImportNode = outDoc.ImportNode(secEnum,true); - root.AppendChild(gkImportNode); - return ConstStrings.CASA_SUCCESS; - } - else - return ConstStrings.CASA_STORE_NOT_AVAILABLE; - - } - else if(StoreID == ConstStrings.CASA_STORE_KWALLET) - { - kwEngine = new KWalletEngine(); - secEnum = kwEngine.Aggregate(); - if (secEnum != null ) - { - XmlNode root = outDoc.DocumentElement; - XmlNodeList gkNode = root.SelectNodes("descendant::KWallet"); - if (gkNode.Count != 0) // If there is something remove it - { - root.RemoveChild(gkNode[0]); - } - XmlNode kwImportNode = outDoc.ImportNode(secEnum,true); - root.AppendChild(kwImportNode); - return ConstStrings.CASA_SUCCESS; - } - else - { - //Console.WriteLine("KWallet some issue"); - return ConstStrings.CASA_STORE_NOT_AVAILABLE; - } - - } - - Logger.DbgLog("A-D Lib: Unknown Operation Requested"); -#endif - return ConstStrings.CASA_OPERATION_FAILED; - } - - public int InitAD() - { - - return ConstStrings.CASA_SUCCESS; - } - - - public int CleanUP_AD() - { - - return ConstStrings.CASA_SUCCESS; - } - } -} +using System; +using System.Collections; +using System.Xml; +using System.IO; +using System.Collections.Specialized; +using Novell.CASA.DataEngines.Common; +using Novell.CASA.CASAPolicy; +#if LINUX +using Novell.CASA.GUI; +#endif + +namespace Novell.CASA.DataEngines +{ + + public class AD + { + + private miCASAEngine micasaengine; +#if LINUX + private GKEngine gkEngine = null; + private KWalletEngine kwEngine = null; +#endif + private AggregationPol aggPol; + + + public AD() + { + // Always Aggregate miCASA. + micasaengine = new miCASAEngine(); +#if LINUX + kwEngine = new KWalletEngine(); + gkEngine = new GKEngine(); +#endif +/* + + // Reading Policy to see what else needs to be Aggregated. + aggPol = (AggregationPol) ICASAPol.GetPolicy(CASAPolType.AGGREGATION_POL); + if (aggPol != null ) + { + ArrayList stores = aggPol.StoreList; + IEnumerator enumerator = stores.GetEnumerator(); + + while(enumerator.MoveNext()) + { + string storeID = (((Store)(enumerator.Current)).StoreName); + + if(storeID.Equals(ConstStrings.KW)) + { + Logger.DbgLog("A-D Lib: KWallet Set up for Aggregation"); + kwEngine = new KWalletEngine(); + } + else if(storeID.Equals(ConstStrings.GK)) + { + Logger.DbgLog("A-D Lib:Gnome Keyring Set up for Aggregation"); + gkEngine = new GKEngine(); + } + // Console.WriteLine("StoreName = " + ((Store)(enumerator.Current)).StoreName + "StoreId = " + ((Store)(enumerator.Current)).StoreId); + } + } + */ + + } + + public XmlDocument Aggregate() + { +#if LINUX + gkEngine = null; + kwEngine = null; +#endif + //Read the Policy Just before you aggregate + + // Reading Policy to see what else needs to be Aggregated. + aggPol = (AggregationPol) ICASAPol.GetPolicy(CASAPolType.AGGREGATION_POL); + if (aggPol != null ) + { + ArrayList stores = aggPol.StoreList; + IEnumerator enumerator = stores.GetEnumerator(); + + while(enumerator.MoveNext()) + { + string storeID = (((Store)(enumerator.Current)).StoreName); + +#if LINUX + if(storeID.Equals(ConstStrings.KW)) + { + Logger.DbgLog("A-D Lib: KWallet Set up for Aggregation"); + kwEngine = new KWalletEngine(); + } + else if(storeID.Equals(ConstStrings.GK)) + { + Logger.DbgLog("A-D Lib:Gnome Keyring Set up for Aggregation"); + gkEngine = new GKEngine(); + } +#endif + // Console.WriteLine("StoreName = " + ((Store)(enumerator.Current)).StoreName + "StoreId = " + ((Store)(enumerator.Current)).StoreId); + } + } + + + + XmlDocument ccf = new XmlDocument(); + XmlElement elem = ccf.CreateElement("CCF"); + ccf.AppendChild(elem); + + // TBD: Lookup Policy here and maybe send it via constructors + XmlNode micasaEnum = micasaengine.Aggregate(); + if (micasaEnum != null) //Atleast should come incase of no secrets + { + XmlNode gotit = ccf.ImportNode(micasaEnum,true); + ccf.DocumentElement.AppendChild(gotit); + } + else + { + // Null comes only when it failed to talk to miCASA. +#if LINUX + Logger.DbgLog("A-D Lib:Failed to Connect to miCASA"); +#endif + } + +#if LINUX + if (gkEngine != null) + { + XmlNode gkSecrets = gkEngine.Aggregate(); + if( null != gkSecrets ) + { + XmlNode gkImportedNode = ccf.ImportNode(gkSecrets,true); + ccf.DocumentElement.AppendChild(gkImportedNode); + } + else + { + Logger.DbgLog("A-D Lib:Failed to Connect to Gnome Keyring"); + + } + } + + + if(kwEngine != null ) + { + XmlNode KwEnum = kwEngine.Aggregate(); + if (KwEnum != null) //Atleast should come incase of no secrets + { + XmlNode kwImported = ccf.ImportNode(KwEnum,true); + ccf.DocumentElement.AppendChild(kwImported); + } + else + { + // Null comes only when it failed to talk to Kwallet. + Logger.DbgLog("A-D Lib:Failed to Connect to KWallet"); + } + } + +#endif + + + return ccf; + + } + + + + /******************************************************************************** + Modifying a Secret + + SetSecret will modify the Value(s) of a Key(s) for an existing secret + SetSecret will also add new secrets + + public int SetSecret(XmlNode secret, int StoreID) + + Parameters + + secret : Secrets XMLNode + 1. If a Key node of a secret is missing then that key will be deleted + 2. For Gnome keyring, Key having Id "GkPassword" cannot be deleted as + Gnome Api's do not allow it. + 3. All Time nodes for a Secret need not be passed as they cannot be set. + 4. Keyring attributes have a fixed datatype of Int and String. + Currently we support only String types. To support int types CCF needs to be modified accordingly. + 5. SetSecret overloaded method, without the opnType parameter, is not supported for GnomeKeyring + + opnType : Operation Type + ConstStrings.OPERATION_ADD_SECRET + ConstStrings.OPERATION_MODIFY_SECRET + + StoreID : int value + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET = 3; + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_GK = 4 + + Returns + An Error code or 0 if operation is successfull. + *********************************************************************************/ + + public int SetSecret(XmlNode secret, int opnType, int StoreID) + { + if (StoreID == ConstStrings.CASA_STORE_MICASA) + return micasaengine.SetSecret(secret, opnType); +#if LINUX + if (StoreID == ConstStrings.CASA_STORE_KWALLET) + return kwEngine.SetSecret(secret, opnType); + if (StoreID == ConstStrings.CASA_STORE_GK) + return gkEngine.SetSecret(secret, opnType); +#endif + else + { +#if LINUX + Logger.DbgLog("A-D Lib:Failed to Set Secret in to miCASA"); +#endif + return -1; + + } + + } + + + + /******************************************************************************** + Modifying a Secret + + SetSecret will modify the Value(s) of a Key(s) for an existing secret + SetSecret will also add new secrets + + public int SetSecret(XmlNode secret, int StoreID) + + Parameters + + secret : Secrets XMLNode + 1. If a Key node of a secret is missing then that key will be deleted + 2. For Gnome keyring, Key having Id "GkPassword" cannot be deleted as + Gnome Api's do not allow it. + 3. All Time nodes for a Secret need not be passed as they cannot be set. + 4. Keyring attributes have a fixed datatype of Int and String. + Currently we support only String types. To support int types CCF needs to be modified accordingly. + + StoreID : int value + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET = 3; + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_GK = 4 + + Returns + An Error code or 0 if operation is successfull. + *********************************************************************************/ + + public int SetSecret(XmlNode secret, int StoreID) + { + if (StoreID == ConstStrings.CASA_STORE_MICASA) + return micasaengine.SetSecret(secret); +#if LINUX + if (StoreID == ConstStrings.CASA_STORE_KWALLET) + return kwEngine.SetSecret(secret); + if (StoreID == ConstStrings.CASA_STORE_GK) + return gkEngine.SetSecret(secret); +#endif + else + { +#if LINUX + Logger.DbgLog("A-D Lib:Failed to Set Secret in to miCASA"); +#endif + return -1; + + } + + } + + + public int GetSecret(XmlNode secret, int StoreID) + { + + //TBD: Check for Store ID and call the right DataEngine. + if (StoreID == ConstStrings.CASA_STORE_MICASA) + return micasaengine.GetSecret(secret); + else + { +#if LINUX + Logger.DbgLog("A-D Lib: Failed to Get Secret in to miCASA"); +#endif + return -1; + } + } + + + /******************************************************************************* + Remove will delete a Secret. + + public int Remove(XmlNode secret, int StoreID) + + + Parameters + + secret : Secrets XmlNode + 1. This node will be deleted from its parent. + + + StoreID : int value + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET = 3; + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_GK = 4 + + + Returns + An Error code or 0 if operation is successfull. + + *********************************************************************************/ + + public int Remove(XmlNode secret, int StoreID) + { + + if (StoreID == ConstStrings.CASA_STORE_MICASA) + return micasaengine.Remove(secret); +#if LINUX + if (StoreID == ConstStrings.CASA_STORE_KWALLET) + return kwEngine.Remove(secret); + if (StoreID == ConstStrings.CASA_STORE_GK) + return gkEngine.Remove(secret); +#endif + return -1; + } + + public int AggregateStore(XmlDocument outDoc, int StoreID) + { + // This need not be policy aware. GUI knows what its doing. + + XmlNode secEnum; + DataEngine engine; + + XmlNode toproot = outDoc.DocumentElement; + if (toproot == null) + { + XmlElement elem = outDoc.CreateElement("CCF"); + outDoc.AppendChild(elem); + } + + if ( StoreID == ConstStrings.CASA_STORE_MICASA ) // If its miCASA + { + engine = micasaengine; + secEnum = engine.Aggregate(); + if (secEnum != null ) + { + XmlNode root = outDoc.DocumentElement; + XmlNodeList miCASANodes = root.SelectNodes("descendant::miCASA"); + // Console.WriteLine("ADLIB: Count is " + miCASANodes.Count); + if (miCASANodes.Count != 0) // If there is something remove it + { + root.RemoveChild(miCASANodes[0]); + } + XmlNode gotit = outDoc.ImportNode(secEnum,true); + root.AppendChild(gotit); + return ConstStrings.CASA_SUCCESS; + } + else + return ConstStrings.CASA_STORE_NOT_AVAILABLE; + } +#if LINUX + else if( StoreID == ConstStrings.CASA_STORE_GK ) + { + gkEngine = new GKEngine(); + secEnum = gkEngine.Aggregate(); + if (secEnum != null ) + { + XmlNode root = outDoc.DocumentElement; + XmlNodeList gkNode = root.SelectNodes("descendant::GK"); + if (gkNode.Count != 0) // If there is something remove it + { + root.RemoveChild(gkNode[0]); + } + XmlNode gkImportNode = outDoc.ImportNode(secEnum,true); + root.AppendChild(gkImportNode); + return ConstStrings.CASA_SUCCESS; + } + else + return ConstStrings.CASA_STORE_NOT_AVAILABLE; + + } + else if(StoreID == ConstStrings.CASA_STORE_KWALLET) + { + kwEngine = new KWalletEngine(); + secEnum = kwEngine.Aggregate(); + if (secEnum != null ) + { + XmlNode root = outDoc.DocumentElement; + XmlNodeList gkNode = root.SelectNodes("descendant::KWallet"); + if (gkNode.Count != 0) // If there is something remove it + { + root.RemoveChild(gkNode[0]); + } + XmlNode kwImportNode = outDoc.ImportNode(secEnum,true); + root.AppendChild(kwImportNode); + return ConstStrings.CASA_SUCCESS; + } + else + { + //Console.WriteLine("KWallet some issue"); + return ConstStrings.CASA_STORE_NOT_AVAILABLE; + } + + } + + Logger.DbgLog("A-D Lib: Unknown Operation Requested"); +#endif + return ConstStrings.CASA_OPERATION_FAILED; + } + + public int InitAD() + { + + return ConstStrings.CASA_SUCCESS; + } + + + public int CleanUP_AD() + { + + return ConstStrings.CASA_SUCCESS; + } + /*********************************************************************************************** + IsStoreAvailable : Checks If Store Is Available + It loads the required dlls for a particular store and returns true if + all required dll/.so are present. + + public static Boolean IsStoreAvailable(int StoreID); + + Parameters + + StoreID : int value + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_KWALLET = 3; + Novell.CASA.DataEngines.Common.ConstStrings.CASA_STORE_GK = 4 + + Remarks + 1. This API needs to be called before any other API of the particular store is called. + 2. This API needs to be called before Aggregate() and AD_Facade constructor is called + as these initializes the Datangines based on the Aggregate Policy set. + 3. The Aggregate Policy needs to be reset appropriately based on the return value of this call. + ***********************************************************************************************/ + + + + public static Boolean IsStoreAvailable(int StoreID) + { + if (StoreID == ConstStrings.CASA_STORE_GK) + return GKEngine.IsStoreAvailable(); + if (StoreID == ConstStrings.CASA_STORE_KWALLET) + return KWalletEngine.IsStoreAvailable(); + return true; + } + + } +} diff --git a/c_adlib/GKEngine.cs b/c_adlib/GKEngine.cs index 221b2321..39880383 100644 --- a/c_adlib/GKEngine.cs +++ b/c_adlib/GKEngine.cs @@ -52,11 +52,11 @@ namespace Novell.CASA.DataEngines public GKEngine() { - } - - ~GKEngine() - { - GnomeKeyring.ReleaseGnomeKeyringLib(); + } + + ~GKEngine() + { + //GnomeKeyring.ReleaseGnomeKeyringLib(); } public XmlNode Aggregate() @@ -297,11 +297,11 @@ namespace Novell.CASA.DataEngines { try { - System.Runtime.InteropServices.Marshal.PrelinkAll(typeof(GnomeKeyring)); - if (GnomeKeyring.IsGnomeKeyringInstalled()) - return true; - else - return false; + System.Runtime.InteropServices.Marshal.PrelinkAll(typeof(GnomeKeyring)); + //if (GnomeKeyring.IsGnomeKeyringInstalled()) + return true; + //else + // return false; } catch(DllNotFoundException d) { diff --git a/c_adlib/KWalletEngine.cs b/c_adlib/KWalletEngine.cs index b7fa00d1..99b73838 100644 --- a/c_adlib/KWalletEngine.cs +++ b/c_adlib/KWalletEngine.cs @@ -21,503 +21,508 @@ ***********************************************************************/ -using System; -using System.Collections; -using System.Xml; -using System.IO; -using Novell.CASA; -using Novell.CASA.DataEngines.Common; -using System.Collections.Specialized; -using System.Runtime.InteropServices; -using Novell.CASA.DataEngines.KWallet; - - - - -namespace Novell.CASA.DataEngines -{ - - /* - * This class is implementation of Data engine for KWallet. - */ - - - class KWalletEngine : DataEngine - { - - string[] EntryTypes = {"Binary","Passwords","Unknown", "Maps"}; - enum KWalletResult : int - { - KWALLET_RESULT_OK, - - KWALLET_RESULT_CANNOT_OPEN_WALLET, - KWALLET_RESULT_CANNOT_OPEN_FOLDER, - KWALLET_RESULT_CANNOT_WRITE_ENTRY, - KWALLET_RESULT_MALFORMED_XML, - KWALLET_RESULT_CANNOT_CREATE_FOLDER, - KWALLET_RESULT_CANNOT_CREATE_WALLET, - KWALLET_RESULT_CANNOT_REMOVE_ENTRY, - KWALLET_RESULT_UNKNOWN_ERROR - }; - - - public KWalletEngine() - { - // TBD: Read Policy information and have a list of wallet names; - - } - - public XmlNode Aggregate() - { - XmlDocument doc = new XmlDocument(); - Hashtable lookup = new Hashtable(); - XmlElement key1; - XmlAttribute Atr; - XmlElement value1; - XmlAttribute idAttr; - String secid, val; - XmlElement currentWallet; - XmlElement Folder; - XmlElement Type; - XmlElement Secret; - String walletName, foldername, entryType, secretval; - - - - //Adding Kwallet Top Node - XmlElement elem = doc.CreateElement(ConstStrings.CCF_KW); - doc.AppendChild(elem); - - EnumSecretList enumList = new EnumSecretList(); - //kwallet.Try(enumList); - kwallet.AggregateKW(enumList); - EnumSecretList tempEnumSecretList1 = enumList; - - //This can be Null only when nothing is aggregated. - if (((String)Marshal.PtrToStringAnsi(tempEnumSecretList1.walletName)) == null ) - { - //TBD: Log that there are no secrets to aggregate - } - else // Something to Aggregate - { - - - while (tempEnumSecretList1 != null) - { - walletName = (String)Marshal.PtrToStringAnsi(tempEnumSecretList1.walletName); - // Console.WriteLine("\n\nWallet name is***# : "+walletName); - - foldername = (String)Marshal.PtrToStringAnsi(tempEnumSecretList1.folderName); - //Console.WriteLine("\tFolder***# : "+foldername); - int entrytype = tempEnumSecretList1.entryType; - //Console.WriteLine("\t\tEntryType ***#: "+entrytype); - entryType = EntryTypes[entrytype]; - //Console.WriteLine("\t\tEntryType in string ***#: "+entryType); - - secretval = (String)Marshal.PtrToStringAnsi(tempEnumSecretList1.secretVal); - //Console.WriteLine("\t\tSecret***# : "+secretval); - - //Adding Wallet - if (lookup.ContainsKey(walletName)) - { - //Console.WriteLine("Wallet Node found"); - currentWallet = (XmlElement)lookup[walletName]; - } - else - { - currentWallet = doc.CreateElement(ConstStrings.CCF_WALLET); - idAttr = doc.CreateAttribute(ConstStrings.CCF_ID); - idAttr.Value = walletName; - currentWallet.SetAttributeNode(idAttr); - elem.AppendChild(currentWallet); - lookup.Add(walletName,currentWallet); - } - - //Adding Folder - String xpath = "descendant::Folder[@Name='"+foldername+"']"; - XmlNodeList folList = currentWallet.SelectNodes(xpath); - if (folList.Count == 0) - { - Folder = doc.CreateElement(ConstStrings.CCF_FOLDER); - XmlAttribute name_attr = doc.CreateAttribute(ConstStrings.CCF_NAME); - name_attr.Value = foldername; - Folder.SetAttributeNode(name_attr); - currentWallet.AppendChild(Folder); - - } - - - //Adding Type - xpath = "descendant::Folder"; - XmlNodeList folderlist = currentWallet.SelectNodes(xpath); - - foreach(XmlNode folder in folderlist) - { - XmlAttributeCollection atcol = folder.Attributes; - XmlAttribute attr = atcol[ConstStrings.CCF_NAME]; - if (attr.InnerXml.Equals(foldername)) - { - xpath = "descendant::Type[@ID='"+entryType+"']"; - XmlNodeList keylist = folder.SelectNodes(xpath); - if (keylist.Count == 0) - { - Type = doc.CreateElement(ConstStrings.CCF_TYPE); - XmlAttribute name_attr = doc.CreateAttribute(ConstStrings.CCF_ID); - name_attr.Value = entryType; - Type.SetAttributeNode(name_attr); - folder.AppendChild(Type); - - } - else - { - //Console.WriteLine("Type Already Added"); - } - - } - - } - - - - //Adding the Secret - xpath = "descendant::Folder"; - folderlist = currentWallet.SelectNodes(xpath); - - foreach(XmlNode folder in folderlist) - { - XmlAttributeCollection atcol = folder.Attributes; - XmlAttribute attr = atcol[ConstStrings.CCF_NAME]; - if (attr.InnerXml.Equals(foldername)) - { - xpath = "descendant::Type[@ID='"+entryType+"']"; - - XmlNodeList keylist = folder.SelectNodes(xpath); - if (keylist.Count == 0) - { - //Console.WriteLine("Construction of CCF Failed"); - } - else - { - - XmlNode TargetType = keylist[0]; //Type Node - string[] split = null; - - int index = secretval.IndexOf('='); - secid = secretval.Substring(0,index); - - - Secret = doc.CreateElement(ConstStrings.CCF_SECRET); - XmlAttribute idattr = doc.CreateAttribute(ConstStrings.CCF_ID); - idattr.Value = secid; - Secret.SetAttributeNode(idattr); - - /*XmlAttribute typeAttr = doc.CreateAttribute(ConstStrings.CCF_TYPE); - typeAttr.Value = entryType; - Secret.SetAttributeNode(typeAttr); - */ - - - - if (entryType.Equals("Maps")) - { - string delim = ";"; - char[] delimiter = delim.ToCharArray(); - string realval = secretval.Substring(index+1); - - for(int x = 1; x < 10 ; x++) - { - split = realval.Split(delimiter, x); - } - foreach(string s in split) - { - int ix; - string key; - string value; - - //Console.WriteLine("The val is :" + s); - if (s.Equals("")) - { - //Console.WriteLine("No Secret Content for a Secret ID"); - key = " "; - value = " "; - } - else - { - ix = s.IndexOf(':'); - key = s.Substring(0,ix); - value = s.Substring(ix+1); - - } - - key1 = doc.CreateElement(ConstStrings.CCF_KEY); - Atr = doc.CreateAttribute(ConstStrings.CCF_ID); - Atr.Value = key; - key1.SetAttributeNode(Atr); - - //Value - value1 = doc.CreateElement(ConstStrings.CCF_VALUE); - value1.InnerText = value; - key1.AppendChild(value1); - Secret.AppendChild(key1); - - TargetType.AppendChild(Secret); - } - }//entrytype=Maps - else if (entryType.Equals("Passwords")) - { - //Console.WriteLine("Passwords"); - val = secretval.Substring(index+1); - - //Key - key1 = doc.CreateElement(ConstStrings.CCF_KEY); - Atr = doc.CreateAttribute(ConstStrings.CCF_ID); - Atr.Value = "Credential"; - key1.SetAttributeNode(Atr); - - //Value - value1 = doc.CreateElement(ConstStrings.CCF_VALUE); - value1.InnerText = val; - key1.AppendChild(value1); - Secret.AppendChild(key1); - - TargetType.AppendChild(Secret); - }//entryType=Password - } - } - } - - - - if (tempEnumSecretList1.next == IntPtr.Zero) - { - // Console.WriteLine("Reached End ##"); - break; - } - - tempEnumSecretList1 = (EnumSecretList)Marshal.PtrToStructure(tempEnumSecretList1.next, typeof(EnumSecretList)); - - } - } - kwallet.FreeResources(); - #if TEST - XmlTextWriter writer = new XmlTextWriter("/root/kwtest.xml",null); - writer.Formatting = Formatting.Indented; - doc.Save(writer); - writer.Close(); - #endif - - - - return doc.ChildNodes[0]; - - - } - - - public int SetSecret(XmlNode secret) - { - try - { - - string walletName = ExtractWalletName(secret); - string folderName = ExtractFolderName(secret); - string keyName = ExtractKeyName(secret); - int secretType = ExtractSecretType(secret); - - if (secretType != 3) //Type not Map - { - - string value = secret.ChildNodes[0].ChildNodes[0].InnerText; //Secret.Key.Value - - return(kwallet.SetSecret(walletName, folderName, secretType, keyName, value, value.Length)); - } - else //If type is Map - { - - NameValueCollection nvc = new NameValueCollection(); - - for (int i =0; i< secret.ChildNodes.Count; i++) - { - - XmlNode key = secret.ChildNodes[i]; - XmlAttributeCollection atcol; - atcol = key.Attributes; - String keyMapName = atcol["ID"].InnerXml; - - string value = key.ChildNodes[0].InnerText; //Secret.Key.Value - - nvc.Add(keyMapName,value); - } - - - return(kwallet.SetSecret(walletName, folderName,keyName,nvc)); - } - } - catch(NullReferenceException n) - { - //Console.WriteLine("Exception in Set Secret Cause :" + n.ToString()); - return (int)KWalletResult.KWALLET_RESULT_MALFORMED_XML; - - } - catch(Exception e) - { - //Console.WriteLine("Exception in Set Secret Cause :" + e.ToString()); - return (int)KWalletResult.KWALLET_RESULT_UNKNOWN_ERROR; - } - } - - public int SetSecret(XmlNode secret, int opnType) - { - return SetSecret(secret); - } - - - - public int GetSecret(XmlNode secret) - { - return ConstStrings.CASA_SUCCESS; - } - - public int Remove(XmlNode secret) - { - try - { - string walletName = ExtractWalletName(secret); - string folderName = ExtractFolderName(secret); - string keyName = ExtractKeyName(secret); - int res = kwallet.DeleteSecret(walletName, folderName, keyName); - if (res == 0) - { - XmlNode root = secret.ParentNode; - root.RemoveChild(secret); - } - return res; - } - catch(NullReferenceException n) - { - //Console.WriteLine("Exception in Set Secret Cause :" + n.ToString()); - return (int)KWalletResult.KWALLET_RESULT_MALFORMED_XML; - - } - catch(Exception e) - { - //Console.WriteLine("Exception in Set Secret Cause :" + e.ToString()); - return (int)KWalletResult.KWALLET_RESULT_UNKNOWN_ERROR; - } - } - - string ExtractWalletName(XmlNode secret) - { - XmlAttributeCollection atcol; - XmlNode parentNode = secret.ParentNode.ParentNode.ParentNode; - atcol = parentNode.Attributes; - String walletname = atcol["ID"].InnerXml; - return walletname; - } - - string ExtractFolderName(XmlNode secret) - { - XmlAttributeCollection atcol; - XmlNode parentNode = secret.ParentNode.ParentNode; //Folder.Type.Secret - atcol = parentNode.Attributes; - String foldername = atcol["Name"].InnerXml; - return foldername; - } - - string ExtractKeyName(XmlNode secret) - { - XmlAttributeCollection atcol; - atcol = secret.Attributes; - String keyname = atcol["ID"].InnerXml; - return keyname; - } - - int ExtractSecretType(XmlNode secret) - { - XmlAttributeCollection atcol; - XmlNode parentNode = secret.ParentNode; //Type.Secret - atcol = parentNode.Attributes; - String entryType = atcol["ID"].InnerXml; - if (entryType.CompareTo("Passwords")== 0) - { - return 1; - } - if (entryType.CompareTo("Binary") == 0) - { - return 2; - } - if (entryType.CompareTo("Maps") == 0) - { - return 3; - } - return 0; - } - - -#if TEST - public static void Main() - { - KWalletEngine kw = new KWalletEngine(); - - - Console.WriteLine(); - Console.WriteLine("********** Menu ***********"); - Console.WriteLine("* 1. Add secret *"); - Console.WriteLine("* 2. Modify secret *"); - Console.WriteLine("* 3. Set secret *"); - Console.WriteLine("* 4. Remove secret *"); - Console.WriteLine("* 5. Refresh *"); - Console.WriteLine("* 6. Quit *"); - Console.WriteLine("***************************"); - Console.WriteLine("For all options the input is the file /root/kwtest.xml"); - - - - Console.WriteLine("Select option and Press enter"); - String line = Console.ReadLine(); - int res = 0; - - if (line.Length > 0) - { - char[] c = line.Substring(0, 1).ToCharArray(); - if (c.Length > 0) - { - if (c[0].Equals('6')) - return; - if (c[0].Equals('5')) - kw.Aggregate (); - else - { - - XmlDocument xmlDoc = new XmlDocument(); - XmlTextReader tr = new XmlTextReader("/root/kwtest.xml"); - tr.Read(); - xmlDoc.Load(tr); - XmlNode root = xmlDoc.FirstChild; - if (root == null) - { - Console.WriteLine("Root is null"); - } - XmlNode secret = root.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0]; - - if (c[0].Equals('4')) - res =kw.Remove(secret); - else if (c[0].Equals('1')) - res = kw.SetSecret(secret,ConstStrings.OPERATION_ADD_SECRET); - else if (c[0].Equals('2')) - res = kw.SetSecret(secret,ConstStrings.OPERATION_MODIFY_SECRET); - else if (c[0].Equals('3')) - res = kw.SetSecret(secret); - } - } - } - Console.WriteLine("Result of Operation = " + res); - - } - #endif - - - } -} - - +using System; +using System.Collections; +using System.Xml; +using System.IO; +using Novell.CASA; +using Novell.CASA.DataEngines.Common; +using System.Collections.Specialized; +using System.Runtime.InteropServices; +using Novell.CASA.DataEngines.KWallet; + + + + +namespace Novell.CASA.DataEngines +{ + + /* + * This class is implementation of Data engine for KWallet. + */ + + + class KWalletEngine : DataEngine + { + + string[] EntryTypes = {"Binary","Passwords","Unknown", "Maps"}; + enum KWalletResult : int + { + KWALLET_RESULT_OK, + + KWALLET_RESULT_CANNOT_OPEN_WALLET, + KWALLET_RESULT_CANNOT_OPEN_FOLDER, + KWALLET_RESULT_CANNOT_WRITE_ENTRY, + KWALLET_RESULT_MALFORMED_XML, + KWALLET_RESULT_CANNOT_CREATE_FOLDER, + KWALLET_RESULT_CANNOT_CREATE_WALLET, + KWALLET_RESULT_CANNOT_REMOVE_ENTRY, + KWALLET_RESULT_UNKNOWN_ERROR + }; + + + public KWalletEngine() + { + // TBD: Read Policy information and have a list of wallet names; + + } + + public XmlNode Aggregate() + { + XmlDocument doc = new XmlDocument(); + Hashtable lookup = new Hashtable(); + XmlElement key1; + XmlAttribute Atr; + XmlElement value1; + XmlAttribute idAttr; + String secid, val; + XmlElement currentWallet; + XmlElement Folder; + XmlElement Type; + XmlElement Secret; + String walletName, foldername, entryType, secretval; + + + + //Adding Kwallet Top Node + XmlElement elem = doc.CreateElement(ConstStrings.CCF_KW); + doc.AppendChild(elem); + + EnumSecretList enumList = new EnumSecretList(); + //kwallet.Try(enumList); + kwallet.AggregateKW(enumList); + EnumSecretList tempEnumSecretList1 = enumList; + + //This can be Null only when nothing is aggregated. + if (((String)Marshal.PtrToStringAnsi(tempEnumSecretList1.walletName)) == null ) + { + //TBD: Log that there are no secrets to aggregate + } + else // Something to Aggregate + { + + + while (tempEnumSecretList1 != null) + { + walletName = (String)Marshal.PtrToStringAnsi(tempEnumSecretList1.walletName); + // Console.WriteLine("\n\nWallet name is***# : "+walletName); + + foldername = (String)Marshal.PtrToStringAnsi(tempEnumSecretList1.folderName); + //Console.WriteLine("\tFolder***# : "+foldername); + int entrytype = tempEnumSecretList1.entryType; + //Console.WriteLine("\t\tEntryType ***#: "+entrytype); + entryType = EntryTypes[entrytype]; + //Console.WriteLine("\t\tEntryType in string ***#: "+entryType); + + secretval = (String)Marshal.PtrToStringAnsi(tempEnumSecretList1.secretVal); + //Console.WriteLine("\t\tSecret***# : "+secretval); + + //Adding Wallet + if (lookup.ContainsKey(walletName)) + { + //Console.WriteLine("Wallet Node found"); + currentWallet = (XmlElement)lookup[walletName]; + } + else + { + currentWallet = doc.CreateElement(ConstStrings.CCF_WALLET); + idAttr = doc.CreateAttribute(ConstStrings.CCF_ID); + idAttr.Value = walletName; + currentWallet.SetAttributeNode(idAttr); + elem.AppendChild(currentWallet); + lookup.Add(walletName,currentWallet); + } + + //Adding Folder + String xpath = "descendant::Folder[@Name='"+foldername+"']"; + XmlNodeList folList = currentWallet.SelectNodes(xpath); + if (folList.Count == 0) + { + Folder = doc.CreateElement(ConstStrings.CCF_FOLDER); + XmlAttribute name_attr = doc.CreateAttribute(ConstStrings.CCF_NAME); + name_attr.Value = foldername; + Folder.SetAttributeNode(name_attr); + currentWallet.AppendChild(Folder); + + } + + + //Adding Type + xpath = "descendant::Folder"; + XmlNodeList folderlist = currentWallet.SelectNodes(xpath); + + foreach(XmlNode folder in folderlist) + { + XmlAttributeCollection atcol = folder.Attributes; + XmlAttribute attr = atcol[ConstStrings.CCF_NAME]; + if (attr.InnerXml.Equals(foldername)) + { + xpath = "descendant::Type[@ID='"+entryType+"']"; + XmlNodeList keylist = folder.SelectNodes(xpath); + if (keylist.Count == 0) + { + Type = doc.CreateElement(ConstStrings.CCF_TYPE); + XmlAttribute name_attr = doc.CreateAttribute(ConstStrings.CCF_ID); + name_attr.Value = entryType; + Type.SetAttributeNode(name_attr); + folder.AppendChild(Type); + + } + else + { + //Console.WriteLine("Type Already Added"); + } + + } + + } + + + + //Adding the Secret + xpath = "descendant::Folder"; + folderlist = currentWallet.SelectNodes(xpath); + + foreach(XmlNode folder in folderlist) + { + XmlAttributeCollection atcol = folder.Attributes; + XmlAttribute attr = atcol[ConstStrings.CCF_NAME]; + if (attr.InnerXml.Equals(foldername)) + { + xpath = "descendant::Type[@ID='"+entryType+"']"; + + XmlNodeList keylist = folder.SelectNodes(xpath); + if (keylist.Count == 0) + { + //Console.WriteLine("Construction of CCF Failed"); + } + else + { + + XmlNode TargetType = keylist[0]; //Type Node + string[] split = null; + + int index = secretval.IndexOf('='); + secid = secretval.Substring(0,index); + + + Secret = doc.CreateElement(ConstStrings.CCF_SECRET); + XmlAttribute idattr = doc.CreateAttribute(ConstStrings.CCF_ID); + idattr.Value = secid; + Secret.SetAttributeNode(idattr); + + /*XmlAttribute typeAttr = doc.CreateAttribute(ConstStrings.CCF_TYPE); + typeAttr.Value = entryType; + Secret.SetAttributeNode(typeAttr); + */ + + + + if (entryType.Equals("Maps")) + { + string delim = ";"; + char[] delimiter = delim.ToCharArray(); + string realval = secretval.Substring(index+1); + + for(int x = 1; x < 10 ; x++) + { + split = realval.Split(delimiter, x); + } + foreach(string s in split) + { + int ix; + string key; + string value; + + //Console.WriteLine("The val is :" + s); + if (s.Equals("")) + { + //Console.WriteLine("No Secret Content for a Secret ID"); + key = " "; + value = " "; + } + else + { + ix = s.IndexOf(':'); + key = s.Substring(0,ix); + value = s.Substring(ix+1); + + } + + key1 = doc.CreateElement(ConstStrings.CCF_KEY); + Atr = doc.CreateAttribute(ConstStrings.CCF_ID); + Atr.Value = key; + key1.SetAttributeNode(Atr); + + //Value + value1 = doc.CreateElement(ConstStrings.CCF_VALUE); + value1.InnerText = value; + key1.AppendChild(value1); + Secret.AppendChild(key1); + + TargetType.AppendChild(Secret); + } + }//entrytype=Maps + else if (entryType.Equals("Passwords")) + { + //Console.WriteLine("Passwords"); + val = secretval.Substring(index+1); + + //Key + key1 = doc.CreateElement(ConstStrings.CCF_KEY); + Atr = doc.CreateAttribute(ConstStrings.CCF_ID); + Atr.Value = "Credential"; + key1.SetAttributeNode(Atr); + + //Value + value1 = doc.CreateElement(ConstStrings.CCF_VALUE); + value1.InnerText = val; + key1.AppendChild(value1); + Secret.AppendChild(key1); + + TargetType.AppendChild(Secret); + }//entryType=Password + } + } + } + + + + if (tempEnumSecretList1.next == IntPtr.Zero) + { + // Console.WriteLine("Reached End ##"); + break; + } + + tempEnumSecretList1 = (EnumSecretList)Marshal.PtrToStructure(tempEnumSecretList1.next, typeof(EnumSecretList)); + + } + } + kwallet.FreeResources(); + #if TEST + XmlTextWriter writer = new XmlTextWriter("/root/kwtest.xml",null); + writer.Formatting = Formatting.Indented; + doc.Save(writer); + writer.Close(); + #endif + + + + return doc.ChildNodes[0]; + + + } + + + public int SetSecret(XmlNode secret) + { + try + { + + string walletName = ExtractWalletName(secret); + string folderName = ExtractFolderName(secret); + string keyName = ExtractKeyName(secret); + int secretType = ExtractSecretType(secret); + + if (secretType != 3) //Type not Map + { + + string value = secret.ChildNodes[0].ChildNodes[0].InnerText; //Secret.Key.Value + + return(kwallet.SetSecret(walletName, folderName, secretType, keyName, value, value.Length)); + } + else //If type is Map + { + + NameValueCollection nvc = new NameValueCollection(); + + for (int i =0; i< secret.ChildNodes.Count; i++) + { + + XmlNode key = secret.ChildNodes[i]; + XmlAttributeCollection atcol; + atcol = key.Attributes; + String keyMapName = atcol["ID"].InnerXml; + + string value = key.ChildNodes[0].InnerText; //Secret.Key.Value + + nvc.Add(keyMapName,value); + } + + + return(kwallet.SetSecret(walletName, folderName,keyName,nvc)); + } + } + catch(NullReferenceException n) + { + //Console.WriteLine("Exception in Set Secret Cause :" + n.ToString()); + return (int)KWalletResult.KWALLET_RESULT_MALFORMED_XML; + + } + catch(Exception e) + { + //Console.WriteLine("Exception in Set Secret Cause :" + e.ToString()); + return (int)KWalletResult.KWALLET_RESULT_UNKNOWN_ERROR; + } + } + + public int SetSecret(XmlNode secret, int opnType) + { + return SetSecret(secret); + } + + + + public int GetSecret(XmlNode secret) + { + return ConstStrings.CASA_SUCCESS; + } + + public int Remove(XmlNode secret) + { + try + { + string walletName = ExtractWalletName(secret); + string folderName = ExtractFolderName(secret); + string keyName = ExtractKeyName(secret); + int res = kwallet.DeleteSecret(walletName, folderName, keyName); + if (res == 0) + { + XmlNode root = secret.ParentNode; + root.RemoveChild(secret); + } + return res; + } + catch(NullReferenceException n) + { + //Console.WriteLine("Exception in Set Secret Cause :" + n.ToString()); + return (int)KWalletResult.KWALLET_RESULT_MALFORMED_XML; + + } + catch(Exception e) + { + //Console.WriteLine("Exception in Set Secret Cause :" + e.ToString()); + return (int)KWalletResult.KWALLET_RESULT_UNKNOWN_ERROR; + } + } + + string ExtractWalletName(XmlNode secret) + { + XmlAttributeCollection atcol; + XmlNode parentNode = secret.ParentNode.ParentNode.ParentNode; + atcol = parentNode.Attributes; + String walletname = atcol["ID"].InnerXml; + return walletname; + } + + string ExtractFolderName(XmlNode secret) + { + XmlAttributeCollection atcol; + XmlNode parentNode = secret.ParentNode.ParentNode; //Folder.Type.Secret + atcol = parentNode.Attributes; + String foldername = atcol["Name"].InnerXml; + return foldername; + } + + string ExtractKeyName(XmlNode secret) + { + XmlAttributeCollection atcol; + atcol = secret.Attributes; + String keyname = atcol["ID"].InnerXml; + return keyname; + } + + int ExtractSecretType(XmlNode secret) + { + XmlAttributeCollection atcol; + XmlNode parentNode = secret.ParentNode; //Type.Secret + atcol = parentNode.Attributes; + String entryType = atcol["ID"].InnerXml; + if (entryType.CompareTo("Passwords")== 0) + { + return 1; + } + if (entryType.CompareTo("Binary") == 0) + { + return 2; + } + if (entryType.CompareTo("Maps") == 0) + { + return 3; + } + return 0; + } + + public static Boolean IsStoreAvailable() + { + return true; + } + + +#if TEST + public static void Main() + { + KWalletEngine kw = new KWalletEngine(); + + + Console.WriteLine(); + Console.WriteLine("********** Menu ***********"); + Console.WriteLine("* 1. Add secret *"); + Console.WriteLine("* 2. Modify secret *"); + Console.WriteLine("* 3. Set secret *"); + Console.WriteLine("* 4. Remove secret *"); + Console.WriteLine("* 5. Refresh *"); + Console.WriteLine("* 6. Quit *"); + Console.WriteLine("***************************"); + Console.WriteLine("For all options the input is the file /root/kwtest.xml"); + + + + Console.WriteLine("Select option and Press enter"); + String line = Console.ReadLine(); + int res = 0; + + if (line.Length > 0) + { + char[] c = line.Substring(0, 1).ToCharArray(); + if (c.Length > 0) + { + if (c[0].Equals('6')) + return; + if (c[0].Equals('5')) + kw.Aggregate (); + else + { + + XmlDocument xmlDoc = new XmlDocument(); + XmlTextReader tr = new XmlTextReader("/root/kwtest.xml"); + tr.Read(); + xmlDoc.Load(tr); + XmlNode root = xmlDoc.FirstChild; + if (root == null) + { + Console.WriteLine("Root is null"); + } + XmlNode secret = root.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0]; + + if (c[0].Equals('4')) + res =kw.Remove(secret); + else if (c[0].Equals('1')) + res = kw.SetSecret(secret,ConstStrings.OPERATION_ADD_SECRET); + else if (c[0].Equals('2')) + res = kw.SetSecret(secret,ConstStrings.OPERATION_MODIFY_SECRET); + else if (c[0].Equals('3')) + res = kw.SetSecret(secret); + } + } + } + Console.WriteLine("Result of Operation = " + res); + + } + #endif + + + } +} + + diff --git a/c_adlib/ad_gk/GnomeKeyring.cs b/c_adlib/ad_gk/GnomeKeyring.cs index 055dbcc5..5577f344 100644 --- a/c_adlib/ad_gk/GnomeKeyring.cs +++ b/c_adlib/ad_gk/GnomeKeyring.cs @@ -110,23 +110,23 @@ namespace Novell.CASA.DataEngines.GK [DllImport("libad_gk.so")] public static extern int CreateItem(string keyringName, int itemType, string displayName, string password, IntPtr[] arrptr, int attrCount); [DllImport("libad_gk.so")] - public static extern int UnlockRing(string sKeyringName, string sPassword); - [DllImport("libad_gk.so")] - public static extern int LoadGnomeKeyringLibrary(); - [DllImport("libad_gk.so")] - public static extern int ReleaseGnomeKeyringLibrary(); - - public static bool IsGnomeKeyringInstalled() - { - if (0 == LoadGnomeKeyringLibrary()) - return true; - else - return false; - } - - public static void ReleaseGnomeKeyringLib() - { - ReleaseGnomeKeyringLibrary(); + public static extern int UnlockRing(string sKeyringName, string sPassword); + [DllImport("libad_gk.so")] + public static extern int LoadGnomeKeyringLibrary(); + [DllImport("libad_gk.so")] + public static extern int ReleaseGnomeKeyringLibrary(); + + public static bool IsGnomeKeyringInstalled() + { + if (0 == LoadGnomeKeyringLibrary()) + return true; + else + return false; + } + + public static void ReleaseGnomeKeyringLib() + { + ReleaseGnomeKeyringLibrary(); } public static void AttemptGKUnlock(string sPassword)