Moving micasa 1.5 trunk to Novell forge.
This commit is contained in:
296
c_adlib/AD_Facade.cs
Normal file
296
c_adlib/AD_Facade.cs
Normal file
@@ -0,0 +1,296 @@
|
||||
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();
|
||||
|
||||
/*
|
||||
|
||||
// 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 <miCASA> 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 <KWallet> 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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int SetSecret(XmlNode secret, int StoreID)
|
||||
{
|
||||
//TBD: Check for Store ID and call the right DataEngine.
|
||||
if (StoreID == ConstStrings.CASA_STORE_MICASA)
|
||||
return micasaengine.SetSecret(secret);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int Remove(XmlNode secret, int StoreID)
|
||||
{
|
||||
|
||||
//TBD: Check for Store ID and call the right DataEngine.
|
||||
return micasaengine.Remove(secret);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
c_adlib/Common.cs
Normal file
65
c_adlib/Common.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
|
||||
|
||||
namespace Novell.CASA.DataEngines.Common
|
||||
{
|
||||
|
||||
public class ConstStrings
|
||||
{
|
||||
|
||||
// Error codes
|
||||
public static int CASA_SUCCESS = 0;
|
||||
public static int CASA_OPERATION_FAILED = 1;
|
||||
public static int CASA_STORE_NOT_AVAILABLE = 3;
|
||||
public static int CASA_DATA_UNAVAILABLE = 4;
|
||||
|
||||
// Store IDs
|
||||
public static string miCASA = "miCASA";
|
||||
public static string KW = "KDE KWallet";
|
||||
public static string GK = "GNOME Keyring";
|
||||
public static string PM = "Password Manager";
|
||||
|
||||
//Store Types
|
||||
public static int CASA_STORE_MICASA = 0;
|
||||
public static int CASA_STORE_FFOX = 1;
|
||||
public static int CASA_STORE_KWALLET =3;
|
||||
public static int CASA_STORE_MOZILLA = 2;
|
||||
public static int CASA_STORE_GK = 4;
|
||||
|
||||
|
||||
//CCF Tag Names
|
||||
|
||||
public static string CCF_ID = "ID";
|
||||
public static string CCF_GKTAG = "GK";
|
||||
public static string CCF_KW = "KWallet";
|
||||
public static string CCF_GKKEYRING = "Keyring";
|
||||
public static string CCF_SECRET = "Secret";
|
||||
public static string CCF_TYPE = "Type";
|
||||
public static string CCF_KEY = "Key";
|
||||
public static string CCF_VALUE = "Value";
|
||||
public static string CCF_TIME = "Time";
|
||||
public static string CCF_CRTIME = "Creation";
|
||||
public static string CCF_MDTIME = "Modified";
|
||||
public static string CCF_ACTIME = "Accessed";
|
||||
public static string CCF_LOCK = "Lock";
|
||||
public static string CCF_LOCKSTATUS = "LockStatus";
|
||||
public static string CCF_LOCKHAND = "LockOnIdle";
|
||||
public static string CCF_LOCKTIME = "LockTimeout";
|
||||
public static string CCF_WALLET = "Wallet";
|
||||
public static string CCF_FOLDER = "Folder";
|
||||
public static string CCF_KEYCHAIN = "Keychain";
|
||||
public static string CCF_KEYCHAINNAME = "Default";
|
||||
public static string CCF_ZONE = "Zone";
|
||||
public static string CCF_SYNCH = "Synch";
|
||||
public static string CCF_NAME = "Name";
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
170
c_adlib/GKEngine.cs
Normal file
170
c_adlib/GKEngine.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.InteropServices;
|
||||
using Gtk;
|
||||
using GLib;
|
||||
using Novell.CASA.DataEngines.Common;
|
||||
using Novell.CASA.DataEngines.GK;
|
||||
|
||||
|
||||
namespace Novell.CASA.DataEngines
|
||||
{
|
||||
|
||||
/*
|
||||
* This class is implementation of Data engine for Gnome-Keyring.
|
||||
*/
|
||||
|
||||
class GKEngine : DataEngine
|
||||
{
|
||||
public GKEngine()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public XmlNode Aggregate()
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
|
||||
XmlNode rootElem = doc.CreateElement(ConstStrings.CCF_GKTAG);
|
||||
doc.AppendChild(rootElem);
|
||||
XmlElement keyringElem;
|
||||
|
||||
ArrayList itemList;
|
||||
ArrayList attrList;
|
||||
ItemInfo itemInfo;
|
||||
KeyringInfo keyringInfo;
|
||||
int itemId;
|
||||
ArrayList keyringList = GnomeKeyring.GKGetKeyrings();
|
||||
IEnumerator kEtor = keyringList.GetEnumerator();
|
||||
IEnumerator iEtor;
|
||||
|
||||
while(kEtor.MoveNext())
|
||||
{
|
||||
string keyring = (string)(kEtor.Current);
|
||||
|
||||
keyringElem = doc.CreateElement(ConstStrings.CCF_GKKEYRING);
|
||||
XmlAttribute idAttr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
idAttr.Value = keyring;
|
||||
keyringElem.SetAttributeNode(idAttr);
|
||||
|
||||
keyringInfo = GnomeKeyring.GKGetKeyringInfo(keyring);
|
||||
|
||||
itemList = GnomeKeyring.GKGetItems(keyring);
|
||||
iEtor = itemList.GetEnumerator();
|
||||
while(iEtor.MoveNext())
|
||||
{
|
||||
itemId = (int)iEtor.Current;
|
||||
itemInfo = GnomeKeyring.GKGetItemInfo(keyring,itemId);
|
||||
attrList = GnomeKeyring.GKGetAttributeList(keyring,itemId);
|
||||
|
||||
XmlElement secretElem = doc.CreateElement(ConstStrings.CCF_SECRET);
|
||||
XmlAttribute secIdAttr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
secIdAttr.Value = itemInfo.displayName + ":" + itemId;
|
||||
|
||||
secretElem.SetAttributeNode(secIdAttr);
|
||||
|
||||
XmlAttribute typeAttr = doc.CreateAttribute(ConstStrings.CCF_TYPE);
|
||||
typeAttr.Value = itemInfo.itemType.ToString();
|
||||
secretElem.SetAttributeNode(typeAttr);
|
||||
|
||||
XmlElement keyElem = doc.CreateElement(ConstStrings.CCF_KEY);
|
||||
XmlAttribute keyIdAttr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
keyIdAttr.Value = "GKPassword";
|
||||
keyElem.SetAttributeNode(keyIdAttr);
|
||||
|
||||
XmlElement valueElem = doc.CreateElement(ConstStrings.CCF_VALUE);
|
||||
valueElem.InnerText = itemInfo.secret;
|
||||
keyElem.AppendChild(valueElem);
|
||||
secretElem.AppendChild(keyElem);
|
||||
|
||||
IEnumerator attrEtor = (IEnumerator)(attrList.GetEnumerator());
|
||||
while(attrEtor.MoveNext())
|
||||
{
|
||||
Novell.CASA.DataEngines.GK.Attribute attr = (Novell.CASA.DataEngines.GK.Attribute)(attrEtor.Current);
|
||||
keyElem = doc.CreateElement(ConstStrings.CCF_KEY);
|
||||
keyIdAttr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
keyIdAttr.Value = attr.key;
|
||||
keyElem.SetAttributeNode(keyIdAttr);
|
||||
|
||||
valueElem = doc.CreateElement(ConstStrings.CCF_VALUE);
|
||||
valueElem.InnerText = attr.value;
|
||||
keyElem.AppendChild(valueElem);
|
||||
secretElem.AppendChild(keyElem);
|
||||
}
|
||||
|
||||
keyringElem.AppendChild(secretElem);
|
||||
XmlElement timeElem = doc.CreateElement(ConstStrings.CCF_TIME);
|
||||
|
||||
XmlElement itemCreatedTimeElem = doc.CreateElement(ConstStrings.CCF_CRTIME);
|
||||
itemCreatedTimeElem.InnerText = itemInfo.mTime.ToString();
|
||||
timeElem.AppendChild(itemCreatedTimeElem);
|
||||
|
||||
XmlElement itemModifiedTimeElem = doc.CreateElement(ConstStrings.CCF_MDTIME);
|
||||
itemModifiedTimeElem.InnerText = itemInfo.cTime.ToString();
|
||||
timeElem.AppendChild(itemModifiedTimeElem);
|
||||
|
||||
secretElem.AppendChild(timeElem);
|
||||
}
|
||||
XmlElement keyringTimeElem = doc.CreateElement(ConstStrings.CCF_TIME);
|
||||
|
||||
XmlElement createdTimeElem = doc.CreateElement(ConstStrings.CCF_CRTIME);
|
||||
createdTimeElem.InnerText = keyringInfo.mTime.ToString();
|
||||
keyringTimeElem.AppendChild(createdTimeElem);
|
||||
|
||||
XmlElement modifiedTimeElem = doc.CreateElement(ConstStrings.CCF_MDTIME);
|
||||
modifiedTimeElem.InnerText = keyringInfo.cTime.ToString();
|
||||
keyringTimeElem.AppendChild(modifiedTimeElem);
|
||||
|
||||
keyringElem.AppendChild(keyringTimeElem);
|
||||
|
||||
XmlElement lockElem = doc.CreateElement(ConstStrings.CCF_LOCK);
|
||||
|
||||
XmlAttribute lockStatusAttr = doc.CreateAttribute(ConstStrings.CCF_LOCKSTATUS);
|
||||
if( keyringInfo.isLocked == 1 )
|
||||
lockStatusAttr.Value = "locked";
|
||||
else
|
||||
lockStatusAttr.Value = "unlocked";
|
||||
lockElem.SetAttributeNode(lockStatusAttr);
|
||||
|
||||
XmlAttribute lockOnIdleAttr = doc.CreateAttribute(ConstStrings.CCF_LOCKHAND);
|
||||
if( keyringInfo.lockOnIdle == 1)
|
||||
lockOnIdleAttr.Value = "true";
|
||||
else
|
||||
lockOnIdleAttr.Value = "false";
|
||||
lockElem.SetAttributeNode(lockOnIdleAttr);
|
||||
|
||||
XmlAttribute lockTimeoutAttr = doc.CreateAttribute(ConstStrings.CCF_LOCKTIME);
|
||||
lockTimeoutAttr.Value = keyringInfo.lockTimeout.ToString();
|
||||
lockElem.SetAttributeNode(lockTimeoutAttr);
|
||||
|
||||
keyringElem.AppendChild(lockElem);
|
||||
rootElem.AppendChild(keyringElem);
|
||||
}
|
||||
#if TEST
|
||||
XmlTextWriter writer = new XmlTextWriter("./gk.xml",null);
|
||||
writer.Formatting = Formatting.Indented;
|
||||
doc.Save(writer);
|
||||
writer.Close();
|
||||
#endif
|
||||
|
||||
return doc.ChildNodes[0];
|
||||
}
|
||||
public int SetSecret(XmlNode secret)
|
||||
{
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
|
||||
public int GetSecret(XmlNode secret)
|
||||
{
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
public int Remove(XmlNode secret)
|
||||
{
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
c_adlib/IDataEngine.cs
Normal file
31
c_adlib/IDataEngine.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Xml;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace Novell.CASA.DataEngines
|
||||
{
|
||||
|
||||
/*
|
||||
* Defines the interfaces to be implemenetd by all Data Engines.
|
||||
*/
|
||||
public interface DataEngine
|
||||
{
|
||||
|
||||
XmlNode Aggregate();
|
||||
|
||||
int GetSecret(XmlNode secret);
|
||||
|
||||
int SetSecret(XmlNode secret);
|
||||
|
||||
int Remove(XmlNode secret);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
339
c_adlib/KWalletEngine.cs
Normal file
339
c_adlib/KWalletEngine.cs
Normal file
@@ -0,0 +1,339 @@
|
||||
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"};
|
||||
|
||||
|
||||
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 = folder;
|
||||
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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (tempEnumSecretList1.next == IntPtr.Zero)
|
||||
{
|
||||
// Console.WriteLine("Reached End ##");
|
||||
break;
|
||||
}
|
||||
|
||||
tempEnumSecretList1 = (EnumSecretList)Marshal.PtrToStructure(tempEnumSecretList1.next, typeof(EnumSecretList));
|
||||
|
||||
}
|
||||
}
|
||||
kwallet.FreeResources();
|
||||
return doc.ChildNodes[0];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int SetSecret(XmlNode secret)
|
||||
{
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int GetSecret(XmlNode secret)
|
||||
{
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int Remove(XmlNode secret)
|
||||
{
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
20
c_adlib/Makefile
Normal file
20
c_adlib/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# configure environment
|
||||
#
|
||||
TARGET = Novell.CASA.A-D
|
||||
CS_NAME = $(TARGET)$(xtra).$(CSH)
|
||||
include global.mak
|
||||
include defaults.$(PLAT)
|
||||
include rules.mak
|
||||
|
||||
|
||||
#
|
||||
# target object and source files
|
||||
#
|
||||
include src.$(PLAT)
|
||||
include objs.$(PLAT)
|
||||
|
||||
#
|
||||
# targets
|
||||
#
|
||||
include target.cs
|
||||
168
c_adlib/Novell.CASA.A-D.csproj
Normal file
168
c_adlib/Novell.CASA.A-D.csproj
Normal file
@@ -0,0 +1,168 @@
|
||||
<VisualStudioProject>
|
||||
<CSHARP
|
||||
ProjectType = "Local"
|
||||
ProductVersion = "7.10.3077"
|
||||
SchemaVersion = "2.0"
|
||||
ProjectGuid = "{25D49F34-F655-4CCF-93F1-449243AF7A32}"
|
||||
>
|
||||
<Build>
|
||||
<Settings
|
||||
ApplicationIcon = ""
|
||||
AssemblyKeyContainerName = ""
|
||||
AssemblyName = "Novell.CASA.DataEngines"
|
||||
AssemblyOriginatorKeyFile = ""
|
||||
DefaultClientScript = "JScript"
|
||||
DefaultHTMLPageLayout = "Grid"
|
||||
DefaultTargetSchema = "IE50"
|
||||
DelaySign = "false"
|
||||
OutputType = "Library"
|
||||
PreBuildEvent = ""
|
||||
PostBuildEvent = ""
|
||||
RootNamespace = "Novell.CASA.DataEngines"
|
||||
RunPostBuildEvent = "OnBuildSuccess"
|
||||
StartupObject = ""
|
||||
>
|
||||
<Config
|
||||
Name = "Debug"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "DEBUG;TRACE"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "true"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = ""
|
||||
Optimize = "false"
|
||||
OutputPath = "bin\Debug\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
<Config
|
||||
Name = "Release"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "TRACE"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "false"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = ""
|
||||
Optimize = "true"
|
||||
OutputPath = "bin\Release\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
</Settings>
|
||||
<References>
|
||||
<Reference
|
||||
Name = "System.Data"
|
||||
AssemblyName = "System.Data"
|
||||
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "System"
|
||||
AssemblyName = "System"
|
||||
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "System.XML"
|
||||
AssemblyName = "System.Xml"
|
||||
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "gdk-sharp"
|
||||
AssemblyName = "gdk-sharp"
|
||||
HintPath = "C:\Program Files\Common Files\GTK\2.4\lib\gtk-sharp-2.0\gdk-sharp.dll"
|
||||
AssemblyFolderKey = "hklm\gtk-sharp"
|
||||
/>
|
||||
<Reference
|
||||
Name = "glib-sharp"
|
||||
AssemblyName = "glib-sharp"
|
||||
HintPath = "C:\Program Files\Common Files\GTK\2.4\lib\gtk-sharp-2.0\glib-sharp.dll"
|
||||
AssemblyFolderKey = "hklm\gtk-sharp"
|
||||
/>
|
||||
<Reference
|
||||
Name = "gtk-sharp"
|
||||
AssemblyName = "gtk-sharp"
|
||||
HintPath = "C:\Program Files\Common Files\GTK\2.4\lib\gtk-sharp-2.0\gtk-sharp.dll"
|
||||
AssemblyFolderKey = "hklm\gtk-sharp"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Novell.CASA.CASAPolicy"
|
||||
Project = "{636A9D7E-BFB5-4EB9-96F8-51FF85A98826}"
|
||||
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Novell.CASA.miCASAWrapper"
|
||||
Project = "{E21DD887-22F4-4935-9851-409715F663B0}"
|
||||
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Novell.CASA.Common"
|
||||
Project = "{57CD94A2-5B4A-40C3-8189-CB760FB78357}"
|
||||
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
/>
|
||||
</References>
|
||||
</Build>
|
||||
<Files>
|
||||
<Include>
|
||||
<File
|
||||
RelPath = "AD_Facade.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Common.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "GKEngine.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "IDataEngine.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "KWalletEngine.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "miCASAEngine.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "ad_gk\GnomeKeyring.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "ad_kw\KWalletEnum.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "ad_kw\KWalletNative.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
</Include>
|
||||
</Files>
|
||||
</CSHARP>
|
||||
</VisualStudioProject>
|
||||
|
||||
286
c_adlib/ad_gk/GnomeKeyring.cs
Normal file
286
c_adlib/ad_gk/GnomeKeyring.cs
Normal file
@@ -0,0 +1,286 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections;
|
||||
using System.Threading;
|
||||
using Gtk;
|
||||
using GLib;
|
||||
|
||||
namespace Novell.CASA.DataEngines.GK
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class KeyringInfo
|
||||
{
|
||||
public int lockOnIdle;
|
||||
public uint lockTimeout;
|
||||
public uint mTime;
|
||||
public uint cTime;
|
||||
public int isLocked;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class NativeItemInfo
|
||||
{
|
||||
public int itemType;
|
||||
public IntPtr displayName;
|
||||
public IntPtr secret;
|
||||
public int mTime;
|
||||
public int cTime;
|
||||
public NativeItemInfo()
|
||||
{
|
||||
displayName = Marshal.AllocHGlobal(128);
|
||||
secret = Marshal.AllocHGlobal(128);
|
||||
}
|
||||
~NativeItemInfo()
|
||||
{
|
||||
Marshal.FreeHGlobal(displayName);
|
||||
Marshal.FreeHGlobal(secret);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemInfo
|
||||
{
|
||||
public string itemType;
|
||||
public string displayName;
|
||||
public string secret;
|
||||
public int mTime;
|
||||
public int cTime;
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class NativeAttribute
|
||||
{
|
||||
public uint type;
|
||||
public IntPtr key;
|
||||
public IntPtr value;
|
||||
}
|
||||
|
||||
public class Attribute
|
||||
{
|
||||
public uint type;
|
||||
public string key;
|
||||
public string value;
|
||||
|
||||
}
|
||||
|
||||
public class GnomeKeyring
|
||||
{
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int GetKeyrings(out IntPtr list);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int GetKeyringInfo(string name,KeyringInfo info);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int GetItems(string keyring,out IntPtr list);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int GetItemInfo(string keyring,int itemId, NativeItemInfo info);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int GetAttributeList(string keyring,int itemId, out IntPtr attrList);
|
||||
[DllImport("libad_gk.so")]
|
||||
public static extern int FreeAttributeList(IntPtr attrList);
|
||||
|
||||
public static KeyringInfo GKGetKeyringInfo(string name)
|
||||
{
|
||||
KeyringInfo info = null;
|
||||
try
|
||||
{
|
||||
info = new KeyringInfo();
|
||||
int retVal = GetKeyringInfo(name,info);
|
||||
if( 0 != retVal )
|
||||
info = null;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
info = null;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public static void PrintKeyringInfo(KeyringInfo info)
|
||||
{
|
||||
if( null == info )
|
||||
return;
|
||||
try
|
||||
{
|
||||
Console.WriteLine("lockOnIdle = " + info.lockOnIdle);
|
||||
Console.WriteLine("lockTimeout = " + info.lockTimeout);
|
||||
Console.WriteLine("mTime = " + info.mTime);
|
||||
Console.WriteLine("cTime = " + info.cTime);
|
||||
Console.WriteLine("isLocked = " + info.isLocked);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemInfo GKGetItemInfo(string keyring, int itemId)
|
||||
{
|
||||
ItemInfo info = null;
|
||||
try
|
||||
{
|
||||
NativeItemInfo nativeItemInfo = new NativeItemInfo();
|
||||
int retVal = GetItemInfo(keyring, itemId, nativeItemInfo);
|
||||
|
||||
if( 0 != retVal )
|
||||
info = null;
|
||||
else
|
||||
{
|
||||
info = new ItemInfo();
|
||||
if(nativeItemInfo.itemType == 0)
|
||||
info.itemType = "Generic Secret";
|
||||
else if(nativeItemInfo.itemType == 1)
|
||||
info.itemType = "Network Password";
|
||||
else if(nativeItemInfo.itemType == 2)
|
||||
info.itemType = "Note";
|
||||
else
|
||||
info.itemType = "No Type"; // need to have a better name
|
||||
|
||||
info.displayName = Marshal.PtrToStringAnsi(nativeItemInfo.displayName);
|
||||
info.secret = Marshal.PtrToStringAnsi(nativeItemInfo.secret);
|
||||
info.mTime = nativeItemInfo.mTime;
|
||||
info.cTime = nativeItemInfo.cTime;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
info = null;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public static void PrintItemInfo(ItemInfo info)
|
||||
{
|
||||
if( null == info )
|
||||
return;
|
||||
try
|
||||
{
|
||||
Console.WriteLine("CS : itemType = " + info.itemType);
|
||||
Console.WriteLine("CS : displayName = " + info.displayName);
|
||||
Console.WriteLine("CS : secret = " + info.secret);
|
||||
Console.WriteLine("CS : mTime = " + info.mTime);
|
||||
Console.WriteLine("CS : cTime = " + info.cTime);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList GKGetKeyrings()
|
||||
{
|
||||
ArrayList retList;
|
||||
try
|
||||
{
|
||||
retList = new ArrayList();
|
||||
IntPtr list = new IntPtr();
|
||||
int retVal = GetKeyrings(out list);
|
||||
if ( 0 != retVal )
|
||||
retList = null;
|
||||
GLib.List keyringList = new List(list,typeof(string));
|
||||
IEnumerator etor = (IEnumerator)(keyringList.GetEnumerator());
|
||||
string name;
|
||||
while(etor.MoveNext())
|
||||
{
|
||||
name = (string)etor.Current;
|
||||
retList.Add(name);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
retList = null;
|
||||
}
|
||||
return retList;
|
||||
}
|
||||
|
||||
public static ArrayList GKGetItems(string keyring)
|
||||
{
|
||||
ArrayList retList = null;
|
||||
try
|
||||
{
|
||||
retList = new ArrayList();
|
||||
IntPtr list = new IntPtr();
|
||||
int retVal = GetItems(keyring,out list);
|
||||
if( 0 != retVal )
|
||||
retList = null;
|
||||
GLib.List itemList = new List(list,typeof(int));
|
||||
IEnumerator etor = (IEnumerator)(itemList.GetEnumerator());
|
||||
int itemId;
|
||||
while(etor.MoveNext())
|
||||
{
|
||||
itemId = (int)etor.Current;
|
||||
retList.Add(itemId);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
retList = null;
|
||||
}
|
||||
return retList;
|
||||
}
|
||||
|
||||
public static ArrayList GKGetAttributeList(string keyring, int itemId)
|
||||
{
|
||||
ArrayList retList = null;
|
||||
try
|
||||
{
|
||||
retList = new ArrayList();
|
||||
IntPtr list = new IntPtr();
|
||||
int retVal = GetAttributeList(keyring, itemId,out list);
|
||||
if( 0 != retVal )
|
||||
retList = null;
|
||||
GLib.List attrList = new List(list,typeof(int));
|
||||
IEnumerator etor = (IEnumerator)(attrList.GetEnumerator());
|
||||
while(etor.MoveNext())
|
||||
{
|
||||
int test = (int)etor.Current;
|
||||
IntPtr ptr = new IntPtr(test);
|
||||
|
||||
NativeAttribute attr = new NativeAttribute();
|
||||
attr = (NativeAttribute)Marshal.PtrToStructure(ptr,typeof(NativeAttribute));
|
||||
|
||||
string key = Marshal.PtrToStringAnsi(attr.key);
|
||||
string value = Marshal.PtrToStringAnsi(attr.value);
|
||||
|
||||
Attribute retAttr = new Attribute();
|
||||
retAttr.type = attr.type;
|
||||
retAttr.key = String.Copy(key);
|
||||
retAttr.value = String.Copy(value);
|
||||
retList.Add(retAttr);
|
||||
}
|
||||
if(retList.Count > 0)
|
||||
FreeAttributeList(list);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
retList = null;
|
||||
}
|
||||
return retList;
|
||||
}
|
||||
|
||||
public static void PrintAttrList(ArrayList attrList)
|
||||
{
|
||||
if( null == attrList )
|
||||
return;
|
||||
Attribute attr;
|
||||
try
|
||||
{
|
||||
IEnumerator etor = (IEnumerator)(attrList.GetEnumerator());
|
||||
while(etor.MoveNext())
|
||||
{
|
||||
attr = (Attribute)(etor.Current);
|
||||
Console.WriteLine("CS : AttrType = " + attr.type);
|
||||
Console.WriteLine("CS : AttrKey = " + attr.key);
|
||||
Console.WriteLine("CS : AttrValue = " + attr.value);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
c_adlib/ad_gk/Makefile
Normal file
20
c_adlib/ad_gk/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# configure environment
|
||||
#
|
||||
TARGET = Novell.CASA.DataEngines.GnomeKeyring
|
||||
CS_NAME = $(TARGET)$(xtra).$(EXE)
|
||||
include global.mak
|
||||
include defaults.$(PLAT)
|
||||
include rules.mak
|
||||
|
||||
|
||||
#
|
||||
# target object and source files
|
||||
#
|
||||
include src.$(PLAT)
|
||||
include objs.$(PLAT)
|
||||
|
||||
#
|
||||
# targets
|
||||
#
|
||||
include target.cs
|
||||
20
c_adlib/ad_gk/native/Makefile
Normal file
20
c_adlib/ad_gk/native/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# configure environment
|
||||
#
|
||||
TARGET = ad_gk
|
||||
include global.mak
|
||||
include defaults.$(PLAT)
|
||||
include rules.mak
|
||||
|
||||
BIN_NAME = $(TARGET)$(xtra).$(BIN)
|
||||
LIB_NAME = $(TARGET)$(xtra).$(LIB)
|
||||
|
||||
#
|
||||
# target object and source files
|
||||
#
|
||||
include objs.$(PLAT)
|
||||
|
||||
#
|
||||
# targets
|
||||
#
|
||||
include target.cl
|
||||
237
c_adlib/ad_gk/native/ad_gk.c
Normal file
237
c_adlib/ad_gk/native/ad_gk.c
Normal file
@@ -0,0 +1,237 @@
|
||||
#include "ad_gk.h"
|
||||
|
||||
void ListKeyringsCb (GnomeKeyringResult result,
|
||||
GList *keyrings,
|
||||
gpointer data)
|
||||
{
|
||||
GList *l = NULL;
|
||||
char *name = NULL;
|
||||
GList **retList = data;
|
||||
|
||||
GetKeyringsCbData *cbData = data;
|
||||
GMainLoop *loop = cbData->loop;
|
||||
retList = cbData->keyringList;
|
||||
*retList = NULL;
|
||||
|
||||
if (result != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
g_print ("Unable to get keyring list - %d\n", result);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (l = keyrings; l != NULL; l = l->next)
|
||||
{
|
||||
name = l->data;
|
||||
*retList = g_list_append (*retList, g_strdup (name));
|
||||
}
|
||||
}
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
void KeyringGetInfoCb(GnomeKeyringResult result,
|
||||
GnomeKeyringInfo *info,
|
||||
gpointer data)
|
||||
{
|
||||
GetKeyringInfoCbData *cbData = data;
|
||||
KeyringInfo *retInfo = cbData->info;
|
||||
if (result != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
g_print ("Unable to get keyring info %d\n", result);
|
||||
}
|
||||
else
|
||||
{
|
||||
retInfo->lockOnIdle = gnome_keyring_info_get_lock_on_idle(info);
|
||||
retInfo->lockTimeout = gnome_keyring_info_get_lock_timeout(info);
|
||||
retInfo->mTime = gnome_keyring_info_get_mtime(info);
|
||||
retInfo->cTime = gnome_keyring_info_get_ctime(info);
|
||||
retInfo->isLocked = gnome_keyring_info_get_is_locked(info);
|
||||
}
|
||||
g_main_loop_quit (cbData->loop);
|
||||
}
|
||||
|
||||
void ListItemCb( GnomeKeyringResult result,
|
||||
GList *list,
|
||||
gpointer data)
|
||||
{
|
||||
GList **retList;
|
||||
GetItemsCbData *cbData = data;
|
||||
retList = cbData->itemList;
|
||||
*retList = NULL;
|
||||
|
||||
if (result != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
g_print ("Unable to get list of items : %d\n", result);
|
||||
}
|
||||
else
|
||||
{
|
||||
*retList = g_list_copy (list);
|
||||
}
|
||||
|
||||
g_main_loop_quit (cbData->loop);
|
||||
}
|
||||
|
||||
void ItemGetInfoCb( GnomeKeyringResult result,
|
||||
GnomeKeyringItemInfo *info,
|
||||
gpointer data)
|
||||
{
|
||||
GetItemInfoCbData *cbData = data;
|
||||
ItemInfo *itemInfo = cbData->info;
|
||||
if (result != GNOME_KEYRING_RESULT_OK)
|
||||
{
|
||||
g_print ("Unable to get Item info: %d\n", result);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemInfo->itemType = gnome_keyring_item_info_get_type(info);
|
||||
strcpy(itemInfo->displayName,gnome_keyring_item_info_get_display_name(info));
|
||||
strcpy(itemInfo->secret,gnome_keyring_item_info_get_secret(info));
|
||||
itemInfo->mTime = gnome_keyring_item_info_get_mtime(info);
|
||||
itemInfo->cTime = gnome_keyring_item_info_get_ctime(info);
|
||||
|
||||
}
|
||||
g_main_loop_quit (cbData->loop);
|
||||
}
|
||||
|
||||
void ItemGetAttributesCb(GnomeKeyringResult result,
|
||||
GnomeKeyringAttributeList *attributes,
|
||||
gpointer data)
|
||||
{
|
||||
GnomeKeyringAttribute *attrList = NULL;
|
||||
int i = 0;
|
||||
GetAttributeListCbData *cbData = data;
|
||||
|
||||
Attribute *attr = NULL;
|
||||
GList **retList;
|
||||
|
||||
retList = cbData->attrList;
|
||||
*retList = NULL;
|
||||
|
||||
if( result != GNOME_KEYRING_RESULT_OK )
|
||||
{
|
||||
g_print("Unable to get the attributes of item\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
attrList = (GnomeKeyringAttribute*)(attributes->data); //GArray has len and data
|
||||
for(i = 0; i < attributes->len; i++ )
|
||||
{
|
||||
if(attrList[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)
|
||||
{
|
||||
attr = (Attribute*)malloc(sizeof(Attribute));
|
||||
|
||||
if( NULL != attr )
|
||||
{
|
||||
memset(attr,0,sizeof(Attribute));
|
||||
attr->type = 0;
|
||||
attr->key = (char*)malloc(KEY_SIZE);
|
||||
if(attr->key != NULL)
|
||||
strcpy(attr->key,attrList[i].name);
|
||||
attr->value = (char*)malloc(VAL_SIZE);
|
||||
if(attr->value != NULL)
|
||||
strcpy(attr->value,attrList[i].value.string);
|
||||
}
|
||||
}
|
||||
else if(attrList[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32)
|
||||
{
|
||||
attr = (Attribute*)malloc(sizeof(Attribute));
|
||||
if( NULL != attr )
|
||||
{
|
||||
memset(attr,0,sizeof(Attribute));
|
||||
attr->type = 0;
|
||||
attr->key = (char*)malloc(KEY_SIZE);
|
||||
if(attr->key != NULL)
|
||||
strcpy(attr->key,attrList[i].name);
|
||||
attr->value = (char*)malloc(VAL_SIZE);
|
||||
if(attr->value != NULL)
|
||||
sprintf(attr->value,"%d",attrList[i].value.integer);
|
||||
}
|
||||
}
|
||||
*retList = g_list_append (*retList, attr);
|
||||
}
|
||||
}
|
||||
g_main_loop_quit (cbData->loop);
|
||||
}
|
||||
|
||||
int GetKeyrings(GList **keyringList)
|
||||
{
|
||||
GList *l = NULL;
|
||||
|
||||
GetKeyringsCbData cbData;
|
||||
cbData.loop = g_main_loop_new (NULL, FALSE);
|
||||
cbData.keyringList = keyringList;
|
||||
|
||||
gnome_keyring_list_keyring_names(ListKeyringsCb,&cbData,NULL);
|
||||
g_main_loop_run(cbData.loop);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int GetKeyringInfo(char *keyring,KeyringInfo *info)
|
||||
{
|
||||
GetKeyringInfoCbData cbData;
|
||||
|
||||
cbData.loop = g_main_loop_new (NULL, FALSE);
|
||||
cbData.info = info;
|
||||
|
||||
gnome_keyring_get_info(keyring, KeyringGetInfoCb,&cbData, NULL);
|
||||
g_main_loop_run (cbData.loop);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int GetItems(char *keyring, GList **itemList)
|
||||
{
|
||||
GList *l = NULL;
|
||||
gint itemId;
|
||||
GetItemsCbData cbData;
|
||||
cbData.loop = g_main_loop_new (NULL, FALSE);
|
||||
cbData.itemList = itemList;
|
||||
|
||||
gnome_keyring_list_item_ids(keyring, ListItemCb, &cbData, NULL);
|
||||
g_main_loop_run (cbData.loop);
|
||||
return SUCCESS;
|
||||
}
|
||||
int GetItemInfo(char *keyring, int itemId, ItemInfo *info)
|
||||
{
|
||||
GetItemInfoCbData cbData;
|
||||
cbData.loop = g_main_loop_new (NULL, FALSE);
|
||||
cbData.info = info;
|
||||
|
||||
gnome_keyring_item_get_info (keyring,itemId, ItemGetInfoCb,
|
||||
&cbData, NULL);
|
||||
g_main_loop_run (cbData.loop);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int GetAttributeList(char *keyring, int itemId, GList **attrList)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
GetAttributeListCbData cbData;
|
||||
cbData.loop = g_main_loop_new (NULL, FALSE);
|
||||
cbData.attrList = attrList;
|
||||
|
||||
gnome_keyring_item_get_attributes (keyring, itemId,
|
||||
ItemGetAttributesCb, &cbData,
|
||||
NULL);
|
||||
g_main_loop_run (cbData.loop);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int FreeAttributeList(GList *attrList)
|
||||
{
|
||||
GList *l;
|
||||
Attribute *attr = NULL;
|
||||
for(l = attrList; l != NULL; l = l->next)
|
||||
{
|
||||
attr = (Attribute*)(l->data);
|
||||
if(attr->key)
|
||||
{
|
||||
free(attr->key);
|
||||
}
|
||||
if(attr->value)
|
||||
{
|
||||
free(attr->value);
|
||||
}
|
||||
}
|
||||
g_list_free(attrList);
|
||||
return SUCCESS;
|
||||
}
|
||||
76
c_adlib/ad_gk/native/ad_gk.h
Normal file
76
c_adlib/ad_gk/native/ad_gk.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef _AD_GK_H_
|
||||
#define _AD_GK_H_
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <glib.h>
|
||||
#include <gnome-keyring.h>
|
||||
|
||||
#define SUCCESS 0
|
||||
#define FAILURE -1
|
||||
|
||||
#define KEY_SIZE 128
|
||||
#define VAL_SIZE 128
|
||||
|
||||
typedef struct _KeyringInfo
|
||||
{
|
||||
int32_t lockOnIdle;
|
||||
uint32_t lockTimeout;
|
||||
uint32_t mTime;
|
||||
uint32_t cTime;
|
||||
int32_t isLocked;
|
||||
}KeyringInfo;
|
||||
|
||||
typedef struct _ItemInfo
|
||||
{
|
||||
int32_t itemType;
|
||||
char *displayName;
|
||||
char *secret;
|
||||
uint32_t mTime;
|
||||
uint32_t cTime;
|
||||
}ItemInfo;
|
||||
|
||||
typedef struct _Attribute
|
||||
{
|
||||
uint32_t type;
|
||||
char *key;
|
||||
char *value;
|
||||
}Attribute;
|
||||
|
||||
|
||||
int GetKeyrings(GList **retList);
|
||||
int GetKeyringInfo(char *keyring,KeyringInfo *info);
|
||||
int GetItems(char *keyring, GList **itemList);
|
||||
int GetItemInfo(char *keyring, int itemId, ItemInfo *info);
|
||||
int GetAttributeList(char *keyring, int itemId, GList **);
|
||||
int FreeAttributeList(GList *attrList);
|
||||
|
||||
typedef struct _GetKeyringsCbData
|
||||
{
|
||||
GList **keyringList;
|
||||
GMainLoop *loop;
|
||||
}GetKeyringsCbData;
|
||||
|
||||
typedef struct _GetKeyringInfoCbData
|
||||
{
|
||||
KeyringInfo *info;
|
||||
GMainLoop *loop;
|
||||
}GetKeyringInfoCbData;
|
||||
|
||||
typedef struct _GetItemsCbData
|
||||
{
|
||||
GList **itemList;
|
||||
GMainLoop *loop;
|
||||
}GetItemsCbData;
|
||||
|
||||
typedef struct _GetItemInfoCbData
|
||||
{
|
||||
ItemInfo *info;
|
||||
GMainLoop *loop;
|
||||
}GetItemInfoCbData;
|
||||
|
||||
typedef struct _GetAttributeListCbData
|
||||
{
|
||||
GList **attrList;
|
||||
GMainLoop *loop;
|
||||
}GetAttributeListCbData;
|
||||
#endif
|
||||
13
c_adlib/ad_gk/native/link.lux
Normal file
13
c_adlib/ad_gk/native/link.lux
Normal file
@@ -0,0 +1,13 @@
|
||||
LINK = $(CPP) \
|
||||
-Wl,-Bsymbolic \
|
||||
-shared \
|
||||
-pthread\
|
||||
-O2 -fno-exceptions -fno-check-new\
|
||||
-Wl,-rpath -Wl,/usr/lib$(ARCH_LIB) \
|
||||
-L/usr/lib$(ARCH_LIB) -lpthread -lc -ldl \
|
||||
-Wl,-soname -Wl,lib$(TARGET).so.$(PROD_NUM) \
|
||||
-o $(LIBDIR)$(XTRA)/lib$(TARGET).so.$(BLD_VER) \
|
||||
-L$(LIBDIR)$(XTRA) \
|
||||
$(OBJDIR)*.$(O) `pkg-config --libs gnome-keyring-1` -lgnome-keyring \
|
||||
`pkg-config --libs glib-2.0` -lglib-2.0
|
||||
|
||||
2
c_adlib/ad_gk/native/objs.lux
Normal file
2
c_adlib/ad_gk/native/objs.lux
Normal file
@@ -0,0 +1,2 @@
|
||||
OBJS=\
|
||||
ad_gk.$(O)
|
||||
2
c_adlib/ad_gk/objs.lux
Normal file
2
c_adlib/ad_gk/objs.lux
Normal file
@@ -0,0 +1,2 @@
|
||||
OBJS=\
|
||||
GnomeKeyring
|
||||
2
c_adlib/ad_gk/src.lux
Normal file
2
c_adlib/ad_gk/src.lux
Normal file
@@ -0,0 +1,2 @@
|
||||
SRC=\
|
||||
GnomeKeyring.cs
|
||||
23
c_adlib/ad_kw/KWalletEnum.cs
Normal file
23
c_adlib/ad_kw/KWalletEnum.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Novell.CASA.DataEngines.KWallet
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class EnumSecretList
|
||||
{
|
||||
|
||||
public IntPtr walletName;
|
||||
public IntPtr folderName;
|
||||
public int entryType;
|
||||
public IntPtr secretVal;
|
||||
public IntPtr next;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
127
c_adlib/ad_kw/KWalletNative.cs
Normal file
127
c_adlib/ad_kw/KWalletNative.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Novell.CASA.DataEngines.KWallet
|
||||
{
|
||||
|
||||
public class kwallet
|
||||
{
|
||||
|
||||
//private static int MAX_NAME_LENGTH = 512;
|
||||
private const string CPP_LIB = "kwallets_rw";
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
[DllImport(CPP_LIB)]
|
||||
public static extern void MyTest(
|
||||
EnumSecretList enumSecretList
|
||||
);
|
||||
|
||||
*/
|
||||
[DllImport(CPP_LIB)]
|
||||
public static extern void Aggregate(
|
||||
EnumSecretList enumSecretList
|
||||
);
|
||||
|
||||
[DllImport(CPP_LIB)]
|
||||
public static extern void FreeList();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public static int Try(EnumSecretList enumSecretList)
|
||||
{
|
||||
MyTest(enumSecretList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
public static int AggregateKW(EnumSecretList enumSecretList)
|
||||
{
|
||||
Aggregate(enumSecretList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int FreeResources()
|
||||
{
|
||||
FreeList();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TBD: All this for future.
|
||||
/*
|
||||
[DllImport(CPP_LIB)]
|
||||
public static extern int ReadSecret
|
||||
(
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
String walletName,
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
String folderName,
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
String key,
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
Byte[] secretVal
|
||||
);
|
||||
|
||||
[DllImport(CPP_LIB)]
|
||||
public static extern int WriteSecret
|
||||
(
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
String walletName,
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
String folderName,
|
||||
int entryType,
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
String key,
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
Byte[] secret
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
[DllImport(CPP_LIB)]
|
||||
public static extern void CloseAllWallets();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int ReadWallet(String walletName, String folderName, String key, Byte[] secretVal)
|
||||
{
|
||||
|
||||
// Read a secret from wallet
|
||||
return (ReadSecret(walletName, folderName, key, secretVal));
|
||||
}
|
||||
|
||||
public static int WriteWallet(String walletName, String folderName,int entryType, String key, Byte[] secretVal)
|
||||
{
|
||||
|
||||
// Write secret to wallet
|
||||
return (WriteSecret( walletName, folderName, entryType, key, secretVal));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void DisconnectApplication()
|
||||
{
|
||||
|
||||
CloseAllWallets();
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
20
c_adlib/ad_kw/Makefile
Normal file
20
c_adlib/ad_kw/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# configure environment
|
||||
#
|
||||
TARGET = Novell.CASA.DataEngines.KWallet
|
||||
CS_NAME = $(TARGET)$(xtra).$(EXE)
|
||||
include global.mak
|
||||
include defaults.$(PLAT)
|
||||
include rules.mak
|
||||
|
||||
|
||||
#
|
||||
# target object and source files
|
||||
#
|
||||
include src.$(PLAT)
|
||||
include objs.$(PLAT)
|
||||
|
||||
#
|
||||
# targets
|
||||
#
|
||||
include target.cs
|
||||
20
c_adlib/ad_kw/native/Makefile
Normal file
20
c_adlib/ad_kw/native/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# configure environment
|
||||
#
|
||||
TARGET = kwallets_rw
|
||||
include global.mak
|
||||
include defaults.$(PLAT)
|
||||
include rules.mak
|
||||
|
||||
BIN_NAME = $(TARGET)$(xtra).$(BIN)
|
||||
LIB_NAME = $(TARGET)$(xtra).$(LIB)
|
||||
|
||||
#
|
||||
# target object and source files
|
||||
#
|
||||
include objs.$(PLAT)
|
||||
|
||||
#
|
||||
# targets
|
||||
#
|
||||
include target.cl
|
||||
49
c_adlib/ad_kw/native/casa_dcop.h
Normal file
49
c_adlib/ad_kw/native/casa_dcop.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// -*- c++ -*-
|
||||
#ifndef DCOPIFACEDEMO_H
|
||||
#define DCOPIFACEDEMO_H
|
||||
|
||||
|
||||
#include <qvbox.h>
|
||||
|
||||
|
||||
/**
|
||||
* Adding DCOP interface to the Console.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
struct EnumSecretList
|
||||
{
|
||||
// struct SecretInfo *sInfo;
|
||||
char *walletName;
|
||||
char *folderName;
|
||||
int entryType;
|
||||
char *secretVal;
|
||||
struct EnumSecretList *next;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class DCOPDemoWidget : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DCOPDemoWidget();
|
||||
~DCOPDemoWidget();
|
||||
|
||||
public slots:
|
||||
|
||||
int ReadAllWalletSecrets(struct EnumSecretList **);
|
||||
|
||||
private:
|
||||
|
||||
int ReadKey(Wallet *, QString, QByteArray*);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
389
c_adlib/ad_kw/native/kwallets_rw.cpp
Normal file
389
c_adlib/ad_kw/native/kwallets_rw.cpp
Normal file
@@ -0,0 +1,389 @@
|
||||
#include<stdio.h>
|
||||
#include <kapp.h>
|
||||
#include <kcmdlineargs.h>
|
||||
#include<kwallet.h>
|
||||
#include <dcopclient.h>
|
||||
|
||||
|
||||
using namespace KWallet;
|
||||
|
||||
#include "kwallets_rw.h"
|
||||
#include "kwallets_rw.moc"
|
||||
//#include "mytest.h"
|
||||
|
||||
|
||||
// char *applName="dcopifacedemo";
|
||||
char *applName="casaconsole";
|
||||
QStringList walletList;
|
||||
|
||||
DCOPDemoWidget *win = new DCOPDemoWidget();
|
||||
|
||||
DCOPDemoWidget::DCOPDemoWidget()
|
||||
{
|
||||
if ( !kapp->dcopClient()->isRegistered() ) {
|
||||
kapp->dcopClient()->registerAs( "casaconsole" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DCOPDemoWidget::~DCOPDemoWidget()
|
||||
{
|
||||
|
||||
for ( QStringList::Iterator walletIter = walletList.begin(); walletIter != walletList.end(); ++walletIter )
|
||||
{
|
||||
QString walletName = (*walletIter);
|
||||
Wallet::disconnectApplication(walletName,applName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int DCOPDemoWidget::ReadKey(Wallet *wallet,QString key, QByteArray *secretVal)
|
||||
{
|
||||
|
||||
// Read the secret from the entry
|
||||
QByteArray value;
|
||||
|
||||
if (wallet->readEntry(key, value)==0)
|
||||
{
|
||||
|
||||
if (value)
|
||||
{
|
||||
|
||||
*secretVal = value;
|
||||
QDataStream convert(*secretVal, IO_ReadOnly);
|
||||
|
||||
|
||||
if (wallet->entryType(key) == 1 )
|
||||
{
|
||||
|
||||
// Convert the ByteArray to QString
|
||||
QString passwd;
|
||||
convert >> passwd;
|
||||
|
||||
} else if (wallet->entryType(key) == 3)
|
||||
{
|
||||
|
||||
// If the entry is of type "map"
|
||||
// Convert the ByteArray to QMap
|
||||
QMap<QString,QString> mapSecret;
|
||||
convert >> mapSecret;
|
||||
|
||||
// Iterate through each map entry.
|
||||
QMap<QString,QString>::Iterator mapIter;
|
||||
QString tempSecret = QString::fromLatin1("");
|
||||
|
||||
for ( mapIter = mapSecret.begin(); mapIter != mapSecret.end(); ++mapIter )
|
||||
{
|
||||
// This logic has to be improved
|
||||
tempSecret.append(mapIter.key().latin1());
|
||||
tempSecret.append(":");
|
||||
tempSecret.append(mapIter.data().latin1());
|
||||
|
||||
if ((++mapIter) != mapSecret.end())
|
||||
tempSecret.append(";");
|
||||
|
||||
--mapIter;
|
||||
}
|
||||
|
||||
// Convert the QString to QByteArray
|
||||
QDataStream stream(*secretVal, IO_WriteOnly);
|
||||
stream << tempSecret ;
|
||||
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
printf("Could not read the entry..inner IF\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
printf("Could not read the entry Inside wallet->readkey\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
struct EnumSecretList *tempEnumSecrets = NULL;
|
||||
|
||||
//void MyTest(struct EnumSecretList *enumWalletSecrets)
|
||||
void Aggregate(struct EnumSecretList *enumWalletSecrets)
|
||||
{
|
||||
|
||||
printf("inside natiove agg");
|
||||
int retVal = 0;
|
||||
// struct EnumSecretList *tempEnumSecrets = NULL;
|
||||
retVal = win->ReadAllWalletSecrets(&tempEnumSecrets);
|
||||
|
||||
struct EnumSecretList *iter = tempEnumSecrets;
|
||||
//struct EnumSecretList *head = tempEnumSecrets;
|
||||
/*
|
||||
if (iter == NULL)
|
||||
{
|
||||
|
||||
printf("Native has given NULLLL\n");
|
||||
enumWalletSecrets = NULL;
|
||||
return;
|
||||
}
|
||||
*/
|
||||
while (iter != NULL)
|
||||
{
|
||||
|
||||
/*
|
||||
printf("\n\n**Wallet Name : %s\n",iter->walletName);
|
||||
printf("\t**Folder Name : %s\n",iter->folderName);
|
||||
printf("\t\t**Secret Type : %d\n",iter->entryType);
|
||||
printf("\t\t\t**Secret Value : %s\n",iter->secretVal);
|
||||
*/
|
||||
|
||||
enumWalletSecrets->walletName = iter->walletName;
|
||||
enumWalletSecrets->folderName = iter->folderName;
|
||||
enumWalletSecrets->secretVal = iter->secretVal;
|
||||
enumWalletSecrets->entryType = iter->entryType;
|
||||
enumWalletSecrets->next = iter->next;
|
||||
|
||||
iter = iter->next;
|
||||
if (iter != NULL)
|
||||
{
|
||||
enumWalletSecrets = enumWalletSecrets->next ;
|
||||
}
|
||||
else
|
||||
{
|
||||
enumWalletSecrets = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
// Free the list
|
||||
struct EnumSecretList *temp;
|
||||
while (head != NULL)
|
||||
{
|
||||
free(head->walletName);
|
||||
free(head->folderName);
|
||||
free(head->secretVal);
|
||||
//free(head->entryType);
|
||||
temp = head->next;
|
||||
free(head);
|
||||
head = temp;
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FreeList()
|
||||
{
|
||||
|
||||
struct EnumSecretList *head = tempEnumSecrets;
|
||||
|
||||
// Free the list
|
||||
struct EnumSecretList *temp;
|
||||
while (head != NULL)
|
||||
{
|
||||
free(head->walletName);
|
||||
free(head->folderName);
|
||||
free(head->secretVal);
|
||||
//free(head->entryType);
|
||||
temp = head->next;
|
||||
free(head);
|
||||
head = temp;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int DCOPDemoWidget::ReadAllWalletSecrets(struct EnumSecretList **enumWalletSecrets)
|
||||
{
|
||||
|
||||
walletList = Wallet::walletList();
|
||||
for ( QStringList::Iterator walletIter = walletList.begin(); walletIter != walletList.end(); ++walletIter )
|
||||
{
|
||||
QString walletName = (*walletIter);
|
||||
// printf("The wallet name is %s\n",(*walletIter).latin1());
|
||||
|
||||
|
||||
// Open the wallet
|
||||
Wallet *wallet = NULL;
|
||||
wallet = Wallet::openWallet(walletName,0,Wallet::Synchronous);
|
||||
|
||||
if (wallet == NULL)
|
||||
{
|
||||
printf("Could not open the wallet\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the folder list of the wallet
|
||||
QStringList folderList = wallet->folderList();
|
||||
|
||||
for ( QStringList::Iterator folderIter = folderList.begin(); folderIter != folderList.end(); ++folderIter)
|
||||
{
|
||||
|
||||
// printf("\t%s\n",(*folderIter).latin1());
|
||||
QString folderName = (*folderIter);
|
||||
|
||||
// Set the current folder
|
||||
if (!(wallet->setFolder(folderName)))
|
||||
{
|
||||
printf("Could not set the folder\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the list of entries in the folder
|
||||
QStringList entryList = wallet->entryList();
|
||||
|
||||
for ( QStringList::Iterator entryIter = entryList.begin(); entryIter != entryList.end(); ++entryIter)
|
||||
{
|
||||
//printf("Entry Name : \t\t%s\n",(*entryIter).latin1());
|
||||
|
||||
// Read the secret from the entry
|
||||
QString key = (*entryIter);
|
||||
|
||||
QByteArray *secretVal = new QByteArray();
|
||||
if (ReadKey(wallet,key,secretVal) != 0)
|
||||
{
|
||||
printf("Could not read \"%s\"\n",key.latin1());
|
||||
break;
|
||||
//FIXME
|
||||
}
|
||||
|
||||
struct EnumSecretList *tempWalletSecrets = (struct EnumSecretList*)malloc(sizeof(struct EnumSecretList));
|
||||
|
||||
if (tempWalletSecrets == NULL) {
|
||||
printf("Memory Allocation failure\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tempWalletSecrets->walletName = (char*)malloc(512);
|
||||
|
||||
if (tempWalletSecrets->walletName == NULL)
|
||||
{
|
||||
printf("Memory Allocation failure\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//printf("Wallet Name is %s\n",walletName.latin1());
|
||||
strcpy(tempWalletSecrets->walletName, walletName.latin1());
|
||||
tempWalletSecrets->folderName = (char*)malloc(512);
|
||||
|
||||
if (tempWalletSecrets->folderName == NULL)
|
||||
{
|
||||
printf("Memory Allocation failure\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// printf("Folder Name is %s\n",folderName.latin1());
|
||||
|
||||
strcpy(tempWalletSecrets->folderName, folderName.latin1());
|
||||
tempWalletSecrets->entryType = wallet->entryType(key);
|
||||
// printf("EntryType is %d\n",wallet->entryType(key));
|
||||
|
||||
|
||||
if (*enumWalletSecrets == NULL)
|
||||
{
|
||||
*enumWalletSecrets = tempWalletSecrets;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct EnumSecretList *iter;
|
||||
for(iter=*enumWalletSecrets; iter->next!=NULL; iter=iter->next);
|
||||
iter->next = tempWalletSecrets;
|
||||
}
|
||||
|
||||
tempWalletSecrets->next = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
QDataStream convert(*secretVal, IO_ReadOnly);
|
||||
QString passwd;
|
||||
convert >> passwd;
|
||||
tempWalletSecrets->secretVal = (char*)malloc(512);
|
||||
|
||||
if (tempWalletSecrets->secretVal == NULL)
|
||||
{
|
||||
printf("Memory Allocation failure\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(tempWalletSecrets->secretVal,key.latin1());
|
||||
//printf("After strcpy - 1 - key is %s\n",key.latin1());
|
||||
strcat(tempWalletSecrets->secretVal,"=");
|
||||
//printf("After strcat = \n");
|
||||
if(passwd)
|
||||
{
|
||||
//printf("Passwd is %s\n",passwd.latin1());
|
||||
strcat(tempWalletSecrets->secretVal,passwd.latin1());
|
||||
}
|
||||
|
||||
// Free memory
|
||||
free(secretVal);
|
||||
// printf("After free\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Print all the secrets
|
||||
/*
|
||||
struct EnumSecretList *iter = *enumWalletSecrets;
|
||||
while (iter != NULL)
|
||||
{
|
||||
printf("\n\nWallet Name : %s\n",iter->walletName);
|
||||
printf("\tFolder Name : %s\n",iter->folderName);
|
||||
printf("\t\tSecret Type : %d\n",iter->entryType);
|
||||
printf("\t\t\t Secret Value : %s\n",iter->secretVal);
|
||||
iter = iter->next;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
return(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
54
c_adlib/ad_kw/native/kwallets_rw.h
Normal file
54
c_adlib/ad_kw/native/kwallets_rw.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// -*- c++ -*-
|
||||
#ifndef DCOPIFACEDEMO_H
|
||||
#define DCOPIFACEDEMO_H
|
||||
#include <qvbox.h>
|
||||
|
||||
|
||||
/**
|
||||
* Adding DCOP interface to an app.
|
||||
*/
|
||||
|
||||
|
||||
struct EnumSecretList
|
||||
{
|
||||
char *walletName;
|
||||
char *folderName;
|
||||
int entryType;
|
||||
char *secretVal;
|
||||
struct EnumSecretList *next;
|
||||
};
|
||||
|
||||
|
||||
struct TryEnumSecretList
|
||||
{
|
||||
char *name;
|
||||
struct TryEnumSecretList *next;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class DCOPDemoWidget : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DCOPDemoWidget();
|
||||
~DCOPDemoWidget();
|
||||
|
||||
public slots:
|
||||
|
||||
// void dump();
|
||||
int ReadAllWalletSecrets(struct EnumSecretList **);
|
||||
// int ReadWalletSecret(QString, QString, QString, QByteArray*);
|
||||
// int WriteWalletSecret(QString, QString, QString, QByteArray , int);
|
||||
|
||||
private:
|
||||
|
||||
int ReadKey(Wallet*, QString, QByteArray*);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
108
c_adlib/ad_kw/native/kwallets_rw.moc
Normal file
108
c_adlib/ad_kw/native/kwallets_rw.moc
Normal file
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
** DCOPDemoWidget meta object code from reading C++ file 'casa_dcop.h'
|
||||
**
|
||||
** Created: Wed Mar 23 15:53:55 2005
|
||||
** by: The Qt MOC ($Id: qt/moc_yacc.cpp 3.3.1 edited Feb 18 14:21 $)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#undef QT_NO_COMPAT
|
||||
//#include "mytest.h"
|
||||
#include "casa_dcop.h"
|
||||
#include <qmetaobject.h>
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <private/qucomextra_p.h>
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
|
||||
#error "This file was generated using the moc from 3.3.1. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
const char *DCOPDemoWidget::className() const
|
||||
{
|
||||
return "DCOPDemoWidget";
|
||||
}
|
||||
|
||||
QMetaObject *DCOPDemoWidget::metaObj = 0;
|
||||
static QMetaObjectCleanUp cleanUp_DCOPDemoWidget( "DCOPDemoWidget", &DCOPDemoWidget::staticMetaObject );
|
||||
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
QString DCOPDemoWidget::tr( const char *s, const char *c )
|
||||
{
|
||||
if ( qApp )
|
||||
return qApp->translate( "DCOPDemoWidget", s, c, QApplication::DefaultCodec );
|
||||
else
|
||||
return QString::fromLatin1( s );
|
||||
}
|
||||
#ifndef QT_NO_TRANSLATION_UTF8
|
||||
QString DCOPDemoWidget::trUtf8( const char *s, const char *c )
|
||||
{
|
||||
if ( qApp )
|
||||
return qApp->translate( "DCOPDemoWidget", s, c, QApplication::UnicodeUTF8 );
|
||||
else
|
||||
return QString::fromUtf8( s );
|
||||
}
|
||||
#endif // QT_NO_TRANSLATION_UTF8
|
||||
|
||||
#endif // QT_NO_TRANSLATION
|
||||
|
||||
QMetaObject* DCOPDemoWidget::staticMetaObject()
|
||||
{
|
||||
if ( metaObj )
|
||||
return metaObj;
|
||||
QMetaObject* parentObject = QObject::staticMetaObject();
|
||||
static const QUMethod slot_0 = {"dump", 0, 0 };
|
||||
// static const QUMethod slot_1 = {"getKWalletSecret", 0, 0 };
|
||||
// static const QUMethod slot_2 = {"setKWalletSecret", 0, 0 };
|
||||
static const QMetaData slot_tbl[] = {
|
||||
{ "dump()", &slot_0, QMetaData::Public },
|
||||
// { "getKWalletSecret()", &slot_1, QMetaData::Public },
|
||||
// { "setKWalletSecret()", &slot_2, QMetaData::Public }
|
||||
};
|
||||
metaObj = QMetaObject::new_metaobject(
|
||||
"DCOPDemoWidget", parentObject,
|
||||
slot_tbl, 3,
|
||||
0, 0,
|
||||
#ifndef QT_NO_PROPERTIES
|
||||
0, 0,
|
||||
0, 0,
|
||||
#endif // QT_NO_PROPERTIES
|
||||
0, 0 );
|
||||
cleanUp_DCOPDemoWidget.setMetaObject( metaObj );
|
||||
return metaObj;
|
||||
}
|
||||
|
||||
void* DCOPDemoWidget::qt_cast( const char* clname )
|
||||
{
|
||||
if ( !qstrcmp( clname, "DCOPDemoWidget" ) )
|
||||
return this;
|
||||
return QObject::qt_cast( clname );
|
||||
}
|
||||
|
||||
bool DCOPDemoWidget::qt_invoke( int _id, QUObject* _o )
|
||||
{
|
||||
switch ( _id - staticMetaObject()->slotOffset() ) {
|
||||
case 0: break;//dump(); break;
|
||||
// case 1: getKWalletSecret(); break;
|
||||
// case 2: setKWalletSecret(); break;
|
||||
default:
|
||||
return QObject::qt_invoke( _id, _o );
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool DCOPDemoWidget::qt_emit( int _id, QUObject* _o )
|
||||
{
|
||||
return QObject::qt_emit(_id,_o);
|
||||
}
|
||||
#ifndef QT_NO_PROPERTIES
|
||||
|
||||
bool DCOPDemoWidget::qt_property( int id, int f, QVariant* v)
|
||||
{
|
||||
return QObject::qt_property( id, f, v);
|
||||
}
|
||||
|
||||
bool DCOPDemoWidget::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
|
||||
#endif // QT_NO_PROPERTIES
|
||||
14
c_adlib/ad_kw/native/link.lux
Normal file
14
c_adlib/ad_kw/native/link.lux
Normal file
@@ -0,0 +1,14 @@
|
||||
LINK = $(CPP) \
|
||||
-Wl,-Bsymbolic \
|
||||
-shared \
|
||||
-pthread\
|
||||
-O2 -fno-exceptions -fno-check-new\
|
||||
-Wl,-rpath -Wl,/usr/lib$(ARC) \
|
||||
-L/usr/lib$(ARC) -lpthread -lc -ldl \
|
||||
-Wl,-soname -Wl,lib$(TARGET).so.$(PROD_NUM) \
|
||||
-o $(LIBDIR)$(XTRA)/lib$(TARGET).so.$(BLD_VER) \
|
||||
-L$(LIBDIR)$(XTRA) \
|
||||
$(OBJDIR)*.$(O) -L/opt/kde3/lib$(ARC) \
|
||||
-L/usr/X11R6/lib$(ARC) -L/usr/lib/qt3/lib$(ARC) \
|
||||
-lkwalletclient -lqt-mt
|
||||
|
||||
2
c_adlib/ad_kw/native/objs.lux
Normal file
2
c_adlib/ad_kw/native/objs.lux
Normal file
@@ -0,0 +1,2 @@
|
||||
OBJS=\
|
||||
kwallets_rw.$(O)
|
||||
3
c_adlib/ad_kw/objs.lux
Normal file
3
c_adlib/ad_kw/objs.lux
Normal file
@@ -0,0 +1,3 @@
|
||||
OBJS=\
|
||||
KWalletEnum\
|
||||
KWalletNative
|
||||
3
c_adlib/ad_kw/src.lux
Normal file
3
c_adlib/ad_kw/src.lux
Normal file
@@ -0,0 +1,3 @@
|
||||
SRC=\
|
||||
KWalletEnum.cs\
|
||||
KWalletNative.cs
|
||||
382
c_adlib/miCASAEngine.cs
Normal file
382
c_adlib/miCASAEngine.cs
Normal file
@@ -0,0 +1,382 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using Novell.CASA;
|
||||
using System.Collections.Specialized;
|
||||
using Novell.CASA.DataEngines.Common;
|
||||
|
||||
|
||||
|
||||
namespace Novell.CASA.DataEngines
|
||||
{
|
||||
|
||||
/*
|
||||
* This class is implementation of Data engine for miCASA.
|
||||
*/
|
||||
|
||||
//TBD: Generally we need to find out if fault is in parameter or miCASA or not available
|
||||
|
||||
class miCASAEngine : DataEngine
|
||||
{
|
||||
|
||||
public SecretStore store = null;
|
||||
|
||||
public miCASAEngine()
|
||||
{
|
||||
|
||||
//TBD: What happens here at miCASA end ?
|
||||
store = SecretStore.getInstance();
|
||||
}
|
||||
|
||||
public XmlNode Aggregate()
|
||||
{
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
XmlElement key1;
|
||||
XmlAttribute Atr;
|
||||
XmlElement value1;
|
||||
XmlElement mi_secret;
|
||||
XmlAttribute synchAttr;
|
||||
XmlAttribute secidAttr;
|
||||
String sKey, sValue;
|
||||
|
||||
|
||||
//Adding miCASA Top Node
|
||||
XmlElement elem = doc.CreateElement(ConstStrings.miCASA);
|
||||
doc.AppendChild(elem);
|
||||
|
||||
|
||||
StringCollection sc = store.enumerateSecretIDs();
|
||||
if (sc != null)
|
||||
{
|
||||
// Adding Keychain
|
||||
XmlElement keychain = doc.CreateElement(ConstStrings.CCF_KEYCHAIN);
|
||||
XmlAttribute id_attr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
id_attr.Value = ConstStrings.CCF_KEYCHAINNAME;
|
||||
keychain.SetAttributeNode(id_attr);
|
||||
elem.AppendChild(keychain);
|
||||
|
||||
|
||||
StringEnumerator se = sc.GetEnumerator();
|
||||
se.Reset();
|
||||
|
||||
while (se.MoveNext())
|
||||
{
|
||||
|
||||
Secret secret = store.getSecret(se.Current);
|
||||
NameValueCollection nvc = secret.getKeyValueCollection();
|
||||
|
||||
mi_secret = doc.CreateElement(ConstStrings.CCF_SECRET);
|
||||
synchAttr = doc.CreateAttribute(ConstStrings.CCF_SYNCH);
|
||||
//TBD:
|
||||
synchAttr.Value = "Persistent Secret" ;
|
||||
secidAttr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
secidAttr.Value = se.Current;
|
||||
mi_secret.SetAttributeNode(secidAttr);
|
||||
mi_secret.SetAttributeNode(synchAttr);
|
||||
|
||||
|
||||
for (int i = 0; i < nvc.Count; i++)
|
||||
{
|
||||
|
||||
sKey = nvc.GetKey(i);
|
||||
sValue = nvc.Get(sKey);
|
||||
|
||||
//Key
|
||||
key1 = doc.CreateElement(ConstStrings.CCF_KEY);
|
||||
Atr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
|
||||
Atr.Value = sKey;
|
||||
key1.SetAttributeNode(Atr);
|
||||
|
||||
//Value
|
||||
value1 = doc.CreateElement(ConstStrings.CCF_VALUE);
|
||||
value1.InnerText = sValue;
|
||||
|
||||
key1.AppendChild(value1);
|
||||
|
||||
mi_secret.AppendChild(key1);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
//Time
|
||||
XmlElement Time1 = doc.CreateElement(ConstStrings.CCF_TIME);
|
||||
|
||||
XmlElement zone1 = doc.CreateElement(ConstStrings.CCF_ZONE);
|
||||
zone1.InnerText = "IST";
|
||||
|
||||
XmlElement cr1 = doc.CreateElement(ConstStrings.CCF_CRTIME);
|
||||
cr1.InnerText = null;
|
||||
|
||||
XmlElement mod1 = doc.CreateElement(ConstStrings.CCF_MDTIME);
|
||||
mod1.InnerText = null;
|
||||
|
||||
XmlElement acc1 = doc.CreateElement(ConstStrings.CCF_ACTIME);
|
||||
acc1.InnerText = null;
|
||||
|
||||
Time1.AppendChild(zone1);
|
||||
Time1.AppendChild(cr1);
|
||||
Time1.AppendChild(mod1);
|
||||
Time1.AppendChild(acc1);
|
||||
|
||||
mi_secret.AppendChild(Time1);
|
||||
*/
|
||||
|
||||
//Finally Add Secret to Elem
|
||||
keychain.AppendChild(mi_secret);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return doc.ChildNodes[0];
|
||||
|
||||
|
||||
}
|
||||
|
||||
internal bool KeyInNewList(NameValueCollection nvc, string key)
|
||||
{
|
||||
if (nvc != null)
|
||||
{
|
||||
for (int i = 0; i < nvc.Count; i++)
|
||||
{
|
||||
string sKey = nvc.GetKey(i);
|
||||
if( key == sKey )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int SetSecret(XmlNode secret)
|
||||
{
|
||||
|
||||
XmlAttributeCollection atcol = secret.Attributes;
|
||||
String secretid = atcol["ID"].InnerXml;
|
||||
Secret secretVal = store.getSecret(secretid);
|
||||
|
||||
NameValueCollection nvc = secretVal.getKeyValueCollection();
|
||||
ArrayList existingKeyList;
|
||||
|
||||
if (nvc.Count == 0)
|
||||
{
|
||||
existingKeyList = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingKeyList = new ArrayList();
|
||||
}
|
||||
|
||||
for(int i = 0; i < nvc.Count; i++ )
|
||||
{
|
||||
existingKeyList.Add(nvc.GetKey(i));
|
||||
}
|
||||
|
||||
XmlNodeList keylist = secret.SelectNodes("descendant::Key");
|
||||
|
||||
NameValueCollection newNVC = new System.Collections.Specialized.NameValueCollection();
|
||||
|
||||
foreach (XmlNode tuple in keylist)
|
||||
{
|
||||
//Get the Key
|
||||
XmlAttributeCollection at = tuple.Attributes;
|
||||
String keyname = (at["ID"]).InnerText;
|
||||
newNVC.Add(keyname, tuple.ChildNodes[0].InnerText);
|
||||
}
|
||||
|
||||
if(null != existingKeyList)
|
||||
{
|
||||
IEnumerator etor = existingKeyList.GetEnumerator();
|
||||
while( etor.MoveNext() )
|
||||
{
|
||||
string key = (string)etor.Current;
|
||||
if(KeyInNewList(newNVC,key) == false)
|
||||
{
|
||||
secretVal.removeKey(key,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 0 ; i < newNVC.Count ; i++)
|
||||
{
|
||||
string key = newNVC.GetKey(i);
|
||||
secretVal.setKeyValuePair(key,newNVC.Get(key));
|
||||
}
|
||||
|
||||
// TBD: Return Value ??
|
||||
store.setSecret(0, secretVal, Secret.SS_CREDSET);
|
||||
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int GetSecret(XmlNode secret)
|
||||
{
|
||||
XmlDocument doc;
|
||||
XmlElement key1;
|
||||
XmlAttribute Atr;
|
||||
XmlElement value1;
|
||||
XmlElement mi_secret;
|
||||
XmlAttribute synchAttr;
|
||||
XmlAttribute secidAttr;
|
||||
String sKey, sValue;
|
||||
|
||||
|
||||
|
||||
XmlAttributeCollection atcol = secret.Attributes;
|
||||
String secretid = atcol["ID"].InnerXml;
|
||||
|
||||
Secret secretVal = store.getSecret(secretid);
|
||||
NameValueCollection nvc = secretVal.getKeyValueCollection();
|
||||
|
||||
if (nvc.Count == 0)
|
||||
{
|
||||
//Console.WriteLine("Secret got deleted, ID is " + secretid) ;
|
||||
return ConstStrings.CASA_DATA_UNAVAILABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Console.WriteLine("Got the secret from miCASA.");
|
||||
doc = secret.OwnerDocument;
|
||||
XmlNode root = secret.ParentNode;
|
||||
XmlNode keychain = secret.ParentNode;
|
||||
|
||||
// Delete the Secret Node.
|
||||
root.RemoveChild(secret);
|
||||
|
||||
mi_secret = doc.CreateElement(ConstStrings.CCF_SECRET);
|
||||
synchAttr = doc.CreateAttribute("Synch");
|
||||
synchAttr.Value = "Persistent Secret";
|
||||
secidAttr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
secidAttr.Value = secretid;
|
||||
mi_secret.SetAttributeNode(secidAttr);
|
||||
mi_secret.SetAttributeNode(synchAttr);
|
||||
|
||||
for (int i = 0; i < nvc.Count; i++)
|
||||
{
|
||||
|
||||
sKey = nvc.GetKey(i);
|
||||
sValue = nvc.Get(sKey);
|
||||
|
||||
//Key
|
||||
key1 = doc.CreateElement(ConstStrings.CCF_KEY);
|
||||
Atr = doc.CreateAttribute(ConstStrings.CCF_ID);
|
||||
Atr.Value = sKey;
|
||||
key1.SetAttributeNode(Atr);
|
||||
|
||||
//Value
|
||||
value1 = doc.CreateElement(ConstStrings.CCF_VALUE);
|
||||
value1.InnerText = sValue;
|
||||
|
||||
key1.AppendChild(value1);
|
||||
|
||||
mi_secret.AppendChild(key1);
|
||||
|
||||
//Console.WriteLine(sKey + " = " + sValue);
|
||||
}
|
||||
|
||||
|
||||
//Time
|
||||
XmlElement Time1 = doc.CreateElement(ConstStrings.CCF_TIME);
|
||||
|
||||
XmlElement zone1 = doc.CreateElement(ConstStrings.CCF_ZONE);
|
||||
zone1.InnerText = "IST";
|
||||
|
||||
XmlElement cr1 = doc.CreateElement(ConstStrings.CCF_CRTIME);
|
||||
cr1.InnerText = null;
|
||||
|
||||
XmlElement mod1 = doc.CreateElement(ConstStrings.CCF_MDTIME);
|
||||
mod1.InnerText = null;
|
||||
|
||||
XmlElement acc1 = doc.CreateElement(ConstStrings.CCF_ACTIME);
|
||||
acc1.InnerText = null;
|
||||
|
||||
Time1.AppendChild(zone1);
|
||||
Time1.AppendChild(cr1);
|
||||
Time1.AppendChild(mod1);
|
||||
Time1.AppendChild(acc1);
|
||||
|
||||
mi_secret.AppendChild(Time1);
|
||||
|
||||
//Finally Add Secret to Elem
|
||||
keychain.AppendChild(mi_secret);
|
||||
|
||||
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int Remove(XmlNode secret)
|
||||
{
|
||||
|
||||
XmlAttributeCollection atcol = secret.Attributes;
|
||||
String secretid = atcol["ID"].InnerXml;
|
||||
|
||||
//TBD: Why no other overloaded API
|
||||
store.removeSecret(secretid.Substring(secretid.IndexOf(":")+1), Secret.SS_CREDSET);
|
||||
|
||||
|
||||
XmlNode root = secret.ParentNode;
|
||||
root.RemoveChild(secret);
|
||||
|
||||
return ConstStrings.CASA_SUCCESS;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
9
c_adlib/objs.lux
Normal file
9
c_adlib/objs.lux
Normal file
@@ -0,0 +1,9 @@
|
||||
OBJS=\
|
||||
Common\
|
||||
IDataEngine\
|
||||
miCASAEngine\
|
||||
AD_Facade\
|
||||
KWalletEngine\
|
||||
GKEngine \
|
||||
../c_gui/Logger
|
||||
|
||||
7
c_adlib/objs.w32
Normal file
7
c_adlib/objs.w32
Normal file
@@ -0,0 +1,7 @@
|
||||
OBJS=\
|
||||
Common\
|
||||
IDataEngine\
|
||||
miCASAEngine\
|
||||
AD_Facade\
|
||||
..\\c_gui\\Logger.cs
|
||||
|
||||
8
c_adlib/src.lux
Normal file
8
c_adlib/src.lux
Normal file
@@ -0,0 +1,8 @@
|
||||
SRC=\
|
||||
Common.cs\
|
||||
IDataEngine.cs\
|
||||
miCASAEngine.cs\
|
||||
AD_Facade.cs\
|
||||
KWalletEngine.cs\
|
||||
GKEngine.cs \
|
||||
../c_gui/Logger.cs
|
||||
6
c_adlib/src.w32
Normal file
6
c_adlib/src.w32
Normal file
@@ -0,0 +1,6 @@
|
||||
SRC=\
|
||||
Common.cs\
|
||||
IDataEngine.cs\
|
||||
miCASAEngine.cs\
|
||||
AD_Facade.cs\
|
||||
..\\c_gui\\Logger.cs
|
||||
Reference in New Issue
Block a user